Skip to content

Commit

Permalink
Merge branch 'rebuy-de:main' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
ekristen authored Jan 18, 2022
2 parents 14363bd + 3b7d60a commit 9ae42d1
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 8 deletions.
13 changes: 12 additions & 1 deletion resources/ec2-network-interfaces.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/ec2"
Expand Down Expand Up @@ -37,13 +40,17 @@ func ListEC2NetworkInterfaces(sess *session.Session) ([]Resource, error) {
}

func (e *EC2NetworkInterface) Remove() error {

if e.eni.Attachment != nil {
_, err := e.svc.DetachNetworkInterface(&ec2.DetachNetworkInterfaceInput{
AttachmentId: e.eni.Attachment.AttachmentId,
Force: aws.Bool(true),
})
if err != nil {
return err
expected := fmt.Sprintf("The interface attachment '%s' does not exist.", *e.eni.Attachment.AttachmentId)
if !strings.Contains(err.Error(), expected) {
return err
}
}
}

Expand Down Expand Up @@ -73,3 +80,7 @@ func (r *EC2NetworkInterface) Properties() types.Properties {
Set("Status", r.eni.Status)
return properties
}

func (r *EC2NetworkInterface) String() string {
return *r.eni.NetworkInterfaceId
}
18 changes: 12 additions & 6 deletions resources/ec2-snapshots.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,19 @@ package resources

import (
"fmt"
"time"

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

type EC2Snapshot struct {
svc *ec2.EC2
id string
tags []*ec2.Tag
svc *ec2.EC2
id string
startTime *time.Time
tags []*ec2.Tag
}

func init() {
Expand All @@ -33,9 +36,10 @@ func ListEC2Snapshots(sess *session.Session) ([]Resource, error) {
resources := make([]Resource, 0)
for _, out := range resp.Snapshots {
resources = append(resources, &EC2Snapshot{
svc: svc,
id: *out.SnapshotId,
tags: out.Tags,
svc: svc,
id: *out.SnapshotId,
startTime: out.StartTime,
tags: out.Tags,
})
}

Expand All @@ -44,6 +48,8 @@ func ListEC2Snapshots(sess *session.Session) ([]Resource, error) {

func (e *EC2Snapshot) Properties() types.Properties {
properties := types.NewProperties()
properties.Set("StartTime", e.startTime.Format(time.RFC3339))

for _, tagValue := range e.tags {
properties.Set(fmt.Sprintf("tag:%v", *tagValue.Key), tagValue.Value)
}
Expand Down
2 changes: 1 addition & 1 deletion resources/iam-policies.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ func ListIAMPolicies(sess *session.Session) ([]Resource, error) {
policy, err := GetIAMPolicy(svc, listedPolicy.Arn)
if err != nil {
logrus.Errorf("Failed to get listed policy %s: %v", *listedPolicy.PolicyName, err)
break
continue
}
policies = append(policies, policy)
}
Expand Down

0 comments on commit 9ae42d1

Please sign in to comment.