mirror of
https://github.com/floci-io/floci.git
synced 2026-11-24 06:20:24 -05:00
feat(athena): support ListTagsForResource for workgroups (#3242)
* feat(athena): support ListTagsForResource for workgroups Fixes #2791. terraform-provider-aws's read/refresh for aws_athena_workgroup calls ListTagsForResource unconditionally, even when no tags are set, and floci's Athena handler had no support for the action: Error: listing tags for Athena WorkGroup ...: InvalidAction: Action ListTagsForResource is not supported Parses the workgroup name out of the ResourceARN (using the existing AwsArnUtils helper) and returns the tags already captured on CreateWorkGroup. The primary workgroup always answers with an empty list, matching a live account, since CreateWorkGroup already rejects "primary" and it can never carry real tags. An ARN for an unsupported resource type, or naming a workgroup that doesn't exist, faults with InvalidRequestException like the rest of this handler's not-found cases. * docs(athena): sync the supported-actions table for ListTagsForResource * fix(athena): reject ListTagsForResource ARNs naming a different service pgermosen (review): listTagsForResource only checked that the ARN's resource path started with workgroup/, never the service, so an ARN naming a completely different service with a coincidentally matching region and workgroup name resolved instead of being rejected the way real AWS rejects a ResourceARN naming the wrong service. Adds the explicit arn.service() == "athena" check, plus a RestAssured test proving a workgroup-shaped ARN under a different service is rejected even when a same-named workgroup genuinely exists. Verified by disabling the check and confirming the new test fails with the exact expected 400-vs-200 mismatch before restoring it. Also adds an SDK-client test (AthenaTest, compat suite) round-tripping ListTagsForResource through the real AthenaClient, per review request to validate request/response shapes the way other management API PRs do.
This commit is contained in:
1 parent
d466ffe099
commit
b988dc5d1a
5 files changed
+255
No files matched your search
@@ -94,6 +94,10 @@ public class AthenaJsonHandler {
|
||||
String tableName = request.get("TableName").asText();
|
||||
yield Response.ok(Map.of("TableMetadata", athenaService.getTableMetadata(catalog, database, tableName))).build();
|
||||
}
|
||||
case "ListTagsForResource" -> {
|
||||
String resourceArn = request.path("ResourceARN").asText(null);
|
||||
yield Response.ok(Map.of("Tags", athenaService.listTagsForResource(resourceArn))).build();
|
||||
}
|
||||
case "DeleteWorkGroup" -> {
|
||||
String wg = request.path("WorkGroup").asText(null);
|
||||
if (wg == null || !wg.matches("[a-zA-Z0-9._-]{1,128}")) {
|
||||
|
||||
@@ -2,6 +2,7 @@ package io.github.hectorvent.floci.services.athena;
|
||||
|
||||
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.common.CsvParser;
|
||||
import io.github.hectorvent.floci.core.storage.StorageBackend;
|
||||
@@ -206,6 +207,40 @@ public class AthenaService {
|
||||
workGroupStore.delete(workGroupKey(region, name));
|
||||
}
|
||||
|
||||
/**
|
||||
* github.com/floci-io/floci/issues/2791: terraform-provider-aws calls this on every
|
||||
* aws_athena_workgroup refresh, tags or not. Only workgroup ARNs are supported - the
|
||||
* primary workgroup can't be tagged and always answers with an empty list, matching a live
|
||||
* account (CreateWorkGroup already rejects "primary", so it can never carry real tags).
|
||||
*/
|
||||
public List<WorkGroupTag> listTagsForResource(String resourceArn) {
|
||||
if (resourceArn == null || resourceArn.isBlank()) {
|
||||
throw new AwsException("InvalidRequestException", "ResourceARN is required.", 400);
|
||||
}
|
||||
AwsArnUtils.Arn arn;
|
||||
try {
|
||||
arn = AwsArnUtils.parse(resourceArn);
|
||||
} catch (IllegalArgumentException e) {
|
||||
throw new AwsException("InvalidRequestException", "Invalid ResourceARN: " + resourceArn, 400);
|
||||
}
|
||||
// pgermosen (review, #3242): without this, an ARN naming a completely different
|
||||
// service (e.g. a Neptune workgroup/-shaped resource that coincidentally shares this
|
||||
// region and name) would resolve instead of being rejected the way a live account
|
||||
// rejects a ResourceARN naming the wrong service.
|
||||
if (!"athena".equals(arn.service()) || !arn.resource().startsWith("workgroup/")) {
|
||||
throw new AwsException("InvalidRequestException",
|
||||
"Unsupported resource type for ListTagsForResource: " + resourceArn, 400);
|
||||
}
|
||||
String name = arn.resource().substring("workgroup/".length());
|
||||
if (DEFAULT_WORKGROUP.equals(name)) {
|
||||
return List.of();
|
||||
}
|
||||
WorkGroup workGroup = workGroupStore.get(workGroupKey(arn.region(), name))
|
||||
.orElseThrow(() -> new AwsException("InvalidRequestException",
|
||||
"WorkGroup " + name + " is not found.", 400));
|
||||
return workGroup.getTags();
|
||||
}
|
||||
|
||||
public List<Map<String, Object>> listWorkGroups(String region) {
|
||||
List<Map<String, Object>> workGroups = new ArrayList<>();
|
||||
workGroups.add(primaryWorkGroupSummary());
|
||||
|
||||
Reference in new issue
Block a user