mirror of
https://github.com/floci-io/floci.git
synced 2026-11-27 07:39:24 -05:00
fix(apigateway): tag REST API VPC links (#6165)
* fix(apigateway): tag REST API VPC links * fix(apigateway): synchronize VPC link tag updates
This commit is contained in:
1 parent
10d3317346
commit
110f58ae34
6 files changed
+249
-1
No files matched your search
@@ -130,6 +130,7 @@ public class ApiGatewayService implements ResourceProvider {
|
||||
* also keeps a mapping from being created under a domain that is being deleted at that moment.
|
||||
*/
|
||||
private final Object domainNameLock = new Object();
|
||||
private final Object vpcLinkTagLock = new Object();
|
||||
private final TlsCertificateManager certificateManager;
|
||||
private final EmulatorConfig config;
|
||||
private final RegionResolver regionResolver;
|
||||
@@ -4657,6 +4658,31 @@ public class ApiGatewayService implements ResourceProvider {
|
||||
.orElseThrow(() -> new AwsException("NotFoundException", "Invalid VPC link identifier specified", 404));
|
||||
}
|
||||
|
||||
/**
|
||||
* Serialize tag writers and replace the map so readers and persistence can safely iterate
|
||||
* previously returned maps, as with custom-domain tags.
|
||||
*/
|
||||
public void tagVpcLink(String region, String vpcLinkId, Map<String, String> tags) {
|
||||
ReservedTags.rejectApiGatewayReservedTagsOnUpdate(tags);
|
||||
synchronized (vpcLinkTagLock) {
|
||||
VpcLink link = getVpcLink(region, vpcLinkId);
|
||||
Map<String, String> merged = new LinkedHashMap<>(link.getTags());
|
||||
merged.putAll(tags);
|
||||
link.setTags(merged);
|
||||
vpcLinkStore.put(vpcLinkKey(region, vpcLinkId), link);
|
||||
}
|
||||
}
|
||||
|
||||
public void untagVpcLink(String region, String vpcLinkId, List<String> tagKeys) {
|
||||
synchronized (vpcLinkTagLock) {
|
||||
VpcLink link = getVpcLink(region, vpcLinkId);
|
||||
Map<String, String> remaining = new LinkedHashMap<>(link.getTags());
|
||||
tagKeys.forEach(remaining::remove);
|
||||
link.setTags(remaining);
|
||||
vpcLinkStore.put(vpcLinkKey(region, vpcLinkId), link);
|
||||
}
|
||||
}
|
||||
|
||||
public List<VpcLink> getVpcLinks(String region) {
|
||||
return vpcLinkStore.scan(k -> k.startsWith(region + "::"));
|
||||
}
|
||||
|
||||
+13
-1
@@ -17,7 +17,8 @@ import java.util.regex.Pattern;
|
||||
* <p>ARN formats: {@code arn:aws:apigateway:<region>::/restapis/<apiId>} for a REST API,
|
||||
* {@code arn:aws:apigateway:<region>::/domainnames/<domainName>} for a custom domain,
|
||||
* {@code arn:aws:apigateway:<region>::/apikeys/<apiKeyId>} for an API key and
|
||||
* {@code arn:aws:apigateway:<region>::/usageplans/<usagePlanId>} for a usage plan. The
|
||||
* {@code arn:aws:apigateway:<region>::/usageplans/<usagePlanId>} for a usage plan and
|
||||
* {@code arn:aws:apigateway:<region>::/vpclinks/<vpcLinkId>} for a REST VPC link. The
|
||||
* {@code apiId}, domain name, key id or plan id is the canonical identifier the underlying
|
||||
* {@link ApiGatewayService} uses for its tag store.
|
||||
*/
|
||||
@@ -28,6 +29,7 @@ public class ApiGatewayTagHandler implements TagHandler {
|
||||
private static final String DOMAIN_NAMES = "/domainnames/";
|
||||
private static final String REST_APIS = "/restapis/";
|
||||
private static final String USAGE_PLANS = "/usageplans/";
|
||||
private static final String VPC_LINKS = "/vpclinks/";
|
||||
private static final Pattern STAGE_RESOURCE = Pattern.compile("/restapis/[^/]+/stages/([^/]+)");
|
||||
|
||||
private final ApiGatewayService service;
|
||||
@@ -62,6 +64,10 @@ public class ApiGatewayTagHandler implements TagHandler {
|
||||
if (usagePlanId != null) {
|
||||
return service.getUsagePlan(region, usagePlanId).getTags();
|
||||
}
|
||||
String vpcLinkId = topLevelIdFromArn(arn, VPC_LINKS);
|
||||
if (vpcLinkId != null) {
|
||||
return service.getVpcLink(region, vpcLinkId).getTags();
|
||||
}
|
||||
String stageName = stageNameFromArn(arn);
|
||||
return stageName != null
|
||||
? service.getStageTags(region, apiIdFromArn(arn), stageName)
|
||||
@@ -74,6 +80,7 @@ public class ApiGatewayTagHandler implements TagHandler {
|
||||
String domainName = topLevelIdFromArn(arn, DOMAIN_NAMES);
|
||||
String apiKeyId = topLevelIdFromArn(arn, API_KEYS);
|
||||
String usagePlanId = topLevelIdFromArn(arn, USAGE_PLANS);
|
||||
String vpcLinkId = topLevelIdFromArn(arn, VPC_LINKS);
|
||||
String stageName = stageNameFromArn(arn);
|
||||
if (domainName != null) {
|
||||
service.tagDomainName(region, domainName, tags);
|
||||
@@ -81,6 +88,8 @@ public class ApiGatewayTagHandler implements TagHandler {
|
||||
service.tagApiKey(region, apiKeyId, tags);
|
||||
} else if (usagePlanId != null) {
|
||||
service.tagUsagePlan(region, usagePlanId, tags);
|
||||
} else if (vpcLinkId != null) {
|
||||
service.tagVpcLink(region, vpcLinkId, tags);
|
||||
} else if (stageName != null) {
|
||||
service.tagStage(region, apiIdFromArn(arn), stageName, tags);
|
||||
} else {
|
||||
@@ -94,6 +103,7 @@ public class ApiGatewayTagHandler implements TagHandler {
|
||||
String domainName = topLevelIdFromArn(arn, DOMAIN_NAMES);
|
||||
String apiKeyId = topLevelIdFromArn(arn, API_KEYS);
|
||||
String usagePlanId = topLevelIdFromArn(arn, USAGE_PLANS);
|
||||
String vpcLinkId = topLevelIdFromArn(arn, VPC_LINKS);
|
||||
String stageName = stageNameFromArn(arn);
|
||||
if (domainName != null) {
|
||||
service.untagDomainName(region, domainName, tagKeys);
|
||||
@@ -101,6 +111,8 @@ public class ApiGatewayTagHandler implements TagHandler {
|
||||
service.untagApiKey(region, apiKeyId, tagKeys);
|
||||
} else if (usagePlanId != null) {
|
||||
service.untagUsagePlan(region, usagePlanId, tagKeys);
|
||||
} else if (vpcLinkId != null) {
|
||||
service.untagVpcLink(region, vpcLinkId, tagKeys);
|
||||
} else if (stageName != null) {
|
||||
service.untagStage(region, apiIdFromArn(arn), stageName, tagKeys);
|
||||
} else {
|
||||
|
||||
Reference in new issue
Block a user