Skip to content
This repository has been archived by the owner on Oct 15, 2024. It is now read-only.

Commit

Permalink
feat: MemoryDBACL resource support (#1079)
Browse files Browse the repository at this point in the history
feat: MemoryDBCluster resource support
feat: MemoryDBParameterGroup resource support
feat: MemoryDBSubnetGroup resource support
feat: MemoryDBUser resource support
  • Loading branch information
JTaylor-myenergi authored Aug 24, 2023
1 parent f8fc2e5 commit f1aff70
Show file tree
Hide file tree
Showing 5 changed files with 446 additions and 0 deletions.
84 changes: 84 additions & 0 deletions resources/memorydb-acl.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
package resources

import (
"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/aws/session"
"github.com/aws/aws-sdk-go/service/memorydb"
"github.com/rebuy-de/aws-nuke/v2/pkg/types"
)

type MemoryDBACL struct {
svc *memorydb.MemoryDB
name *string
tags []*memorydb.Tag
}

func init() {
register("MemoryDBACL", ListMemoryDBACLs)
}

func ListMemoryDBACLs(sess *session.Session) ([]Resource, error) {
svc := memorydb.New(sess)
var resources []Resource

params := &memorydb.DescribeACLsInput{MaxResults: aws.Int64(50)}
for {
resp, err := svc.DescribeACLs(params)
if err != nil {
return nil, err
}

for _, acl := range resp.ACLs {
tags, err := svc.ListTags(&memorydb.ListTagsInput{
ResourceArn: acl.ARN,
})

if err != nil {
continue
}

resources = append(resources, &MemoryDBACL{
svc: svc,
name: acl.Name,
tags: tags.TagList,
})

}

if resp.NextToken == nil {
break
}

params.NextToken = resp.NextToken
}

return resources, nil
}

func (i *MemoryDBACL) Remove() error {
params := &memorydb.DeleteACLInput{
ACLName: i.name,
}

_, err := i.svc.DeleteACL(params)
if err != nil {
return err
}

return nil
}

func (i *MemoryDBACL) String() string {
return *i.name
}

func (i *MemoryDBACL) Properties() types.Properties {
properties := types.NewProperties()
properties.Set("Name", i.name)

for _, tag := range i.tags {
properties.SetTag(tag.Key, tag.Value)
}

return properties
}
84 changes: 84 additions & 0 deletions resources/memorydb-cluster.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
package resources

import (
"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/aws/session"
"github.com/aws/aws-sdk-go/service/memorydb"
"github.com/rebuy-de/aws-nuke/v2/pkg/types"
)

type MemoryDBCluster struct {
svc *memorydb.MemoryDB
name *string
tags []*memorydb.Tag
}

func init() {
register("MemoryDBCluster", ListMemoryDbClusters)
}

func ListMemoryDbClusters(sess *session.Session) ([]Resource, error) {
svc := memorydb.New(sess)
var resources []Resource

params := &memorydb.DescribeClustersInput{MaxResults: aws.Int64(100)}

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

for _, cluster := range resp.Clusters {
tags, err := svc.ListTags(&memorydb.ListTagsInput{
ResourceArn: cluster.ARN,
})

if err != nil {
continue
}

resources = append(resources, &MemoryDBCluster{
svc: svc,
name: cluster.Name,
tags: tags.TagList,
})
}

if resp.NextToken == nil {
break
}

params.NextToken = resp.NextToken
}

return resources, nil
}

func (c *MemoryDBCluster) Remove() error {
params := &memorydb.DeleteClusterInput{
ClusterName: c.name,
}

_, err := c.svc.DeleteCluster(params)
if err != nil {
return err
}

return nil
}

func (i *MemoryDBCluster) String() string {
return *i.name
}

func (i *MemoryDBCluster) Properties() types.Properties {
properties := types.NewProperties()
properties.Set("Name", i.name)

for _, tag := range i.tags {
properties.SetTag(tag.Key, tag.Value)
}

return properties
}
98 changes: 98 additions & 0 deletions resources/memorydb-parametergroups.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
package resources

import (
"fmt"
"strings"

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

type MemoryDBParameterGroup struct {
svc *memorydb.MemoryDB
name *string
family *string
tags []*memorydb.Tag
}

func init() {
register("MemoryDBParameterGroup", ListMemoryDBParameterGroups)
}

func ListMemoryDBParameterGroups(sess *session.Session) ([]Resource, error) {
svc := memorydb.New(sess)
var resources []Resource

params := &memorydb.DescribeParameterGroupsInput{MaxResults: aws.Int64(100)}

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

for _, parameterGroup := range resp.ParameterGroups {
tags, err := svc.ListTags(&memorydb.ListTagsInput{
ResourceArn: parameterGroup.ARN,
})

if err != nil {
continue
}

resources = append(resources, &MemoryDBParameterGroup{
svc: svc,
name: parameterGroup.Name,
family: parameterGroup.Family,
tags: tags.TagList,
})
}

if resp.NextToken == nil {
break
}

params.NextToken = resp.NextToken
}

return resources, nil
}

func (i *MemoryDBParameterGroup) Filter() error {
if strings.HasPrefix(*i.name, "default.") {
return fmt.Errorf("Cannot delete default parameter group")
}
return nil
}

func (i *MemoryDBParameterGroup) Remove() error {
params := &memorydb.DeleteParameterGroupInput{
ParameterGroupName: i.name,
}

_, err := i.svc.DeleteParameterGroup(params)
if err != nil {
return err
}

return nil
}

func (i *MemoryDBParameterGroup) String() string {
return *i.name
}

func (i *MemoryDBParameterGroup) Properties() types.Properties {
properties := types.NewProperties()
properties.
Set("Name", i.name).
Set("Family", i.family)

for _, tag := range i.tags {
properties.SetTag(tag.Key, tag.Value)
}

return properties
}
85 changes: 85 additions & 0 deletions resources/memorydb-subnetgroups.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
package resources

import (
"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/aws/session"
"github.com/aws/aws-sdk-go/service/memorydb"
"github.com/rebuy-de/aws-nuke/v2/pkg/types"
)

type MemoryDBSubnetGroup struct {
svc *memorydb.MemoryDB
name *string
tags []*memorydb.Tag
}

func init() {
register("MemoryDBSubnetGroup", ListMemoryDBSubnetGroups)
}

func ListMemoryDBSubnetGroups(sess *session.Session) ([]Resource, error) {
svc := memorydb.New(sess)
var resources []Resource

params := &memorydb.DescribeSubnetGroupsInput{MaxResults: aws.Int64(100)}

for {
resp, err := svc.DescribeSubnetGroups(params)
if err != nil {
return nil, err
}
for _, subnetGroup := range resp.SubnetGroups {
tags, err := svc.ListTags(&memorydb.ListTagsInput{
ResourceArn: subnetGroup.ARN,
})

if err != nil {
continue
}

resources = append(resources, &MemoryDBSubnetGroup{
svc: svc,
name: subnetGroup.Name,
tags: tags.TagList,
})

}

if resp.NextToken == nil {
break
}

params.NextToken = resp.NextToken
}

return resources, nil
}

func (i *MemoryDBSubnetGroup) Remove() error {
params := &memorydb.DeleteSubnetGroupInput{
SubnetGroupName: i.name,
}

_, err := i.svc.DeleteSubnetGroup(params)
if err != nil {
return err
}

return nil
}

func (i *MemoryDBSubnetGroup) String() string {
return *i.name
}

func (i *MemoryDBSubnetGroup) Properties() types.Properties {
properties := types.NewProperties()
properties.
Set("Name", i.name)

for _, tag := range i.tags {
properties.SetTag(tag.Key, tag.Value)
}

return properties
}
Loading

0 comments on commit f1aff70

Please sign in to comment.