Skip to content
This repository was archived by the owner on Oct 15, 2024. It is now read-only.

Commit 1e5ecf2

Browse files
authored
Add API Gateway v2 APIs as a resource (#538)
1 parent dd8b161 commit 1e5ecf2

File tree

1 file changed

+82
-0
lines changed

1 file changed

+82
-0
lines changed

resources/apigatewayv2-apis.go

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
package resources
2+
3+
import (
4+
"github.com/aws/aws-sdk-go/aws"
5+
"github.com/aws/aws-sdk-go/aws/session"
6+
"github.com/aws/aws-sdk-go/service/apigatewayv2"
7+
"github.com/rebuy-de/aws-nuke/pkg/types"
8+
)
9+
10+
type APIGatewayV2API struct {
11+
svc *apigatewayv2.ApiGatewayV2
12+
v2APIID *string
13+
name *string
14+
protocolType *string
15+
version *string
16+
tags map[string]*string
17+
}
18+
19+
func init() {
20+
register("APIGatewayV2API", ListAPIGatewayV2APIs)
21+
}
22+
23+
func ListAPIGatewayV2APIs(sess *session.Session) ([]Resource, error) {
24+
svc := apigatewayv2.New(sess)
25+
resources := []Resource{}
26+
27+
params := &apigatewayv2.GetApisInput{
28+
MaxResults: aws.String("100"),
29+
}
30+
31+
for {
32+
output, err := svc.GetApis(params)
33+
if err != nil {
34+
return nil, err
35+
}
36+
37+
for _, item := range output.Items {
38+
resources = append(resources, &APIGatewayV2API{
39+
svc: svc,
40+
v2APIID: item.ApiId,
41+
name: item.Name,
42+
protocolType: item.ProtocolType,
43+
version: item.Version,
44+
tags: item.Tags,
45+
})
46+
}
47+
48+
if output.NextToken == nil {
49+
break
50+
}
51+
52+
params.NextToken = output.NextToken
53+
}
54+
55+
return resources, nil
56+
}
57+
58+
func (f *APIGatewayV2API) Remove() error {
59+
60+
_, err := f.svc.DeleteApi(&apigatewayv2.DeleteApiInput{
61+
ApiId: f.v2APIID,
62+
})
63+
64+
return err
65+
}
66+
67+
func (f *APIGatewayV2API) String() string {
68+
return *f.v2APIID
69+
}
70+
71+
func (f *APIGatewayV2API) Properties() types.Properties {
72+
properties := types.NewProperties()
73+
for key, tag := range f.tags {
74+
properties.SetTag(&key, tag)
75+
}
76+
properties.
77+
Set("APIID", f.v2APIID).
78+
Set("Name", f.name).
79+
Set("ProtocolType", f.protocolType).
80+
Set("Version", f.version)
81+
return properties
82+
}

0 commit comments

Comments
 (0)