mirror of
https://github.com/floci-io/floci.git
synced 2026-11-22 21:50:46 -05:00
feat(iam): add ListInstanceProfileTags (#4140)
TagInstanceProfile and UntagInstanceProfile already existed; the read side was missing. Mirrors ListUserTags's response shape, and sorts the result by tag key to match the documented AWS behavior. Also adds the instance-profile tag actions to AwsQueryController's IAM_ACTIONS fallback set, completing the Tag/Untag/List triple already present there for users, roles and policies. Covers the trio in the SDK compatibility suite (compatibility-tests), which previously had no instance-profile tagging coverage.
This commit is contained in:
1 parent
63c0c3ada5
commit
2f5aa99701
6 files changed
+170
No files matched your search
@@ -57,6 +57,8 @@ import software.amazon.awssdk.services.iam.model.ListAttachedUserPoliciesRespons
|
||||
import software.amazon.awssdk.services.iam.model.ListEntitiesForPolicyResponse;
|
||||
import software.amazon.awssdk.services.iam.model.ListGroupsForUserRequest;
|
||||
import software.amazon.awssdk.services.iam.model.ListGroupsForUserResponse;
|
||||
import software.amazon.awssdk.services.iam.model.ListInstanceProfileTagsRequest;
|
||||
import software.amazon.awssdk.services.iam.model.ListInstanceProfileTagsResponse;
|
||||
import software.amazon.awssdk.services.iam.model.ListInstanceProfilesResponse;
|
||||
import software.amazon.awssdk.services.iam.model.ListRolePoliciesRequest;
|
||||
import software.amazon.awssdk.services.iam.model.ListRolePoliciesResponse;
|
||||
@@ -71,7 +73,10 @@ import software.amazon.awssdk.services.iam.model.RemoveRoleFromInstanceProfileRe
|
||||
import software.amazon.awssdk.services.iam.model.RemoveUserFromGroupRequest;
|
||||
import software.amazon.awssdk.services.iam.model.SimulatePrincipalPolicyRequest;
|
||||
import software.amazon.awssdk.services.iam.model.StatusType;
|
||||
import software.amazon.awssdk.services.iam.model.Tag;
|
||||
import software.amazon.awssdk.services.iam.model.TagInstanceProfileRequest;
|
||||
import software.amazon.awssdk.services.iam.model.TagUserRequest;
|
||||
import software.amazon.awssdk.services.iam.model.UntagInstanceProfileRequest;
|
||||
import software.amazon.awssdk.services.iam.model.UntagUserRequest;
|
||||
import software.amazon.awssdk.services.iam.model.UpdateAccessKeyRequest;
|
||||
import software.amazon.awssdk.services.iam.model.UpdateLoginProfileRequest;
|
||||
@@ -540,6 +545,32 @@ class IamTest {
|
||||
.anyMatch(p -> INSTANCE_PROFILE_NAME.equals(p.instanceProfileName()));
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(44)
|
||||
void tagInstanceProfile() {
|
||||
iam.tagInstanceProfile(TagInstanceProfileRequest.builder()
|
||||
.instanceProfileName(INSTANCE_PROFILE_NAME)
|
||||
.tags(Tag.builder().key("env").value("sdk-test").build())
|
||||
.build());
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(45)
|
||||
void listInstanceProfileTags() {
|
||||
ListInstanceProfileTagsResponse response = iam.listInstanceProfileTags(
|
||||
ListInstanceProfileTagsRequest.builder().instanceProfileName(INSTANCE_PROFILE_NAME).build());
|
||||
|
||||
assertThat(response.tags())
|
||||
.anyMatch(t -> "env".equals(t.key()));
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(46)
|
||||
void untagInstanceProfile() {
|
||||
iam.untagInstanceProfile(UntagInstanceProfileRequest.builder()
|
||||
.instanceProfileName(INSTANCE_PROFILE_NAME).tagKeys("env").build());
|
||||
}
|
||||
|
||||
// ── Login Profile ──────────────────────────────────────────────────
|
||||
|
||||
@Test
|
||||
|
||||
@@ -140,6 +140,7 @@ type.
|
||||
| ListInstanceProfilesForRole | Lists instance profiles associated with a role. |
|
||||
| TagInstanceProfile | Adds tags to an instance profile. |
|
||||
| UntagInstanceProfile | Removes tags from an instance profile. |
|
||||
| ListInstanceProfileTags | Lists tags stored for an instance profile. |
|
||||
|
||||
### Access Keys
|
||||
|
||||
|
||||
@@ -102,6 +102,7 @@ public class AwsQueryController {
|
||||
"TagUser", "UntagUser", "ListUserTags",
|
||||
"TagRole", "UntagRole", "ListRoleTags",
|
||||
"TagPolicy", "UntagPolicy", "ListPolicyTags",
|
||||
"TagInstanceProfile", "UntagInstanceProfile", "ListInstanceProfileTags",
|
||||
"CreateLoginProfile", "GetLoginProfile", "DeleteLoginProfile", "UpdateLoginProfile",
|
||||
"GenerateCredentialReport", "GetCredentialReport",
|
||||
"GetAccountSummary", "GetAccountAuthorizationDetails",
|
||||
|
||||
@@ -25,6 +25,7 @@ import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.TreeMap;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
/**
|
||||
@@ -122,6 +123,7 @@ public class IamQueryHandler {
|
||||
case "UntagRole" -> handleUntagRole(params);
|
||||
case "TagInstanceProfile" -> handleTagInstanceProfile(params);
|
||||
case "UntagInstanceProfile" -> handleUntagInstanceProfile(params);
|
||||
case "ListInstanceProfileTags" -> handleListInstanceProfileTags(params);
|
||||
case "ListRoleTags" -> handleListRoleTags(params);
|
||||
|
||||
// Managed Policies
|
||||
@@ -1522,4 +1524,13 @@ public class IamQueryHandler {
|
||||
iamService.untagInstanceProfile(getParam(params, "InstanceProfileName"), extractTagKeys(params));
|
||||
return Response.ok(AwsQueryResponse.envelopeNoResult("UntagInstanceProfile", AwsNamespaces.IAM)).build();
|
||||
}
|
||||
|
||||
private Response handleListInstanceProfileTags(MultivaluedMap<String, String> params) {
|
||||
String instanceProfileName = getParam(params, "InstanceProfileName");
|
||||
// AWS documents the result as sorted by tag key.
|
||||
Map<String, String> tags = new TreeMap<>(iamService.listInstanceProfileTags(instanceProfileName));
|
||||
String result = new XmlBuilder().start("Tags").raw(tagsXml(tags)).end("Tags")
|
||||
.elem("IsTruncated", false).build();
|
||||
return Response.ok(AwsQueryResponse.envelope("ListInstanceProfileTags", AwsNamespaces.IAM, result)).build();
|
||||
}
|
||||
}
|
||||
@@ -2633,4 +2633,8 @@ public class IamService implements SessionAccountLookup, ResourceProvider {
|
||||
tagKeys.forEach(profile.getTags()::remove);
|
||||
instanceProfiles.put(instanceProfileName, profile);
|
||||
}
|
||||
|
||||
public Map<String, String> listInstanceProfileTags(String instanceProfileName) {
|
||||
return getInstanceProfile(instanceProfileName).getTags();
|
||||
}
|
||||
}
|
||||
+122
@@ -7,6 +7,8 @@ import java.util.UUID;
|
||||
|
||||
import static io.restassured.RestAssured.given;
|
||||
import static org.hamcrest.Matchers.containsString;
|
||||
import static org.hamcrest.Matchers.not;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
/**
|
||||
* Verifies TagInstanceProfile and UntagInstanceProfile wire compatibility:
|
||||
@@ -197,4 +199,124 @@ class InstanceProfileTagsIntegrationTest {
|
||||
.then().statusCode(400)
|
||||
.body(containsString("ValidationError"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void listInstanceProfileTagsReturnsTagsPreviouslySet() {
|
||||
String profile = "list-test-" + UUID.randomUUID().toString().substring(0, 8);
|
||||
createProfile(profile);
|
||||
|
||||
given()
|
||||
.contentType("application/x-www-form-urlencoded")
|
||||
.formParam("Action", "TagInstanceProfile")
|
||||
.formParam("InstanceProfileName", profile)
|
||||
.formParam("Tags.member.1.Key", "team")
|
||||
.formParam("Tags.member.1.Value", "platform")
|
||||
.header("Authorization", auth(ACCOUNT, "iam"))
|
||||
.when().post("/")
|
||||
.then().statusCode(200);
|
||||
|
||||
given()
|
||||
.contentType("application/x-www-form-urlencoded")
|
||||
.formParam("Action", "ListInstanceProfileTags")
|
||||
.formParam("InstanceProfileName", profile)
|
||||
.header("Authorization", auth(ACCOUNT, "iam"))
|
||||
.when().post("/")
|
||||
.then().statusCode(200)
|
||||
.body(containsString("<Key>team</Key>"))
|
||||
.body(containsString("<Value>platform</Value>"));
|
||||
}
|
||||
|
||||
/** AWS documents ListInstanceProfileTags as returning results sorted by tag key. */
|
||||
@Test
|
||||
void listInstanceProfileTagsAreSortedByKey() {
|
||||
String profile = "list-sort-" + UUID.randomUUID().toString().substring(0, 8);
|
||||
createProfile(profile);
|
||||
|
||||
given()
|
||||
.contentType("application/x-www-form-urlencoded")
|
||||
.formParam("Action", "TagInstanceProfile")
|
||||
.formParam("InstanceProfileName", profile)
|
||||
.formParam("Tags.member.1.Key", "zebra")
|
||||
.formParam("Tags.member.1.Value", "1")
|
||||
.formParam("Tags.member.2.Key", "alpha")
|
||||
.formParam("Tags.member.2.Value", "2")
|
||||
.header("Authorization", auth(ACCOUNT, "iam"))
|
||||
.when().post("/")
|
||||
.then().statusCode(200);
|
||||
|
||||
String body = given()
|
||||
.contentType("application/x-www-form-urlencoded")
|
||||
.formParam("Action", "ListInstanceProfileTags")
|
||||
.formParam("InstanceProfileName", profile)
|
||||
.header("Authorization", auth(ACCOUNT, "iam"))
|
||||
.when().post("/")
|
||||
.then().statusCode(200)
|
||||
.extract().asString();
|
||||
|
||||
assertTrue(body.indexOf("<Key>alpha</Key>") < body.indexOf("<Key>zebra</Key>"),
|
||||
"expected alpha before zebra in: " + body);
|
||||
}
|
||||
|
||||
@Test
|
||||
void listInstanceProfileTagsOnUntaggedProfileReturnsEmptyList() {
|
||||
String profile = "list-empty-" + UUID.randomUUID().toString().substring(0, 8);
|
||||
createProfile(profile);
|
||||
|
||||
given()
|
||||
.contentType("application/x-www-form-urlencoded")
|
||||
.formParam("Action", "ListInstanceProfileTags")
|
||||
.formParam("InstanceProfileName", profile)
|
||||
.header("Authorization", auth(ACCOUNT, "iam"))
|
||||
.when().post("/")
|
||||
.then().statusCode(200)
|
||||
.body(not(containsString("<Key>")));
|
||||
}
|
||||
|
||||
@Test
|
||||
void listInstanceProfileTagsRoutedViaActionFallbackWhenAuthHeaderAbsent() {
|
||||
// Exercises AwsQueryController.inferServiceFromAction -> IAM_ACTIONS dispatch
|
||||
// when no Authorization header is present (no SigV4 credential scope to resolve).
|
||||
// The whole scenario stays unauthenticated so the create and the later calls
|
||||
// land in the same account context.
|
||||
String profile = "list-fallback-" + UUID.randomUUID().toString().substring(0, 8);
|
||||
|
||||
given()
|
||||
.contentType("application/x-www-form-urlencoded")
|
||||
.formParam("Action", "CreateInstanceProfile")
|
||||
.formParam("InstanceProfileName", profile)
|
||||
.when().post("/")
|
||||
.then().statusCode(200);
|
||||
|
||||
given()
|
||||
.contentType("application/x-www-form-urlencoded")
|
||||
.formParam("Action", "TagInstanceProfile")
|
||||
.formParam("InstanceProfileName", profile)
|
||||
.formParam("Tags.member.1.Key", "team")
|
||||
.formParam("Tags.member.1.Value", "platform")
|
||||
.when().post("/")
|
||||
.then().statusCode(200);
|
||||
|
||||
given()
|
||||
.contentType("application/x-www-form-urlencoded")
|
||||
.formParam("Action", "ListInstanceProfileTags")
|
||||
.formParam("InstanceProfileName", profile)
|
||||
.when().post("/")
|
||||
.then().statusCode(200)
|
||||
.body(containsString("ListInstanceProfileTagsResponse"))
|
||||
.body(containsString("<Key>team</Key>"));
|
||||
}
|
||||
|
||||
@Test
|
||||
void listInstanceProfileTagsOnNonexistentProfileReturnsNoSuchEntity() {
|
||||
String profile = "list-no-such-" + UUID.randomUUID().toString().substring(0, 8);
|
||||
|
||||
given()
|
||||
.contentType("application/x-www-form-urlencoded")
|
||||
.formParam("Action", "ListInstanceProfileTags")
|
||||
.formParam("InstanceProfileName", profile)
|
||||
.header("Authorization", auth(ACCOUNT, "iam"))
|
||||
.when().post("/")
|
||||
.then().statusCode(404)
|
||||
.body(containsString("NoSuchEntity"));
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user