mirror of
https://github.com/floci-io/floci.git
synced 2026-11-28 16:11:48 -05:00
feat(ec2): page and filter DescribeTags as AWS does (#6109)
* feat(ec2): page and filter DescribeTags as AWS does DescribeTags ignored MaxResults and NextToken, so SDK paginators got a single page, and matched filter values exactly: tag:<key> was dropped, the * and ? wildcards matched literally, and a filter name given twice kept only the last one. It now pages with MaxResults (5 to 1000, InvalidMaxResults otherwise) and NextToken, takes tag:<key> as the documented alternate spelling of a key filter plus a value filter, honours wildcards, ORs the values of one filter and ANDs separate filters. Results are ordered by resource id so a page boundary stays put while no tags change. Signed-off-by: Hector Ventura <hectorvent@gmail.com> * fix(ec2): bound filter wildcards and refuse every out-of-range MaxResults EC2 filter wildcards were translated to a regex, so a caller-supplied pattern of many stars backtracked for seconds against a long value and `*` skipped line terminators. They now use the two-pointer glob IAM and S3 already share, which every EC2 Describe filter goes through. DescribeTags treated MaxResults=0 and negative values as unpaged; any value sent outside 5 to 1000 now answers InvalidMaxResults, and only a missing MaxResults is unpaged. A NextToken whose offset is at or past the end returns an empty last page instead of overflowing into a token that fails on the next call. The compat case moves to its own @Order. Signed-off-by: Hector Ventura <hectorvent@gmail.com> --------- Signed-off-by: Hector Ventura <hectorvent@gmail.com>
This commit is contained in:
1 parent
3baa38a346
commit
e5591dda32
6 files changed
+300
-77
No files matched your search
@@ -860,6 +860,40 @@ class Ec2Tests {
|
||||
.build());
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(52)
|
||||
@DisplayName("DescribeTags - paginator pages with MaxResults and honours tag:<key>")
|
||||
void describeTagsPaginatesAndFiltersByTagKey() {
|
||||
String pagedVpcId = ec2.createVpc(CreateVpcRequest.builder().cidrBlock("10.98.0.0/16").build())
|
||||
.vpc().vpcId();
|
||||
try {
|
||||
List<Tag> tags = new ArrayList<>();
|
||||
for (int i = 1; i <= 12; i++) {
|
||||
tags.add(Tag.builder().key(String.format("Page%02d", i)).value(i == 1 ? "TeamA" : "v").build());
|
||||
}
|
||||
ec2.createTags(CreateTagsRequest.builder().resources(pagedVpcId).tags(tags).build());
|
||||
Filter byId = Filter.builder().name("resource-id").values(pagedVpcId).build();
|
||||
|
||||
List<DescribeTagsResponse> pages = ec2.describeTagsPaginator(DescribeTagsRequest.builder()
|
||||
.filters(byId).maxResults(5).build()).stream().toList();
|
||||
assertThat(pages).extracting(page -> page.tags().size()).containsExactly(5, 5, 2);
|
||||
assertThat(pages.get(2).nextToken()).isNull();
|
||||
assertThat(pages.stream().flatMap(page -> page.tags().stream()).map(TagDescription::key).distinct())
|
||||
.hasSize(12);
|
||||
|
||||
assertThat(ec2.describeTags(DescribeTagsRequest.builder()
|
||||
.filters(byId, Filter.builder().name("tag:Page01").values("Team?").build())
|
||||
.build()).tags())
|
||||
.singleElement()
|
||||
.satisfies(tag -> {
|
||||
assertThat(tag.key()).isEqualTo("Page01");
|
||||
assertThat(tag.resourceType()).isEqualTo(ResourceType.VPC);
|
||||
});
|
||||
} finally {
|
||||
ec2.deleteVpc(DeleteVpcRequest.builder().vpcId(pagedVpcId).build());
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
@Order(38)
|
||||
@DisplayName("DescribeInstances - tags reflected on instance")
|
||||
|
||||
Reference in new issue
Block a user