mirror of
https://github.com/floci-io/floci.git
synced 2026-11-27 07:39:24 -05:00
fix(apigateway): return integration defaults and patch timeout (#4798)
* fix(apigateway): return integration defaults and patch timeout * fix(apigateway): read defaults for legacy integrations * fix(apigateway): preserve response transfer mode in configuration * fix(apigateway): reject malformed response transfer mode * fix(apigateway): restrict stored stream mode to proxy integrations
This commit is contained in:
1 parent
d8a76d1376
commit
27bfb54c6e
5 files changed
+279
-25
No files matched your search
+15
-15
@@ -461,7 +461,7 @@ public class ApiGatewayController {
|
||||
@SuppressWarnings("unchecked")
|
||||
Map<String, Object> request = objectMapper.readValue(body, Map.class);
|
||||
MethodConfig method = service.putMethod(region, apiId, resourceId, httpMethod, request);
|
||||
return Response.status(201).entity(toMethodNode(method).toString()).type(MediaType.APPLICATION_JSON).build();
|
||||
return Response.status(201).entity(toMethodNode(method, resourceId).toString()).type(MediaType.APPLICATION_JSON).build();
|
||||
} catch (IOException e) {
|
||||
throw new AwsException("BadRequestException", e.getMessage(), 400);
|
||||
}
|
||||
@@ -474,7 +474,7 @@ public class ApiGatewayController {
|
||||
@PathParam("resourceId") String resourceId,
|
||||
@PathParam("httpMethod") String httpMethod) {
|
||||
String region = regionResolver.resolveRegion(headers);
|
||||
return Response.ok(toMethodNode(service.getMethod(region, apiId, resourceId, httpMethod)).toString()).type(MediaType.APPLICATION_JSON).build();
|
||||
return Response.ok(toMethodNode(service.getMethod(region, apiId, resourceId, httpMethod), resourceId).toString()).type(MediaType.APPLICATION_JSON).build();
|
||||
}
|
||||
|
||||
@PATCH
|
||||
@@ -487,7 +487,7 @@ public class ApiGatewayController {
|
||||
String region = regionResolver.resolveRegion(headers);
|
||||
List<Map<String, String>> patchOperations = parsePatchOperations(body);
|
||||
MethodConfig method = service.updateMethod(region, apiId, resourceId, httpMethod, patchOperations);
|
||||
return Response.ok(toMethodNode(method).toString()).type(MediaType.APPLICATION_JSON).build();
|
||||
return Response.ok(toMethodNode(method, resourceId).toString()).type(MediaType.APPLICATION_JSON).build();
|
||||
}
|
||||
|
||||
@DELETE
|
||||
@@ -515,7 +515,7 @@ public class ApiGatewayController {
|
||||
@SuppressWarnings("unchecked")
|
||||
Map<String, Object> request = objectMapper.readValue(body, Map.class);
|
||||
io.github.hectorvent.floci.services.apigateway.model.Integration integration = service.putIntegration(region, apiId, resourceId, httpMethod, request);
|
||||
return Response.status(201).entity(toIntegrationNode(integration).toString()).type(MediaType.APPLICATION_JSON).build();
|
||||
return Response.status(201).entity(toIntegrationNode(integration, resourceId).toString()).type(MediaType.APPLICATION_JSON).build();
|
||||
} catch (IOException e) {
|
||||
throw new AwsException("BadRequestException", e.getMessage(), 400);
|
||||
}
|
||||
@@ -528,7 +528,7 @@ public class ApiGatewayController {
|
||||
@PathParam("resourceId") String resourceId,
|
||||
@PathParam("httpMethod") String httpMethod) {
|
||||
String region = regionResolver.resolveRegion(headers);
|
||||
return Response.ok(toIntegrationNode(service.getIntegration(region, apiId, resourceId, httpMethod)).toString()).type(MediaType.APPLICATION_JSON).build();
|
||||
return Response.ok(toIntegrationNode(service.getIntegration(region, apiId, resourceId, httpMethod), resourceId).toString()).type(MediaType.APPLICATION_JSON).build();
|
||||
}
|
||||
|
||||
@PATCH
|
||||
@@ -541,7 +541,7 @@ public class ApiGatewayController {
|
||||
String region = regionResolver.resolveRegion(headers);
|
||||
List<Map<String, String>> patchOperations = parsePatchOperations(body);
|
||||
io.github.hectorvent.floci.services.apigateway.model.Integration integration = service.updateIntegration(region, apiId, resourceId, httpMethod, patchOperations);
|
||||
return Response.ok(toIntegrationNode(integration).toString()).type(MediaType.APPLICATION_JSON).build();
|
||||
return Response.ok(toIntegrationNode(integration, resourceId).toString()).type(MediaType.APPLICATION_JSON).build();
|
||||
}
|
||||
|
||||
@DELETE
|
||||
@@ -2178,7 +2178,7 @@ public class ApiGatewayController {
|
||||
return node;
|
||||
}
|
||||
|
||||
private ObjectNode toMethodNode(MethodConfig m) {
|
||||
private ObjectNode toMethodNode(MethodConfig m, String resourceId) {
|
||||
ObjectNode node = objectMapper.createObjectNode();
|
||||
node.put("httpMethod", m.getHttpMethod());
|
||||
node.put("authorizationType", m.getAuthorizationType());
|
||||
@@ -2198,7 +2198,7 @@ public class ApiGatewayController {
|
||||
node.set("requestModels", models);
|
||||
}
|
||||
if (m.getMethodIntegration() != null) {
|
||||
node.set("methodIntegration", toIntegrationNode(m.getMethodIntegration()));
|
||||
node.set("methodIntegration", toIntegrationNode(m.getMethodIntegration(), resourceId));
|
||||
}
|
||||
return node;
|
||||
}
|
||||
@@ -2209,22 +2209,22 @@ public class ApiGatewayController {
|
||||
return node;
|
||||
}
|
||||
|
||||
private ObjectNode toIntegrationNode(io.github.hectorvent.floci.services.apigateway.model.Integration i) {
|
||||
private ObjectNode toIntegrationNode(io.github.hectorvent.floci.services.apigateway.model.Integration i,
|
||||
String resourceId) {
|
||||
ObjectNode node = objectMapper.createObjectNode();
|
||||
node.put("type", i.getType());
|
||||
node.put("httpMethod", i.getHttpMethod());
|
||||
node.put("uri", i.getUri());
|
||||
node.put("passthroughBehavior", i.getPassthroughBehavior());
|
||||
if (i.getContentHandling() != null) node.put("contentHandling", i.getContentHandling());
|
||||
if (i.getTimeoutInMillis() != null) node.put("timeoutInMillis", i.getTimeoutInMillis());
|
||||
node.put("timeoutInMillis", i.getTimeoutInMillis() != null ? i.getTimeoutInMillis() : 29000);
|
||||
if (i.getConnectionType() != null) node.put("connectionType", i.getConnectionType());
|
||||
if (i.getConnectionId() != null) node.put("connectionId", i.getConnectionId());
|
||||
if (i.getCredentials() != null) node.put("credentials", i.getCredentials());
|
||||
if (i.getCacheNamespace() != null) node.put("cacheNamespace", i.getCacheNamespace());
|
||||
if (!i.getCacheKeyParameters().isEmpty()) {
|
||||
ArrayNode keys = node.putArray("cacheKeyParameters");
|
||||
i.getCacheKeyParameters().forEach(keys::add);
|
||||
}
|
||||
node.put("cacheNamespace", i.getCacheNamespace() != null ? i.getCacheNamespace() : resourceId);
|
||||
ArrayNode keys = node.putArray("cacheKeyParameters");
|
||||
i.getCacheKeyParameters().forEach(keys::add);
|
||||
node.put("responseTransferMode", i.getResponseTransferMode());
|
||||
if (i.getTlsConfig() != null) {
|
||||
node.putObject("tlsConfig")
|
||||
.put("insecureSkipVerification", i.getTlsConfig().isInsecureSkipVerification());
|
||||
|
||||
+54
-9
@@ -590,20 +590,17 @@ public class ApiGatewayService implements ResourceProvider {
|
||||
|
||||
integration.setContentHandling((String) request.get("contentHandling"));
|
||||
integration.setCredentials((String) request.get("credentials"));
|
||||
integration.setCacheNamespace((String) request.get("cacheNamespace"));
|
||||
integration.setCacheNamespace(request.get("cacheNamespace") != null
|
||||
? (String) request.get("cacheNamespace") : resourceId);
|
||||
integration.setResponseTransferMode(transferMode(request.get("responseTransferMode")));
|
||||
validateTransferMode(integration.getResponseTransferMode(), integration.getType());
|
||||
if (request.get("connectionType") != null) {
|
||||
integration.setConnectionType((String) request.get("connectionType"));
|
||||
}
|
||||
integration.setConnectionId((String) request.get("connectionId"));
|
||||
|
||||
if (request.get("timeoutInMillis") instanceof Number timeout) {
|
||||
// AWS accepts 50ms upward; the 29s ceiling applies only to edge-optimized APIs, and
|
||||
// Regional/private APIs (Floci's default) may exceed it, so only the floor is enforced.
|
||||
if (timeout.intValue() < 50) {
|
||||
throw new AwsException("BadRequestException",
|
||||
"Invalid timeout value: " + timeout.intValue(), 400);
|
||||
}
|
||||
integration.setTimeoutInMillis(timeout.intValue());
|
||||
integration.setTimeoutInMillis(parseIntegrationTimeout(timeout));
|
||||
}
|
||||
|
||||
if (request.get("cacheKeyParameters") instanceof List<?> cacheKeys) {
|
||||
@@ -2680,6 +2677,8 @@ public class ApiGatewayService implements ResourceProvider {
|
||||
public Integration updateIntegration(String region, String apiId, String resourceId, String httpMethod, List<Map<String, String>> patchOperations) {
|
||||
Integration integration = getIntegration(region, apiId, resourceId, httpMethod);
|
||||
if (patchOperations != null) {
|
||||
String nextType = integration.getType();
|
||||
String nextTransferMode = integration.getResponseTransferMode();
|
||||
for (Map<String, String> op : patchOperations) {
|
||||
String opType = op.get("op");
|
||||
if (!"add".equals(opType) && !"replace".equals(opType)) {
|
||||
@@ -2692,14 +2691,23 @@ public class ApiGatewayService implements ResourceProvider {
|
||||
}
|
||||
switch (path) {
|
||||
case "/type":
|
||||
nextType = value;
|
||||
break;
|
||||
case "/httpMethod":
|
||||
case "/uri":
|
||||
case "/passthroughBehavior":
|
||||
break;
|
||||
case "/timeoutInMillis":
|
||||
parseIntegrationTimeout(value);
|
||||
break;
|
||||
case "/responseTransferMode":
|
||||
nextTransferMode = transferMode(value);
|
||||
break;
|
||||
default:
|
||||
throw new AwsException("BadRequestException", "Unsupported path: " + path, 400);
|
||||
}
|
||||
}
|
||||
validateTransferMode(nextTransferMode, nextType);
|
||||
for (Map<String, String> op : patchOperations) {
|
||||
String path = op.get("path");
|
||||
String value = op.get("value");
|
||||
@@ -2716,6 +2724,12 @@ public class ApiGatewayService implements ResourceProvider {
|
||||
case "/passthroughBehavior":
|
||||
integration.setPassthroughBehavior(value);
|
||||
break;
|
||||
case "/timeoutInMillis":
|
||||
integration.setTimeoutInMillis(parseIntegrationTimeout(value));
|
||||
break;
|
||||
case "/responseTransferMode":
|
||||
integration.setResponseTransferMode(transferMode(value));
|
||||
break;
|
||||
default:
|
||||
throw new IllegalStateException("Unreachable: validated above");
|
||||
}
|
||||
@@ -2725,6 +2739,36 @@ public class ApiGatewayService implements ResourceProvider {
|
||||
return integration;
|
||||
}
|
||||
|
||||
private int parseIntegrationTimeout(Object value) {
|
||||
try {
|
||||
int timeout = Integer.parseInt(String.valueOf(value));
|
||||
if (timeout >= 50) {
|
||||
return timeout;
|
||||
}
|
||||
} catch (NumberFormatException ignored) {
|
||||
// Return the same AWS-style error for non-numeric and out-of-range values.
|
||||
}
|
||||
throw new AwsException("BadRequestException", "Invalid timeout value: " + value, 400);
|
||||
}
|
||||
|
||||
private String transferMode(Object value) {
|
||||
if (value == null) {
|
||||
return "BUFFERED";
|
||||
}
|
||||
if ("BUFFERED".equals(value) || "STREAM".equals(value)) {
|
||||
return (String) value;
|
||||
}
|
||||
throw new AwsException("BadRequestException", "Invalid response transfer mode: " + value, 400);
|
||||
}
|
||||
|
||||
private void validateTransferMode(String mode, String type) {
|
||||
if ("STREAM".equals(mode) && !"HTTP_PROXY".equalsIgnoreCase(type)
|
||||
&& !"AWS_PROXY".equalsIgnoreCase(type)) {
|
||||
throw new AwsException("BadRequestException",
|
||||
"Response transfer mode STREAM requires HTTP_PROXY or AWS_PROXY integration type", 400);
|
||||
}
|
||||
}
|
||||
|
||||
// ──────────────────────────── Tags ────────────────────────────
|
||||
|
||||
public Map<String, String> getTags(String region, String apiId) {
|
||||
@@ -3632,7 +3676,8 @@ public class ApiGatewayService implements ResourceProvider {
|
||||
integrationRequest.put("uri", integrationExt.get("uri"));
|
||||
integrationRequest.put("passthroughBehavior", integrationExt.get("passthroughBehavior"));
|
||||
for (String field : List.of("contentHandling", "timeoutInMillis", "connectionType",
|
||||
"connectionId", "credentials", "cacheNamespace", "cacheKeyParameters", "tlsConfig")) {
|
||||
"connectionId", "credentials", "cacheNamespace", "cacheKeyParameters", "tlsConfig",
|
||||
"responseTransferMode")) {
|
||||
if (integrationExt.get(field) != null) {
|
||||
integrationRequest.put(field, integrationExt.get(field));
|
||||
}
|
||||
|
||||
+10
-1
@@ -18,12 +18,13 @@ public class Integration {
|
||||
private String httpMethod;
|
||||
private String passthroughBehavior = "WHEN_NO_MATCH"; // WHEN_NO_MATCH, WHEN_NO_TEMPLATES, NEVER
|
||||
private String contentHandling; // CONVERT_TO_BINARY, CONVERT_TO_TEXT, or null to pass through
|
||||
private Integer timeoutInMillis; // 50–29000; AWS caps REST integrations at 29s
|
||||
private Integer timeoutInMillis = 29000; // AWS default; regional/private APIs may use more
|
||||
private String connectionType = "INTERNET"; // INTERNET or VPC_LINK
|
||||
private String connectionId; // VpcLink id when connectionType is VPC_LINK
|
||||
private String credentials; // IAM role ARN assumed for AWS integrations
|
||||
private String cacheNamespace;
|
||||
private List<String> cacheKeyParameters = new ArrayList<>();
|
||||
private String responseTransferMode = "BUFFERED";
|
||||
private TlsConfig tlsConfig;
|
||||
private Map<String, String> requestParameters = new HashMap<>(); // integration.request.* → method.request.*
|
||||
private Map<String, String> requestTemplates = new HashMap<>();
|
||||
@@ -106,6 +107,14 @@ public class Integration {
|
||||
this.cacheKeyParameters = cacheKeyParameters != null ? cacheKeyParameters : new ArrayList<>();
|
||||
}
|
||||
|
||||
public String getResponseTransferMode() {
|
||||
return responseTransferMode != null ? responseTransferMode : "BUFFERED";
|
||||
}
|
||||
|
||||
public void setResponseTransferMode(String responseTransferMode) {
|
||||
this.responseTransferMode = responseTransferMode;
|
||||
}
|
||||
|
||||
public TlsConfig getTlsConfig() {
|
||||
return tlsConfig;
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user