Skip to content

Commit

Permalink
Improving Internal Tools and Documentation (#33)
Browse files Browse the repository at this point in the history
* docs: add note about continued attribution

* chore: improve internal tooling
  • Loading branch information
ekristen committed Jan 30, 2024
1 parent 4e0c69b commit 17e590e
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 19 deletions.
12 changes: 10 additions & 2 deletions docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ Remove all resources from an AWS account.
*aws-nuke* is stable, but it is likely that not all AWS resources are covered by it. Be encouraged to add missing
resources and create a Pull Request or to create an [Issue](https://github.com/ekristen/aws-nuke/issues/new).

## History
## History of this Fork

This is a full fork of the original tool written by the folks over at [rebuy-de](https://github.com/rebuy-de). This fork became necessary
after attempting to make contributions and respond to issues to learn that the current maintainers only have time to
Expand All @@ -16,7 +16,15 @@ decision to fork and maintain it.
Since then the rebuy-de team has taken up interest in responding to their issues and pull requests, but I have decided
to continue maintaining this fork as I have a few things I want to do with it that I don't think they will be interested.

## libnuke
### Continued Attribution

I want to make it clear that I am not trying to take credit for the work of the original authors, and I will continue
to give them credit for their work. I also want to make sure any contributors are also recognized and attributed for
their work. Since this has diverged from the upstream, I've written tooling and scripts to cherry-pick commits from
upstream and apply them to this fork, then modify the resources to work with the new library and submit as a PR to this
fork.

## Introducing libnuke

Officially over the Christmas break of 2023, I decided to create [libnuke](https://github.com/ekristen/libnuke) which
is a library that can be used to create similar tools for other cloud providers. This library is used by both this tool,
Expand Down
2 changes: 2 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,11 @@ require (
github.com/mattn/go-isatty v0.0.20 // indirect
github.com/mb0/glob v0.0.0-20160210091149-1eb79d2de6c4 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/rogpeppe/go-internal v1.11.0 // indirect
github.com/russross/blackfriday/v2 v2.1.0 // indirect
github.com/stevenle/topsort v0.2.0 // indirect
github.com/xrash/smetrics v0.0.0-20201216005158-039620a65673 // indirect
golang.org/x/net v0.19.0 // indirect
golang.org/x/sync v0.6.0 // indirect
golang.org/x/sys v0.16.0 // indirect
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c // indirect
Expand Down
11 changes: 6 additions & 5 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,9 @@ github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/rogpeppe/go-internal v1.9.0 h1:73kH8U+JUqXU8lRuOHeVHaa/SZPifC7BkcraZVejAe8=
github.com/rogpeppe/go-internal v1.9.0/go.mod h1:WtVeX8xhTBvf0smdhujwtBcq4Qrzq/fJaraNFVN+nFs=
github.com/rogpeppe/go-internal v1.11.0 h1:cWPaGQEPrBb5/AsnsZesgZZ9yb1OQ+GOISoDNXVBh4M=
github.com/rogpeppe/go-internal v1.11.0/go.mod h1:ddIwULY96R17DhadqLgMfk9H9tvdUzkipdSkR5nkCZA=
github.com/russross/blackfriday/v2 v2.1.0 h1:JIOH55/0cWyOuilr9/qlrm0BSXldqnqwMsf35Ld67mk=
github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
github.com/sirupsen/logrus v1.9.3 h1:dueUQJ1C2q9oE3F7wvmSGAaVtTmUizReu6fjN8uqzbQ=
Expand All @@ -62,8 +63,8 @@ golang.org/x/mod v0.4.2/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
golang.org/x/net v0.0.0-20210405180319-a5a99cb37ef4/go.mod h1:p54w0d4576C0XHj96bSt6lcn1PtDYWL6XObtHCRCNQM=
golang.org/x/net v0.17.0 h1:pVaXccu2ozPjCXewfr1S7xza/zcXTity9cCdXQYSjIM=
golang.org/x/net v0.17.0/go.mod h1:NxSsAGuq816PNPmqtQdLE42eU2Fs7NoRIZrHJAlaCOE=
golang.org/x/net v0.19.0 h1:zTwKpTd2XuCqf8huc7Fo2iSy+4RHPd10s4KzeTnVr1c=
golang.org/x/net v0.19.0/go.mod h1:CfAk/cbD4CthTvqiEl8NpboMuiuOYsAr/7NOjZJtv1U=
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20210220032951-036812b2e83c/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.6.0 h1:5BMeUDZ7vkXGfEr1x9B4bRcTH4lpkTkpdh0T/J+qjbQ=
Expand All @@ -81,8 +82,8 @@ golang.org/x/sys v0.16.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
golang.org/x/text v0.13.0 h1:ablQoSUd0tRdKxZewP80B+BaqeKJuVhuRxj/dkrun3k=
golang.org/x/text v0.13.0/go.mod h1:TvPlkZtksWOMsz7fbANvkp4WM8x/WCo/om8BMLbz+aE=
golang.org/x/text v0.14.0 h1:ScX5w1eTa3QqT8oi6+ziP7dTV1S2+ALU0bI+0zXKWiQ=
golang.org/x/text v0.14.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU=
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
golang.org/x/tools v0.1.1/go.mod h1:o0xws9oXOQQZyjljx8fwUC0k7L1pTE6eaCbjGeHmOkk=
Expand Down
18 changes: 16 additions & 2 deletions tools/compare-resources/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,12 @@ import (
var OriginalRegisterRegex = regexp.MustCompile("register\\(\"(?P<resource>.*)\",\\s?(?P<function>\\w+)(,)?(\\s+mapCloudControl\\(\"(?P<cc>.*)\"\\))?")
var NewRegisterRegex = regexp.MustCompile(`resource.Registration{\s+Name:\s+(?P<name>.*),`)

var aliases = map[string]string{
"NetpuneSnapshot": "NeptuneSnapshot",
"EKSFargateProfiles": "EKSFargateProfile",
"EKSNodegroups": "EKSNodegroup",
}

func main() {
args := os.Args[1:]

Expand Down Expand Up @@ -104,14 +110,22 @@ func main() {

fmt.Println("\nResources not in local aws-nuke:")
for _, resource := range awsNukeResourceTypes {
if !slices.Contains(localResourceTypes, resource) {
_, ok := aliases[resource]
if !slices.Contains(localResourceTypes, resource) && !ok {
fmt.Println("->", resource)
}
}

fmt.Println("\nResources not in aws-nuke:")
for _, resource := range localResourceTypes {
if !slices.Contains(awsNukeResourceTypes, resource) {
found := false
for _, v := range aliases {
if v == resource {
found = true
}
}

if !slices.Contains(awsNukeResourceTypes, resource) && !found {
fmt.Println("+>", resource)
}
}
Expand Down
22 changes: 12 additions & 10 deletions tools/migrate-resource/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,18 @@ func main() {
panic("no arguments given")
}

if len(args) != 2 {
fmt.Println("usage: migrate-resource <source-aws-nuke> <resource-type>")
os.Exit(1)
}

originalSourceDir := filepath.Join(args[0], "resources")

repl := regexp.MustCompile("func init\\(\\) {\\s+.*[\\s+].*\\s}")
match := regexp.MustCompile("register\\(\"(?P<resource>.*)\",\\s?(?P<function>\\w+)(,)?(\\s+mapCloudControl\\(\"(?P<cc>.*)\"\\))?")
funcMatch := regexp.MustCompile("func List.*{")

filename := filepath.Join(originalSourceDir, "resources", args[0]+".go")
filename := filepath.Join(originalSourceDir, "resources", args[1]+".go")

originalFileContents, err := os.ReadFile(filename)
if err != nil {
Expand All @@ -60,14 +65,6 @@ func main() {
panic("no matches")
}
resourceType := matches[1]
funcName := matches[2]
cc := ""
if len(matches) == 4 {
cc = matches[3]
}

fmt.Println(cc)
fmt.Println(funcName)

data := struct {
ResourceType string
Expand Down Expand Up @@ -107,8 +104,13 @@ func main() {
newContents = strings.ReplaceAll(newContents, "config.FeatureFlags", "*featureflag.FeatureFlags")
newContents = strings.ReplaceAll(newContents, ") Remove() error {", ") Remove(_ context.Context) error {")

cwd, err := os.Getwd()
if err != nil {
panic(err)
}

if err := os.WriteFile(
filepath.Join(".", "resources", args[0]+".go"), []byte(newContents), 0644); err != nil {
filepath.Join(cwd, "resources", args[1]+".go"), []byte(newContents), 0644); err != nil {
panic(err)
}
}

0 comments on commit 17e590e

Please sign in to comment.