fix(bedrock): list guardrails in the tagging api and route its writes (#6646)

* fix(bedrock): list guardrails in the tagging api and route its writes

guardrails were not a ResourceProvider, so GetResources with bedrock:guardrail came back empty, and TagResources had no bedrock handler to forward to. list the draft of each guardrail with its own tags and add a tagging-api-only handler that calls the existing tag methods.

* test(bedrock): cover guardrail discovery and tagging writes with the sdk
This commit is contained in:
berce authored and GitHub committed 2026-10-26 12:05:47 -04:00
1 parent 8b13c75fa2
commit c4ad788e62
6 files changed
+184 -1

No files matched your search

@@ -9,6 +9,9 @@ import io.github.hectorvent.floci.core.common.AwsException;
import io.github.hectorvent.floci.core.common.PaginatedResult;
import io.github.hectorvent.floci.core.common.Pagination;
import io.github.hectorvent.floci.core.common.RegionResolver;
import io.github.hectorvent.floci.core.resource.ExplorerResource;
import io.github.hectorvent.floci.core.resource.ResourceProvider;
import io.github.hectorvent.floci.core.resource.SupportedResourceType;
import io.github.hectorvent.floci.core.storage.StorageBackend;
import io.github.hectorvent.floci.core.storage.StorageFactory;
import io.github.hectorvent.floci.services.bedrock.model.Guardrail;
@@ -25,6 +28,7 @@ import java.util.HashMap;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.Set;
import java.util.UUID;
import java.util.regex.Pattern;
@@ -39,7 +43,7 @@ import java.util.regex.Pattern;
* this signing name but serves the {@code /model/...} routes.
*/
@ApplicationScoped
public class BedrockService {
public class BedrockService implements ResourceProvider {
public static final String DRAFT_VERSION = "DRAFT";
public static final String READY = "READY";
@@ -274,6 +278,30 @@ public class BedrockService {
guardrails.put(storageKey(region, guardrail.getGuardrailId(), DRAFT_VERSION), guardrail);
}
// Resource discovery (Resource Groups Tagging API, Resource Explorer)
@Override
public List<ExplorerResource> getResources() {
List<ExplorerResource> resources = new ArrayList<>();
for (String key : guardrails.keys()) {
// Versions share the draft's ARN, and tags live on the draft, so only the draft is listed.
if (!key.endsWith("::" + DRAFT_VERSION)) {
continue;
}
guardrails.get(key).ifPresent(guardrail -> resources.add(new ExplorerResource(
guardrail.getGuardrailArn(), "bedrock:guardrail", "bedrock",
key.substring(0, key.indexOf("::")), guardrail.getAccountId(),
guardrail.getCreatedAt() != null ? guardrail.getCreatedAt() : Instant.now(),
guardrail.getTags() != null ? guardrail.getTags() : Map.of())));
}
return resources;
}
@Override
public Set<SupportedResourceType> getSupportedResourceTypes() {
return Set.of(new SupportedResourceType("bedrock:guardrail", "bedrock", true));
}
// Helpers
private void applyPolicies(Guardrail guardrail, JsonNode request, String region) {
@@ -0,0 +1,48 @@
package io.github.hectorvent.floci.services.bedrock;
import io.github.hectorvent.floci.core.common.TagHandler;
import io.github.hectorvent.floci.core.common.TaggingApiOnly;
import jakarta.enterprise.context.ApplicationScoped;
import jakarta.inject.Inject;
import java.util.List;
import java.util.Map;
/**
* Lets Resource Groups Tagging API writes reach a guardrail's own tags (#6235).
*
* <p>A separate {@link TaggingApiOnly} bean because Bedrock tags through its own
* {@code TagResource} action: a default-qualified handler would also serve guardrails on
* {@code /tags/{arn}}, which AWS does not define.
*/
@ApplicationScoped
@TaggingApiOnly
public class BedrockTagHandler implements TagHandler {
private final BedrockService bedrockService;
@Inject
public BedrockTagHandler(BedrockService bedrockService) {
this.bedrockService = bedrockService;
}
@Override
public String serviceKey() {
return "bedrock";
}
@Override
public Map<String, String> listTags(String region, String arn) {
return bedrockService.listTags(arn, region);
}
@Override
public void tagResource(String region, String arn, Map<String, String> tags) {
bedrockService.tagResource(arn, tags, region);
}
@Override
public void untagResource(String region, String arn, List<String> tagKeys) {
bedrockService.untagResource(arn, tagKeys, region);
}
}