Skip to content

Commit

Permalink
feat(resource): add SSMQuickSetupConfigurationManager resource
Browse files Browse the repository at this point in the history
  • Loading branch information
ekristen committed Jan 3, 2025
1 parent f82fbbc commit 54919bd
Show file tree
Hide file tree
Showing 3 changed files with 85 additions and 0 deletions.
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -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=
Expand Down
82 changes: 82 additions & 0 deletions resources/ssmquicksetup-configuration-manager.go
Original file line number Diff line number Diff line change
@@ -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(&registry.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()
}

0 comments on commit 54919bd

Please sign in to comment.