Skip to content

Commit

Permalink
Merge pull request #414 from ekristen/fix-inspector2
Browse files Browse the repository at this point in the history
fix(inspector2): disable only enabled services
  • Loading branch information
ekristen authored Nov 11, 2024
2 parents a17f53d + 12bee2b commit a3f1210
Showing 1 changed file with 28 additions and 6 deletions.
34 changes: 28 additions & 6 deletions resources/inspector2.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (

"github.com/ekristen/libnuke/pkg/registry"
"github.com/ekristen/libnuke/pkg/resource"
"github.com/ekristen/libnuke/pkg/types"

"github.com/ekristen/aws-nuke/v3/pkg/nuke"
)
Expand Down Expand Up @@ -39,7 +40,13 @@ func (l *Inspector2Lister) List(_ context.Context, o interface{}) ([]resource.Re
if *a.State.Status != inspector2.StatusDisabled {
resources = append(resources, &Inspector2{
svc: svc,
accountID: a.AccountId,
AccountID: a.AccountId,
ResourceState: map[string]string{
inspector2.ResourceScanTypeEc2: *a.ResourceState.Ec2.Status,
inspector2.ResourceScanTypeEcr: *a.ResourceState.Ecr.Status,
inspector2.ResourceScanTypeLambda: *a.ResourceState.Lambda.Status,
inspector2.ResourceScanTypeLambdaCode: *a.ResourceState.LambdaCode.Status,
},
})
}
}
Expand All @@ -48,14 +55,25 @@ func (l *Inspector2Lister) List(_ context.Context, o interface{}) ([]resource.Re
}

type Inspector2 struct {
svc *inspector2.Inspector2
accountID *string
svc *inspector2.Inspector2
AccountID *string
ResourceState map[string]string `property:"tagPrefix=resourceType"`
}

func (e *Inspector2) GetEnabledResources() []string {
var resources = make([]string, 0)
for k, v := range e.ResourceState {
if v == inspector2.StatusEnabled {
resources = append(resources, k)
}
}
return resources
}

func (e *Inspector2) Remove(_ context.Context) error {
_, err := e.svc.Disable(&inspector2.DisableInput{
AccountIds: []*string{e.accountID},
ResourceTypes: aws.StringSlice(inspector2.ResourceScanType_Values()),
AccountIds: []*string{e.AccountID},
ResourceTypes: aws.StringSlice(e.GetEnabledResources()),
})
if err != nil {
return err
Expand All @@ -65,5 +83,9 @@ func (e *Inspector2) Remove(_ context.Context) error {
}

func (e *Inspector2) String() string {
return *e.accountID
return *e.AccountID
}

func (e *Inspector2) Properties() types.Properties {
return types.NewPropertiesFromStruct(e)
}

0 comments on commit a3f1210

Please sign in to comment.