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

Commit

Permalink
add support for QLDB ledgers (#841)
Browse files Browse the repository at this point in the history
  • Loading branch information
jvanbuel authored Oct 11, 2022
1 parent 8e23ba5 commit 8062fc7
Show file tree
Hide file tree
Showing 2 changed files with 99 additions and 0 deletions.
1 change: 1 addition & 0 deletions pkg/config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ type DisableDeletionProtection struct {
EC2Instance bool `yaml:"EC2Instance"`
CloudformationStack bool `yaml:"CloudformationStack"`
ELBv2 bool `yaml:"ELBv2"`
QLDBLedger bool `yaml:"QLDBLedger"`
}

type PresetDefinitions struct {
Expand Down
98 changes: 98 additions & 0 deletions resources/qldb_ledger.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
package resources

import (
"time"

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

type QLDBLedger struct {
svc *qldb.QLDB
ledger *qldb.DescribeLedgerOutput

featureFlags config.FeatureFlags
}

func init() {
register("QLDBLedger", ListQLDBLedgers)
}

func ListQLDBLedgers(sess *session.Session) ([]Resource, error) {
svc := qldb.New(sess)

params := &qldb.ListLedgersInput{}
resources := make([]Resource, 0)

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

for _, ledger := range resp.Ledgers {
ledgerDescription, err := svc.DescribeLedger(&qldb.DescribeLedgerInput{Name: ledger.Name})
if err != nil {
return nil, err
}

resources = append(resources, &QLDBLedger{
svc: svc,
ledger: ledgerDescription,
})
}
if resp.NextToken == nil {
break
}

params.NextToken = resp.NextToken
}

return resources, nil
}

func (l *QLDBLedger) FeatureFlags(ff config.FeatureFlags) {
l.featureFlags = ff
}

func (l *QLDBLedger) Remove() error {
if aws.BoolValue(l.ledger.DeletionProtection) && l.featureFlags.DisableDeletionProtection.QLDBLedger {
modifyParams := &qldb.UpdateLedgerInput{
DeletionProtection: aws.Bool(false),
Name: l.ledger.Name,
}
_, err := l.svc.UpdateLedger((modifyParams))
if err != nil {
return err
}
}

params := &qldb.DeleteLedgerInput{
Name: l.ledger.Name,
}

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

return nil
}

func (l *QLDBLedger) Properties() types.Properties {
properties := types.NewProperties()
properties.Set("Name", l.ledger.Name)
properties.Set("DeletionProtection", l.ledger.DeletionProtection)
properties.Set("Arn", l.ledger.Arn)
properties.Set("CreationDateTime", l.ledger.CreationDateTime.Format(time.RFC3339))
properties.Set("State", l.ledger.State)
properties.Set("PermissionsMode", l.ledger.PermissionsMode)
properties.Set("EncryptionDescription", l.ledger.EncryptionDescription)
return properties
}
func (l *QLDBLedger) String() string {
return aws.StringValue(l.ledger.Name)
}

0 comments on commit 8062fc7

Please sign in to comment.