Skip to content
This repository was archived by the owner on Oct 15, 2024. It is now read-only.
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
82 changes: 82 additions & 0 deletions resources/apigatewayv2-apis.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
package resources

import (
"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/pkg/types"
)

type APIGatewayV2API struct {
svc *apigatewayv2.ApiGatewayV2
v2APIID *string
name *string
protocolType *string
version *string
tags map[string]*string
}

func init() {
register("APIGatewayV2API", ListAPIGatewayV2APIs)
}

func ListAPIGatewayV2APIs(sess *session.Session) ([]Resource, error) {
svc := apigatewayv2.New(sess)
resources := []Resource{}

params := &apigatewayv2.GetApisInput{
MaxResults: aws.String("100"),
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have absolutely no idea why one would use a string for such an option
https://docs.aws.amazon.com/sdk-for-go/api/service/apigatewayv2/#GetApisInput

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My guess is that something with API generation went wrong and that cannot get reverted without breaking other peoples stuff.

}

for {
output, err := svc.GetApis(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,
tags: item.Tags,
})
}

if output.NextToken == nil {
break
}

params.NextToken = output.NextToken
}

return resources, nil
}

func (f *APIGatewayV2API) Remove() error {

_, err := f.svc.DeleteApi(&apigatewayv2.DeleteApiInput{
ApiId: f.v2APIID,
})

return err
}

func (f *APIGatewayV2API) String() string {
return *f.v2APIID
}

func (f *APIGatewayV2API) Properties() types.Properties {
properties := types.NewProperties()
for key, tag := range f.tags {
properties.SetTag(&key, tag)
}
properties.
Set("APIID", f.v2APIID).
Set("Name", f.name).
Set("ProtocolType", f.protocolType).
Set("Version", f.version)
return properties
}