mirror of
https://github.com/floci-io/floci.git
synced 2026-11-27 07:39:24 -05:00
fix(apigateway): retain V2 integration and authorizer credentials (#6795)
Retain credential choices through management, imports, copies and CloudFormation Body parsing. Carry quick-create credentials only for Lambda targets. Reconcile the accepted shared ARN classifier and CloudFormation import rollback on current main. Signed-off-by: Andre Kurait <AndreKurait@gmail.com>
This commit is contained in:
1 parent
0a3efd65fe
commit
02852f0e67
13 files changed
+314
-2
No files matched your search
@@ -2800,6 +2800,9 @@ public class ApiGatewayController {
|
||||
if (i.getConnectionType() != null) node.put("connectionType", i.getConnectionType());
|
||||
if (i.getConnectionId() != null) node.put("connectionId", i.getConnectionId());
|
||||
node.put("payloadFormatVersion", i.getPayloadFormatVersion());
|
||||
if (i.getCredentialsArn() != null) {
|
||||
node.put("credentialsArn", i.getCredentialsArn());
|
||||
}
|
||||
if (i.getIntegrationUri() != null) node.put("integrationUri", i.getIntegrationUri());
|
||||
if (i.getRequestTemplates() != null) {
|
||||
ObjectNode requestTemplates = node.putObject("requestTemplates");
|
||||
@@ -2933,6 +2936,9 @@ public class ApiGatewayController {
|
||||
jwt.put("issuer", a.getJwtConfiguration().issuer());
|
||||
}
|
||||
}
|
||||
if (a.getAuthorizerCredentialsArn() != null) {
|
||||
node.put("authorizerCredentialsArn", a.getAuthorizerCredentialsArn());
|
||||
}
|
||||
if (a.getAuthorizerUri() != null) {
|
||||
node.put("authorizerUri", a.getAuthorizerUri());
|
||||
}
|
||||
|
||||
+6
@@ -589,6 +589,9 @@ public class ApiGatewayV2JsonHandler {
|
||||
auth.getJwtConfiguration().audience().forEach(aud::add);
|
||||
}
|
||||
}
|
||||
if (auth.getAuthorizerCredentialsArn() != null) {
|
||||
node.put("AuthorizerCredentialsArn", auth.getAuthorizerCredentialsArn());
|
||||
}
|
||||
if (auth.getAuthorizerUri() != null) {
|
||||
node.put("AuthorizerUri", auth.getAuthorizerUri());
|
||||
}
|
||||
@@ -628,6 +631,9 @@ public class ApiGatewayV2JsonHandler {
|
||||
if (i.getConnectionType() != null) node.put("ConnectionType", i.getConnectionType());
|
||||
if (i.getConnectionId() != null) node.put("ConnectionId", i.getConnectionId());
|
||||
node.put("PayloadFormatVersion", i.getPayloadFormatVersion());
|
||||
if (i.getCredentialsArn() != null) {
|
||||
node.put("CredentialsArn", i.getCredentialsArn());
|
||||
}
|
||||
if (i.getIntegrationUri() != null) node.put("IntegrationUri", i.getIntegrationUri());
|
||||
if (i.getRequestTemplates() != null) {
|
||||
ObjectNode requestTemplates = node.putObject("RequestTemplates");
|
||||
|
||||
+2
@@ -526,6 +526,7 @@ public class ApiGatewayV2OpenApiImporter {
|
||||
if (!identitySource.isEmpty()) {
|
||||
request.put("identitySource", identitySource);
|
||||
}
|
||||
putIfPresent(request, "authorizerCredentialsArn", stringValue(authDef.get("authorizerCredentials")));
|
||||
putIfPresent(request, "authorizerUri", stringValue(authDef.get("authorizerUri")));
|
||||
putIfPresent(request, "authorizerPayloadFormatVersion",
|
||||
stringValue(authDef.get("authorizerPayloadFormatVersion")));
|
||||
@@ -665,6 +666,7 @@ public class ApiGatewayV2OpenApiImporter {
|
||||
if (type != null) {
|
||||
request.put("integrationType", type.toUpperCase(Locale.ROOT));
|
||||
}
|
||||
putIfPresent(request, "credentialsArn", stringValue(definition.get("credentials")));
|
||||
putIfPresent(request, "integrationUri", stringValue(definition.get("uri")));
|
||||
putIfPresent(request, "integrationMethod", stringValue(definition.get("httpMethod")));
|
||||
putIfPresent(request, "connectionType", upper(stringValue(definition.get("connectionType"))));
|
||||
|
||||
+14
-1
@@ -143,11 +143,15 @@ public class ApiGatewayV2Service {
|
||||
String target = targetValue != null ? String.valueOf(targetValue) : null;
|
||||
if ("HTTP".equals(protocolType) && target != null && !target.isBlank()) {
|
||||
boolean isLambdaTarget = AwsArnUtils.looksLikeArn(target);
|
||||
Integration integration = createIntegration(region, apiId, Map.of(
|
||||
Map<String, Object> integrationRequest = new HashMap<>(Map.of(
|
||||
"integrationType", isLambdaTarget ? "AWS_PROXY" : "HTTP_PROXY",
|
||||
"integrationUri", target,
|
||||
"integrationMethod", isLambdaTarget ? "POST" : "ANY",
|
||||
"payloadFormatVersion", "2.0"));
|
||||
if (isLambdaTarget) {
|
||||
integrationRequest.put("credentialsArn", request.get("credentialsArn"));
|
||||
}
|
||||
Integration integration = createIntegration(region, apiId, integrationRequest);
|
||||
createRoute(region, apiId, Map.of(
|
||||
"routeKey", "$default",
|
||||
"target", "integrations/" + integration.getIntegrationId()));
|
||||
@@ -381,6 +385,7 @@ public class ApiGatewayV2Service {
|
||||
auth.setJwtConfiguration(new Authorizer.JwtConfiguration(audience, issuer));
|
||||
}
|
||||
|
||||
auth.setAuthorizerCredentialsArn((String) request.get("authorizerCredentialsArn"));
|
||||
auth.setAuthorizerUri((String) request.get("authorizerUri"));
|
||||
auth.setAuthorizerPayloadFormatVersion((String) request.get("authorizerPayloadFormatVersion"));
|
||||
auth.setAuthorizerResultTtlInSeconds(authorizerResultTtl(request.get("authorizerResultTtlInSeconds")));
|
||||
@@ -418,6 +423,7 @@ public class ApiGatewayV2Service {
|
||||
restored.setName(authorizer.getName());
|
||||
restored.setJwtConfiguration(authorizer.getJwtConfiguration());
|
||||
restored.setIdentitySource(authorizer.getIdentitySource());
|
||||
restored.setAuthorizerCredentialsArn(authorizer.getAuthorizerCredentialsArn());
|
||||
restored.setAuthorizerUri(authorizer.getAuthorizerUri());
|
||||
restored.setAuthorizerPayloadFormatVersion(authorizer.getAuthorizerPayloadFormatVersion());
|
||||
restored.setAuthorizerResultTtlInSeconds(authorizer.getAuthorizerResultTtlInSeconds());
|
||||
@@ -434,6 +440,9 @@ public class ApiGatewayV2Service {
|
||||
if (request.containsKey("name") && request.get("name") != null) {
|
||||
auth.setName((String) request.get("name"));
|
||||
}
|
||||
if (request.get("authorizerCredentialsArn") != null) {
|
||||
auth.setAuthorizerCredentialsArn((String) request.get("authorizerCredentialsArn"));
|
||||
}
|
||||
if (request.containsKey("authorizerType") && request.get("authorizerType") != null) {
|
||||
auth.setAuthorizerType((String) request.get("authorizerType"));
|
||||
}
|
||||
@@ -691,6 +700,7 @@ public class ApiGatewayV2Service {
|
||||
Integration integration = new Integration();
|
||||
integration.setIntegrationId(shortId(8));
|
||||
integration.setIntegrationType((String) request.get("integrationType"));
|
||||
integration.setCredentialsArn((String) request.get("credentialsArn"));
|
||||
integration.setIntegrationUri((String) request.get("integrationUri"));
|
||||
integration.setConnectionType((String) request.get("connectionType"));
|
||||
integration.setPayloadFormatVersion((String) request.getOrDefault("payloadFormatVersion", "2.0"));
|
||||
@@ -746,6 +756,9 @@ public class ApiGatewayV2Service {
|
||||
Map<String, Object> request) {
|
||||
Integration integration = getIntegration(region, apiId, integrationId);
|
||||
|
||||
if (request.get("credentialsArn") != null) {
|
||||
integration.setCredentialsArn((String) request.get("credentialsArn"));
|
||||
}
|
||||
if (request.containsKey("integrationType") && request.get("integrationType") != null) {
|
||||
integration.setIntegrationType((String) request.get("integrationType"));
|
||||
}
|
||||
|
||||
@@ -18,8 +18,13 @@ public class Authorizer {
|
||||
private Integer authorizerResultTtlInSeconds;
|
||||
private Boolean enableSimpleResponses;
|
||||
|
||||
private String authorizerCredentialsArn;
|
||||
|
||||
public Authorizer() {}
|
||||
|
||||
public String getAuthorizerCredentialsArn() { return authorizerCredentialsArn; }
|
||||
public void setAuthorizerCredentialsArn(String authorizerCredentialsArn) { this.authorizerCredentialsArn = authorizerCredentialsArn; }
|
||||
|
||||
public String getAuthorizerId() { return authorizerId; }
|
||||
public void setAuthorizerId(String authorizerId) { this.authorizerId = authorizerId; }
|
||||
|
||||
|
||||
@@ -21,10 +21,16 @@ public class Integration {
|
||||
private Map<String, String> requestParameters;
|
||||
private String connectionId;
|
||||
|
||||
private String credentialsArn;
|
||||
|
||||
public Integration() {}
|
||||
|
||||
public String getCredentialsArn() { return credentialsArn; }
|
||||
public void setCredentialsArn(String credentialsArn) { this.credentialsArn = credentialsArn; }
|
||||
|
||||
/** Shallow copy. Add new fields here so callers like {@code withResolvedUri} keep them. */
|
||||
public Integration(Integration src) {
|
||||
this.credentialsArn = src.credentialsArn;
|
||||
this.integrationId = src.integrationId;
|
||||
this.integrationType = src.integrationType;
|
||||
this.connectionType = src.connectionType;
|
||||
|
||||
+2
@@ -313,6 +313,7 @@ public class ApiGatewayV2CfnProvisioner implements CfnResourceProvisioner {
|
||||
Map<String, Object> integrationRequest = new HashMap<>();
|
||||
integrationRequest.put("integrationType", integrationType.toUpperCase(Locale.ROOT));
|
||||
putOpenApiIntegrationValue(integrationRequest, "integrationUri", integration, "uri");
|
||||
putOpenApiIntegrationValue(integrationRequest, "credentialsArn", integration, "credentials");
|
||||
putOpenApiIntegrationValue(integrationRequest, "integrationMethod", integration,
|
||||
"httpMethod");
|
||||
putOpenApiIntegrationValue(integrationRequest, "payloadFormatVersion", integration,
|
||||
@@ -378,6 +379,7 @@ public class ApiGatewayV2CfnProvisioner implements CfnResourceProvisioner {
|
||||
request.put("authorizerType", authorizerType);
|
||||
putOpenApiAuthorizerIdentitySource(request, definition);
|
||||
putOpenApiAuthorizerValue(request, "authorizerUri", definition, "authorizerUri");
|
||||
putOpenApiAuthorizerValue(request, "authorizerCredentialsArn", definition, "authorizerCredentials");
|
||||
putOpenApiAuthorizerValue(request, "authorizerPayloadFormatVersion", definition,
|
||||
"authorizerPayloadFormatVersion");
|
||||
putOpenApiAuthorizerValue(request, "authorizerResultTtlInSeconds", definition,
|
||||
|
||||
Reference in new issue
Block a user