Skip to content

Commit

Permalink
chore: migrate to aws-nuke-v3/libnuke resource format
Browse files Browse the repository at this point in the history
  • Loading branch information
ekristen committed Feb 23, 2024
1 parent a6ed443 commit beae288
Show file tree
Hide file tree
Showing 3 changed files with 78 additions and 24 deletions.
34 changes: 26 additions & 8 deletions resources/redshiftserverless-namespaces.go
Original file line number Diff line number Diff line change
@@ -1,24 +1,42 @@
package resources

import (
"context"
"github.com/gotidy/ptr"

"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/aws/session"

"github.com/aws/aws-sdk-go/service/redshiftserverless"
"github.com/rebuy-de/aws-nuke/v2/pkg/types"

"github.com/ekristen/libnuke/pkg/registry"
"github.com/ekristen/libnuke/pkg/resource"
"github.com/ekristen/libnuke/pkg/types"

"github.com/ekristen/aws-nuke/pkg/nuke"
)

type RedshiftServerlessNamespace struct {
svc *redshiftserverless.RedshiftServerless
namespace *redshiftserverless.Namespace
}

const RedshiftServerlessNamespaceResource = "RedshiftServerlessNamespace"

func init() {
register("RedshiftServerlessNamespace", ListRedshiftServerlessNamespaces)
registry.Register(&registry.Registration{
Name: RedshiftServerlessNamespaceResource,
Scope: nuke.Account,
Lister: &RedshiftServerlessNamespaceLister{},
})
}

func ListRedshiftServerlessNamespaces(sess *session.Session) ([]Resource, error) {
svc := redshiftserverless.New(sess)
resources := []Resource{}
type RedshiftServerlessNamespaceLister struct{}

func (l *RedshiftServerlessNamespaceLister) List(_ context.Context, o interface{}) ([]resource.Resource, error) {
opts := o.(*nuke.ListerOpts)

svc := redshiftserverless.New(opts.Session)
resources := make([]resource.Resource, 0)

params := &redshiftserverless.ListNamespacesInput{
MaxResults: aws.Int64(100),
Expand Down Expand Up @@ -55,7 +73,7 @@ func (n *RedshiftServerlessNamespace) Properties() types.Properties {
return properties
}

func (n *RedshiftServerlessNamespace) Remove() error {
func (n *RedshiftServerlessNamespace) Remove(_ context.Context) error {
_, err := n.svc.DeleteNamespace(&redshiftserverless.DeleteNamespaceInput{
NamespaceName: n.namespace.NamespaceName,
})
Expand All @@ -64,5 +82,5 @@ func (n *RedshiftServerlessNamespace) Remove() error {
}

func (n *RedshiftServerlessNamespace) String() string {
return *n.namespace.NamespaceName
return ptr.ToString(n.namespace.NamespaceName)
}
34 changes: 26 additions & 8 deletions resources/redshiftserverless-snapshots.go
Original file line number Diff line number Diff line change
@@ -1,24 +1,42 @@
package resources

import (
"context"
"github.com/gotidy/ptr"

"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/aws/session"

"github.com/aws/aws-sdk-go/service/redshiftserverless"
"github.com/rebuy-de/aws-nuke/v2/pkg/types"

"github.com/ekristen/libnuke/pkg/registry"
"github.com/ekristen/libnuke/pkg/resource"
"github.com/ekristen/libnuke/pkg/types"

"github.com/ekristen/aws-nuke/pkg/nuke"
)

type RedshiftServerlessSnapshot struct {
svc *redshiftserverless.RedshiftServerless
snapshot *redshiftserverless.Snapshot
}

const RedshiftServerlessSnapshotResource = "RedshiftServerlessSnapshot"

func init() {
register("RedshiftServerlessSnapshot", ListRedshiftServerlessSnapshots)
registry.Register(&registry.Registration{
Name: RedshiftServerlessSnapshotResource,
Scope: nuke.Account,
Lister: &RedshiftServerlessSnapshotLister{},
})
}

func ListRedshiftServerlessSnapshots(sess *session.Session) ([]Resource, error) {
svc := redshiftserverless.New(sess)
resources := []Resource{}
type RedshiftServerlessSnapshotLister struct{}

func (l *RedshiftServerlessSnapshotLister) List(_ context.Context, o interface{}) ([]resource.Resource, error) {
opts := o.(*nuke.ListerOpts)

svc := redshiftserverless.New(opts.Session)
resources := make([]resource.Resource, 0)

params := &redshiftserverless.ListSnapshotsInput{
MaxResults: aws.Int64(100),
Expand Down Expand Up @@ -56,7 +74,7 @@ func (s *RedshiftServerlessSnapshot) Properties() types.Properties {
return properties
}

func (s *RedshiftServerlessSnapshot) Remove() error {
func (s *RedshiftServerlessSnapshot) Remove(_ context.Context) error {
_, err := s.svc.DeleteSnapshot(&redshiftserverless.DeleteSnapshotInput{
SnapshotName: s.snapshot.SnapshotName,
})
Expand All @@ -65,5 +83,5 @@ func (s *RedshiftServerlessSnapshot) Remove() error {
}

func (s *RedshiftServerlessSnapshot) String() string {
return *s.snapshot.SnapshotName
return ptr.ToString(s.snapshot.SnapshotName)
}
34 changes: 26 additions & 8 deletions resources/redshiftserverless-workgroups.go
Original file line number Diff line number Diff line change
@@ -1,24 +1,42 @@
package resources

import (
"context"
"github.com/gotidy/ptr"

"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/aws/session"

"github.com/aws/aws-sdk-go/service/redshiftserverless"
"github.com/rebuy-de/aws-nuke/v2/pkg/types"

"github.com/ekristen/libnuke/pkg/registry"
"github.com/ekristen/libnuke/pkg/resource"
"github.com/ekristen/libnuke/pkg/types"

"github.com/ekristen/aws-nuke/pkg/nuke"
)

type RedshiftServerlessWorkgroup struct {
svc *redshiftserverless.RedshiftServerless
workgroup *redshiftserverless.Workgroup
}

const RedshiftServerlessWorkgroupResource = "RedshiftServerlessWorkgroup"

func init() {
register("RedshiftServerlessWorkgroup", ListRedshiftServerlessWorkgroups)
registry.Register(&registry.Registration{
Name: RedshiftServerlessWorkgroupResource,
Scope: nuke.Account,
Lister: &RedshiftServerlessWorkgroupLister{},
})
}

func ListRedshiftServerlessWorkgroups(sess *session.Session) ([]Resource, error) {
svc := redshiftserverless.New(sess)
resources := []Resource{}
type RedshiftServerlessWorkgroupLister struct{}

func (l *RedshiftServerlessWorkgroupLister) List(_ context.Context, o interface{}) ([]resource.Resource, error) {
opts := o.(*nuke.ListerOpts)

svc := redshiftserverless.New(opts.Session)
resources := make([]resource.Resource, 0)

params := &redshiftserverless.ListWorkgroupsInput{
MaxResults: aws.Int64(100),
Expand Down Expand Up @@ -56,7 +74,7 @@ func (w *RedshiftServerlessWorkgroup) Properties() types.Properties {
return properties
}

func (w *RedshiftServerlessWorkgroup) Remove() error {
func (w *RedshiftServerlessWorkgroup) Remove(_ context.Context) error {
_, err := w.svc.DeleteWorkgroup(&redshiftserverless.DeleteWorkgroupInput{
WorkgroupName: w.workgroup.WorkgroupName,
})
Expand All @@ -65,5 +83,5 @@ func (w *RedshiftServerlessWorkgroup) Remove() error {
}

func (w *RedshiftServerlessWorkgroup) String() string {
return *w.workgroup.WorkgroupName
return ptr.ToString(w.workgroup.WorkgroupName)
}

0 comments on commit beae288

Please sign in to comment.