Skip to content

Commit f7ebb4d

Browse files
committed
fix(access-analyzer): scan all types, filter org level
1 parent ce918d3 commit f7ebb4d

File tree

1 file changed

+15
-5
lines changed

1 file changed

+15
-5
lines changed

resources/accessanalyzer-analyzer.go

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,11 @@ package resources
22

33
import (
44
"context"
5+
"errors"
6+
"strings"
7+
8+
"github.com/gotidy/ptr"
59

6-
"github.com/aws/aws-sdk-go/aws"
710
"github.com/aws/aws-sdk-go/service/accessanalyzer"
811

912
"github.com/ekristen/libnuke/pkg/registry"
@@ -30,12 +33,10 @@ type AccessAnalyzerLister struct{}
3033
func (l *AccessAnalyzerLister) List(_ context.Context, o interface{}) ([]resource.Resource, error) {
3134
opts := o.(*nuke.ListerOpts)
3235
svc := accessanalyzer.New(opts.Session)
36+
resources := make([]resource.Resource, 0)
3337

34-
params := &accessanalyzer.ListAnalyzersInput{
35-
Type: aws.String("ACCOUNT"),
36-
}
38+
params := &accessanalyzer.ListAnalyzersInput{}
3739

38-
resources := make([]resource.Resource, 0)
3940
if err := svc.ListAnalyzersPages(params,
4041
func(page *accessanalyzer.ListAnalyzersOutput, lastPage bool) bool {
4142
for _, analyzer := range page.Analyzers {
@@ -44,6 +45,7 @@ func (l *AccessAnalyzerLister) List(_ context.Context, o interface{}) ([]resourc
4445
ARN: analyzer.Arn,
4546
Name: analyzer.Name,
4647
Status: analyzer.Status,
48+
Type: analyzer.Type,
4749
Tags: analyzer.Tags,
4850
})
4951
}
@@ -60,9 +62,17 @@ type AccessAnalyzer struct {
6062
ARN *string `description:"The ARN of the analyzer"`
6163
Name *string `description:"The name of the analyzer"`
6264
Status *string `description:"The status of the analyzer"`
65+
Type *string `description:"The type of the analyzer"`
6366
Tags map[string]*string `description:"The tags of the analyzer"`
6467
}
6568

69+
func (r *AccessAnalyzer) Filter() error {
70+
if strings.Contains(ptr.ToString(r.Name), "ORGANIZATION") {
71+
return errors.New("cannot delete organization analyzer")
72+
}
73+
return nil
74+
}
75+
6676
func (r *AccessAnalyzer) Remove(_ context.Context) error {
6777
_, err := r.svc.DeleteAnalyzer(&accessanalyzer.DeleteAnalyzerInput{AnalyzerName: r.Name})
6878

0 commit comments

Comments
 (0)