-
-
Notifications
You must be signed in to change notification settings - Fork 38
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add(resources): MemoryDB from upstream (#35)
* feat: MemoryDBACL resource support (#1079) feat: MemoryDBCluster resource support feat: MemoryDBParameterGroup resource support feat: MemoryDBSubnetGroup resource support feat: MemoryDBUser resource support * Filter open-access MemoryDB ACL (#1089) * migrate: memorydb resources to libnuke format --------- Co-authored-by: James Taylor <[email protected]> Co-authored-by: Philipp Trulson <[email protected]>
- Loading branch information
1 parent
019a00a
commit c8faec9
Showing
5 changed files
with
528 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,108 @@ | ||
package resources | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
|
||
"github.com/aws/aws-sdk-go/aws" | ||
"github.com/aws/aws-sdk-go/service/memorydb" | ||
|
||
"github.com/ekristen/libnuke/pkg/resource" | ||
"github.com/ekristen/libnuke/pkg/types" | ||
|
||
"github.com/ekristen/aws-nuke/pkg/nuke" | ||
) | ||
|
||
type MemoryDBACL struct { | ||
svc *memorydb.MemoryDB | ||
name *string | ||
tags []*memorydb.Tag | ||
} | ||
|
||
const MemoryDBACLResource = "MemoryDBACL" | ||
|
||
func init() { | ||
resource.Register(&resource.Registration{ | ||
Name: MemoryDBACLResource, | ||
Scope: nuke.Account, | ||
Lister: &MemoryDBACLLister{}, | ||
}) | ||
} | ||
|
||
type MemoryDBACLLister struct{} | ||
|
||
func (l *MemoryDBACLLister) List(_ context.Context, o interface{}) ([]resource.Resource, error) { | ||
opts := o.(*nuke.ListerOpts) | ||
|
||
svc := memorydb.New(opts.Session) | ||
var resources []resource.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) Filter() error { | ||
if *i.name == "open-access" { | ||
return fmt.Errorf("open-access ACL can't be deleted") | ||
} else { | ||
return nil | ||
} | ||
} | ||
|
||
func (i *MemoryDBACL) Remove(_ context.Context) 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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
package resources | ||
|
||
import ( | ||
"context" | ||
|
||
"github.com/aws/aws-sdk-go/aws" | ||
"github.com/aws/aws-sdk-go/service/memorydb" | ||
|
||
"github.com/ekristen/libnuke/pkg/resource" | ||
"github.com/ekristen/libnuke/pkg/types" | ||
|
||
"github.com/ekristen/aws-nuke/pkg/nuke" | ||
) | ||
|
||
type MemoryDBCluster struct { | ||
svc *memorydb.MemoryDB | ||
name *string | ||
tags []*memorydb.Tag | ||
} | ||
|
||
const MemoryDBClusterResource = "MemoryDBCluster" | ||
|
||
func init() { | ||
resource.Register(&resource.Registration{ | ||
Name: MemoryDBClusterResource, | ||
Scope: nuke.Account, | ||
Lister: &MemoryDBClusterLister{}, | ||
}) | ||
} | ||
|
||
type MemoryDBClusterLister struct{} | ||
|
||
func (l *MemoryDBClusterLister) List(_ context.Context, o interface{}) ([]resource.Resource, error) { | ||
opts := o.(*nuke.ListerOpts) | ||
|
||
svc := memorydb.New(opts.Session) | ||
var resources []resource.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(_ context.Context) 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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,112 @@ | ||
package resources | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
"strings" | ||
|
||
"github.com/aws/aws-sdk-go/aws" | ||
"github.com/aws/aws-sdk-go/service/memorydb" | ||
|
||
"github.com/ekristen/libnuke/pkg/resource" | ||
"github.com/ekristen/libnuke/pkg/types" | ||
|
||
"github.com/ekristen/aws-nuke/pkg/nuke" | ||
) | ||
|
||
type MemoryDBParameterGroup struct { | ||
svc *memorydb.MemoryDB | ||
name *string | ||
family *string | ||
tags []*memorydb.Tag | ||
} | ||
|
||
const MemoryDBParameterGroupResource = "MemoryDBParameterGroup" | ||
|
||
func init() { | ||
resource.Register(&resource.Registration{ | ||
Name: MemoryDBParameterGroupResource, | ||
Scope: nuke.Account, | ||
Lister: &MemoryDBParameterGroupLister{}, | ||
}) | ||
} | ||
|
||
type MemoryDBParameterGroupLister struct{} | ||
|
||
func (l *MemoryDBParameterGroupLister) List(_ context.Context, o interface{}) ([]resource.Resource, error) { | ||
opts := o.(*nuke.ListerOpts) | ||
|
||
svc := memorydb.New(opts.Session) | ||
var resources []resource.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(_ context.Context) 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 | ||
} |
Oops, something went wrong.