mirror of
https://github.com/floci-io/floci.git
synced 2026-11-23 22:11:36 -05:00
feat(apigateway): persist UpdateStage methodSettings patch operations on v1 stages (#1004)
UpdateStage patch paths of the form /<resourcePath>/<httpMethod>/<settingKey> (e.g. /*/*/metrics/enabled, /*/*/throttling/burstLimit, /pets/GET/caching/enabled) were silently accepted but discarded, so GetStage returned no methodSettings field and the Terraform aws_api_gateway_method_settings resource failed with "empty result" when read after apply. Adds a MethodSetting POJO with the AWS-documented fields, stores them on Stage in a Map keyed by "<resourcePath>/<httpMethod>", parses the patch path suffix against the canonical setting keys (metrics, logging, throttling, caching), and serialises the map under "methodSettings" in toStageNode so GetStage round-trips the values the patch wrote. New ApiGatewayStageMethodSettingsIntegrationTest covers the three Terraform scenarios (wildcard throttling + logging, wildcard caching, and per-method overrides); verified failing on main and passing with this change.
This commit is contained in:
1 parent
3a31c792fa
commit
214d404733
5 files changed
+322
No files matched your search
+19
@@ -1577,6 +1577,25 @@ public class ApiGatewayController {
|
||||
ObjectNode vars = node.putObject("variables");
|
||||
s.getVariables().forEach(vars::put);
|
||||
}
|
||||
if (!s.getMethodSettings().isEmpty()) {
|
||||
ObjectNode methodSettings = node.putObject("methodSettings");
|
||||
s.getMethodSettings().forEach((key, setting) -> methodSettings.set(key, toMethodSettingNode(setting)));
|
||||
}
|
||||
return node;
|
||||
}
|
||||
|
||||
private ObjectNode toMethodSettingNode(io.github.hectorvent.floci.services.apigateway.model.MethodSetting setting) {
|
||||
ObjectNode node = objectMapper.createObjectNode();
|
||||
node.put("metricsEnabled", setting.isMetricsEnabled());
|
||||
node.put("loggingLevel", setting.getLoggingLevel());
|
||||
node.put("dataTraceEnabled", setting.isDataTraceEnabled());
|
||||
node.put("throttlingBurstLimit", setting.getThrottlingBurstLimit());
|
||||
node.put("throttlingRateLimit", setting.getThrottlingRateLimit());
|
||||
node.put("cachingEnabled", setting.isCachingEnabled());
|
||||
node.put("cacheTtlInSeconds", setting.getCacheTtlInSeconds());
|
||||
node.put("cacheDataEncrypted", setting.isCacheDataEncrypted());
|
||||
node.put("requireAuthorizationForCacheControl", setting.isRequireAuthorizationForCacheControl());
|
||||
node.put("unauthorizedCacheControlHeaderStrategy", setting.getUnauthorizedCacheControlHeaderStrategy());
|
||||
return node;
|
||||
}
|
||||
|
||||
|
||||
@@ -18,6 +18,7 @@ import io.github.hectorvent.floci.services.apigateway.model.ApiGatewayResource;
|
||||
import io.github.hectorvent.floci.services.apigateway.model.ApiKey;
|
||||
import io.github.hectorvent.floci.services.apigateway.model.Authorizer;
|
||||
import io.github.hectorvent.floci.services.apigateway.model.BasePathMapping;
|
||||
import io.github.hectorvent.floci.services.apigateway.model.MethodSetting;
|
||||
import io.github.hectorvent.floci.services.apigateway.model.CustomDomain;
|
||||
import io.github.hectorvent.floci.services.apigateway.model.Deployment;
|
||||
import io.github.hectorvent.floci.services.apigateway.model.Integration;
|
||||
@@ -469,6 +470,8 @@ public class ApiGatewayService {
|
||||
String varKey = path.substring("/variables/" .length());
|
||||
LOG.infov("Setting stage variable {0} = {1}", varKey, value);
|
||||
stage.getVariables().put(varKey, value);
|
||||
} else {
|
||||
applyMethodSettingPatch(stage, path, value);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -477,6 +480,64 @@ public class ApiGatewayService {
|
||||
return stage;
|
||||
}
|
||||
|
||||
private static final List<String> METHOD_SETTING_KEYS = List.of(
|
||||
"metrics/enabled",
|
||||
"logging/loglevel",
|
||||
"logging/dataTrace",
|
||||
"throttling/burstLimit",
|
||||
"throttling/rateLimit",
|
||||
"caching/enabled",
|
||||
"caching/ttlInSeconds",
|
||||
"caching/dataEncrypted",
|
||||
"caching/requireAuthorizationForCacheControl",
|
||||
"caching/unauthorizedCacheControlHeaderStrategy"
|
||||
);
|
||||
|
||||
/**
|
||||
* Applies a method-settings patch operation in the form
|
||||
* <code>/{resourcePath}/{httpMethod}/{settingKey}</code>, e.g.
|
||||
* <code>/*/*/metrics/enabled</code> or
|
||||
* <code>/pets/GET/throttling/burstLimit</code>. Unknown setting keys are
|
||||
* silently ignored to match real API Gateway's lenient PATCH semantics.
|
||||
*/
|
||||
private void applyMethodSettingPatch(Stage stage, String path, String value) {
|
||||
for (String settingKey : METHOD_SETTING_KEYS) {
|
||||
String suffix = "/" + settingKey;
|
||||
if (!path.endsWith(suffix)) continue;
|
||||
|
||||
String prefix = path.substring(1, path.length() - suffix.length());
|
||||
int lastSlash = prefix.lastIndexOf('/');
|
||||
if (lastSlash < 0) return;
|
||||
String resourcePath = prefix.substring(0, lastSlash);
|
||||
String httpMethod = prefix.substring(lastSlash + 1);
|
||||
String methodKey = resourcePath + "/" + httpMethod;
|
||||
|
||||
MethodSetting setting = stage.getMethodSettings()
|
||||
.computeIfAbsent(methodKey, k -> new MethodSetting());
|
||||
applyMethodSettingValue(setting, settingKey, value);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
private void applyMethodSettingValue(MethodSetting setting, String settingKey, String value) {
|
||||
if (value == null) return;
|
||||
switch (settingKey) {
|
||||
case "metrics/enabled" -> setting.setMetricsEnabled(Boolean.parseBoolean(value));
|
||||
case "logging/loglevel" -> setting.setLoggingLevel(value);
|
||||
case "logging/dataTrace" -> setting.setDataTraceEnabled(Boolean.parseBoolean(value));
|
||||
case "throttling/burstLimit" -> setting.setThrottlingBurstLimit(Integer.parseInt(value));
|
||||
case "throttling/rateLimit" -> setting.setThrottlingRateLimit(Double.parseDouble(value));
|
||||
case "caching/enabled" -> setting.setCachingEnabled(Boolean.parseBoolean(value));
|
||||
case "caching/ttlInSeconds" -> setting.setCacheTtlInSeconds(Integer.parseInt(value));
|
||||
case "caching/dataEncrypted" -> setting.setCacheDataEncrypted(Boolean.parseBoolean(value));
|
||||
case "caching/requireAuthorizationForCacheControl" ->
|
||||
setting.setRequireAuthorizationForCacheControl(Boolean.parseBoolean(value));
|
||||
case "caching/unauthorizedCacheControlHeaderStrategy" ->
|
||||
setting.setUnauthorizedCacheControlHeaderStrategy(value);
|
||||
default -> { /* unreachable: caller pre-filters by METHOD_SETTING_KEYS */ }
|
||||
}
|
||||
}
|
||||
|
||||
public void deleteStage(String region, String apiId, String stageName) {
|
||||
getStage(region, apiId, stageName);
|
||||
stageStore.delete(stageKey(region, apiId, stageName));
|
||||
|
||||
@@ -0,0 +1,63 @@
|
||||
package io.github.hectorvent.floci.services.apigateway.model;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
|
||||
|
||||
/**
|
||||
* Per-method settings on an API Gateway v1 Stage, addressed by the
|
||||
* <code>{resourcePath}/{httpMethod}</code> key in
|
||||
* {@link Stage#getMethodSettings()}.
|
||||
*
|
||||
* <p>Mirrors the fields documented at
|
||||
* <a href="https://docs.aws.amazon.com/apigateway/latest/api/API_MethodSetting.html">AWS
|
||||
* MethodSetting</a>; the defaults match the values real API Gateway returns
|
||||
* when the method has never been configured (throttling limits {@code -1}
|
||||
* mean "no override").
|
||||
*/
|
||||
@JsonIgnoreProperties(ignoreUnknown = true)
|
||||
public class MethodSetting {
|
||||
|
||||
private static final int UNSET_THROTTLING_BURST_LIMIT = -1;
|
||||
private static final double UNSET_THROTTLING_RATE_LIMIT = -1.0d;
|
||||
private static final int UNSET_CACHE_TTL_SECONDS = 0;
|
||||
|
||||
private boolean metricsEnabled;
|
||||
private String loggingLevel = "OFF";
|
||||
private boolean dataTraceEnabled;
|
||||
private int throttlingBurstLimit = UNSET_THROTTLING_BURST_LIMIT;
|
||||
private double throttlingRateLimit = UNSET_THROTTLING_RATE_LIMIT;
|
||||
private boolean cachingEnabled;
|
||||
private int cacheTtlInSeconds = UNSET_CACHE_TTL_SECONDS;
|
||||
private boolean cacheDataEncrypted;
|
||||
private boolean requireAuthorizationForCacheControl;
|
||||
private String unauthorizedCacheControlHeaderStrategy = "SUCCEED_WITH_RESPONSE_HEADER";
|
||||
|
||||
public boolean isMetricsEnabled() { return metricsEnabled; }
|
||||
public void setMetricsEnabled(boolean v) { this.metricsEnabled = v; }
|
||||
|
||||
public String getLoggingLevel() { return loggingLevel; }
|
||||
public void setLoggingLevel(String v) { this.loggingLevel = v; }
|
||||
|
||||
public boolean isDataTraceEnabled() { return dataTraceEnabled; }
|
||||
public void setDataTraceEnabled(boolean v) { this.dataTraceEnabled = v; }
|
||||
|
||||
public int getThrottlingBurstLimit() { return throttlingBurstLimit; }
|
||||
public void setThrottlingBurstLimit(int v) { this.throttlingBurstLimit = v; }
|
||||
|
||||
public double getThrottlingRateLimit() { return throttlingRateLimit; }
|
||||
public void setThrottlingRateLimit(double v) { this.throttlingRateLimit = v; }
|
||||
|
||||
public boolean isCachingEnabled() { return cachingEnabled; }
|
||||
public void setCachingEnabled(boolean v) { this.cachingEnabled = v; }
|
||||
|
||||
public int getCacheTtlInSeconds() { return cacheTtlInSeconds; }
|
||||
public void setCacheTtlInSeconds(int v) { this.cacheTtlInSeconds = v; }
|
||||
|
||||
public boolean isCacheDataEncrypted() { return cacheDataEncrypted; }
|
||||
public void setCacheDataEncrypted(boolean v) { this.cacheDataEncrypted = v; }
|
||||
|
||||
public boolean isRequireAuthorizationForCacheControl() { return requireAuthorizationForCacheControl; }
|
||||
public void setRequireAuthorizationForCacheControl(boolean v) { this.requireAuthorizationForCacheControl = v; }
|
||||
|
||||
public String getUnauthorizedCacheControlHeaderStrategy() { return unauthorizedCacheControlHeaderStrategy; }
|
||||
public void setUnauthorizedCacheControlHeaderStrategy(String v) { this.unauthorizedCacheControlHeaderStrategy = v; }
|
||||
}
|
||||
@@ -12,6 +12,7 @@ public class Stage {
|
||||
private String deploymentId;
|
||||
private String description;
|
||||
private Map<String, String> variables = new HashMap<>();
|
||||
private Map<String, MethodSetting> methodSettings = new HashMap<>();
|
||||
private long createdDate;
|
||||
private long lastUpdatedDate;
|
||||
|
||||
@@ -47,6 +48,14 @@ public class Stage {
|
||||
this.variables = variables != null ? variables : new HashMap<>();
|
||||
}
|
||||
|
||||
public Map<String, MethodSetting> getMethodSettings() {
|
||||
return methodSettings;
|
||||
}
|
||||
|
||||
public void setMethodSettings(Map<String, MethodSetting> methodSettings) {
|
||||
this.methodSettings = methodSettings != null ? methodSettings : new HashMap<>();
|
||||
}
|
||||
|
||||
public long getCreatedDate() {
|
||||
return createdDate;
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user