mirror of
https://github.com/floci-io/floci.git
synced 2026-11-24 06:20:24 -05:00
feat(appconfig): implement resource tagging and predefined deployment strategies (#533)
* feat(appconfig): implement resource tagging and predefined deployment strategies Add AppConfigTagHandler to handle ListTagsForResource/TagResource/UntagResource for AppConfig ARNs, and seed built-in strategies (AppConfig.AllAtOnce etc) so Terraform's aws_appconfig_* resources provision without errors. * feat(appconfig): match AWS AppConfig built-in strategy values: Set correct FinalBakeTimeInMinutes (AllAtOnce: 10, Linear50: 1) and descriptions for predefined deployment strategies. Fix test @Order gap.
This commit is contained in:
1 parent
c69580764e
commit
7d79bedbd9
4 files changed
+234
No files matched your search
@@ -153,9 +153,45 @@ public class AppConfigService {
|
||||
}
|
||||
|
||||
public DeploymentStrategy getDeploymentStrategy(String id) {
|
||||
// AWS predefined built-in strategies
|
||||
DeploymentStrategy builtin = builtinStrategy(id);
|
||||
if (builtin != null) return builtin;
|
||||
return strategyStore.get(id).orElseThrow(() -> new AwsException("ResourceNotFoundException", "Deployment strategy not found", 404));
|
||||
}
|
||||
|
||||
private static DeploymentStrategy builtinStrategy(String id) {
|
||||
return switch (id) {
|
||||
case "AppConfig.AllAtOnce" -> {
|
||||
DeploymentStrategy s = new DeploymentStrategy();
|
||||
s.setId(id); s.setName(id);
|
||||
s.setDescription("Quick");
|
||||
s.setDeploymentDurationInMinutes(0); s.setGrowthFactor(100f);
|
||||
s.setFinalBakeTimeInMinutes(10); s.setGrowthType("LINEAR");
|
||||
s.setReplicateTo("NONE");
|
||||
yield s;
|
||||
}
|
||||
case "AppConfig.Linear50PercentEvery30Seconds" -> {
|
||||
DeploymentStrategy s = new DeploymentStrategy();
|
||||
s.setId(id); s.setName(id);
|
||||
s.setDescription("Test/Demo");
|
||||
s.setDeploymentDurationInMinutes(1); s.setGrowthFactor(50f);
|
||||
s.setFinalBakeTimeInMinutes(1); s.setGrowthType("LINEAR");
|
||||
s.setReplicateTo("NONE");
|
||||
yield s;
|
||||
}
|
||||
case "AppConfig.Canary10Percent20Minutes" -> {
|
||||
DeploymentStrategy s = new DeploymentStrategy();
|
||||
s.setId(id); s.setName(id);
|
||||
s.setDescription("AWS Recommended");
|
||||
s.setDeploymentDurationInMinutes(20); s.setGrowthFactor(10f);
|
||||
s.setFinalBakeTimeInMinutes(10); s.setGrowthType("EXPONENTIAL");
|
||||
s.setReplicateTo("NONE");
|
||||
yield s;
|
||||
}
|
||||
default -> null;
|
||||
};
|
||||
}
|
||||
|
||||
// ──────────────────────────── Deployment ────────────────────────────
|
||||
|
||||
public Deployment startDeployment(String appId, String envId, Map<String, Object> request) {
|
||||
@@ -195,6 +231,24 @@ public class AppConfigService {
|
||||
return activeConfigStore.get(envId + "::" + profileId).orElse(null);
|
||||
}
|
||||
|
||||
// ──────────────────────────── Tags ────────────────────────────
|
||||
|
||||
public Map<String, String> getApplicationTags(String appId) {
|
||||
return getApplication(appId).getTags();
|
||||
}
|
||||
|
||||
public void tagApplication(String appId, Map<String, String> tags) {
|
||||
Application app = getApplication(appId);
|
||||
app.getTags().putAll(tags);
|
||||
applicationStore.put(appId, app);
|
||||
}
|
||||
|
||||
public void untagApplication(String appId, List<String> tagKeys) {
|
||||
Application app = getApplication(appId);
|
||||
tagKeys.forEach(app.getTags()::remove);
|
||||
applicationStore.put(appId, app);
|
||||
}
|
||||
|
||||
private static String shortId(int length) {
|
||||
return UUID.randomUUID().toString().replace("-", "").substring(0, length);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,83 @@
|
||||
package io.github.hectorvent.floci.services.appconfig;
|
||||
|
||||
import io.github.hectorvent.floci.core.common.AwsException;
|
||||
import io.github.hectorvent.floci.core.common.TagHandler;
|
||||
import jakarta.enterprise.context.ApplicationScoped;
|
||||
import jakarta.inject.Inject;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* {@link TagHandler} implementation for AppConfig.
|
||||
*
|
||||
* <p>Supported ARN formats:
|
||||
* <ul>
|
||||
* <li>{@code arn:aws:appconfig:<region>:<account>:application/<appId>}
|
||||
* <li>{@code arn:aws:appconfig:<region>:<account>:application/<appId>/environment/<envId>}
|
||||
* <li>{@code arn:aws:appconfig:<region>:<account>:application/<appId>/configurationprofile/<profileId>}
|
||||
* </ul>
|
||||
* Only application-level tags are stored; environment and configurationprofile tag calls
|
||||
* are accepted (no-op) to satisfy Terraform provider reads.
|
||||
*/
|
||||
@ApplicationScoped
|
||||
public class AppConfigTagHandler implements TagHandler {
|
||||
|
||||
private final AppConfigService service;
|
||||
|
||||
@Inject
|
||||
public AppConfigTagHandler(AppConfigService service) {
|
||||
this.service = service;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String serviceKey() {
|
||||
return "appconfig";
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map<String, String> listTags(String region, String arn) {
|
||||
ResourceRef ref = parseArn(arn);
|
||||
return switch (ref.type()) {
|
||||
case "application" -> service.getApplicationTags(ref.id());
|
||||
default -> Map.of();
|
||||
};
|
||||
}
|
||||
|
||||
@Override
|
||||
public void tagResource(String region, String arn, Map<String, String> tags) {
|
||||
ResourceRef ref = parseArn(arn);
|
||||
if ("application".equals(ref.type())) {
|
||||
service.tagApplication(ref.id(), tags);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void untagResource(String region, String arn, List<String> tagKeys) {
|
||||
ResourceRef ref = parseArn(arn);
|
||||
if ("application".equals(ref.type())) {
|
||||
service.untagApplication(ref.id(), tagKeys);
|
||||
}
|
||||
}
|
||||
|
||||
private record ResourceRef(String type, String id) {}
|
||||
|
||||
private static ResourceRef parseArn(String arn) {
|
||||
// arn:aws:appconfig:<region>:<account>:<resource>
|
||||
String[] arnParts = arn.split(":", 6);
|
||||
if (arnParts.length < 6) {
|
||||
throw new AwsException("BadRequestException", "Invalid resource ARN: " + arn, 400);
|
||||
}
|
||||
String[] parts = arnParts[5].split("/");
|
||||
if (parts.length >= 2 && "application".equals(parts[0])) {
|
||||
// application/<appId>
|
||||
if (parts.length == 2) return new ResourceRef("application", parts[1]);
|
||||
// application/<appId>/environment/<envId>
|
||||
// application/<appId>/configurationprofile/<profileId>
|
||||
if (parts.length == 4) return new ResourceRef(parts[2], parts[3]);
|
||||
// application/<appId>/environment/<envId>/deployment/<num>
|
||||
if (parts.length == 6) return new ResourceRef(parts[4], parts[5]);
|
||||
}
|
||||
throw new AwsException("BadRequestException", "Invalid resource ARN: " + arn, 400);
|
||||
}
|
||||
}
|
||||
@@ -4,6 +4,9 @@ import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
|
||||
import com.fasterxml.jackson.annotation.JsonProperty;
|
||||
import io.quarkus.runtime.annotations.RegisterForReflection;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
@RegisterForReflection
|
||||
@JsonIgnoreProperties(ignoreUnknown = true)
|
||||
public class Application {
|
||||
@@ -13,6 +16,7 @@ public class Application {
|
||||
private String name;
|
||||
@JsonProperty("Description")
|
||||
private String description;
|
||||
private Map<String, String> tags = new HashMap<>();
|
||||
|
||||
public Application() {}
|
||||
|
||||
@@ -24,4 +28,7 @@ public class Application {
|
||||
|
||||
public String getDescription() { return description; }
|
||||
public void setDescription(String description) { this.description = description; }
|
||||
|
||||
public Map<String, String> getTags() { return tags; }
|
||||
public void setTags(Map<String, String> tags) { this.tags = tags != null ? tags : new HashMap<>(); }
|
||||
}
|
||||
Reference in new issue
Block a user