-
Notifications
You must be signed in to change notification settings - Fork 706
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add API Gateway v2 VPC links & properties for some resources (#540)
* Add properties to old API GW resources * Add API Gateway v2 VPC Link resource
- Loading branch information
1 parent
1e5ecf2
commit 1a7a6a9
Showing
3 changed files
with
111 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |