Skip to content

Commit

Permalink
Merge pull request #253 from ekristen/various-fixes
Browse files Browse the repository at this point in the history
fix: various fixes
  • Loading branch information
ekristen authored Aug 21, 2024
2 parents f78d31a + 17f634b commit 9b2b17d
Show file tree
Hide file tree
Showing 12 changed files with 198 additions and 122 deletions.
8 changes: 8 additions & 0 deletions resources/applicationautoscaling-scalable-targets.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package resources

import (
"context"
"slices"

"github.com/gotidy/ptr"

Expand Down Expand Up @@ -32,9 +33,16 @@ func (l *ApplicationAutoScalingScalableTargetLister) List(_ context.Context, o i

namespaces := applicationautoscaling.ServiceNamespace_Values()

// Note: Workspaces is not a valid namespace for DescribeScalableTargets anymore according to the API
invalidNamespaces := []string{applicationautoscaling.ServiceNamespaceWorkspaces}

params := &applicationautoscaling.DescribeScalableTargetsInput{}
resources := make([]resource.Resource, 0)
for _, namespace := range namespaces {
if slices.Contains(invalidNamespaces, namespace) {
continue
}

for {
params.ServiceNamespace = ptr.String(namespace)
resp, err := svc.DescribeScalableTargets(params)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,22 +5,17 @@ import (
"fmt"

"github.com/gotidy/ptr"
"github.com/sirupsen/logrus"

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

"github.com/ekristen/aws-nuke/v3/pkg/nuke"
"github.com/ekristen/libnuke/pkg/registry"
"github.com/ekristen/libnuke/pkg/resource"
)
"github.com/ekristen/libnuke/pkg/types"

type CloudFrontDistributionDeployment struct {
svc *cloudfront.CloudFront
distributionID *string
eTag *string
distributionConfig *cloudfront.DistributionConfig
status string
}
"github.com/ekristen/aws-nuke/v3/pkg/nuke"
)

const CloudFrontDistributionDeploymentResource = "CloudFrontDistributionDeployment"

Expand Down Expand Up @@ -61,44 +56,57 @@ func (l *CloudFrontDistributionDeploymentLister) List(_ context.Context, o inter
}

for _, distribution := range distributions {
params := &cloudfront.GetDistributionInput{
resp, err := svc.GetDistribution(&cloudfront.GetDistributionInput{
Id: distribution.Id,
}
resp, err := svc.GetDistribution(params)
})
if err != nil {
return nil, err
logrus.WithError(err).Error("unable to get distribution, skipping")
continue
}

resources = append(resources, &CloudFrontDistributionDeployment{
svc: svc,
distributionID: resp.Distribution.Id,
ID: resp.Distribution.Id,
eTag: resp.ETag,
distributionConfig: resp.Distribution.DistributionConfig,
status: ptr.ToString(resp.Distribution.Status),
Status: resp.Distribution.Status,
})
}

return resources, nil
}

func (f *CloudFrontDistributionDeployment) Remove(_ context.Context) error {
f.distributionConfig.Enabled = aws.Bool(false)
type CloudFrontDistributionDeployment struct {
svc *cloudfront.CloudFront
ID *string
Status *string
eTag *string
distributionConfig *cloudfront.DistributionConfig
}

func (r *CloudFrontDistributionDeployment) Remove(_ context.Context) error {
r.distributionConfig.Enabled = aws.Bool(false)

_, err := f.svc.UpdateDistribution(&cloudfront.UpdateDistributionInput{
Id: f.distributionID,
DistributionConfig: f.distributionConfig,
IfMatch: f.eTag,
_, err := r.svc.UpdateDistribution(&cloudfront.UpdateDistributionInput{
Id: r.ID,
DistributionConfig: r.distributionConfig,
IfMatch: r.eTag,
})

return err
}

func (f *CloudFrontDistributionDeployment) Filter() error {
if !ptr.ToBool(f.distributionConfig.Enabled) && f.status != "InProgress" {
func (r *CloudFrontDistributionDeployment) Filter() error {
if !ptr.ToBool(r.distributionConfig.Enabled) && ptr.ToString(r.Status) != "InProgress" {
return fmt.Errorf("already disabled")
}
return nil
}

func (f *CloudFrontDistributionDeployment) String() string {
return *f.distributionID
func (r *CloudFrontDistributionDeployment) Properties() types.Properties {
return types.NewPropertiesFromStruct(r)
}

func (r *CloudFrontDistributionDeployment) String() string {
return *r.ID
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@ package resources

import (
"context"

"fmt"

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

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

"github.com/ekristen/aws-nuke/v3/pkg/nuke"
)
Expand Down Expand Up @@ -47,31 +47,39 @@ func (l *CloudWatchEventsRuleLister) List(_ context.Context, o interface{}) ([]r

for _, rule := range resp.Rules {
resources = append(resources, &CloudWatchEventsRule{
svc: svc,
name: rule.Name,
busName: bus.Name,
svc: svc,
Name: rule.Name,
ARN: rule.Arn,
State: rule.State,
EventBusName: bus.Name,
})
}
}
return resources, nil
}

type CloudWatchEventsRule struct {
svc *cloudwatchevents.CloudWatchEvents
name *string
busName *string
svc *cloudwatchevents.CloudWatchEvents
Name *string
ARN *string
State *string
EventBusName *string
}

func (rule *CloudWatchEventsRule) Remove(_ context.Context) error {
_, err := rule.svc.DeleteRule(&cloudwatchevents.DeleteRuleInput{
Name: rule.name,
EventBusName: rule.busName,
func (r *CloudWatchEventsRule) Remove(_ context.Context) error {
_, err := r.svc.DeleteRule(&cloudwatchevents.DeleteRuleInput{
Name: r.Name,
EventBusName: r.EventBusName,
Force: aws.Bool(true),
})
return err
}

func (rule *CloudWatchEventsRule) String() string {
func (r *CloudWatchEventsRule) Properties() types.Properties {
return types.NewPropertiesFromStruct(r)
}

func (r *CloudWatchEventsRule) String() string {
// TODO: remove Rule:, mark as breaking change for filters
return fmt.Sprintf("Rule: %s", *rule.name)
return fmt.Sprintf("Rule: %s", *r.Name)
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (

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

"github.com/ekristen/aws-nuke/v3/pkg/nuke"
)
Expand Down Expand Up @@ -37,27 +38,31 @@ func (l *ConfigServiceConfigurationRecorderLister) List(_ context.Context, o int
resources := make([]resource.Resource, 0)
for _, configurationRecorder := range resp.ConfigurationRecorders {
resources = append(resources, &ConfigServiceConfigurationRecorder{
svc: svc,
configurationRecorderName: configurationRecorder.Name,
svc: svc,
Name: configurationRecorder.Name,
})
}

return resources, nil
}

type ConfigServiceConfigurationRecorder struct {
svc *configservice.ConfigService
configurationRecorderName *string
svc *configservice.ConfigService
Name *string
}

func (f *ConfigServiceConfigurationRecorder) Remove(_ context.Context) error {
_, err := f.svc.DeleteConfigurationRecorder(&configservice.DeleteConfigurationRecorderInput{
ConfigurationRecorderName: f.configurationRecorderName,
func (r *ConfigServiceConfigurationRecorder) Remove(_ context.Context) error {
_, err := r.svc.DeleteConfigurationRecorder(&configservice.DeleteConfigurationRecorderInput{
ConfigurationRecorderName: r.Name,
})

return err
}

func (f *ConfigServiceConfigurationRecorder) String() string {
return *f.configurationRecorderName
func (r *ConfigServiceConfigurationRecorder) Properties() types.Properties {
return types.NewPropertiesFromStruct(r)
}

func (r *ConfigServiceConfigurationRecorder) String() string {
return *r.Name
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (

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

"github.com/ekristen/aws-nuke/v3/pkg/nuke"
)
Expand All @@ -25,7 +26,7 @@ type ConfigServiceDeliveryChannelLister struct{}

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

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

params := &configservice.DescribeDeliveryChannelsInput{}
Expand All @@ -34,30 +35,33 @@ func (l *ConfigServiceDeliveryChannelLister) List(_ context.Context, o interface
return nil, err
}

resources := make([]resource.Resource, 0)
for _, deliveryChannel := range resp.DeliveryChannels {
resources = append(resources, &ConfigServiceDeliveryChannel{
svc: svc,
deliveryChannelName: deliveryChannel.Name,
svc: svc,
Name: deliveryChannel.Name,
})
}

return resources, nil
}

type ConfigServiceDeliveryChannel struct {
svc *configservice.ConfigService
deliveryChannelName *string
svc *configservice.ConfigService
Name *string
}

func (f *ConfigServiceDeliveryChannel) Remove(_ context.Context) error {
_, err := f.svc.DeleteDeliveryChannel(&configservice.DeleteDeliveryChannelInput{
DeliveryChannelName: f.deliveryChannelName,
func (r *ConfigServiceDeliveryChannel) Remove(_ context.Context) error {
_, err := r.svc.DeleteDeliveryChannel(&configservice.DeleteDeliveryChannelInput{
DeliveryChannelName: r.Name,
})

return err
}

func (f *ConfigServiceDeliveryChannel) String() string {
return *f.deliveryChannelName
func (r *ConfigServiceDeliveryChannel) Properties() types.Properties {
return types.NewPropertiesFromStruct(r)
}

func (r *ConfigServiceDeliveryChannel) String() string {
return *r.Name
}
23 changes: 14 additions & 9 deletions resources/dax-clusters.go → resources/dax-cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (

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

"github.com/ekristen/aws-nuke/v3/pkg/nuke"
)
Expand Down Expand Up @@ -46,8 +47,8 @@ func (l *DAXClusterLister) List(_ context.Context, o interface{}) ([]resource.Re

for _, cluster := range output.Clusters {
resources = append(resources, &DAXCluster{
svc: svc,
clusterName: cluster.ClusterName,
svc: svc,
Name: cluster.ClusterName,
})
}

Expand All @@ -62,18 +63,22 @@ func (l *DAXClusterLister) List(_ context.Context, o interface{}) ([]resource.Re
}

type DAXCluster struct {
svc *dax.DAX
clusterName *string
svc *dax.DAX
Name *string
}

func (f *DAXCluster) Remove(_ context.Context) error {
_, err := f.svc.DeleteCluster(&dax.DeleteClusterInput{
ClusterName: f.clusterName,
func (r *DAXCluster) Remove(_ context.Context) error {
_, err := r.svc.DeleteCluster(&dax.DeleteClusterInput{
ClusterName: r.Name,
})

return err
}

func (f *DAXCluster) String() string {
return *f.clusterName
func (r *DAXCluster) Properties() types.Properties {
return types.NewPropertiesFromStruct(r)
}

func (r *DAXCluster) String() string {
return *r.Name
}
Loading

0 comments on commit 9b2b17d

Please sign in to comment.