Skip to content

Commit

Permalink
Merge pull request #116 from ekristen/parity-owner-id
Browse files Browse the repository at this point in the history
feat: upgrade to [email protected], add OwnerID properties
  • Loading branch information
ekristen authored Mar 8, 2024
2 parents db586ea + 32ed611 commit 5f7e651
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 25 deletions.
8 changes: 3 additions & 5 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,16 @@ go 1.21.6

require (
github.com/aws/aws-sdk-go v1.50.24
github.com/ekristen/libnuke v0.10.1
github.com/ekristen/libnuke v0.11.0
github.com/fatih/color v1.16.0
github.com/golang/mock v1.6.0
github.com/google/uuid v1.6.0
github.com/gotidy/ptr v1.4.0
github.com/pkg/errors v0.9.1
github.com/sirupsen/logrus v1.9.3
github.com/stretchr/testify v1.8.4
github.com/stretchr/testify v1.9.0
github.com/urfave/cli/v2 v2.27.1
golang.org/x/text v0.14.0
gopkg.in/yaml.v3 v3.0.1
)

Expand All @@ -29,12 +30,9 @@ require (
github.com/russross/blackfriday/v2 v2.1.0 // indirect
github.com/stevenle/topsort v0.2.0 // indirect
github.com/xrash/smetrics v0.0.0-20201216005158-039620a65673 // indirect
golang.org/x/mod v0.9.0 // indirect
golang.org/x/net v0.19.0 // indirect
golang.org/x/sync v0.6.0 // indirect
golang.org/x/sys v0.16.0 // indirect
golang.org/x/text v0.14.0 // indirect
golang.org/x/tools v0.6.0 // indirect
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
)
14 changes: 4 additions & 10 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ3
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/ekristen/libnuke v0.10.1 h1:+BRdDPuFR/5a8eJu1gpShXYbYs9tJ2kemM83EsbPp2g=
github.com/ekristen/libnuke v0.10.1/go.mod h1:WhYx7LDAkvkXwwfhWCASRn7fbifF8kfyhNsUj5zCCVs=
github.com/ekristen/libnuke v0.11.0 h1:SdSaAVnuAdGDqNlV82uAa+2FD9NeQyH96rIMduheh6o=
github.com/ekristen/libnuke v0.11.0/go.mod h1:sBdA04l9IMMejQw5gO9k6o/a0GffSYhgZYaUSdRjIac=
github.com/fatih/color v1.16.0 h1:zmkK9Ngbjj+K0yRhTVONQh1p/HknKYSlNT+vZCzyokM=
github.com/fatih/color v1.16.0/go.mod h1:fL2Sau1YI5c0pdGEVCbKQbLXB6edEj1ZgiY4NijnWvE=
github.com/golang/mock v1.6.0 h1:ErTB+efbowRARo13NNdxyJji2egdxLGQhRaY+DUumQc=
Expand Down Expand Up @@ -50,8 +50,8 @@ github.com/stevenle/topsort v0.2.0 h1:LLWgtp34HPX6/RBDRS0kElVxGOTzGBLI1lSAa5Lb46
github.com/stevenle/topsort v0.2.0/go.mod h1:ck2WG2/ZrOr6dLApQ/5Xrqy5wv3T0qhKYWE7r9tkibc=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk=
github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo=
github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg=
github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
github.com/urfave/cli/v2 v2.27.1 h1:8xSQ6szndafKVRmfyeUMxkNUJQMjL1F2zmsZ+qHpfho=
github.com/urfave/cli/v2 v2.27.1/go.mod h1:8qnjx1vcq5s2/wpsqoZFndg2CE5tNFyrTvS6SinrnYQ=
github.com/xrash/smetrics v0.0.0-20201216005158-039620a65673 h1:bAn7/zixMGCfxrRTfdpNzjtPYqr8smhKouy9mxVdGPU=
Expand All @@ -60,8 +60,6 @@ github.com/yuin/goldmark v1.3.5/go.mod h1:mwnBkeHKe2W/ZEtQ+71ViKU8L12m81fl3OWwC1
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
golang.org/x/crypto v0.0.0-20191011191535-87dc89f01550/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
golang.org/x/mod v0.4.2/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
golang.org/x/mod v0.9.0 h1:KENHtAZL2y3NLMYZeHY9DW8HW8V+kQyJsY/V9JlKvCs=
golang.org/x/mod v0.9.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs=
golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
golang.org/x/net v0.0.0-20210405180319-a5a99cb37ef4/go.mod h1:p54w0d4576C0XHj96bSt6lcn1PtDYWL6XObtHCRCNQM=
Expand Down Expand Up @@ -89,10 +87,6 @@ golang.org/x/text v0.14.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU=
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
golang.org/x/tools v0.1.1/go.mod h1:o0xws9oXOQQZyjljx8fwUC0k7L1pTE6eaCbjGeHmOkk=
golang.org/x/tools v0.1.12 h1:VveCTK38A2rkS8ZqFY25HIDFscX5X9OoEhJd3quQmXU=
golang.org/x/tools v0.1.12/go.mod h1:hNGJHUnrk76NpqgfD5Aqm5Crs+Hm0VOH/i9J2+nxYbc=
golang.org/x/tools v0.6.0 h1:BOw41kyTf3PuCW1pVQf8+Cyg8pMlkYB1oo9iJ6D/lKM=
golang.org/x/tools v0.6.0/go.mod h1:Xwgl3UAJ/d3gWutnCtw505GrjyAbvKui8lOU390QaIU=
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
Expand Down
8 changes: 7 additions & 1 deletion resources/ec2-dhcp-options.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ func (l *EC2DHCPOptionLister) List(_ context.Context, o interface{}) ([]resource
id: out.DhcpOptionsId,
tags: out.Tags,
defaultVPC: defVpcDhcpOptsID == ptr.ToString(out.DhcpOptionsId),
ownerID: out.OwnerId,
})
}

Expand All @@ -63,6 +64,7 @@ type EC2DHCPOption struct {
id *string
tags []*ec2.Tag
defaultVPC bool
ownerID *string
}

func (e *EC2DHCPOption) Remove(_ context.Context) error {
Expand All @@ -80,10 +82,14 @@ func (e *EC2DHCPOption) Remove(_ context.Context) error {

func (e *EC2DHCPOption) Properties() types.Properties {
properties := types.NewProperties()

properties.Set("DefaultVPC", e.defaultVPC)
properties.Set("OwnerID", e.ownerID)

for _, tagValue := range e.tags {
properties.SetTag(tagValue.Key, tagValue.Value)
}
properties.Set("DefaultVPC", e.defaultVPC)

return properties
}

Expand Down
11 changes: 10 additions & 1 deletion resources/ec2-internet-gateway-attachments.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,10 @@ func (l *EC2InternetGatewayAttachmentLister) List(_ context.Context, o interface
resources = append(resources, &EC2InternetGatewayAttachment{
svc: svc,
vpcID: vpc.VpcId,
vpcOwnerID: vpc.OwnerId,
vpcTags: vpc.Tags,
igwID: igw.InternetGatewayId,
igwOwnerID: igw.OwnerId,
igwTags: igw.Tags,
defaultVPC: *vpc.IsDefault,
})
Expand All @@ -75,8 +77,10 @@ func (l *EC2InternetGatewayAttachmentLister) List(_ context.Context, o interface
type EC2InternetGatewayAttachment struct {
svc *ec2.EC2
vpcID *string
vpcOwnerID *string
vpcTags []*ec2.Tag
igwID *string
igwOwnerID *string
igwTags []*ec2.Tag
defaultVPC bool
}
Expand All @@ -97,13 +101,18 @@ func (e *EC2InternetGatewayAttachment) Remove(_ context.Context) error {

func (e *EC2InternetGatewayAttachment) Properties() types.Properties {
properties := types.NewProperties()

properties.Set("DefaultVPC", e.defaultVPC)
properties.SetWithPrefix("vpc", "OwnerID", e.vpcOwnerID)
properties.SetWithPrefix("igw", "OwnerID", e.igwOwnerID)

for _, tagValue := range e.igwTags {
properties.SetTagWithPrefix("igw", tagValue.Key, tagValue.Value)
}
for _, tagValue := range e.vpcTags {
properties.SetTagWithPrefix("vpc", tagValue.Key, tagValue.Value)
}
properties.Set("DefaultVPC", e.defaultVPC)

return properties
}

Expand Down
20 changes: 12 additions & 8 deletions resources/ec2-route-tables.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,6 @@ func init() {
})
}

type EC2RouteTable struct {
svc *ec2.EC2
routeTable *ec2.RouteTable
defaultVPC bool
vpc *ec2.Vpc
}

type EC2RouteTableLister struct{}

func (l *EC2RouteTableLister) List(_ context.Context, o interface{}) ([]resource.Resource, error) {
Expand Down Expand Up @@ -64,12 +57,21 @@ func (l *EC2RouteTableLister) List(_ context.Context, o interface{}) ([]resource
routeTable: out,
defaultVPC: defVpcID == ptr.ToString(out.VpcId),
vpc: vpc,
ownerID: out.OwnerId,
})
}

return resources, nil
}

type EC2RouteTable struct {
svc *ec2.EC2
routeTable *ec2.RouteTable
defaultVPC bool
vpc *ec2.Vpc
ownerID *string
}

func (e *EC2RouteTable) Filter() error {
for _, association := range e.routeTable.Associations {
if *association.Main {
Expand Down Expand Up @@ -97,7 +99,9 @@ func (e *EC2RouteTable) Properties() types.Properties {
properties := types.NewProperties()

properties.Set("DefaultVPC", e.defaultVPC)
properties.Set("vpcID", e.routeTable.VpcId)
properties.Set("OwnerID", e.ownerID)
properties.Set("vpcID", e.vpc.VpcId) // TODO: deprecate and remove this
properties.SetWithPrefix("vpc", "ID", e.vpc.VpcId)

for _, tagValue := range e.routeTable.Tags {
properties.SetTag(tagValue.Key, tagValue.Value)
Expand Down

0 comments on commit 5f7e651

Please sign in to comment.