mirror of
https://github.com/floci-io/floci.git
synced 2026-12-01 01:12:48 -05:00
fix(cloudformation): clear dropped API Gateway v2 route and authorizer settings (#7992)
This commit is contained in:
1 parent
46207993fb
commit
195a036b63
11 files changed
+935
-25
No files matched your search
@@ -494,6 +494,26 @@ public class ApiGatewayV2Service {
|
||||
return auth;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the URI, payload format version, JWT configuration, result TTL and simple-responses flag
|
||||
* exactly as given, null included. UpdateAuthorizer keeps a field the request leaves out, so it
|
||||
* cannot remove one that CloudFormation dropped.
|
||||
*/
|
||||
public Authorizer replaceAuthorizerSettings(String region, String apiId, String authorizerId,
|
||||
String authorizerUri, String authorizerPayloadFormatVersion,
|
||||
Authorizer.JwtConfiguration jwtConfiguration,
|
||||
Integer authorizerResultTtlInSeconds,
|
||||
Boolean enableSimpleResponses) {
|
||||
Authorizer auth = getAuthorizer(region, apiId, authorizerId);
|
||||
auth.setAuthorizerUri(authorizerUri);
|
||||
auth.setAuthorizerPayloadFormatVersion(authorizerPayloadFormatVersion);
|
||||
auth.setJwtConfiguration(jwtConfiguration);
|
||||
auth.setAuthorizerResultTtlInSeconds(authorizerResultTtlInSeconds);
|
||||
auth.setEnableSimpleResponses(enableSimpleResponses);
|
||||
authorizerStore.put(authorizerKey(region, apiId, authorizerId), auth);
|
||||
return auth;
|
||||
}
|
||||
|
||||
// AuthorizerResultTtlInSeconds is modeled as an integer in [0, 3600]. doubleValue() keeps the
|
||||
// bounds check exact for a Long or BigInteger body value that intValue() would wrap into range.
|
||||
static Integer authorizerResultTtl(Object value) {
|
||||
@@ -609,6 +629,19 @@ public class ApiGatewayV2Service {
|
||||
return route;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the authorizer id and the target exactly as given, null included. UpdateRoute keeps a
|
||||
* field the request leaves out, so it cannot remove one that CloudFormation dropped.
|
||||
*/
|
||||
public Route replaceRouteLinks(String region, String apiId, String routeId, String authorizerId,
|
||||
String target) {
|
||||
Route route = getRoute(region, apiId, routeId);
|
||||
route.setAuthorizerId(authorizerId);
|
||||
route.setTarget(target);
|
||||
routeStore.put(routeKey(region, apiId, routeId), route);
|
||||
return route;
|
||||
}
|
||||
|
||||
private void ensureRouteKeyAvailable(String region, String apiId, String requestedRouteKey,
|
||||
String currentRouteId) {
|
||||
if (requestedRouteKey == null) {
|
||||
|
||||
+28
@@ -855,6 +855,22 @@ public class ApiGatewayV2CfnProvisioner implements CfnResourceProvisioner {
|
||||
authorizer = apiGatewayV2Service.createAuthorizer(region, apiId, req);
|
||||
} else {
|
||||
authorizer = apiGatewayV2Service.updateAuthorizer(region, apiId, r.getPhysicalId(), req);
|
||||
Set<String> dropped = ctx.droppedProperties(props);
|
||||
if (dropped.contains("AuthorizerUri") || dropped.contains("AuthorizerPayloadFormatVersion")
|
||||
|| dropped.contains("JwtConfiguration") || dropped.contains("AuthorizerResultTtlInSeconds")
|
||||
|| dropped.contains("EnableSimpleResponses")) {
|
||||
// UpdateAuthorizer keeps a field it is not given, so a dropped one is cleared here and
|
||||
// the others keep what the update left, a value set outside the stack included.
|
||||
authorizer = apiGatewayV2Service.replaceAuthorizerSettings(region, apiId, r.getPhysicalId(),
|
||||
dropped.contains("AuthorizerUri") ? null : authorizer.getAuthorizerUri(),
|
||||
dropped.contains("AuthorizerPayloadFormatVersion")
|
||||
? null : authorizer.getAuthorizerPayloadFormatVersion(),
|
||||
dropped.contains("JwtConfiguration") ? null : authorizer.getJwtConfiguration(),
|
||||
dropped.contains("AuthorizerResultTtlInSeconds")
|
||||
? null : authorizer.getAuthorizerResultTtlInSeconds(),
|
||||
dropped.contains("EnableSimpleResponses")
|
||||
? null : authorizer.getEnableSimpleResponses());
|
||||
}
|
||||
}
|
||||
r.setPhysicalId(authorizer.getAuthorizerId());
|
||||
r.getAttributes().put("AuthorizerId", authorizer.getAuthorizerId());
|
||||
@@ -881,6 +897,18 @@ public class ApiGatewayV2CfnProvisioner implements CfnResourceProvisioner {
|
||||
route = apiGatewayV2Service.createRoute(region, apiId, req);
|
||||
} else {
|
||||
route = apiGatewayV2Service.updateRoute(region, apiId, r.getPhysicalId(), req);
|
||||
Set<String> dropped = ctx.droppedProperties(props);
|
||||
if (dropped.contains("AuthorizerId") || dropped.contains("Target")) {
|
||||
// UpdateRoute keeps a field it is not given, so a dropped one is cleared here and the
|
||||
// other keeps what the update left, a value set outside the stack included.
|
||||
// A route that stays JWT or CUSTOM keeps its authorizer: without it the route would be
|
||||
// served without any authorizer.
|
||||
String type = route.getAuthorizationType();
|
||||
boolean protectedRoute = "JWT".equalsIgnoreCase(type) || "CUSTOM".equalsIgnoreCase(type);
|
||||
route = apiGatewayV2Service.replaceRouteLinks(region, apiId, r.getPhysicalId(),
|
||||
dropped.contains("AuthorizerId") && !protectedRoute ? null : route.getAuthorizerId(),
|
||||
dropped.contains("Target") ? null : route.getTarget());
|
||||
}
|
||||
}
|
||||
r.setPhysicalId(route.getRouteId());
|
||||
r.getAttributes().put("RouteId", route.getRouteId());
|
||||
|
||||
Reference in new issue
Block a user