Skip to content

Commit f606889

Browse files
authored
fix(aws): paginate IAM, RDS, and ECR list calls (#1812)
Four AWS list calls made a single API request without iterating pagination tokens, silently capping results at the first page. Same class of bug as the EC2 DescribeInstances/DescribeTags fixes already in v1. - iam.ListPolicyVersions in GetIamPolicyDocumentContextE searched for the default version, which could live on any page once AWS lifts the current five-version limit. - rds.DescribeOptionGroups in GetOptionsOfOptionGroupContextE filtered by name; switching to NewDescribeOptionGroupsPaginator keeps the contract defensive against any future pagination changes. - rds.DescribeOrderableDBInstanceOptions in instanceTypeExistsForEngineAndRegionContextE could miss matches if the first page was empty but later pages had results. - ecr.ListImages in DeleteECRRepoContextE deleted only the first page of images, leaking the rest and leaving DeleteRepository to fail. Switch each to the SDK's paginator helpers and the established loop pattern (see modules/aws/ec2.go:338). OSS-3454.
1 parent 99e37e8 commit f606889

3 files changed

Lines changed: 48 additions & 38 deletions

File tree

modules/aws/ecr.go

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -119,23 +119,26 @@ func DeleteECRRepoContextE(t testing.TestingT, ctx context.Context, region strin
119119
return err
120120
}
121121

122-
resp, err := client.ListImages(ctx, &ecr.ListImagesInput{RepositoryName: repo.RepositoryName})
123-
if err != nil {
124-
return err
125-
}
122+
paginator := ecr.NewListImagesPaginator(client, &ecr.ListImagesInput{RepositoryName: repo.RepositoryName})
123+
for paginator.HasMorePages() {
124+
page, err := paginator.NextPage(ctx)
125+
if err != nil {
126+
return err
127+
}
128+
129+
if len(page.ImageIds) == 0 {
130+
continue
131+
}
126132

127-
if len(resp.ImageIds) > 0 {
128-
_, err = client.BatchDeleteImage(ctx, &ecr.BatchDeleteImageInput{
133+
if _, err := client.BatchDeleteImage(ctx, &ecr.BatchDeleteImageInput{
129134
RepositoryName: repo.RepositoryName,
130-
ImageIds: resp.ImageIds,
131-
})
132-
if err != nil {
135+
ImageIds: page.ImageIds,
136+
}); err != nil {
133137
return err
134138
}
135139
}
136140

137-
_, err = client.DeleteRepository(ctx, &ecr.DeleteRepositoryInput{RepositoryName: repo.RepositoryName})
138-
if err != nil {
141+
if _, err := client.DeleteRepository(ctx, &ecr.DeleteRepositoryInput{RepositoryName: repo.RepositoryName}); err != nil {
139142
return err
140143
}
141144

modules/aws/iam.go

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -110,18 +110,21 @@ func GetIamPolicyDocumentContextE(t testing.TestingT, ctx context.Context, regio
110110
return "", err
111111
}
112112

113-
versions, err := iamClient.ListPolicyVersions(ctx, &iam.ListPolicyVersionsInput{
113+
var defaultVersion string
114+
115+
paginator := iam.NewListPolicyVersionsPaginator(iamClient, &iam.ListPolicyVersionsInput{
114116
PolicyArn: &policyARN,
115117
})
116-
if err != nil {
117-
return "", err
118-
}
119-
120-
var defaultVersion string
118+
for paginator.HasMorePages() {
119+
page, err := paginator.NextPage(ctx)
120+
if err != nil {
121+
return "", err
122+
}
121123

122-
for _, version := range versions.Versions {
123-
if version.IsDefaultVersion && version.VersionId != nil {
124-
defaultVersion = *version.VersionId
124+
for _, version := range page.Versions {
125+
if version.IsDefaultVersion && version.VersionId != nil {
126+
defaultVersion = *version.VersionId
127+
}
125128
}
126129
}
127130

modules/aws/rds.go

Lines changed: 22 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -369,18 +369,21 @@ func GetOptionsOfOptionGroupContextE(t testing.TestingT, ctx context.Context, op
369369
return []types.Option{}, err
370370
}
371371

372-
input := rds.DescribeOptionGroupsInput{OptionGroupName: aws.String(optionGroupName)}
373-
374-
output, err := rdsClient.DescribeOptionGroups(ctx, &input)
375-
if err != nil {
376-
return []types.Option{}, err
377-
}
372+
paginator := rds.NewDescribeOptionGroupsPaginator(rdsClient, &rds.DescribeOptionGroupsInput{
373+
OptionGroupName: aws.String(optionGroupName),
374+
})
375+
for paginator.HasMorePages() {
376+
page, err := paginator.NextPage(ctx)
377+
if err != nil {
378+
return []types.Option{}, err
379+
}
378380

379-
if len(output.OptionGroupsList) == 0 {
380-
return []types.Option{}, fmt.Errorf("no option groups found for name %s in region %s", optionGroupName, awsRegion)
381+
if len(page.OptionGroupsList) > 0 {
382+
return page.OptionGroupsList[0].Options, nil
383+
}
381384
}
382385

383-
return output.OptionGroupsList[0].Options, nil
386+
return []types.Option{}, fmt.Errorf("no option groups found for name %s in region %s", optionGroupName, awsRegion)
384387
}
385388

386389
// GetOptionsOfOptionGroupContext gets the options of the option group specified.
@@ -624,19 +627,20 @@ func GetRecommendedRdsInstanceTypeWithClientE(t testing.TestingT, rdsClient *rds
624627
// instanceTypeExistsForEngineAndRegionContextE returns a boolean that represents whether the provided instance type (e.g. db.t2.micro) exists for the given region and db engine type.
625628
// This function will return an error if the RDS AWS SDK call fails.
626629
func instanceTypeExistsForEngineAndRegionContextE(ctx context.Context, client *rds.Client, engine string, engineVersion string, instanceType string) (bool, error) {
627-
input := rds.DescribeOrderableDBInstanceOptionsInput{
630+
paginator := rds.NewDescribeOrderableDBInstanceOptionsPaginator(client, &rds.DescribeOrderableDBInstanceOptionsInput{
628631
Engine: aws.String(engine),
629632
EngineVersion: aws.String(engineVersion),
630633
DBInstanceClass: aws.String(instanceType),
631-
}
632-
633-
out, err := client.DescribeOrderableDBInstanceOptions(ctx, &input)
634-
if err != nil {
635-
return false, err
636-
}
634+
})
635+
for paginator.HasMorePages() {
636+
page, err := paginator.NextPage(ctx)
637+
if err != nil {
638+
return false, err
639+
}
637640

638-
if len(out.OrderableDBInstanceOptions) > 0 {
639-
return true, nil
641+
if len(page.OrderableDBInstanceOptions) > 0 {
642+
return true, nil
643+
}
640644
}
641645

642646
return false, nil

0 commit comments

Comments
 (0)