Skip to content

Commit

Permalink
fix pagination bug (#35)
Browse files Browse the repository at this point in the history
  • Loading branch information
mcalhoun authored Aug 30, 2022
1 parent c0b9b0a commit ffe99d0
Showing 1 changed file with 14 additions and 7 deletions.
21 changes: 14 additions & 7 deletions internal/service/securityhub/find.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,21 +46,28 @@ func FindSecurityHubControl(conn *securityhub.SecurityHub, controlArn string) (*
StandardsSubscriptionArn: s.StandardsSubscriptionArn,
}

controls, err := conn.DescribeStandardsControls(input)

for _, c := range controls.Controls {
if *c.StandardsControlArn == controlArn {
return c, nil
var foundControl *securityhub.StandardsControl
err := conn.DescribeStandardsControlsPages(input, func(page *securityhub.DescribeStandardsControlsOutput, lastPage bool) bool {
for _, c := range page.Controls {
if *c.StandardsControlArn == controlArn {
foundControl = c
return false
}
}
}
return !lastPage
})

if err != nil {
return nil, err
}

if foundControl != nil {
return foundControl, nil
}
}

return nil, &resource.NotFoundError{
Message: fmt.Sprintf("%s is not a valid control arn", controlArn),
Message: fmt.Sprintf("Could not find a control with arn %s", controlArn),
}
}

Expand Down

0 comments on commit ffe99d0

Please sign in to comment.