From dcafe549aa6441eea5b2c3ea1c8d07b7f9430bc9 Mon Sep 17 00:00:00 2001 From: Chase Freeman Date: Mon, 22 Jul 2024 17:16:17 -0500 Subject: [PATCH 1/3] feat(apigateway): add created date to apigateways --- resources/apigateway-restapis.go | 76 +++++++++++++++++--------------- resources/apigatewayv2-apis.go | 6 ++- 2 files changed, 46 insertions(+), 36 deletions(-) diff --git a/resources/apigateway-restapis.go b/resources/apigateway-restapis.go index 5c2973a0..4ba6df55 100644 --- a/resources/apigateway-restapis.go +++ b/resources/apigateway-restapis.go @@ -2,9 +2,10 @@ package resources import ( "context" + "time" "github.com/aws/aws-sdk-go/aws" - "github.com/aws/aws-sdk-go/service/apigateway" + "github.com/aws/aws-sdk-go/service/apigatewayv2" "github.com/ekristen/libnuke/pkg/registry" "github.com/ekristen/libnuke/pkg/resource" @@ -13,82 +14,87 @@ import ( "github.com/ekristen/aws-nuke/v3/pkg/nuke" ) -const APIGatewayRestAPIResource = "APIGatewayRestAPI" +const APIGatewayV2APIResource = "APIGatewayV2API" func init() { registry.Register(®istry.Registration{ - Name: APIGatewayRestAPIResource, + Name: APIGatewayV2APIResource, Scope: nuke.Account, - Lister: &APIGatewayRestAPILister{}, + Lister: &APIGatewayV2APILister{}, }) } -type APIGatewayRestAPILister struct{} +type APIGatewayV2APILister struct{} -type APIGatewayRestAPI struct { - svc *apigateway.APIGateway - restAPIID *string - name *string - version *string - tags map[string]*string -} - -func (l *APIGatewayRestAPILister) List(_ context.Context, o interface{}) ([]resource.Resource, error) { +func (l *APIGatewayV2APILister) List(_ context.Context, o interface{}) ([]resource.Resource, error) { opts := o.(*nuke.ListerOpts) - svc := apigateway.New(opts.Session) - + svc := apigatewayv2.New(opts.Session) var resources []resource.Resource - params := &apigateway.GetRestApisInput{ - Limit: aws.Int64(100), + params := &apigatewayv2.GetApisInput{ + MaxResults: aws.String("100"), } for { - output, err := svc.GetRestApis(params) + output, err := svc.GetApis(params) if err != nil { return nil, err } for _, item := range output.Items { - resources = append(resources, &APIGatewayRestAPI{ - svc: svc, - restAPIID: item.Id, - name: item.Name, - version: item.Version, - tags: item.Tags, + resources = append(resources, &APIGatewayV2API{ + svc: svc, + v2APIID: item.ApiId, + name: item.Name, + protocolType: item.ProtocolType, + version: item.Version, + createdDate: item.CreatedDate, + tags: item.Tags, }) } - if output.Position == nil { + if output.NextToken == nil { break } - params.Position = output.Position + params.NextToken = output.NextToken } return resources, nil } -func (f *APIGatewayRestAPI) Remove(_ context.Context) error { - _, err := f.svc.DeleteRestApi(&apigateway.DeleteRestApiInput{ - RestApiId: f.restAPIID, +type APIGatewayV2API struct { + svc *apigatewayv2.ApiGatewayV2 + v2APIID *string + name *string + protocolType *string + version *string + createdDate *time.Time + tags map[string]*string +} + +func (f *APIGatewayV2API) Remove(_ context.Context) error { + _, err := f.svc.DeleteApi(&apigatewayv2.DeleteApiInput{ + ApiId: f.v2APIID, }) return err } -func (f *APIGatewayRestAPI) String() string { - return *f.restAPIID +func (f *APIGatewayV2API) String() string { + return *f.v2APIID } -func (f *APIGatewayRestAPI) Properties() types.Properties { +func (f *APIGatewayV2API) Properties() types.Properties { properties := types.NewProperties() for key, tag := range f.tags { properties.SetTag(&key, tag) } properties. - Set("APIID", f.restAPIID). + Set("APIID", f.v2APIID). Set("Name", f.name). - Set("Version", f.version) + Set("ProtocolType", f.protocolType). + Set("Version", f.version). + Set("CreatedDate", f.createdDate.Format(time.RFC3339)) return properties } diff --git a/resources/apigatewayv2-apis.go b/resources/apigatewayv2-apis.go index 8d5fdb98..4ba6df55 100644 --- a/resources/apigatewayv2-apis.go +++ b/resources/apigatewayv2-apis.go @@ -2,6 +2,7 @@ package resources import ( "context" + "time" "github.com/aws/aws-sdk-go/aws" "github.com/aws/aws-sdk-go/service/apigatewayv2" @@ -47,6 +48,7 @@ func (l *APIGatewayV2APILister) List(_ context.Context, o interface{}) ([]resour name: item.Name, protocolType: item.ProtocolType, version: item.Version, + createdDate: item.CreatedDate, tags: item.Tags, }) } @@ -67,6 +69,7 @@ type APIGatewayV2API struct { name *string protocolType *string version *string + createdDate *time.Time tags map[string]*string } @@ -91,6 +94,7 @@ func (f *APIGatewayV2API) Properties() types.Properties { Set("APIID", f.v2APIID). Set("Name", f.name). Set("ProtocolType", f.protocolType). - Set("Version", f.version) + Set("Version", f.version). + Set("CreatedDate", f.createdDate.Format(time.RFC3339)) return properties } From 5902f1a290089cf8e8649667919181cbb50da301 Mon Sep 17 00:00:00 2001 From: Chase Freeman Date: Mon, 22 Jul 2024 17:22:39 -0500 Subject: [PATCH 2/3] feat(apigateway): fix creationdate --- resources/apigateway-restapis.go | 84 +++++++++++++------------------- resources/apigatewayv2-apis.go | 51 ++++++++----------- 2 files changed, 53 insertions(+), 82 deletions(-) diff --git a/resources/apigateway-restapis.go b/resources/apigateway-restapis.go index 4ba6df55..0aa8e69b 100644 --- a/resources/apigateway-restapis.go +++ b/resources/apigateway-restapis.go @@ -1,99 +1,83 @@ package resources import ( - "context" "time" "github.com/aws/aws-sdk-go/aws" - "github.com/aws/aws-sdk-go/service/apigatewayv2" - - "github.com/ekristen/libnuke/pkg/registry" - "github.com/ekristen/libnuke/pkg/resource" - "github.com/ekristen/libnuke/pkg/types" - - "github.com/ekristen/aws-nuke/v3/pkg/nuke" + "github.com/aws/aws-sdk-go/aws/session" + "github.com/aws/aws-sdk-go/service/apigateway" + "github.com/rebuy-de/aws-nuke/v2/pkg/types" ) -const APIGatewayV2APIResource = "APIGatewayV2API" +type APIGatewayRestAPI struct { + svc *apigateway.APIGateway + restAPIID *string + name *string + version *string + createdDate *time.Time + tags map[string]*string +} func init() { - registry.Register(®istry.Registration{ - Name: APIGatewayV2APIResource, - Scope: nuke.Account, - Lister: &APIGatewayV2APILister{}, - }) + register("APIGatewayRestAPI", ListAPIGatewayRestApis) } -type APIGatewayV2APILister struct{} - -func (l *APIGatewayV2APILister) List(_ context.Context, o interface{}) ([]resource.Resource, error) { - opts := o.(*nuke.ListerOpts) - svc := apigatewayv2.New(opts.Session) - var resources []resource.Resource +func ListAPIGatewayRestApis(sess *session.Session) ([]Resource, error) { + svc := apigateway.New(sess) + resources := []Resource{} - params := &apigatewayv2.GetApisInput{ - MaxResults: aws.String("100"), + params := &apigateway.GetRestApisInput{ + Limit: aws.Int64(100), } for { - output, err := svc.GetApis(params) + output, err := svc.GetRestApis(params) if err != nil { return nil, err } for _, item := range output.Items { - resources = append(resources, &APIGatewayV2API{ - svc: svc, - v2APIID: item.ApiId, - name: item.Name, - protocolType: item.ProtocolType, - version: item.Version, - createdDate: item.CreatedDate, - tags: item.Tags, + resources = append(resources, &APIGatewayRestAPI{ + svc: svc, + restAPIID: item.Id, + name: item.Name, + version: item.Version, + createdDate: item.CreatedDate, + tags: item.Tags, }) } - if output.NextToken == nil { + if output.Position == nil { break } - params.NextToken = output.NextToken + params.Position = output.Position } return resources, nil } -type APIGatewayV2API struct { - svc *apigatewayv2.ApiGatewayV2 - v2APIID *string - name *string - protocolType *string - version *string - createdDate *time.Time - tags map[string]*string -} +func (f *APIGatewayRestAPI) Remove() error { -func (f *APIGatewayV2API) Remove(_ context.Context) error { - _, err := f.svc.DeleteApi(&apigatewayv2.DeleteApiInput{ - ApiId: f.v2APIID, + _, err := f.svc.DeleteRestApi(&apigateway.DeleteRestApiInput{ + RestApiId: f.restAPIID, }) return err } -func (f *APIGatewayV2API) String() string { - return *f.v2APIID +func (f *APIGatewayRestAPI) String() string { + return *f.restAPIID } -func (f *APIGatewayV2API) Properties() types.Properties { +func (f *APIGatewayRestAPI) Properties() types.Properties { properties := types.NewProperties() for key, tag := range f.tags { properties.SetTag(&key, tag) } properties. - Set("APIID", f.v2APIID). + Set("APIID", f.restAPIID). Set("Name", f.name). - Set("ProtocolType", f.protocolType). Set("Version", f.version). Set("CreatedDate", f.createdDate.Format(time.RFC3339)) return properties diff --git a/resources/apigatewayv2-apis.go b/resources/apigatewayv2-apis.go index 4ba6df55..b1dfc4dc 100644 --- a/resources/apigatewayv2-apis.go +++ b/resources/apigatewayv2-apis.go @@ -1,35 +1,31 @@ package resources import ( - "context" "time" "github.com/aws/aws-sdk-go/aws" + "github.com/aws/aws-sdk-go/aws/session" "github.com/aws/aws-sdk-go/service/apigatewayv2" - - "github.com/ekristen/libnuke/pkg/registry" - "github.com/ekristen/libnuke/pkg/resource" - "github.com/ekristen/libnuke/pkg/types" - - "github.com/ekristen/aws-nuke/v3/pkg/nuke" + "github.com/rebuy-de/aws-nuke/v2/pkg/types" ) -const APIGatewayV2APIResource = "APIGatewayV2API" +type APIGatewayV2API struct { + svc *apigatewayv2.ApiGatewayV2 + v2APIID *string + name *string + protocolType *string + version *string + createdDate *time.Time + tags map[string]*string +} func init() { - registry.Register(®istry.Registration{ - Name: APIGatewayV2APIResource, - Scope: nuke.Account, - Lister: &APIGatewayV2APILister{}, - }) + register("APIGatewayV2API", ListAPIGatewayV2APIs) } -type APIGatewayV2APILister struct{} - -func (l *APIGatewayV2APILister) List(_ context.Context, o interface{}) ([]resource.Resource, error) { - opts := o.(*nuke.ListerOpts) - svc := apigatewayv2.New(opts.Session) - var resources []resource.Resource +func ListAPIGatewayV2APIs(sess *session.Session) ([]Resource, error) { + svc := apigatewayv2.New(sess) + resources := []Resource{} params := &apigatewayv2.GetApisInput{ MaxResults: aws.String("100"), @@ -63,17 +59,8 @@ func (l *APIGatewayV2APILister) List(_ context.Context, o interface{}) ([]resour return resources, nil } -type APIGatewayV2API struct { - svc *apigatewayv2.ApiGatewayV2 - v2APIID *string - name *string - protocolType *string - version *string - createdDate *time.Time - tags map[string]*string -} +func (f *APIGatewayV2API) Remove() error { -func (f *APIGatewayV2API) Remove(_ context.Context) error { _, err := f.svc.DeleteApi(&apigatewayv2.DeleteApiInput{ ApiId: f.v2APIID, }) @@ -94,7 +81,7 @@ func (f *APIGatewayV2API) Properties() types.Properties { Set("APIID", f.v2APIID). Set("Name", f.name). Set("ProtocolType", f.protocolType). - Set("Version", f.version). - Set("CreatedDate", f.createdDate.Format(time.RFC3339)) + Set("Version", f.version) + Set("CreatedDate", f.createdDate.Format(time.RFC3339)). return properties -} +} \ No newline at end of file From d8e22791df8135430be5d81ed1147e1c1a8e6a5d Mon Sep 17 00:00:00 2001 From: Chase Freeman Date: Mon, 22 Jul 2024 17:25:00 -0500 Subject: [PATCH 3/3] feat(apigateway): fix --- resources/apigateway-restapis.go | 34 ++++++++++++++------- resources/apigatewayv2-apis.go | 51 ++++++++++++++++++++------------ 2 files changed, 56 insertions(+), 29 deletions(-) diff --git a/resources/apigateway-restapis.go b/resources/apigateway-restapis.go index 0aa8e69b..9be96efd 100644 --- a/resources/apigateway-restapis.go +++ b/resources/apigateway-restapis.go @@ -1,14 +1,31 @@ package resources import ( + "context" "time" "github.com/aws/aws-sdk-go/aws" - "github.com/aws/aws-sdk-go/aws/session" "github.com/aws/aws-sdk-go/service/apigateway" - "github.com/rebuy-de/aws-nuke/v2/pkg/types" + + "github.com/ekristen/libnuke/pkg/registry" + "github.com/ekristen/libnuke/pkg/resource" + "github.com/ekristen/libnuke/pkg/types" + + "github.com/ekristen/aws-nuke/v3/pkg/nuke" ) +const APIGatewayRestAPIResource = "APIGatewayRestAPI" + +func init() { + registry.Register(®istry.Registration{ + Name: APIGatewayRestAPIResource, + Scope: nuke.Account, + Lister: &APIGatewayRestAPILister{}, + }) +} + +type APIGatewayRestAPILister struct{} + type APIGatewayRestAPI struct { svc *apigateway.APIGateway restAPIID *string @@ -18,13 +35,11 @@ type APIGatewayRestAPI struct { tags map[string]*string } -func init() { - register("APIGatewayRestAPI", ListAPIGatewayRestApis) -} +func (l *APIGatewayRestAPILister) List(_ context.Context, o interface{}) ([]resource.Resource, error) { + opts := o.(*nuke.ListerOpts) + svc := apigateway.New(opts.Session) -func ListAPIGatewayRestApis(sess *session.Session) ([]Resource, error) { - svc := apigateway.New(sess) - resources := []Resource{} + var resources []resource.Resource params := &apigateway.GetRestApisInput{ Limit: aws.Int64(100), @@ -57,8 +72,7 @@ func ListAPIGatewayRestApis(sess *session.Session) ([]Resource, error) { return resources, nil } -func (f *APIGatewayRestAPI) Remove() error { - +func (f *APIGatewayRestAPI) Remove(_ context.Context) error { _, err := f.svc.DeleteRestApi(&apigateway.DeleteRestApiInput{ RestApiId: f.restAPIID, }) diff --git a/resources/apigatewayv2-apis.go b/resources/apigatewayv2-apis.go index b1dfc4dc..4ba6df55 100644 --- a/resources/apigatewayv2-apis.go +++ b/resources/apigatewayv2-apis.go @@ -1,31 +1,35 @@ package resources import ( + "context" "time" "github.com/aws/aws-sdk-go/aws" - "github.com/aws/aws-sdk-go/aws/session" "github.com/aws/aws-sdk-go/service/apigatewayv2" - "github.com/rebuy-de/aws-nuke/v2/pkg/types" + + "github.com/ekristen/libnuke/pkg/registry" + "github.com/ekristen/libnuke/pkg/resource" + "github.com/ekristen/libnuke/pkg/types" + + "github.com/ekristen/aws-nuke/v3/pkg/nuke" ) -type APIGatewayV2API struct { - svc *apigatewayv2.ApiGatewayV2 - v2APIID *string - name *string - protocolType *string - version *string - createdDate *time.Time - tags map[string]*string -} +const APIGatewayV2APIResource = "APIGatewayV2API" func init() { - register("APIGatewayV2API", ListAPIGatewayV2APIs) + registry.Register(®istry.Registration{ + Name: APIGatewayV2APIResource, + Scope: nuke.Account, + Lister: &APIGatewayV2APILister{}, + }) } -func ListAPIGatewayV2APIs(sess *session.Session) ([]Resource, error) { - svc := apigatewayv2.New(sess) - resources := []Resource{} +type APIGatewayV2APILister struct{} + +func (l *APIGatewayV2APILister) List(_ context.Context, o interface{}) ([]resource.Resource, error) { + opts := o.(*nuke.ListerOpts) + svc := apigatewayv2.New(opts.Session) + var resources []resource.Resource params := &apigatewayv2.GetApisInput{ MaxResults: aws.String("100"), @@ -59,8 +63,17 @@ func ListAPIGatewayV2APIs(sess *session.Session) ([]Resource, error) { return resources, nil } -func (f *APIGatewayV2API) Remove() error { +type APIGatewayV2API struct { + svc *apigatewayv2.ApiGatewayV2 + v2APIID *string + name *string + protocolType *string + version *string + createdDate *time.Time + tags map[string]*string +} +func (f *APIGatewayV2API) Remove(_ context.Context) error { _, err := f.svc.DeleteApi(&apigatewayv2.DeleteApiInput{ ApiId: f.v2APIID, }) @@ -81,7 +94,7 @@ func (f *APIGatewayV2API) Properties() types.Properties { Set("APIID", f.v2APIID). Set("Name", f.name). Set("ProtocolType", f.protocolType). - Set("Version", f.version) - Set("CreatedDate", f.createdDate.Format(time.RFC3339)). + Set("Version", f.version). + Set("CreatedDate", f.createdDate.Format(time.RFC3339)) return properties -} \ No newline at end of file +}