From 54919bdedffe8c8689f3759292e1480ab469d7a4 Mon Sep 17 00:00:00 2001 From: Erik Kristensen Date: Fri, 3 Jan 2025 13:08:09 -0700 Subject: [PATCH 1/4] feat(resource): add SSMQuickSetupConfigurationManager resource --- go.mod | 1 + go.sum | 2 + .../ssmquicksetup-configuration-manager.go | 82 +++++++++++++++++++ 3 files changed, 85 insertions(+) create mode 100644 resources/ssmquicksetup-configuration-manager.go diff --git a/go.mod b/go.mod index bddba488..47630365 100644 --- a/go.mod +++ b/go.mod @@ -35,6 +35,7 @@ require ( github.com/aws/aws-sdk-go-v2/service/internal/checksum v1.4.7 // indirect github.com/aws/aws-sdk-go-v2/service/internal/presigned-url v1.12.7 // indirect github.com/aws/aws-sdk-go-v2/service/internal/s3shared v1.18.7 // indirect + github.com/aws/aws-sdk-go-v2/service/ssmquicksetup v1.3.2 // indirect github.com/aws/aws-sdk-go-v2/service/sso v1.24.8 // indirect github.com/aws/aws-sdk-go-v2/service/ssooidc v1.28.7 // indirect github.com/benbjohnson/clock v1.3.0 // indirect diff --git a/go.sum b/go.sum index 9536d20d..0416494b 100644 --- a/go.sum +++ b/go.sum @@ -28,6 +28,8 @@ github.com/aws/aws-sdk-go-v2/service/internal/s3shared v1.18.7 h1:Hi0KGbrnr57bEH github.com/aws/aws-sdk-go-v2/service/internal/s3shared v1.18.7/go.mod h1:wKNgWgExdjjrm4qvfbTorkvocEstaoDl4WCvGfeCy9c= github.com/aws/aws-sdk-go-v2/service/s3 v1.71.1 h1:aOVVZJgWbaH+EJYPvEgkNhCEbXXvH7+oML36oaPK3zE= github.com/aws/aws-sdk-go-v2/service/s3 v1.71.1/go.mod h1:r+xl5yzMk9083rMR+sJ5TYj9Tihvf/l1oxzZXDgGj2Q= +github.com/aws/aws-sdk-go-v2/service/ssmquicksetup v1.3.2 h1:4siT1z3nEVxJq1jZYu1SRoct5xgbKen+ammCuZBZ2zI= +github.com/aws/aws-sdk-go-v2/service/ssmquicksetup v1.3.2/go.mod h1:KSO1+erW2SUB6Mw/Qamu1fOT5fn/mzd9G79ENbYqyRQ= github.com/aws/aws-sdk-go-v2/service/sso v1.24.8 h1:CvuUmnXI7ebaUAhbJcDy9YQx8wHR69eZ9I7q5hszt/g= github.com/aws/aws-sdk-go-v2/service/sso v1.24.8/go.mod h1:XDeGv1opzwm8ubxddF0cgqkZWsyOtw4lr6dxwmb6YQg= github.com/aws/aws-sdk-go-v2/service/ssooidc v1.28.7 h1:F2rBfNAL5UyswqoeWv9zs74N/NanhK16ydHW1pahX6E= diff --git a/resources/ssmquicksetup-configuration-manager.go b/resources/ssmquicksetup-configuration-manager.go new file mode 100644 index 00000000..60ef9283 --- /dev/null +++ b/resources/ssmquicksetup-configuration-manager.go @@ -0,0 +1,82 @@ +package resources + +import ( + "context" + "strings" + + "github.com/gotidy/ptr" + + "github.com/aws/aws-sdk-go-v2/service/ssmquicksetup" + + "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" +) + +const SSMQuickSetupConfigurationManagerResource = "SSMQuickSetupConfigurationManager" + +func init() { + registry.Register(®istry.Registration{ + Name: SSMQuickSetupConfigurationManagerResource, + Scope: nuke.Account, + Resource: &SSMQuickSetupConfigurationManager{}, + Lister: &SSMQuickSetupConfigurationManagerLister{}, + }) +} + +type SSMQuickSetupConfigurationManagerLister struct{} + +func (l *SSMQuickSetupConfigurationManagerLister) List(ctx context.Context, o interface{}) ([]resource.Resource, error) { + opts := o.(*nuke.ListerOpts) + svc := ssmquicksetup.NewFromConfig(*opts.Config) + var resources []resource.Resource + + res, err := svc.ListConfigurationManagers(ctx, &ssmquicksetup.ListConfigurationManagersInput{}) + if err != nil { + return nil, err + } + + for _, p := range res.ConfigurationManagersList { + resources = append(resources, &SSMQuickSetupConfigurationManager{ + svc: svc, + ARN: p.ManagerArn, + Name: p.Name, + }) + } + + return resources, nil +} + +type SSMQuickSetupConfigurationManager struct { + svc *ssmquicksetup.Client + ARN *string + Name *string +} + +// GetName returns the name of the resource or the last part of the ARN if not set so that the stringer resource has +// a value to display +func (r *SSMQuickSetupConfigurationManager) GetName() string { + if ptr.ToString(r.Name) != "" { + return ptr.ToString(r.Name) + } + + parts := strings.Split(ptr.ToString(r.ARN), "/") + return parts[len(parts)-1] +} + +func (r *SSMQuickSetupConfigurationManager) Remove(ctx context.Context) error { + _, err := r.svc.DeleteConfigurationManager(ctx, &ssmquicksetup.DeleteConfigurationManagerInput{ + ManagerArn: r.ARN, + }) + return err +} + +func (r *SSMQuickSetupConfigurationManager) Properties() types.Properties { + return types.NewPropertiesFromStruct(r) +} + +func (r *SSMQuickSetupConfigurationManager) String() string { + return r.GetName() +} From 8ba1fbb0b6d5bbbfc1c3058eadf136eaab6ed6cf Mon Sep 17 00:00:00 2001 From: Erik Kristensen Date: Fri, 3 Jan 2025 13:08:24 -0700 Subject: [PATCH 2/4] chore(tools/create-resource): switch to aws-go-sdk-v2 --- tools/create-resource/main.go | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/tools/create-resource/main.go b/tools/create-resource/main.go index 148b42ec..a2c5e6de 100644 --- a/tools/create-resource/main.go +++ b/tools/create-resource/main.go @@ -16,8 +16,7 @@ const resourceTemplate = `package resources import ( "context" - "github.com/aws/aws-sdk-go/aws" - "github.com/aws/aws-sdk-go/service/{{.Service}}" + "github.com/aws/aws-sdk-go-v2/service/{{.Service}}" "github.com/ekristen/libnuke/pkg/resource" "github.com/ekristen/libnuke/pkg/registry" @@ -41,12 +40,12 @@ type {{.Combined}}Lister struct{} func (l *{{.Combined}}Lister) List(_ context.Context, o interface{}) ([]resource.Resource, error) { opts := o.(*nuke.ListerOpts) - svc := {{.Service}}.New(opts.Session) + svc := {{.Service}}.NewFromConfig(*opts.Config) var resources []resource.Resource // NOTE: you might have to modify the code below to actually work, this currently does not // inspect the aws sdk instead is a jumping off point - res, err := svc.List{{.ResourceTypeTitle}}s(&{{.Service}}.List{{.ResourceTypeTitle}}sInput{}) + res, err := svc.List{{.ResourceTypeTitle}}s(ctx, &{{.Service}}.List{{.ResourceTypeTitle}}sInput{}) if err != nil { return nil, err } @@ -63,13 +62,13 @@ func (l *{{.Combined}}Lister) List(_ context.Context, o interface{}) ([]resource } type {{.Combined}} struct { - svc *{{.Service}}.{{.ServiceTitle}} + svc *{{.Service}}.Client ID *string Tags []*{{.Service}}.Tag } -func (r *{{.Combined}}) Remove(_ context.Context) error { - _, err := r.svc.Delete{{.ResourceTypeTitle}}(&{{.Service}}.Delete{{.ResourceTypeTitle}}Input{ +func (r *{{.Combined}}) Remove(ctx context.Context) error { + _, err := r.svc.Delete{{.ResourceTypeTitle}}(ctx, &{{.Service}}.Delete{{.ResourceTypeTitle}}Input{ {{.ResourceTypeTitle}}Id: r.id, }) return err From d31fa127b02d636c78c7a42b8e32396a091ef9d1 Mon Sep 17 00:00:00 2001 From: Erik Kristensen Date: Fri, 3 Jan 2025 13:37:42 -0700 Subject: [PATCH 3/4] fix(command/run): logging output back to stdout --- pkg/commands/nuke/nuke.go | 2 ++ 1 file changed, 2 insertions(+) diff --git a/pkg/commands/nuke/nuke.go b/pkg/commands/nuke/nuke.go index 63d21954..8b6719e5 100644 --- a/pkg/commands/nuke/nuke.go +++ b/pkg/commands/nuke/nuke.go @@ -3,6 +3,7 @@ package nuke import ( "context" "fmt" + "os" "slices" "strings" "time" @@ -75,6 +76,7 @@ func execute(c *cli.Context) error { //nolint:funlen,gocyclo } logger := logrus.StandardLogger() + logger.SetOutput(os.Stdout) // Parse the user supplied configuration file to pass in part to configure the nuke process. parsedConfig, err := config.New(libconfig.Options{ From 03086f45b9eb401b08148e9d9cce50937e42d944 Mon Sep 17 00:00:00 2001 From: Erik Kristensen Date: Fri, 3 Jan 2025 13:44:53 -0700 Subject: [PATCH 4/4] docs: auto-generated docs for resources --- .../ssm-quick-setup-configuration-manager.md | 31 +++++++++++++++++++ mkdocs.yml | 1 + 2 files changed, 32 insertions(+) create mode 100644 docs/resources/ssm-quick-setup-configuration-manager.md diff --git a/docs/resources/ssm-quick-setup-configuration-manager.md b/docs/resources/ssm-quick-setup-configuration-manager.md new file mode 100644 index 00000000..ba66cfaa --- /dev/null +++ b/docs/resources/ssm-quick-setup-configuration-manager.md @@ -0,0 +1,31 @@ +--- +generated: true +--- + +# SSMQuickSetupConfigurationManager + + +## Resource + +```text +SSMQuickSetupConfigurationManager +``` + +## Properties + + +- `ARN`: No Description +- `Name`: No Description + +!!! note - Using Properties + Properties are what [Filters](../config-filtering.md) are written against in your configuration. You use the property + names to write filters for what you want to **keep** and omit from the nuke process. + +### String Property + +The string representation of a resource is generally the value of the Name, ID or ARN field of the resource. Not all +resources support properties. To write a filter against the string representation, simply omit the `property` field in +the filter. + +The string value is always what is used in the output of the log format when a resource is identified. + diff --git a/mkdocs.yml b/mkdocs.yml index 668c7bf7..e188d0cb 100644 --- a/mkdocs.yml +++ b/mkdocs.yml @@ -558,6 +558,7 @@ nav: - SSM Maintenance Window: resources/ssm-maintenance-window.md - SSM Parameter: resources/ssm-parameter.md - SSM Patch Baseline: resources/ssm-patch-baseline.md + - SSM Quick Setup Configuration Manager: resources/ssm-quick-setup-configuration-manager.md - SSM Resource Data Sync: resources/ssm-resource-data-sync.md - Sage Maker App: resources/sage-maker-app.md - Sage Maker Domain: resources/sage-maker-domain.md