Skip to content

Commit

Permalink
Add API Gateway v2 VPC links & properties for some resources (#540)
Browse files Browse the repository at this point in the history
* Add properties to old API GW resources

* Add API Gateway v2 VPC Link resource
  • Loading branch information
der-eismann committed Aug 28, 2020
1 parent 1e5ecf2 commit 1a7a6a9
Show file tree
Hide file tree
Showing 3 changed files with 111 additions and 0 deletions.
19 changes: 19 additions & 0 deletions resources/apigateway-restapis.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,15 @@ import (
"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/pkg/types"
)

type APIGatewayRestAPI struct {
svc *apigateway.APIGateway
restAPIID *string
name *string
version *string
tags map[string]*string
}

func init() {
Expand All @@ -33,6 +37,9 @@ func ListAPIGatewayRestApis(sess *session.Session) ([]Resource, error) {
resources = append(resources, &APIGatewayRestAPI{
svc: svc,
restAPIID: item.Id,
name: item.Name,
version: item.Version,
tags: item.Tags,
})
}

Expand All @@ -58,3 +65,15 @@ func (f *APIGatewayRestAPI) Remove() error {
func (f *APIGatewayRestAPI) String() string {
return *f.restAPIID
}

func (f *APIGatewayRestAPI) Properties() types.Properties {
properties := types.NewProperties()
for key, tag := range f.tags {
properties.SetTag(&key, tag)
}
properties.
Set("APIID", f.restAPIID).
Set("Name", f.name).
Set("Version", f.version)
return properties
}
16 changes: 16 additions & 0 deletions resources/apigateway-vpclinks.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,14 @@ import (
"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/pkg/types"
)

type APIGatewayVpcLink struct {
svc *apigateway.APIGateway
vpcLinkID *string
name *string
tags map[string]*string
}

func init() {
Expand All @@ -33,6 +36,8 @@ func ListAPIGatewayVpcLinks(sess *session.Session) ([]Resource, error) {
resources = append(resources, &APIGatewayVpcLink{
svc: svc,
vpcLinkID: item.Id,
name: item.Name,
tags: item.Tags,
})
}

Expand All @@ -58,3 +63,14 @@ func (f *APIGatewayVpcLink) Remove() error {
func (f *APIGatewayVpcLink) String() string {
return *f.vpcLinkID
}

func (f *APIGatewayVpcLink) Properties() types.Properties {
properties := types.NewProperties()
for key, tag := range f.tags {
properties.SetTag(&key, tag)
}
properties.
Set("VPCLinkID", f.vpcLinkID).
Set("Name", f.name)
return properties
}
76 changes: 76 additions & 0 deletions resources/apigatewayv2-vpclinks.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
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 APIGatewayV2VpcLink struct {
svc *apigatewayv2.ApiGatewayV2
vpcLinkID *string
name *string
tags map[string]*string
}

func init() {
register("APIGatewayV2VpcLink", ListAPIGatewayV2VpcLinks)
}

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

params := &apigatewayv2.GetVpcLinksInput{
MaxResults: aws.String("100"),
}

for {
output, err := svc.GetVpcLinks(params)
if err != nil {
return nil, err
}

for _, item := range output.Items {
resources = append(resources, &APIGatewayV2VpcLink{
svc: svc,
vpcLinkID: item.VpcLinkId,
name: item.Name,
tags: item.Tags,
})
}

if output.NextToken == nil {
break
}

params.NextToken = output.NextToken
}

return resources, nil
}

func (f *APIGatewayV2VpcLink) Remove() error {

_, err := f.svc.DeleteVpcLink(&apigatewayv2.DeleteVpcLinkInput{
VpcLinkId: f.vpcLinkID,
})

return err
}

func (f *APIGatewayV2VpcLink) String() string {
return *f.vpcLinkID
}

func (f *APIGatewayV2VpcLink) Properties() types.Properties {
properties := types.NewProperties()
for key, tag := range f.tags {
properties.SetTag(&key, tag)
}
properties.
Set("VPCLinkID", f.vpcLinkID).
Set("Name", f.name)
return properties
}

0 comments on commit 1a7a6a9

Please sign in to comment.