feat(ecr): update and validate pull-through cache rules (#4342)

This commit is contained in:
XuJian authored and GitHub committed 2026-09-24 15:38:19 -04:00
1 parent 077b65df5c
commit b658c5f020
6 files changed
+210 -3

No files matched your search

@@ -46,6 +46,8 @@ public class EcrJsonHandler {
case "CreateRepository" -> handleCreateRepository(request, region);
case "CreatePullThroughCacheRule" -> handleCreatePullThroughCacheRule(request, region);
case "DescribePullThroughCacheRules" -> handleDescribePullThroughCacheRules(request, region);
case "UpdatePullThroughCacheRule" -> handleUpdatePullThroughCacheRule(request, region);
case "ValidatePullThroughCacheRule" -> handleValidatePullThroughCacheRule(request, region);
case "DeletePullThroughCacheRule" -> handleDeletePullThroughCacheRule(request, region);
case "DescribeRepositories" -> handleDescribeRepositories(request, region);
case "BatchGetRepositoryScanningConfiguration" ->
@@ -136,6 +138,51 @@ public class EcrJsonHandler {
return Response.ok(buildPullThroughCacheRule(rule, false, false)).build();
}
private Response handleUpdatePullThroughCacheRule(JsonNode request, String region) {
PullThroughCacheRule rule = service.updatePullThroughCacheRule(
request.path("ecrRepositoryPrefix").asText(null),
request.path("registryId").asText(null),
request.path("credentialArn").asText(null),
request.path("customRoleArn").asText(null),
region);
ObjectNode response = objectMapper.createObjectNode();
response.put("ecrRepositoryPrefix", rule.getEcrRepositoryPrefix());
response.put("registryId", rule.getRegistryId());
response.put("updatedAt", rule.getUpdatedAt().getEpochSecond());
if (rule.getCredentialArn() != null) {
response.put("credentialArn", rule.getCredentialArn());
}
if (rule.getCustomRoleArn() != null) {
response.put("customRoleArn", rule.getCustomRoleArn());
}
if (rule.getUpstreamRepositoryPrefix() != null) {
response.put("upstreamRepositoryPrefix", rule.getUpstreamRepositoryPrefix());
}
return Response.ok(response).build();
}
private Response handleValidatePullThroughCacheRule(JsonNode request, String region) {
PullThroughCacheRule rule = service.validatePullThroughCacheRule(
request.path("ecrRepositoryPrefix").asText(null),
request.path("registryId").asText(null),
region);
ObjectNode response = objectMapper.createObjectNode();
response.put("ecrRepositoryPrefix", rule.getEcrRepositoryPrefix());
response.put("registryId", rule.getRegistryId());
response.put("upstreamRegistryUrl", rule.getUpstreamRegistryUrl());
if (rule.getCredentialArn() != null) {
response.put("credentialArn", rule.getCredentialArn());
}
if (rule.getCustomRoleArn() != null) {
response.put("customRoleArn", rule.getCustomRoleArn());
}
if (rule.getUpstreamRepositoryPrefix() != null) {
response.put("upstreamRepositoryPrefix", rule.getUpstreamRepositoryPrefix());
}
response.put("isValid", true);
return Response.ok(response).build();
}
private Response handleDescribeRepositories(JsonNode request, String region) {
List<String> names = parseStringList(request.path("repositoryNames"));
String registryId = request.path("registryId").asText(null);
@@ -185,6 +185,43 @@ public class EcrService implements ResourceProvider {
return rule;
}
public PullThroughCacheRule updatePullThroughCacheRule(String ecrRepositoryPrefix,
String registryId,
String credentialArn,
String customRoleArn,
String region) {
String prefix = normalizePullThroughCachePrefix(ecrRepositoryPrefix);
validatePullThroughCachePrefix(prefix, "ecrRepositoryPrefix");
String account = effectiveAccount(registryId);
validateRegistryId(account);
validateCredentialArn(credentialArn);
validateCustomRoleArn(customRoleArn);
String key = pullThroughCacheRuleKey(region, account, prefix);
PullThroughCacheRule rule = pullThroughCacheRuleStore.get(key)
.orElseThrow(() -> pullThroughCacheRuleNotFound(prefix, account));
if (credentialArn != null) {
rule.setCredentialArn(credentialArn);
}
if (customRoleArn != null) {
rule.setCustomRoleArn(customRoleArn);
}
rule.setUpdatedAt(Instant.now());
pullThroughCacheRuleStore.put(key, rule);
return rule;
}
public PullThroughCacheRule validatePullThroughCacheRule(String ecrRepositoryPrefix,
String registryId,
String region) {
String prefix = normalizePullThroughCachePrefix(ecrRepositoryPrefix);
validatePullThroughCachePrefix(prefix, "ecrRepositoryPrefix");
String account = effectiveAccount(registryId);
validateRegistryId(account);
return pullThroughCacheRuleStore.get(pullThroughCacheRuleKey(region, account, prefix))
.orElseThrow(() -> pullThroughCacheRuleNotFound(prefix, account));
}
/**
* Recreates {@link Repository} metadata entries for registry namespaces found in the catalog.
* Namespaces created by Floci are {@code <account>/<region>/<repoName>}; pre-proxy registry