mirror of
https://github.com/floci-io/floci.git
synced 2026-11-24 06:20:24 -05:00
feat(apigateway): persist API key tags and add GetApiKey route (#1677)
* feat(apigateway): persist API key tags and add GetApiKey route
CreateApiKey now stores the request tags and returns them from CreateApiKey, GetApiKey and GetApiKeys. Adds the missing GET /apikeys/{apiKeyId} route, which omits the value unless includeValue=true and returns 404 when the key is unknown.
* fix(apigateway): always emit tags object and harden API key tag parsing
Address review feedback: toApiKeyNode always emits "tags" (AWS returns "tags": {} even when empty); createApiKey coerces tag keys/values to String instead of an unchecked cast; the integration test initialises the shared apiKeyId to a sentinel and asserts the JSON error body on the 404 path.
* fix(apigateway): align 404 message and strip api key values from list by default
Address maintainer review: getApiKey now returns the AWS-accurate "Invalid API Key identifier specified" message; GetApiKeys honors the includeValues query param and omits each key's value unless requested (was leaking values by default); toApiKeyNode emits tags only when non-empty. Tests updated accordingly.
This commit is contained in:
1 parent
0626cd94d6
commit
2288da7f23
4 files changed
+133
-3
No files matched your search
+26
-2
@@ -613,15 +613,35 @@ public class ApiGatewayController {
|
||||
|
||||
@GET
|
||||
@Path("/apikeys")
|
||||
public Response getApiKeys(@Context HttpHeaders headers) {
|
||||
public Response getApiKeys(@Context HttpHeaders headers,
|
||||
@QueryParam("includeValues") boolean includeValues) {
|
||||
String region = regionResolver.resolveRegion(headers);
|
||||
List<ApiKey> keys = service.getApiKeys(region);
|
||||
ObjectNode root = objectMapper.createObjectNode();
|
||||
ArrayNode items = root.putArray("item");
|
||||
keys.forEach(k -> items.add(toApiKeyNode(k)));
|
||||
keys.forEach(k -> {
|
||||
ObjectNode node = toApiKeyNode(k);
|
||||
if (!includeValues) {
|
||||
node.remove("value");
|
||||
}
|
||||
items.add(node);
|
||||
});
|
||||
return Response.ok(root.toString()).type(MediaType.APPLICATION_JSON).build();
|
||||
}
|
||||
|
||||
@GET
|
||||
@Path("/apikeys/{apiKeyId}")
|
||||
public Response getApiKey(@Context HttpHeaders headers,
|
||||
@PathParam("apiKeyId") String apiKeyId,
|
||||
@QueryParam("includeValue") boolean includeValue) {
|
||||
String region = regionResolver.resolveRegion(headers);
|
||||
ObjectNode node = toApiKeyNode(service.getApiKey(region, apiKeyId));
|
||||
if (!includeValue) {
|
||||
node.remove("value");
|
||||
}
|
||||
return Response.ok(node.toString()).type(MediaType.APPLICATION_JSON).build();
|
||||
}
|
||||
|
||||
@POST
|
||||
@Path("/usageplans")
|
||||
public Response createUsagePlan(@Context HttpHeaders headers, String body) {
|
||||
@@ -1642,6 +1662,10 @@ public class ApiGatewayController {
|
||||
node.put("name", k.getName());
|
||||
node.put("value", k.getValue());
|
||||
node.put("enabled", k.isEnabled());
|
||||
if (k.getTags() != null && !k.getTags().isEmpty()) {
|
||||
ObjectNode tags = node.putObject("tags");
|
||||
k.getTags().forEach(tags::put);
|
||||
}
|
||||
return node;
|
||||
}
|
||||
|
||||
|
||||
@@ -661,6 +661,12 @@ public class ApiGatewayService {
|
||||
apiKey.setCreatedDate(System.currentTimeMillis() / 1000L);
|
||||
apiKey.setLastUpdatedDate(apiKey.getCreatedDate());
|
||||
|
||||
Map<String, String> tags = new HashMap<>();
|
||||
if (request.get("tags") instanceof Map<?, ?> rawTags) {
|
||||
rawTags.forEach((key, value) -> tags.put(String.valueOf(key), String.valueOf(value)));
|
||||
}
|
||||
apiKey.setTags(tags);
|
||||
|
||||
apiKeyStore.put(apiKeyGlobalKey(region, apiKey.getId()), apiKey);
|
||||
LOG.infov("Created API Key {0}", apiKey.getId());
|
||||
return apiKey;
|
||||
@@ -668,7 +674,7 @@ public class ApiGatewayService {
|
||||
|
||||
public ApiKey getApiKey(String region, String apiKeyId) {
|
||||
return apiKeyStore.get(apiKeyGlobalKey(region, apiKeyId))
|
||||
.orElseThrow(() -> new AwsException("NotFoundException", "API Key not found", 404));
|
||||
.orElseThrow(() -> new AwsException("NotFoundException", "Invalid API Key identifier specified", 404));
|
||||
}
|
||||
|
||||
public List<ApiKey> getApiKeys(String region) {
|
||||
|
||||
@@ -3,6 +3,9 @@ package io.github.hectorvent.floci.services.apigateway.model;
|
||||
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
|
||||
import io.quarkus.runtime.annotations.RegisterForReflection;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
@RegisterForReflection
|
||||
@JsonIgnoreProperties(ignoreUnknown = true)
|
||||
public class ApiKey {
|
||||
@@ -12,6 +15,7 @@ public class ApiKey {
|
||||
private boolean enabled;
|
||||
private long createdDate;
|
||||
private long lastUpdatedDate;
|
||||
private Map<String, String> tags = new HashMap<>();
|
||||
|
||||
public ApiKey() {}
|
||||
|
||||
@@ -32,4 +36,7 @@ public class ApiKey {
|
||||
|
||||
public long getLastUpdatedDate() { return lastUpdatedDate; }
|
||||
public void setLastUpdatedDate(long lastUpdatedDate) { this.lastUpdatedDate = lastUpdatedDate; }
|
||||
|
||||
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