Skip to content
This repository has been archived by the owner on Oct 15, 2024. It is now read-only.

Commit

Permalink
Enable paging for KMS Keys (#549)
Browse files Browse the repository at this point in the history
  • Loading branch information
hligit authored Sep 3, 2020
1 parent 3fe7ac3 commit 7d12644
Showing 1 changed file with 38 additions and 21 deletions.
59 changes: 38 additions & 21 deletions resources/kms-keys.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,32 +23,49 @@ func init() {

func ListKMSKeys(sess *session.Session) ([]Resource, error) {
svc := kms.New(sess)
resources := make([]Resource, 0)

var innerErr error
err := svc.ListKeysPages(nil, func(resp *kms.ListKeysOutput, lastPage bool) bool {
for _, key := range resp.Keys {
tags, err := svc.ListResourceTags(&kms.ListResourceTagsInput{
KeyId: key.KeyId,
})
if err != nil {
innerErr = err
return false
}

resp, err := svc.DescribeKey(&kms.DescribeKeyInput{
KeyId: key.KeyId,
})
if err != nil {
innerErr = err
return false
}

resources = append(resources, &KMSKey{
svc: svc,
id: *resp.KeyMetadata.KeyId,
state: *resp.KeyMetadata.KeyState,
manager: resp.KeyMetadata.KeyManager,
tags: tags.Tags,
})
}

if lastPage {
return false
}

return true
})

resp, err := svc.ListKeys(nil)
if err != nil {
return nil, err
}

resources := make([]Resource, 0)
for _, key := range resp.Keys {
tags, err := svc.ListResourceTags(&kms.ListResourceTagsInput{
KeyId: key.KeyId,
})

resp, err := svc.DescribeKey(&kms.DescribeKeyInput{
KeyId: key.KeyId,
})
if err != nil {
return nil, err
}

resources = append(resources, &KMSKey{
svc: svc,
id: *resp.KeyMetadata.KeyId,
state: *resp.KeyMetadata.KeyState,
manager: resp.KeyMetadata.KeyManager,
tags: tags.Tags,
})
if innerErr != nil {
return nil, err
}

return resources, nil
Expand Down

0 comments on commit 7d12644

Please sign in to comment.