Skip to content

Commit

Permalink
feat(apigateway): add created date to apigateways
Browse files Browse the repository at this point in the history
  • Loading branch information
ChaseFreeman17 committed Jul 22, 2024
1 parent 512552c commit dcafe54
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 36 deletions.
76 changes: 41 additions & 35 deletions resources/apigateway-restapis.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -13,82 +14,87 @@ import (
"github.com/ekristen/aws-nuke/v3/pkg/nuke"
)

const APIGatewayRestAPIResource = "APIGatewayRestAPI"
const APIGatewayV2APIResource = "APIGatewayV2API"

Check failure on line 17 in resources/apigateway-restapis.go

View workflow job for this annotation

GitHub Actions / golangci-lint

other declaration of APIGatewayV2APIResource

Check failure on line 17 in resources/apigateway-restapis.go

View workflow job for this annotation

GitHub Actions / test

other declaration of APIGatewayV2APIResource

func init() {
registry.Register(&registry.Registration{
Name: APIGatewayRestAPIResource,
Name: APIGatewayV2APIResource,
Scope: nuke.Account,
Lister: &APIGatewayRestAPILister{},
Lister: &APIGatewayV2APILister{},
})
}

type APIGatewayRestAPILister struct{}
type APIGatewayV2APILister struct{}

Check failure on line 27 in resources/apigateway-restapis.go

View workflow job for this annotation

GitHub Actions / golangci-lint

other declaration of APIGatewayV2APILister

Check failure on line 27 in resources/apigateway-restapis.go

View workflow job for this annotation

GitHub Actions / test

other declaration of APIGatewayV2APILister

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 {

Check failure on line 66 in resources/apigateway-restapis.go

View workflow job for this annotation

GitHub Actions / golangci-lint

other declaration of APIGatewayV2API

Check failure on line 66 in resources/apigateway-restapis.go

View workflow job for this annotation

GitHub Actions / test

other declaration of APIGatewayV2API
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
}
6 changes: 5 additions & 1 deletion resources/apigatewayv2-apis.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package resources

import (
"context"
"time"

"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/service/apigatewayv2"
Expand Down Expand Up @@ -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,
})
}
Expand All @@ -67,6 +69,7 @@ type APIGatewayV2API struct {
name *string
protocolType *string
version *string
createdDate *time.Time
tags map[string]*string
}

Expand All @@ -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
}

0 comments on commit dcafe54

Please sign in to comment.