Skip to content

Commit

Permalink
Merge pull request #87 from ekristen/redshift-serverless
Browse files Browse the repository at this point in the history
feat: add redshift serverless resources
  • Loading branch information
ekristen authored Feb 23, 2024
2 parents dd910da + 28d08c1 commit 51ea591
Show file tree
Hide file tree
Showing 3 changed files with 260 additions and 0 deletions.
86 changes: 86 additions & 0 deletions resources/redshiftserverless-namespaces.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
package resources

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

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

"github.com/aws/aws-sdk-go/service/redshiftserverless"

"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() {
registry.Register(&registry.Registration{
Name: RedshiftServerlessNamespaceResource,
Scope: nuke.Account,
Lister: &RedshiftServerlessNamespaceLister{},
})
}

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),
}

for {
output, err := svc.ListNamespaces(params)
if err != nil {
return nil, err
}

for _, namespace := range output.Namespaces {
resources = append(resources, &RedshiftServerlessNamespace{
svc: svc,
namespace: namespace,
})
}

if output.NextToken == nil {
break
}

params.NextToken = output.NextToken
}

return resources, nil
}

func (n *RedshiftServerlessNamespace) Properties() types.Properties {
properties := types.NewProperties().
Set("CreationDate", n.namespace.CreationDate).
Set("NamespaceName", n.namespace.NamespaceName)

return properties
}

func (n *RedshiftServerlessNamespace) Remove(_ context.Context) error {
_, err := n.svc.DeleteNamespace(&redshiftserverless.DeleteNamespaceInput{
NamespaceName: n.namespace.NamespaceName,
})

return err
}

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

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

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

"github.com/aws/aws-sdk-go/service/redshiftserverless"

"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() {
registry.Register(&registry.Registration{
Name: RedshiftServerlessSnapshotResource,
Scope: nuke.Account,
Lister: &RedshiftServerlessSnapshotLister{},
})
}

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),
}

for {
output, err := svc.ListSnapshots(params)
if err != nil {
return nil, err
}

for _, snapshot := range output.Snapshots {
resources = append(resources, &RedshiftServerlessSnapshot{
svc: svc,
snapshot: snapshot,
})
}

if output.NextToken == nil {
break
}

params.NextToken = output.NextToken
}

return resources, nil
}

func (s *RedshiftServerlessSnapshot) Properties() types.Properties {
properties := types.NewProperties().
Set("CreateTime", s.snapshot.SnapshotCreateTime).
Set("Namespace", s.snapshot.NamespaceName).
Set("SnapshotName", s.snapshot.SnapshotName)

return properties
}

func (s *RedshiftServerlessSnapshot) Remove(_ context.Context) error {
_, err := s.svc.DeleteSnapshot(&redshiftserverless.DeleteSnapshotInput{
SnapshotName: s.snapshot.SnapshotName,
})

return err
}

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

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

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

"github.com/aws/aws-sdk-go/service/redshiftserverless"

"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() {
registry.Register(&registry.Registration{
Name: RedshiftServerlessWorkgroupResource,
Scope: nuke.Account,
Lister: &RedshiftServerlessWorkgroupLister{},
})
}

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),
}

for {
output, err := svc.ListWorkgroups(params)
if err != nil {
return nil, err
}

for _, workgroup := range output.Workgroups {
resources = append(resources, &RedshiftServerlessWorkgroup{
svc: svc,
workgroup: workgroup,
})
}

if output.NextToken == nil {
break
}

params.NextToken = output.NextToken
}

return resources, nil
}

func (w *RedshiftServerlessWorkgroup) Properties() types.Properties {
properties := types.NewProperties().
Set("CreationDate", w.workgroup.CreationDate).
Set("Namespace", w.workgroup.NamespaceName).
Set("WorkgroupName", w.workgroup.WorkgroupName)

return properties
}

func (w *RedshiftServerlessWorkgroup) Remove(_ context.Context) error {
_, err := w.svc.DeleteWorkgroup(&redshiftserverless.DeleteWorkgroupInput{
WorkgroupName: w.workgroup.WorkgroupName,
})

return err
}

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

0 comments on commit 51ea591

Please sign in to comment.