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

Commit

Permalink
Merge branch 'main' into feature/redshift-scheduled-action
Browse files Browse the repository at this point in the history
  • Loading branch information
der-eismann authored Aug 24, 2023
2 parents a3f5ee5 + e641116 commit 827677a
Show file tree
Hide file tree
Showing 11 changed files with 786 additions and 0 deletions.
74 changes: 74 additions & 0 deletions resources/cloudfront-key-groups.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
package resources

import (
"time"

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

type CloudFrontKeyGroup struct {
svc *cloudfront.CloudFront
ID *string
name *string
lastModifiedTime *time.Time
}

func init() {
register("CloudFrontKeyGroup", ListCloudFrontKeyGroups)
}

func ListCloudFrontKeyGroups(sess *session.Session) ([]Resource, error) {
svc := cloudfront.New(sess)
resources := []Resource{}
params := &cloudfront.ListKeyGroupsInput{}

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

for _, item := range resp.KeyGroupList.Items {
resources = append(resources, &CloudFrontKeyGroup{
svc: svc,
ID: item.KeyGroup.Id,
name: item.KeyGroup.KeyGroupConfig.Name,
lastModifiedTime: item.KeyGroup.LastModifiedTime,
})
}

if resp.KeyGroupList.NextMarker == nil {
break
}

params.Marker = resp.KeyGroupList.NextMarker
}

return resources, nil
}

func (f *CloudFrontKeyGroup) Remove() error {
resp, err := f.svc.GetKeyGroup(&cloudfront.GetKeyGroupInput{
Id: f.ID,
})
if err != nil {
return err
}

_, err = f.svc.DeleteKeyGroup(&cloudfront.DeleteKeyGroupInput{
Id: f.ID,
IfMatch: resp.ETag,
})

return err
}

func (f *CloudFrontKeyGroup) Properties() types.Properties {
properties := types.NewProperties()
properties.Set("ID", f.ID)
properties.Set("Name", f.name)
properties.Set("LastModifiedTime", f.lastModifiedTime.Format(time.RFC3339))
return properties
}
74 changes: 74 additions & 0 deletions resources/cloudfront-public-keys.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
package resources

import (
"time"

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

type CloudFrontPublicKey struct {
svc *cloudfront.CloudFront
ID *string
name *string
createdTime *time.Time
}

func init() {
register("CloudFrontPublicKey", ListCloudFrontPublicKeys)
}

func ListCloudFrontPublicKeys(sess *session.Session) ([]Resource, error) {
svc := cloudfront.New(sess)
resources := []Resource{}
params := &cloudfront.ListPublicKeysInput{}

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

for _, item := range resp.PublicKeyList.Items {
resources = append(resources, &CloudFrontPublicKey{
svc: svc,
ID: item.Id,
name: item.Name,
createdTime: item.CreatedTime,
})
}

if resp.PublicKeyList.NextMarker == nil {
break
}

params.Marker = resp.PublicKeyList.NextMarker
}

return resources, nil
}

func (f *CloudFrontPublicKey) Remove() error {
resp, err := f.svc.GetPublicKey(&cloudfront.GetPublicKeyInput{
Id: f.ID,
})
if err != nil {
return err
}

_, err = f.svc.DeletePublicKey(&cloudfront.DeletePublicKeyInput{
Id: f.ID,
IfMatch: resp.ETag,
})

return err
}

func (f *CloudFrontPublicKey) Properties() types.Properties {
properties := types.NewProperties()
properties.Set("ID", f.ID)
properties.Set("Name", f.name)
properties.Set("CreatedTime", f.createdTime.Format(time.RFC3339))
return properties
}
10 changes: 10 additions & 0 deletions resources/elasticache-subnetgroups.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
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/elasticache"
Expand Down Expand Up @@ -35,6 +38,13 @@ func ListElasticacheSubnetGroups(sess *session.Session) ([]Resource, error) {
return resources, nil
}

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

func (i *ElasticacheSubnetGroup) Remove() error {
params := &elasticache.DeleteCacheSubnetGroupInput{
CacheSubnetGroupName: i.name,
Expand Down
74 changes: 74 additions & 0 deletions resources/elasticache-usergroups.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
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/elasticache"
"github.com/rebuy-de/aws-nuke/v2/pkg/types"
)

type ElasticacheUserGroup struct {
svc *elasticache.ElastiCache
groupId *string
}

func init() {
register("ElasticacheUserGroup", ListElasticacheUserGroups)
}

func ListElasticacheUserGroups(sess *session.Session) ([]Resource, error) {
svc := elasticache.New(sess)
resources := []Resource{}
var nextToken *string

for {
params := &elasticache.DescribeUserGroupsInput{
MaxRecords: aws.Int64(100),
Marker: nextToken,
}
resp, err := svc.DescribeUserGroups(params)
if err != nil {
return nil, err
}

for _, userGroup := range resp.UserGroups {
resources = append(resources, &ElasticacheUserGroup{
svc: svc,
groupId: userGroup.UserGroupId,
})
}

// Check if there are more results
if resp.Marker == nil {
break // No more results, exit the loop
}

// Set the nextToken for the next iteration
nextToken = resp.Marker
}

return resources, nil
}

func (i *ElasticacheUserGroup) Remove() error {
params := &elasticache.DeleteUserGroupInput{
UserGroupId: i.groupId,
}

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

return nil
}

func (i *ElasticacheUserGroup) Properties() types.Properties {
properties := types.NewProperties()
properties.Set("ID", i.groupId)
return properties
}

func (i *ElasticacheUserGroup) String() string {
return *i.groupId
}
87 changes: 87 additions & 0 deletions resources/elasticache-users.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
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/elasticache"
"github.com/rebuy-de/aws-nuke/v2/pkg/types"
)

type ElasticacheUser struct {
svc *elasticache.ElastiCache
userId *string
userName *string
}

func init() {
register("ElasticacheUser", ListElasticacheUsers)
}

func ListElasticacheUsers(sess *session.Session) ([]Resource, error) {
svc := elasticache.New(sess)
resources := []Resource{}
var nextToken *string

for {
params := &elasticache.DescribeUsersInput{
MaxRecords: aws.Int64(100),
Marker: nextToken,
}
resp, err := svc.DescribeUsers(params)
if err != nil {
return nil, err
}

for _, user := range resp.Users {
resources = append(resources, &ElasticacheUser{
svc: svc,
userId: user.UserId,
userName: user.UserName,
})
}

// Check if there are more results
if resp.Marker == nil {
break // No more results, exit the loop
}

// Set the nextToken for the next iteration
nextToken = resp.Marker
}

return resources, nil
}

func (i *ElasticacheUser) Filter() error {
if strings.HasPrefix(*i.userName, "default") {
return fmt.Errorf("cannot delete default user")
}
return nil
}

func (i *ElasticacheUser) Remove() error {
params := &elasticache.DeleteUserInput{
UserId: i.userId,
}

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

return nil
}

func (i *ElasticacheUser) Properties() types.Properties {
properties := types.NewProperties()
properties.Set("ID", i.userId)
properties.Set("UserName", i.userName)
return properties
}

func (i *ElasticacheUser) String() string {
return *i.userId
}
Loading

0 comments on commit 827677a

Please sign in to comment.