Skip to content

Commit

Permalink
Merge pull request #206 from ekristen/fix-kms-alias-pagination
Browse files Browse the repository at this point in the history
feat(kms-alias): support pagination
  • Loading branch information
ekristen authored Jul 6, 2024
2 parents 22fa90e + 30e1dbe commit 0a60088
Showing 1 changed file with 14 additions and 15 deletions.
29 changes: 14 additions & 15 deletions resources/kms-aliases.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,6 @@ import (
"fmt"
"strings"

"github.com/gotidy/ptr"

"github.com/aws/aws-sdk-go/service/kms"

"github.com/ekristen/libnuke/pkg/registry"
Expand All @@ -34,43 +32,44 @@ func (l *KMSAliasLister) List(_ context.Context, o interface{}) ([]resource.Reso

svc := kms.New(opts.Session)

resp, err := svc.ListAliases(nil)
resources := make([]resource.Resource, 0)
err := svc.ListAliasesPages(nil, func(page *kms.ListAliasesOutput, lastPage bool) bool {
for _, alias := range page.Aliases {
resources = append(resources, &KMSAlias{
svc: svc,
name: alias.AliasName,
})
}
return true
})
if err != nil {
return nil, err
}

resources := make([]resource.Resource, 0)
for _, alias := range resp.Aliases {
resources = append(resources, &KMSAlias{
svc: svc,
name: ptr.ToString(alias.AliasName),
})
}

return resources, nil
}

type KMSAlias struct {
svc *kms.KMS
name string
name *string
}

func (e *KMSAlias) Filter() error {
if strings.HasPrefix(e.name, "alias/aws/") {
if strings.HasPrefix(*e.name, "alias/aws/") {
return fmt.Errorf("cannot delete AWS alias")
}
return nil
}

func (e *KMSAlias) Remove(_ context.Context) error {
_, err := e.svc.DeleteAlias(&kms.DeleteAliasInput{
AliasName: &e.name,
AliasName: e.name,
})
return err
}

func (e *KMSAlias) String() string {
return e.name
return *e.name
}

func (e *KMSAlias) Properties() types.Properties {
Expand Down

0 comments on commit 0a60088

Please sign in to comment.