Skip to content

Commit 9e523fa

Browse files
authored
Added support to query the aws_ecr_image_scan_finding table using the image_digest query parameter. Closes #2356 (#2357)
1 parent 3d2b869 commit 9e523fa

File tree

1 file changed

+22
-5
lines changed

1 file changed

+22
-5
lines changed

aws/table_aws_ecr_image_scan_finding.go

+22-5
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,8 @@ func tableAwsEcrImageScanFinding(_ context.Context) *plugin.Table {
3333
// image_digest as it's more common/friendly to use.
3434
KeyColumns: []*plugin.KeyColumn{
3535
{Name: "repository_name", Require: plugin.Required},
36-
{Name: "image_tag", Require: plugin.Required},
36+
{Name: "image_tag", Require: plugin.AnyOf},
37+
{Name: "image_digest", Require: plugin.AnyOf},
3738
},
3839
},
3940
GetMatrixItemFunc: SupportedRegionMatrix(ecrv1.EndpointsID),
@@ -125,8 +126,8 @@ func listAwsEcrImageScanFindings(ctx context.Context, d *plugin.QueryData, _ *pl
125126
}
126127

127128
imageTag := d.EqualsQuals["image_tag"]
129+
imageDigest := d.EqualsQuals["image_digest"]
128130
repositoryName := d.EqualsQuals["repository_name"]
129-
130131

131132
// Limiting the results
132133
maxLimit := int32(1000)
@@ -140,11 +141,27 @@ func listAwsEcrImageScanFindings(ctx context.Context, d *plugin.QueryData, _ *pl
140141
input := &ecr.DescribeImageScanFindingsInput{
141142
MaxResults: aws.Int32(maxLimit),
142143
RepositoryName: aws.String(repositoryName.GetStringValue()),
143-
ImageId: &types.ImageIdentifier{
144-
ImageTag: aws.String(imageTag.GetStringValue()),
145-
},
146144
}
147145

146+
imageInfo := &types.ImageIdentifier{}
147+
148+
// Ideally, both image_tag and image_digest could be used.
149+
// However, they cannot be passed together simultaneously.
150+
// 1. If ImageTag is provided, it takes precedence and is used as the input parameter.
151+
// 2. If both ImageTag and ImageDigest are provided, ImageTag will be prioritized to keep the existing table behavior unchanged.
152+
// 3. If only ImageDigest is provided, the ImageDigest value will be used as the input parameter.
153+
if imageTag != nil {
154+
imageInfo.ImageTag = aws.String(imageTag.GetStringValue())
155+
}
156+
if imageTag != nil && imageDigest != nil {
157+
imageInfo.ImageTag = aws.String(imageTag.GetStringValue())
158+
}
159+
if imageTag == nil && imageDigest != nil {
160+
imageInfo.ImageDigest = aws.String(imageDigest.GetStringValue())
161+
}
162+
163+
input.ImageId = imageInfo
164+
148165
paginator := ecr.NewDescribeImageScanFindingsPaginator(svc, input, func(o *ecr.DescribeImageScanFindingsPaginatorOptions) {
149166
o.Limit = maxLimit
150167
o.StopOnDuplicateToken = true

0 commit comments

Comments
 (0)