mirror of
https://github.com/floci-io/floci.git
synced 2026-11-27 07:39:24 -05:00
fix(appconfig): serve legacy deployed configuration requests (#5658)
* fix(appconfig): serve legacy deployed configuration requests Signed-off-by: Jackson Price <59149601+jprice8@users.noreply.github.com> * fix(appconfig): keep 404 for an unknown application or profile GetConfiguration now maps only a missing environment to BadRequestException, as a missing or undeployed environment was observed on AWS. An unknown application or configuration profile stays ResourceNotFoundException (404), as the API reference lists. Signed-off-by: Jackson Price <59149601+jprice8@users.noreply.github.com> * docs(appconfig): note GetConfiguration error codes Signed-off-by: Jackson Price <59149601+jprice8@users.noreply.github.com> --------- Signed-off-by: Jackson Price <59149601+jprice8@users.noreply.github.com>
This commit is contained in:
1 parent
f3e1cb6006
commit
91c67c69df
5 files changed
+414
-5
No files matched your search
+33
-1
@@ -4,6 +4,7 @@ import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.fasterxml.jackson.databind.node.ArrayNode;
|
||||
import com.fasterxml.jackson.databind.node.ObjectNode;
|
||||
import io.github.hectorvent.floci.core.common.Pagination;
|
||||
import io.github.hectorvent.floci.services.appconfig.AppConfigDataService.LegacyConfiguration;
|
||||
import io.github.hectorvent.floci.services.appconfig.model.Application;
|
||||
import io.github.hectorvent.floci.services.appconfig.model.ConfigurationProfile;
|
||||
import io.github.hectorvent.floci.services.appconfig.model.Deployment;
|
||||
@@ -21,8 +22,10 @@ import jakarta.ws.rs.Path;
|
||||
import jakarta.ws.rs.PathParam;
|
||||
import jakarta.ws.rs.Produces;
|
||||
import jakarta.ws.rs.QueryParam;
|
||||
import jakarta.ws.rs.core.Context;
|
||||
import jakarta.ws.rs.core.MediaType;
|
||||
import jakarta.ws.rs.core.Response;
|
||||
import jakarta.ws.rs.core.UriInfo;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.List;
|
||||
@@ -33,11 +36,14 @@ import java.util.Map;
|
||||
@Consumes(MediaType.APPLICATION_JSON)
|
||||
public class AppConfigController {
|
||||
private final AppConfigService service;
|
||||
private final AppConfigDataService dataService;
|
||||
private final ObjectMapper objectMapper;
|
||||
|
||||
@Inject
|
||||
public AppConfigController(AppConfigService service, ObjectMapper objectMapper) {
|
||||
public AppConfigController(AppConfigService service, AppConfigDataService dataService,
|
||||
ObjectMapper objectMapper) {
|
||||
this.service = service;
|
||||
this.dataService = dataService;
|
||||
this.objectMapper = objectMapper;
|
||||
}
|
||||
|
||||
@@ -268,4 +274,30 @@ public class AppConfigController {
|
||||
public Response getDeployment(@PathParam("appId") String appId, @PathParam("envId") String envId, @PathParam("deploymentNumber") int deploymentNumber) {
|
||||
return Response.ok(service.getDeployment(appId, envId, deploymentNumber)).build();
|
||||
}
|
||||
|
||||
// ──────────────────────────── Configuration ────────────────────────────
|
||||
|
||||
// The deprecated GetConfiguration: superseded by AppConfigData, but still an AppConfig operation.
|
||||
// The response type comes from the stored version (Ion for variant flags when Accept asks for it),
|
||||
// never from negotiation, so a non-JSON Accept header is not refused.
|
||||
@GET
|
||||
@Path("/applications/{appId}/environments/{envId}/configurations/{configuration}")
|
||||
@Produces(MediaType.WILDCARD)
|
||||
public Response getConfiguration(@PathParam("appId") String appId,
|
||||
@PathParam("envId") String envId,
|
||||
@PathParam("configuration") String configuration,
|
||||
@QueryParam("client_id") String clientId,
|
||||
@HeaderParam("Accept") String accept,
|
||||
@Context UriInfo uriInfo) {
|
||||
// Read raw: @QueryParam turns an empty value into null, but AWS rejects an empty version.
|
||||
String clientVersion = uriInfo.getQueryParameters().getFirst("client_configuration_version");
|
||||
LegacyConfiguration data = dataService.getConfiguration(
|
||||
appId, envId, configuration, clientId, clientVersion, accept);
|
||||
// A version stored without a content type would otherwise go out as the */* of @Produces.
|
||||
String contentType = data.contentType() != null ? data.contentType() : MediaType.APPLICATION_OCTET_STREAM;
|
||||
return Response.ok(data.content())
|
||||
.header("Content-Type", contentType)
|
||||
.header("Configuration-Version", data.configurationVersion())
|
||||
.build();
|
||||
}
|
||||
}
|
||||
+52
-4
@@ -130,7 +130,9 @@ public class AppConfigDataService {
|
||||
byte[] content = new byte[0];
|
||||
String contentType = "application/octet-stream";
|
||||
if (version != null) {
|
||||
ResolvedContent resolved = resolveContent(session, version, accept);
|
||||
ConfigurationProfile profile = appConfigService.getConfigurationProfile(
|
||||
session.getApplicationId(), session.getConfigurationProfileId());
|
||||
ResolvedContent resolved = resolveContent(profile, version, accept);
|
||||
content = resolved.bytes();
|
||||
contentType = resolved.contentType();
|
||||
}
|
||||
@@ -140,10 +142,54 @@ public class AppConfigDataService {
|
||||
pollInterval);
|
||||
}
|
||||
|
||||
private ResolvedContent resolveContent(ConfigurationSession session, HostedConfigurationVersion version,
|
||||
public LegacyConfiguration getConfiguration(String application, String environment, String configuration,
|
||||
String clientId, String clientVersion, String accept) {
|
||||
for (String identifier : new String[]{application, environment, configuration, clientId}) {
|
||||
requireIdentifier(identifier, "Configuration identifier or client_id");
|
||||
if (identifier.length() > 64) {
|
||||
throw new AwsException("BadRequestException", "Identifiers must not exceed 64 characters", 400);
|
||||
}
|
||||
}
|
||||
if (clientVersion != null && (clientVersion.isEmpty() || clientVersion.length() > 1024)) {
|
||||
throw new AwsException("BadRequestException", "Invalid client_configuration_version", 400);
|
||||
}
|
||||
Application app = appConfigService.resolveApplication(application);
|
||||
Environment env;
|
||||
try {
|
||||
env = appConfigService.resolveEnvironment(app.getId(), environment);
|
||||
} catch (AwsException e) {
|
||||
if (!"ResourceNotFoundException".equals(e.getErrorCode())) {
|
||||
throw e;
|
||||
}
|
||||
// AWS answers a missing environment as it does an undeployed one; an unknown application or
|
||||
// profile stays ResourceNotFoundException.
|
||||
throw new AwsException("BadRequestException", e.getMessage(), 400);
|
||||
}
|
||||
ConfigurationProfile profile = appConfigService.resolveConfigurationProfile(app.getId(), configuration);
|
||||
String active = appConfigService.getActiveVersion(env.getId(), profile.getId());
|
||||
if (active == null) {
|
||||
throw new AwsException("BadRequestException", "No configuration is deployed", 400);
|
||||
}
|
||||
HostedConfigurationVersion version = appConfigService.getHostedConfigurationVersion(
|
||||
app.getId(), profile.getId(), hostedVersionNumber(active));
|
||||
if (active.equals(clientVersion)) {
|
||||
return new LegacyConfiguration(new byte[0], version.getContentType(), active);
|
||||
}
|
||||
ResolvedContent content = resolveContent(profile, version, accept);
|
||||
return new LegacyConfiguration(content.bytes(), content.contentType(), active);
|
||||
}
|
||||
|
||||
/** A deployed version that is not a version number names no hosted configuration version. */
|
||||
private static int hostedVersionNumber(String deployedVersion) {
|
||||
try {
|
||||
return Integer.parseInt(deployedVersion);
|
||||
} catch (NumberFormatException e) {
|
||||
throw new AwsException("ResourceNotFoundException", "Hosted configuration version not found", 404);
|
||||
}
|
||||
}
|
||||
|
||||
private ResolvedContent resolveContent(ConfigurationProfile profile, HostedConfigurationVersion version,
|
||||
String accept) {
|
||||
ConfigurationProfile profile = appConfigService.getConfigurationProfile(
|
||||
session.getApplicationId(), session.getConfigurationProfileId());
|
||||
if (!"AWS.AppConfig.FeatureFlags".equals(profile.getType())) {
|
||||
return new ResolvedContent(version.getContent(), version.getContentType());
|
||||
}
|
||||
@@ -251,6 +297,8 @@ public class AppConfigDataService {
|
||||
|
||||
private record ResolvedContent(byte[] bytes, String contentType) {}
|
||||
|
||||
public record LegacyConfiguration(byte[] content, String contentType, String configurationVersion) {}
|
||||
|
||||
public record ConfigurationData(byte[] content, String contentType, String configurationVersion,
|
||||
String nextPollConfigurationToken, int nextPollIntervalInSeconds) {}
|
||||
}
|
||||
Reference in new issue
Block a user