mirror of
https://github.com/floci-io/floci.git
synced 2026-11-27 07:39:24 -05:00
fix(appconfig): accept names in management APIs (#5417)
* fix(appconfig): accept names in management APIs * fix(appconfig): handle profile identifier collisions * test(appconfig): clean up identifier precedence fixtures
This commit is contained in:
1 parent
ea8da22226
commit
4ff263271c
3 files changed
+275
-44
No files matched your search
@@ -61,11 +61,11 @@ public class AppConfigService {
|
||||
return app;
|
||||
}
|
||||
|
||||
public Application getApplication(String id) {
|
||||
return applicationStore.get(id).orElseThrow(() -> new AwsException("ResourceNotFoundException", "Application not found", 404));
|
||||
public Application getApplication(String idOrName) {
|
||||
return resolveApplication(idOrName);
|
||||
}
|
||||
|
||||
/** The application whose ID or name is {@code idOrName}; the AppConfigData APIs accept either. */
|
||||
/** The application whose ID or name is {@code idOrName}. */
|
||||
public Application resolveApplication(String idOrName) {
|
||||
return applicationStore.get(idOrName)
|
||||
.or(() -> listApplications().stream().filter(a -> idOrName.equals(a.getName())).findFirst())
|
||||
@@ -76,14 +76,16 @@ public class AppConfigService {
|
||||
return applicationStore.scan(k -> true);
|
||||
}
|
||||
|
||||
public void deleteApplication(String id) {
|
||||
applicationStore.delete(id);
|
||||
public void deleteApplication(String idOrName) {
|
||||
applicationStore.get(idOrName)
|
||||
.or(() -> listApplications().stream().filter(a -> idOrName.equals(a.getName())).findFirst())
|
||||
.ifPresent(application -> applicationStore.delete(application.getId()));
|
||||
}
|
||||
|
||||
// ──────────────────────────── Environment ────────────────────────────
|
||||
|
||||
public Environment createEnvironment(String appId, Map<String, Object> request) {
|
||||
getApplication(appId);
|
||||
public Environment createEnvironment(String applicationIdentifier, Map<String, Object> request) {
|
||||
String appId = resolveApplication(applicationIdentifier).getId();
|
||||
Environment env = new Environment();
|
||||
env.setId(shortId(7));
|
||||
env.setApplicationId(appId);
|
||||
@@ -94,10 +96,9 @@ public class AppConfigService {
|
||||
return env;
|
||||
}
|
||||
|
||||
public Environment getEnvironment(String appId, String envId) {
|
||||
Environment env = environmentStore.get(envId).orElseThrow(() -> new AwsException("ResourceNotFoundException", "Environment not found", 404));
|
||||
if (!env.getApplicationId().equals(appId)) throw new AwsException("ResourceNotFoundException", "Environment not found in this application", 404);
|
||||
return env;
|
||||
public Environment getEnvironment(String applicationIdentifier, String environmentIdentifier) {
|
||||
String appId = resolveApplication(applicationIdentifier).getId();
|
||||
return resolveEnvironment(appId, environmentIdentifier);
|
||||
}
|
||||
|
||||
public synchronized void deleteEnvironment(String applicationIdentifier, String environmentIdentifier) {
|
||||
@@ -123,7 +124,8 @@ public class AppConfigService {
|
||||
.orElseThrow(() -> new AwsException("ResourceNotFoundException", "Environment not found", 404));
|
||||
}
|
||||
|
||||
public List<Environment> listEnvironments(String appId) {
|
||||
public List<Environment> listEnvironments(String applicationIdentifier) {
|
||||
String appId = resolveApplication(applicationIdentifier).getId();
|
||||
return environmentStore.scan(k -> true).stream()
|
||||
.filter(e -> e.getApplicationId().equals(appId))
|
||||
.toList();
|
||||
@@ -131,8 +133,8 @@ public class AppConfigService {
|
||||
|
||||
// ──────────────────────────── Configuration Profile ────────────────────────────
|
||||
|
||||
public ConfigurationProfile createConfigurationProfile(String appId, Map<String, Object> request) {
|
||||
getApplication(appId);
|
||||
public ConfigurationProfile createConfigurationProfile(String applicationIdentifier, Map<String, Object> request) {
|
||||
String appId = resolveApplication(applicationIdentifier).getId();
|
||||
ConfigurationProfile profile = new ConfigurationProfile();
|
||||
profile.setId(shortId(7));
|
||||
profile.setApplicationId(appId);
|
||||
@@ -144,10 +146,9 @@ public class AppConfigService {
|
||||
return profile;
|
||||
}
|
||||
|
||||
public ConfigurationProfile getConfigurationProfile(String appId, String profileId) {
|
||||
ConfigurationProfile profile = profileStore.get(profileId).orElseThrow(() -> new AwsException("ResourceNotFoundException", "Configuration profile not found", 404));
|
||||
if (!profile.getApplicationId().equals(appId)) throw new AwsException("ResourceNotFoundException", "Profile not found in this application", 404);
|
||||
return profile;
|
||||
public ConfigurationProfile getConfigurationProfile(String applicationIdentifier, String profileIdentifier) {
|
||||
String appId = resolveApplication(applicationIdentifier).getId();
|
||||
return resolveConfigurationProfile(appId, profileIdentifier);
|
||||
}
|
||||
|
||||
/** The configuration profile of {@code appId} whose ID or name is {@code idOrName}. */
|
||||
@@ -158,23 +159,35 @@ public class AppConfigService {
|
||||
.orElseThrow(() -> new AwsException("ResourceNotFoundException", "Configuration profile not found", 404));
|
||||
}
|
||||
|
||||
public List<ConfigurationProfile> listConfigurationProfiles(String appId) {
|
||||
public List<ConfigurationProfile> listConfigurationProfiles(String applicationIdentifier) {
|
||||
String appId = resolveApplication(applicationIdentifier).getId();
|
||||
return profileStore.scan(k -> true).stream()
|
||||
.filter(p -> p.getApplicationId().equals(appId))
|
||||
.toList();
|
||||
}
|
||||
|
||||
public void deleteConfigurationProfile(String appId, String profileId) {
|
||||
public void deleteConfigurationProfile(String applicationIdentifier, String profileIdentifier) {
|
||||
String appId = resolveApplication(applicationIdentifier).getId();
|
||||
// Unlike deleteApplication (a single, unscoped ID), a profile is nested under an
|
||||
// application - a mismatched appId must not be able to delete another application's
|
||||
// profile just because its bare profileId is guessed/known. A profileId that doesn't
|
||||
// exist at all is still an idempotent no-op, matching deleteApplication's convention;
|
||||
// only an existing-but-wrongly-scoped one is rejected.
|
||||
profileStore.get(profileId).ifPresent(profile -> {
|
||||
if (!profile.getApplicationId().equals(appId)) {
|
||||
throw new AwsException("ResourceNotFoundException", "Configuration profile not found in this application", 404);
|
||||
}
|
||||
});
|
||||
ConfigurationProfile exactProfile = profileStore.get(profileIdentifier).orElse(null);
|
||||
ConfigurationProfile profile = exactProfile != null && appId.equals(exactProfile.getApplicationId())
|
||||
? exactProfile
|
||||
: listConfigurationProfiles(appId).stream()
|
||||
.filter(candidate -> profileIdentifier.equals(candidate.getName()))
|
||||
.findFirst()
|
||||
.orElse(null);
|
||||
if (profile == null && exactProfile != null) {
|
||||
throw new AwsException("ResourceNotFoundException",
|
||||
"Configuration profile not found in this application", 404);
|
||||
}
|
||||
if (profile == null) {
|
||||
return;
|
||||
}
|
||||
String profileId = profile.getId();
|
||||
// A hosted configuration version isn't independently addressable outside its profile's
|
||||
// lifecycle - cascade the delete so a caller can't still fetch versions for a profile
|
||||
// that's supposedly gone.
|
||||
@@ -184,8 +197,13 @@ public class AppConfigService {
|
||||
|
||||
// ──────────────────────────── Hosted Configuration Version ────────────────────────────
|
||||
|
||||
public HostedConfigurationVersion createHostedConfigurationVersion(String appId, String profileId, byte[] content, String contentType, String description) {
|
||||
getConfigurationProfile(appId, profileId);
|
||||
public HostedConfigurationVersion createHostedConfigurationVersion(String applicationIdentifier,
|
||||
String profileIdentifier,
|
||||
byte[] content,
|
||||
String contentType,
|
||||
String description) {
|
||||
String appId = resolveApplication(applicationIdentifier).getId();
|
||||
String profileId = resolveConfigurationProfile(appId, profileIdentifier).getId();
|
||||
String prefix = appId + "::" + profileId + "::";
|
||||
int nextVersion = versionStore.scan(k -> k.startsWith(prefix))
|
||||
.stream().mapToInt(HostedConfigurationVersion::getVersionNumber).max().orElse(0) + 1;
|
||||
@@ -202,12 +220,19 @@ public class AppConfigService {
|
||||
return version;
|
||||
}
|
||||
|
||||
public HostedConfigurationVersion getHostedConfigurationVersion(String appId, String profileId, int versionNumber) {
|
||||
public HostedConfigurationVersion getHostedConfigurationVersion(String applicationIdentifier,
|
||||
String profileIdentifier,
|
||||
int versionNumber) {
|
||||
String appId = resolveApplication(applicationIdentifier).getId();
|
||||
String profileId = resolveConfigurationProfile(appId, profileIdentifier).getId();
|
||||
return versionStore.get(appId + "::" + profileId + "::" + versionNumber)
|
||||
.orElseThrow(() -> new AwsException("ResourceNotFoundException", "Hosted configuration version not found", 404));
|
||||
}
|
||||
|
||||
public List<HostedConfigurationVersionSummary> listHostedConfigurationVersions(String appId, String profileId) {
|
||||
public List<HostedConfigurationVersionSummary> listHostedConfigurationVersions(String applicationIdentifier,
|
||||
String profileIdentifier) {
|
||||
String appId = resolveApplication(applicationIdentifier).getId();
|
||||
String profileId = resolveConfigurationProfile(appId, profileIdentifier).getId();
|
||||
String prefix = appId + "::" + profileId + "::";
|
||||
return versionStore.scan(k -> k.startsWith(prefix))
|
||||
.stream()
|
||||
@@ -224,7 +249,11 @@ public class AppConfigService {
|
||||
.toList();
|
||||
}
|
||||
|
||||
public void deleteHostedConfigurationVersion(String appId, String profileId, int versionNumber) {
|
||||
public void deleteHostedConfigurationVersion(String applicationIdentifier,
|
||||
String profileIdentifier,
|
||||
int versionNumber) {
|
||||
String appId = resolveApplication(applicationIdentifier).getId();
|
||||
String profileId = resolveConfigurationProfile(appId, profileIdentifier).getId();
|
||||
versionStore.delete(appId + "::" + profileId + "::" + versionNumber);
|
||||
}
|
||||
|
||||
@@ -310,13 +339,16 @@ public class AppConfigService {
|
||||
|
||||
// ──────────────────────────── Deployment ────────────────────────────
|
||||
|
||||
public synchronized Deployment startDeployment(String appId, String envId, Map<String, Object> request) {
|
||||
getEnvironment(appId, envId);
|
||||
String profileId = (String) request.get("ConfigurationProfileId");
|
||||
public synchronized Deployment startDeployment(String applicationIdentifier,
|
||||
String environmentIdentifier,
|
||||
Map<String, Object> request) {
|
||||
String appId = resolveApplication(applicationIdentifier).getId();
|
||||
String envId = resolveEnvironment(appId, environmentIdentifier).getId();
|
||||
String profileId = resolveConfigurationProfile(
|
||||
appId, (String) request.get("ConfigurationProfileId")).getId();
|
||||
String version = (String) request.get("ConfigurationVersion");
|
||||
String strategyId = (String) request.get("DeploymentStrategyId");
|
||||
|
||||
getConfigurationProfile(appId, profileId);
|
||||
getDeploymentStrategy(strategyId);
|
||||
|
||||
Deployment deployment = new Deployment();
|
||||
@@ -342,14 +374,21 @@ public class AppConfigService {
|
||||
return deployment;
|
||||
}
|
||||
|
||||
public Deployment getDeployment(String appId, String envId, int deploymentNumber) {
|
||||
getEnvironment(appId, envId);
|
||||
public Deployment getDeployment(String applicationIdentifier,
|
||||
String environmentIdentifier,
|
||||
int deploymentNumber) {
|
||||
String appId = resolveApplication(applicationIdentifier).getId();
|
||||
String envId = resolveEnvironment(appId, environmentIdentifier).getId();
|
||||
return deploymentStore.get(appId + "::" + envId + "::" + deploymentNumber)
|
||||
.orElseThrow(() -> new AwsException("ResourceNotFoundException", "Deployment not found", 404));
|
||||
}
|
||||
|
||||
public DeploymentPage listDeployments(String appId, String envId, Integer maxResults, String nextToken) {
|
||||
getEnvironment(appId, envId);
|
||||
public DeploymentPage listDeployments(String applicationIdentifier,
|
||||
String environmentIdentifier,
|
||||
Integer maxResults,
|
||||
String nextToken) {
|
||||
String appId = resolveApplication(applicationIdentifier).getId();
|
||||
String envId = resolveEnvironment(appId, environmentIdentifier).getId();
|
||||
int pageSize = maxResults == null ? 50 : maxResults;
|
||||
if (pageSize < 1 || pageSize > 50) {
|
||||
throw new AwsException("BadRequestException", "max_results must be between 1 and 50", 400);
|
||||
@@ -442,13 +481,13 @@ public class AppConfigService {
|
||||
public void tagApplication(String appId, Map<String, String> tags) {
|
||||
Application app = getApplication(appId);
|
||||
app.getTags().putAll(tags);
|
||||
applicationStore.put(appId, app);
|
||||
applicationStore.put(app.getId(), app);
|
||||
}
|
||||
|
||||
public void untagApplication(String appId, List<String> tagKeys) {
|
||||
Application app = getApplication(appId);
|
||||
tagKeys.forEach(app.getTags()::remove);
|
||||
applicationStore.put(appId, app);
|
||||
applicationStore.put(app.getId(), app);
|
||||
}
|
||||
|
||||
private static String shortId(int length) {
|
||||
|
||||
Reference in new issue
Block a user