From 1777427696134a65186588dd1268efcb034e88f1 Mon Sep 17 00:00:00 2001 From: Erik Kristensen Date: Fri, 8 Mar 2024 16:06:25 -0700 Subject: [PATCH 1/3] feat: upgrade to libnuke@0.11.0, add OwnerID properties --- go.mod | 4 ++-- go.sum | 5 +++++ resources/ec2-dhcp-options.go | 8 +++++++- resources/ec2-internet-gateway-attachments.go | 11 +++++++++- resources/ec2-route-tables.go | 20 +++++++++++-------- 5 files changed, 36 insertions(+), 12 deletions(-) diff --git a/go.mod b/go.mod index 2c603446..48e0f505 100644 --- a/go.mod +++ b/go.mod @@ -4,14 +4,14 @@ 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 gopkg.in/yaml.v3 v3.0.1 ) diff --git a/go.sum b/go.sum index 6115db3e..e439e0bb 100644 --- a/go.sum +++ b/go.sum @@ -8,6 +8,10 @@ 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.10.2 h1:kMrJqgFhmsYSEs9FCkZN90hGcf6OFESZmkBmUQ9snvI= +github.com/ekristen/libnuke v0.10.2/go.mod h1:sBdA04l9IMMejQw5gO9k6o/a0GffSYhgZYaUSdRjIac= +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= @@ -52,6 +56,7 @@ github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+ 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/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= diff --git a/resources/ec2-dhcp-options.go b/resources/ec2-dhcp-options.go index bca399a6..0541f3b4 100644 --- a/resources/ec2-dhcp-options.go +++ b/resources/ec2-dhcp-options.go @@ -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, }) } @@ -63,6 +64,7 @@ type EC2DHCPOption struct { id *string tags []*ec2.Tag defaultVPC bool + ownerID *string } func (e *EC2DHCPOption) Remove(_ context.Context) error { @@ -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 } diff --git a/resources/ec2-internet-gateway-attachments.go b/resources/ec2-internet-gateway-attachments.go index 13653ef8..38e62e45 100644 --- a/resources/ec2-internet-gateway-attachments.go +++ b/resources/ec2-internet-gateway-attachments.go @@ -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, }) @@ -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 } @@ -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 } diff --git a/resources/ec2-route-tables.go b/resources/ec2-route-tables.go index 0bcf179e..8680c9e6 100644 --- a/resources/ec2-route-tables.go +++ b/resources/ec2-route-tables.go @@ -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) { @@ -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 { @@ -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.SetWithPrefix("vpc", "vpcID", e.vpc.VpcId) + properties.SetWithPrefix("vpc", "ID", e.vpc.VpcId) for _, tagValue := range e.routeTable.Tags { properties.SetTag(tagValue.Key, tagValue.Value) From 9c7e306f9d7b6eacb3caca0352bdd6ed10361637 Mon Sep 17 00:00:00 2001 From: Erik Kristensen Date: Fri, 8 Mar 2024 16:08:24 -0700 Subject: [PATCH 2/3] chore: go mod tidy --- go.mod | 4 +--- go.sum | 13 +------------ 2 files changed, 2 insertions(+), 15 deletions(-) diff --git a/go.mod b/go.mod index 48e0f505..f62f436f 100644 --- a/go.mod +++ b/go.mod @@ -13,6 +13,7 @@ require ( github.com/sirupsen/logrus v1.9.3 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 ) @@ -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 ) diff --git a/go.sum b/go.sum index e439e0bb..01bbe06e 100644 --- a/go.sum +++ b/go.sum @@ -6,10 +6,6 @@ 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.10.2 h1:kMrJqgFhmsYSEs9FCkZN90hGcf6OFESZmkBmUQ9snvI= -github.com/ekristen/libnuke v0.10.2/go.mod h1:sBdA04l9IMMejQw5gO9k6o/a0GffSYhgZYaUSdRjIac= 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= @@ -54,8 +50,7 @@ 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= @@ -65,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= @@ -94,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= From 32ed6115407e14c281561629037e1f87fba4581a Mon Sep 17 00:00:00 2001 From: Erik Kristensen Date: Fri, 8 Mar 2024 16:16:57 -0700 Subject: [PATCH 3/3] chore: fix the property name back to original, note future removal --- resources/ec2-route-tables.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/resources/ec2-route-tables.go b/resources/ec2-route-tables.go index 8680c9e6..39b2850c 100644 --- a/resources/ec2-route-tables.go +++ b/resources/ec2-route-tables.go @@ -100,7 +100,7 @@ func (e *EC2RouteTable) Properties() types.Properties { properties.Set("DefaultVPC", e.defaultVPC) properties.Set("OwnerID", e.ownerID) - properties.SetWithPrefix("vpc", "vpcID", e.vpc.VpcId) + properties.Set("vpcID", e.vpc.VpcId) // TODO: deprecate and remove this properties.SetWithPrefix("vpc", "ID", e.vpc.VpcId) for _, tagValue := range e.routeTable.Tags {