mirror of
https://github.com/floci-io/floci.git
synced 2026-12-01 17:33:03 -05:00
fix(appconfig): keep environment monitors and report deployment sources (#6665)
CreateEnvironment dropped the Monitors it was sent, and StartDeployment and GetDeployment never reported the deployed profile's name or location. AWS documents all three on these operations. - CreateEnvironment stores Monitors and environment reads return them. They are checked against AWS's limits (at most five; AlarmArn of 1 to 2048 characters; AlarmRoleArn an IAM role ARN in any partition) and refused with BadRequestException before anything is stored. An environment created without monitors returns no Monitors member, as AWS's own example shows. - StartDeployment records the profile's ConfigurationName and ConfigurationLocationUri, and GetDeployment returns them. - Records stored by earlier builds load unchanged: the new members are omitted when absent, so their responses stay byte-identical. A configuration profile created without Type still reports none: AWS documents no default, and its CreateConfigurationProfile example returns a null Type. Signed-off-by: Jackson Price <59149601+jprice8@users.noreply.github.com>
This commit is contained in:
1 parent
4506645d0f
commit
b280a7764a
9 files changed
+521
-2
No files matched your search
@@ -2,6 +2,7 @@ package io.github.hectorvent.floci.services.appconfig;
|
||||
|
||||
import com.fasterxml.jackson.core.type.TypeReference;
|
||||
import io.github.hectorvent.floci.config.EmulatorConfig;
|
||||
import io.github.hectorvent.floci.core.common.AwsArnUtils;
|
||||
import io.github.hectorvent.floci.core.common.AwsException;
|
||||
import io.github.hectorvent.floci.core.storage.StorageBackend;
|
||||
import io.github.hectorvent.floci.core.storage.StorageFactory;
|
||||
@@ -14,6 +15,7 @@ import io.github.hectorvent.floci.services.appconfig.model.DeploymentSummary;
|
||||
import io.github.hectorvent.floci.services.appconfig.model.Environment;
|
||||
import io.github.hectorvent.floci.services.appconfig.model.HostedConfigurationVersion;
|
||||
import io.github.hectorvent.floci.services.appconfig.model.HostedConfigurationVersionSummary;
|
||||
import io.github.hectorvent.floci.services.appconfig.model.Monitor;
|
||||
import jakarta.enterprise.context.ApplicationScoped;
|
||||
import jakarta.inject.Inject;
|
||||
import org.jboss.logging.Logger;
|
||||
@@ -24,6 +26,7 @@ import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
@ApplicationScoped
|
||||
public class AppConfigService {
|
||||
@@ -38,6 +41,9 @@ public class AppConfigService {
|
||||
private final StorageBackend<String, String> activeConfigStore; // envId::profileId -> versionNumber
|
||||
private final Map<String, DeploymentPageToken> deploymentPageTokens = new ConcurrentHashMap<>();
|
||||
private static final int MAX_DEPLOYMENT_PAGE_TOKENS = 1000;
|
||||
private static final int MAX_MONITORS = 5;
|
||||
private static final int MAX_ARN_LENGTH = 2048;
|
||||
private static final Pattern ROLE_ARN = Pattern.compile("arn:" + AwsArnUtils.PARTITION_REGEX + ":iam::\\d{12}:role/.*");
|
||||
|
||||
@Inject
|
||||
public AppConfigService(StorageFactory storageFactory, EmulatorConfig config) {
|
||||
@@ -85,6 +91,7 @@ public class AppConfigService {
|
||||
// ──────────────────────────── Environment ────────────────────────────
|
||||
|
||||
public Environment createEnvironment(String applicationIdentifier, Map<String, Object> request) {
|
||||
List<Monitor> monitors = monitors(request.get("Monitors"));
|
||||
String appId = resolveApplication(applicationIdentifier).getId();
|
||||
Environment env = new Environment();
|
||||
env.setId(shortId(7));
|
||||
@@ -92,6 +99,7 @@ public class AppConfigService {
|
||||
env.setName((String) request.get("Name"));
|
||||
env.setDescription((String) request.get("Description"));
|
||||
env.setState("READY");
|
||||
env.setMonitors(monitors);
|
||||
environmentStore.put(env.getId(), env);
|
||||
return env;
|
||||
}
|
||||
@@ -131,6 +139,32 @@ public class AppConfigService {
|
||||
.toList();
|
||||
}
|
||||
|
||||
/** The request's Monitors, checked against the limits AWS documents for CreateEnvironment. */
|
||||
private static List<Monitor> monitors(Object value) {
|
||||
if (value == null) {
|
||||
return null;
|
||||
}
|
||||
if (!(value instanceof List<?> entries) || entries.size() > MAX_MONITORS) {
|
||||
throw new AwsException("BadRequestException", "Monitors must be a list of at most " + MAX_MONITORS + " monitors", 400);
|
||||
}
|
||||
List<Monitor> result = new ArrayList<>();
|
||||
for (Object entry : entries) {
|
||||
if (!(entry instanceof Map<?, ?> monitor)
|
||||
|| !(monitor.get("AlarmArn") instanceof String alarmArn)
|
||||
|| alarmArn.isEmpty() || alarmArn.length() > MAX_ARN_LENGTH) {
|
||||
throw new AwsException("BadRequestException",
|
||||
"Each monitor requires a string AlarmArn of 1 to " + MAX_ARN_LENGTH + " characters", 400);
|
||||
}
|
||||
Object role = monitor.get("AlarmRoleArn");
|
||||
if (role != null && (!(role instanceof String roleArn)
|
||||
|| roleArn.length() > MAX_ARN_LENGTH || !ROLE_ARN.matcher(roleArn).matches())) {
|
||||
throw new AwsException("BadRequestException", "AlarmRoleArn must be the ARN of an IAM role", 400);
|
||||
}
|
||||
result.add(new Monitor(alarmArn, (String) role));
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
// ──────────────────────────── Configuration Profile ────────────────────────────
|
||||
|
||||
public ConfigurationProfile createConfigurationProfile(String applicationIdentifier, Map<String, Object> request) {
|
||||
@@ -344,8 +378,9 @@ public class AppConfigService {
|
||||
Map<String, Object> request) {
|
||||
String appId = resolveApplication(applicationIdentifier).getId();
|
||||
String envId = resolveEnvironment(appId, environmentIdentifier).getId();
|
||||
String profileId = resolveConfigurationProfile(
|
||||
appId, (String) request.get("ConfigurationProfileId")).getId();
|
||||
ConfigurationProfile profile = resolveConfigurationProfile(
|
||||
appId, (String) request.get("ConfigurationProfileId"));
|
||||
String profileId = profile.getId();
|
||||
String version = (String) request.get("ConfigurationVersion");
|
||||
String strategyId = (String) request.get("DeploymentStrategyId");
|
||||
|
||||
@@ -355,6 +390,8 @@ public class AppConfigService {
|
||||
deployment.setApplicationId(appId);
|
||||
deployment.setEnvironmentId(envId);
|
||||
deployment.setConfigurationProfileId(profileId);
|
||||
deployment.setConfigurationName(profile.getName());
|
||||
deployment.setConfigurationLocationUri(profile.getLocationUri());
|
||||
deployment.setConfigurationVersion(version);
|
||||
deployment.setDeploymentStrategyId(strategyId);
|
||||
int nextDeploymentNumber = deploymentStore.scan(key -> true).stream()
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package io.github.hectorvent.floci.services.appconfig.model;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
|
||||
import com.fasterxml.jackson.annotation.JsonInclude;
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
import io.quarkus.runtime.annotations.RegisterForReflection;
|
||||
|
||||
@@ -17,6 +18,10 @@ public class Deployment {
|
||||
private int deploymentNumber;
|
||||
@JsonProperty("ConfigurationName")
|
||||
private String configurationName;
|
||||
// Omitted rather than null on deployments stored before it was recorded, so they read back unchanged.
|
||||
@JsonProperty("ConfigurationLocationUri")
|
||||
@JsonInclude(JsonInclude.Include.NON_NULL)
|
||||
private String configurationLocationUri;
|
||||
@JsonProperty("ConfigurationVersion")
|
||||
private String configurationVersion;
|
||||
@JsonProperty("DeploymentStrategyId")
|
||||
@@ -43,6 +48,9 @@ public class Deployment {
|
||||
public String getConfigurationName() { return configurationName; }
|
||||
public void setConfigurationName(String configurationName) { this.configurationName = configurationName; }
|
||||
|
||||
public String getConfigurationLocationUri() { return configurationLocationUri; }
|
||||
public void setConfigurationLocationUri(String configurationLocationUri) { this.configurationLocationUri = configurationLocationUri; }
|
||||
|
||||
public String getConfigurationVersion() { return configurationVersion; }
|
||||
public void setConfigurationVersion(String configurationVersion) { this.configurationVersion = configurationVersion; }
|
||||
|
||||
|
||||
@@ -1,9 +1,12 @@
|
||||
package io.github.hectorvent.floci.services.appconfig.model;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
|
||||
import com.fasterxml.jackson.annotation.JsonInclude;
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
import io.quarkus.runtime.annotations.RegisterForReflection;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@RegisterForReflection
|
||||
@JsonIgnoreProperties(ignoreUnknown = true)
|
||||
public class Environment {
|
||||
@@ -17,6 +20,10 @@ public class Environment {
|
||||
private String description;
|
||||
@JsonProperty("State")
|
||||
private String state; // READY, DEPLOYING, ROLLING_BACK, ROLLED_BACK
|
||||
// Null when the environment was created without monitors: AWS then returns no Monitors member.
|
||||
@JsonProperty("Monitors")
|
||||
@JsonInclude(JsonInclude.Include.NON_NULL)
|
||||
private List<Monitor> monitors;
|
||||
|
||||
public Environment() {}
|
||||
|
||||
@@ -34,4 +41,7 @@ public class Environment {
|
||||
|
||||
public String getState() { return state; }
|
||||
public void setState(String state) { this.state = state; }
|
||||
|
||||
public List<Monitor> getMonitors() { return monitors; }
|
||||
public void setMonitors(List<Monitor> monitors) { this.monitors = monitors != null ? List.copyOf(monitors) : null; }
|
||||
}
|
||||
@@ -0,0 +1,14 @@
|
||||
package io.github.hectorvent.floci.services.appconfig.model;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
|
||||
import com.fasterxml.jackson.annotation.JsonInclude;
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
import io.quarkus.runtime.annotations.RegisterForReflection;
|
||||
|
||||
/** A CloudWatch alarm an environment names for AppConfig to watch during deployments. */
|
||||
@RegisterForReflection
|
||||
@JsonIgnoreProperties(ignoreUnknown = true)
|
||||
@JsonInclude(JsonInclude.Include.NON_NULL)
|
||||
public record Monitor(@JsonProperty("AlarmArn") String alarmArn,
|
||||
@JsonProperty("AlarmRoleArn") String alarmRoleArn) {
|
||||
}
|
||||
Reference in new issue
Block a user