Skip to content

Commit

Permalink
feat(apigateway): fix creationdate
Browse files Browse the repository at this point in the history
  • Loading branch information
ChaseFreeman17 committed Jul 22, 2024
1 parent dcafe54 commit 5902f1a
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 82 deletions.
84 changes: 34 additions & 50 deletions resources/apigateway-restapis.go
Original file line number Diff line number Diff line change
@@ -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"

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

View workflow job for this annotation

GitHub Actions / test

no required module provides package github.com/rebuy-de/aws-nuke/v2/pkg/types; to add it:
)

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(&registry.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
Expand Down
51 changes: 19 additions & 32 deletions resources/apigatewayv2-apis.go
Original file line number Diff line number Diff line change
@@ -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(&registry.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"),
Expand Down Expand Up @@ -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,
})
Expand All @@ -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

Check failure on line 86 in resources/apigatewayv2-apis.go

View workflow job for this annotation

GitHub Actions / golangci-lint

expected selector or type assertion, found 'return' (typecheck)
}
}

Check failure on line 87 in resources/apigatewayv2-apis.go

View workflow job for this annotation

GitHub Actions / golangci-lint

expected '}', found 'EOF' (typecheck)

0 comments on commit 5902f1a

Please sign in to comment.