From 17e590edd4c203d62b2ea2da747acc59d6d606e9 Mon Sep 17 00:00:00 2001 From: Erik Kristensen Date: Thu, 25 Jan 2024 16:12:50 -0700 Subject: [PATCH] Improving Internal Tools and Documentation (#33) * docs: add note about continued attribution * chore: improve internal tooling --- docs/index.md | 12 ++++++++++-- go.mod | 2 ++ go.sum | 11 ++++++----- tools/compare-resources/main.go | 18 ++++++++++++++++-- tools/migrate-resource/main.go | 22 ++++++++++++---------- 5 files changed, 46 insertions(+), 19 deletions(-) diff --git a/docs/index.md b/docs/index.md index 94192c1eb..7799c8a3b 100644 --- a/docs/index.md +++ b/docs/index.md @@ -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 @@ -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, diff --git a/go.mod b/go.mod index 282ac855e..01db66fe5 100644 --- a/go.mod +++ b/go.mod @@ -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 diff --git a/go.sum b/go.sum index 30db4bcec..1629f290c 100644 --- a/go.sum +++ b/go.sum @@ -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= @@ -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= @@ -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= diff --git a/tools/compare-resources/main.go b/tools/compare-resources/main.go index cfac79f0f..14fa98732 100644 --- a/tools/compare-resources/main.go +++ b/tools/compare-resources/main.go @@ -13,6 +13,12 @@ import ( var OriginalRegisterRegex = regexp.MustCompile("register\\(\"(?P.*)\",\\s?(?P\\w+)(,)?(\\s+mapCloudControl\\(\"(?P.*)\"\\))?") var NewRegisterRegex = regexp.MustCompile(`resource.Registration{\s+Name:\s+(?P.*),`) +var aliases = map[string]string{ + "NetpuneSnapshot": "NeptuneSnapshot", + "EKSFargateProfiles": "EKSFargateProfile", + "EKSNodegroups": "EKSNodegroup", +} + func main() { args := os.Args[1:] @@ -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) } } diff --git a/tools/migrate-resource/main.go b/tools/migrate-resource/main.go index 92b67c79a..f3fc4048b 100644 --- a/tools/migrate-resource/main.go +++ b/tools/migrate-resource/main.go @@ -41,13 +41,18 @@ func main() { panic("no arguments given") } + if len(args) != 2 { + fmt.Println("usage: migrate-resource ") + os.Exit(1) + } + originalSourceDir := filepath.Join(args[0], "resources") repl := regexp.MustCompile("func init\\(\\) {\\s+.*[\\s+].*\\s}") match := regexp.MustCompile("register\\(\"(?P.*)\",\\s?(?P\\w+)(,)?(\\s+mapCloudControl\\(\"(?P.*)\"\\))?") 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 { @@ -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 @@ -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) } }