Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add API Gateway v2 APIs as a resource #538

Merged
merged 1 commit into from
Aug 28, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
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 {
der-eismann marked this conversation as resolved.
Show resolved Hide resolved
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
}