fix(cognito): include domains in user pool responses (#5448)

* fix(cognito): include domains in user pool responses

* test(cognito): cover UpdateUserPool domain fields

* fix(cognito): scope user pool domain lookups by account

* fix(cognito): avoid stale domain responses after reset

* fix(cognito): drop redundant domain delete lock
This commit is contained in:
Som Samantray authored and GitHub committed 2026-10-12 12:09:33 -04:00
1 parent e8a300f4d5
commit 34c11b8981
5 files changed
+226 -1

No files matched your search

@@ -7,6 +7,7 @@ import com.fasterxml.jackson.databind.node.ArrayNode;
import com.fasterxml.jackson.databind.node.ObjectNode;
import io.github.hectorvent.floci.core.common.AwsErrorResponse;
import io.github.hectorvent.floci.core.common.AwsException;
import io.github.hectorvent.floci.services.cognito.CognitoService.UserPoolDomainNames;
import io.github.hectorvent.floci.services.cognito.model.CognitoGroup;
import io.github.hectorvent.floci.services.cognito.model.CognitoUser;
import io.github.hectorvent.floci.services.cognito.model.IdentityProvider;
@@ -1132,6 +1133,14 @@ public class CognitoJsonHandler {
node.put("CreationDate", (double) p.getCreationDate());
node.put("LastModifiedDate", (double) p.getLastModifiedDate());
UserPoolDomainNames domains = service.findDomainNamesForPool(p.getId());
if (domains.domain() != null) {
node.put("Domain", domains.domain());
}
if (domains.customDomain() != null) {
node.put("CustomDomain", domains.customDomain());
}
node.set("Policies", objectMapper.valueToTree(p.getPolicies() != null ? p.getPolicies() : new HashMap<>()));
node.put("DeletionProtection", p.getDeletionProtection() != null ? p.getDeletionProtection() : "INACTIVE");
node.set("LambdaConfig", objectMapper.valueToTree(p.getLambdaConfig() != null ? p.getLambdaConfig() : new HashMap<>()));
@@ -1729,6 +1729,32 @@ public class CognitoService implements ResourceProvider {
.findFirst();
}
public UserPoolDomainNames findDomainNamesForPool(String poolId) {
String domain = null;
String customDomain = null;
List<UserPoolDomain> domains;
if (domainStore instanceof AccountAwareStorageBackend<UserPoolDomain> aware) {
domains = new ArrayList<>(aware.scanForAccount(regionResolver.getAccountId(), key -> true));
domains.addAll(aware.scanUnscopedLegacy(
userPoolDomain -> regionResolver.getAccountId().equals(userPoolDomain.getAwsAccountId())));
} else {
domains = domainStore.scan(key -> true);
}
for (UserPoolDomain userPoolDomain : domains) {
if (!poolId.equals(userPoolDomain.getUserPoolId())) {
continue;
}
if (userPoolDomain.isCustomDomain() && customDomain == null) {
customDomain = userPoolDomain.getDomain();
} else if (!userPoolDomain.isCustomDomain() && domain == null) {
domain = userPoolDomain.getDomain();
}
}
return new UserPoolDomainNames(domain, customDomain);
}
public record UserPoolDomainNames(String domain, String customDomain) { }
private List<UserPoolDomain> allDomains() {
return domainStore instanceof AccountAwareStorageBackend<UserPoolDomain> aware
? aware.scanAllAccounts()