Skip to content

Commit

Permalink
feat(apigateway): fix
Browse files Browse the repository at this point in the history
  • Loading branch information
ChaseFreeman17 committed Jul 22, 2024
1 parent 5902f1a commit d8e2279
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 29 deletions.
34 changes: 24 additions & 10 deletions resources/apigateway-restapis.go
Original file line number Diff line number Diff line change
@@ -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(&registry.Registration{
Name: APIGatewayRestAPIResource,
Scope: nuke.Account,
Lister: &APIGatewayRestAPILister{},
})
}

type APIGatewayRestAPILister struct{}

type APIGatewayRestAPI struct {
svc *apigateway.APIGateway
restAPIID *string
Expand All @@ -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),
Expand Down Expand Up @@ -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,
})
Expand Down
51 changes: 32 additions & 19 deletions resources/apigatewayv2-apis.go
Original file line number Diff line number Diff line change
@@ -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(&registry.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"),
Expand Down Expand Up @@ -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,
})
Expand All @@ -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
}
}

0 comments on commit d8e2279

Please sign in to comment.