This repository has been archived by the owner on Oct 15, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 725
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fixup! Merge branch 'main' of rebuy/nuke into add_budgets
- Loading branch information
1 parent
eab5b39
commit 44ea18d
Showing
27 changed files
with
950 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
package resources | ||
|
||
import ( | ||
"github.com/aws/aws-sdk-go/aws" | ||
"github.com/aws/aws-sdk-go/aws/session" | ||
"github.com/aws/aws-sdk-go/service/accessanalyzer" | ||
"github.com/rebuy-de/aws-nuke/pkg/types" | ||
) | ||
|
||
type AccessAnalyzer struct { | ||
svc *accessanalyzer.AccessAnalyzer | ||
arn string | ||
name string | ||
status string | ||
tags map[string]*string | ||
} | ||
|
||
func init() { | ||
register("AccessAnalyzer", ListAccessAnalyzer) | ||
} | ||
|
||
func ListAccessAnalyzer(sess *session.Session) ([]Resource, error) { | ||
svc := accessanalyzer.New(sess) | ||
|
||
params := &accessanalyzer.ListAnalyzersInput{ | ||
Type: aws.String("ACCOUNT"), | ||
} | ||
|
||
resources := make([]Resource, 0) | ||
err := svc.ListAnalyzersPages(params, | ||
func(page *accessanalyzer.ListAnalyzersOutput, lastPage bool) bool { | ||
for _, analyzer := range page.Analyzers { | ||
resources = append(resources, &AccessAnalyzer{ | ||
svc: svc, | ||
arn: *analyzer.Arn, | ||
name: *analyzer.Name, | ||
status: *analyzer.Status, | ||
tags: analyzer.Tags, | ||
}) | ||
} | ||
return true | ||
}) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
return resources, nil | ||
} | ||
|
||
func (a *AccessAnalyzer) Remove() error { | ||
_, err := a.svc.DeleteAnalyzer(&accessanalyzer.DeleteAnalyzerInput{AnalyzerName: &a.name}) | ||
|
||
return err | ||
} | ||
|
||
func (a *AccessAnalyzer) Properties() types.Properties { | ||
properties := types.NewProperties() | ||
|
||
properties.Set("ARN", a.arn) | ||
properties.Set("Name", a.name) | ||
properties.Set("Status", a.status) | ||
for k, v := range a.tags { | ||
properties.SetTag(&k, v) | ||
} | ||
|
||
return properties | ||
} | ||
|
||
func (a *AccessAnalyzer) String() string { | ||
return a.name | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
package resources | ||
|
||
import ( | ||
"github.com/aws/aws-sdk-go/aws/session" | ||
"github.com/aws/aws-sdk-go/service/accessanalyzer" | ||
"github.com/rebuy-de/aws-nuke/pkg/types" | ||
) | ||
|
||
type ArchiveRule struct { | ||
svc *accessanalyzer.AccessAnalyzer | ||
ruleName string | ||
analyzerName string | ||
} | ||
|
||
func init() { | ||
register("ArchiveRule", ListArchiveRule) | ||
} | ||
|
||
func ListArchiveRule(sess *session.Session) ([]Resource, error) { | ||
svc := accessanalyzer.New(sess) | ||
|
||
analyzers, err := ListAccessAnalyzer(sess) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
resources := make([]Resource, 0) | ||
|
||
for _, analyzer := range analyzers { | ||
a, ok := analyzer.(*AccessAnalyzer) | ||
if !ok { | ||
continue | ||
} | ||
|
||
params := &accessanalyzer.ListArchiveRulesInput{ | ||
AnalyzerName: &a.name, | ||
} | ||
|
||
err = svc.ListArchiveRulesPages(params, | ||
func(page *accessanalyzer.ListArchiveRulesOutput, lastPage bool) bool { | ||
for _, archiveRule := range page.ArchiveRules { | ||
resources = append(resources, &ArchiveRule{ | ||
svc: svc, | ||
ruleName: *archiveRule.RuleName, | ||
analyzerName: a.name, | ||
}) | ||
} | ||
return true | ||
}) | ||
if err != nil { | ||
return nil, err | ||
} | ||
} | ||
|
||
return resources, nil | ||
} | ||
|
||
func (a *ArchiveRule) Remove() error { | ||
_, err := a.svc.DeleteArchiveRule(&accessanalyzer.DeleteArchiveRuleInput{ | ||
AnalyzerName: &a.analyzerName, | ||
RuleName: &a.ruleName, | ||
}) | ||
|
||
return err | ||
} | ||
|
||
func (a *ArchiveRule) Properties() types.Properties { | ||
properties := types.NewProperties() | ||
|
||
properties.Set("RuleName", a.ruleName) | ||
properties.Set("AnalyzerName", a.analyzerName) | ||
|
||
return properties | ||
} | ||
|
||
func (a *ArchiveRule) String() string { | ||
return a.ruleName | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.