Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added support to query the aws_ecr_image_scan_finding table using the image_digest query parameter. Closes #2356 #2357

Merged
merged 1 commit into from
Dec 17, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 22 additions & 5 deletions aws/table_aws_ecr_image_scan_finding.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@ func tableAwsEcrImageScanFinding(_ context.Context) *plugin.Table {
// image_digest as it's more common/friendly to use.
KeyColumns: []*plugin.KeyColumn{
{Name: "repository_name", Require: plugin.Required},
{Name: "image_tag", Require: plugin.Required},
{Name: "image_tag", Require: plugin.AnyOf},
{Name: "image_digest", Require: plugin.AnyOf},
},
},
GetMatrixItemFunc: SupportedRegionMatrix(ecrv1.EndpointsID),
Expand Down Expand Up @@ -125,8 +126,8 @@ func listAwsEcrImageScanFindings(ctx context.Context, d *plugin.QueryData, _ *pl
}

imageTag := d.EqualsQuals["image_tag"]
imageDigest := d.EqualsQuals["image_digest"]
repositoryName := d.EqualsQuals["repository_name"]


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

imageInfo := &types.ImageIdentifier{}

// Ideally, both image_tag and image_digest could be used.
// However, they cannot be passed together simultaneously.
// 1. If ImageTag is provided, it takes precedence and is used as the input parameter.
// 2. If both ImageTag and ImageDigest are provided, ImageTag will be prioritized to keep the existing table behavior unchanged.
// 3. If only ImageDigest is provided, the ImageDigest value will be used as the input parameter.
if imageTag != nil {
imageInfo.ImageTag = aws.String(imageTag.GetStringValue())
}
if imageTag != nil && imageDigest != nil {
imageInfo.ImageTag = aws.String(imageTag.GetStringValue())
}
if imageTag == nil && imageDigest != nil {
imageInfo.ImageDigest = aws.String(imageDigest.GetStringValue())
}

input.ImageId = imageInfo

paginator := ecr.NewDescribeImageScanFindingsPaginator(svc, input, func(o *ecr.DescribeImageScanFindingsPaginatorOptions) {
o.Limit = maxLimit
o.StopOnDuplicateToken = true
Expand Down
Loading