Skip to content

Commit

Permalink
Merge pull request #461 from ekristen/bunch-of-fixes
Browse files Browse the repository at this point in the history
feat: various feats and fixes
  • Loading branch information
ekristen authored Dec 13, 2024
2 parents ff99ac3 + 462e441 commit eeb0f02
Show file tree
Hide file tree
Showing 9 changed files with 350 additions and 163 deletions.
26 changes: 26 additions & 0 deletions docs/resources/neptune-cluster.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ NeptuneCluster


- `ID`: No Description
- `Status`: No Description
- `tag:<key>:`: This resource has tags with property `Tags`. These are key/value pairs that are
added as their own property with the prefix of `tag:` (e.g. [tag:example: "value"])

!!! note - Using Properties
Properties are what [Filters](../config-filtering.md) are written against in your configuration. You use the property
Expand All @@ -28,3 +31,26 @@ the filter.

The string value is always what is used in the output of the log format when a resource is identified.

## Settings

- `DisableDeletionProtection`


### DisableDeletionProtection

!!! note
There is currently no description for this setting. Often times settings are fairly self-explanatory. However, we
are working on adding descriptions for all settings.

```text
DisableDeletionProtection
```

### DependsOn

!!! important - Experimental Feature
This resource depends on a resource using the experimental feature. This means that the resource will
only be deleted if all the resources of a particular type are deleted first or reach a terminal state.

- [NeptuneInstance](./neptune-instance.md)

29 changes: 29 additions & 0 deletions docs/resources/neptune-instance.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,10 @@ NeptuneInstance
## Properties


- `ClusterID`: No Description
- `ID`: No Description
- `Name`: No Description
- `Status`: No Description
- `tag:<key>:`: This resource has tags with property `Tags`. These are key/value pairs that are
added as their own property with the prefix of `tag:` (e.g. [tag:example: "value"])

Expand All @@ -31,3 +33,30 @@ the filter.

The string value is always what is used in the output of the log format when a resource is identified.

## Settings

- `DisableClusterDeletionProtection`
- `DisableDeletionProtection`


### DisableClusterDeletionProtection

!!! note
There is currently no description for this setting. Often times settings are fairly self-explanatory. However, we
are working on adding descriptions for all settings.

```text
DisableClusterDeletionProtection
```


### DisableDeletionProtection

!!! note
There is currently no description for this setting. Often times settings are fairly self-explanatory. However, we
are working on adding descriptions for all settings.

```text
DisableDeletionProtection
```

7 changes: 6 additions & 1 deletion docs/resources/sfn-state-machine.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,12 @@ SFNStateMachine
## Properties


- `ARN`: No Description
- `ARN`: The Amazon Resource Name (ARN) that identifies the state machine.
- `CreationDate`: The date the state machine was created.
- `Name`: The name of the state machine.
- `Type`: The type of the state machine.
- `tag:<key>:`: This resource has tags with property `Tags`. These are key/value pairs that are
added as their own property with the prefix of `tag:` (e.g. [tag:example: "value"])

!!! note - Using Properties
Properties are what [Filters](../config-filtering.md) are written against in your configuration. You use the property
Expand Down
129 changes: 129 additions & 0 deletions resources/neptune-cluster.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,129 @@
package resources

import (
"context"
"fmt"

"github.com/gotidy/ptr"

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

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

"github.com/ekristen/aws-nuke/v3/pkg/nuke"
)

const NeptuneClusterResource = "NeptuneCluster"

func init() {
registry.Register(&registry.Registration{
Name: NeptuneClusterResource,
Scope: nuke.Account,
Resource: &NeptuneCluster{},
Lister: &NeptuneClusterLister{},
DependsOn: []string{
NeptuneInstanceResource,
},
Settings: []string{
"DisableDeletionProtection",
},
})
}

type NeptuneClusterLister struct{}

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

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

params := &neptune.DescribeDBClustersInput{
MaxRecords: aws.Int64(100),
}

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

for _, dbCluster := range output.DBClusters {
var dbTags []*neptune.Tag
tags, err := svc.ListTagsForResource(&neptune.ListTagsForResourceInput{
ResourceName: dbCluster.DBClusterArn,
})
if err != nil {
opts.Logger.WithError(err).Warn("failed to list tags for resource")
} else {
dbTags = tags.TagList
}

resources = append(resources, &NeptuneCluster{
svc: svc,
ID: dbCluster.DBClusterIdentifier,
Status: dbCluster.Status,
Tags: dbTags,
})
}

if output.Marker == nil {
break
}

params.Marker = output.Marker
}

return resources, nil
}

type NeptuneCluster struct {
svc *neptune.Neptune
settings *libsettings.Setting

ID *string
Status *string
Tags []*neptune.Tag
}

func (r *NeptuneCluster) Settings(settings *libsettings.Setting) {
r.settings = settings
}

func (r *NeptuneCluster) Filter() error {
if ptr.ToString(r.Status) == "deleting" {
return fmt.Errorf("already deleting")
}
return nil
}

func (r *NeptuneCluster) Remove(_ context.Context) error {
if r.settings.GetBool("DisableDeletionProtection") {
_, err := r.svc.ModifyDBCluster(&neptune.ModifyDBClusterInput{
DBClusterIdentifier: r.ID,
DeletionProtection: ptr.Bool(false),
})
if err != nil {
return err
}
}

_, err := r.svc.DeleteDBCluster(&neptune.DeleteDBClusterInput{
DBClusterIdentifier: r.ID,
SkipFinalSnapshot: ptr.Bool(true),
})

return err
}

func (r *NeptuneCluster) Properties() types.Properties {
return types.NewPropertiesFromStruct(r)
}

func (r *NeptuneCluster) String() string {
return *r.ID
}
77 changes: 0 additions & 77 deletions resources/neptune-clusters.go

This file was deleted.

Loading

0 comments on commit eeb0f02

Please sign in to comment.