forked from rebuy-de/aws-nuke
/
appsync-graphqlapis.go
77 lines (64 loc) · 1.67 KB
/
appsync-graphqlapis.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
package resources
import (
"github.com/BigDwarf/aws-nuke/v2/pkg/types"
"github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/aws/session"
"github.com/aws/aws-sdk-go/service/appsync"
)
// AppSyncGraphqlAPI - An AWS AppSync GraphQL API
type AppSyncGraphqlAPI struct {
svc *appsync.AppSync
apiID *string
name *string
tags map[string]*string
}
func init() {
register("AppSyncGraphqlAPI", ListAppSyncGraphqlAPIs)
}
// ListAppSyncGraphqlAPIs - List all AWS AppSync GraphQL APIs in the account
func ListAppSyncGraphqlAPIs(sess *session.Session) ([]Resource, error) {
svc := appsync.New(sess)
resources := []Resource{}
params := &appsync.ListGraphqlApisInput{
MaxResults: aws.Int64(25),
}
for {
resp, err := svc.ListGraphqlApis(params)
if err != nil {
return nil, err
}
for _, graphqlAPI := range resp.GraphqlApis {
resources = append(resources, &AppSyncGraphqlAPI{
svc: svc,
apiID: graphqlAPI.ApiId,
name: graphqlAPI.Name,
tags: graphqlAPI.Tags,
})
}
if resp.NextToken == nil {
break
}
params.NextToken = resp.NextToken
}
return resources, nil
}
// Remove - remove an AWS AppSync GraphQL API
func (f *AppSyncGraphqlAPI) Remove() error {
_, err := f.svc.DeleteGraphqlApi(&appsync.DeleteGraphqlApiInput{
ApiId: f.apiID,
})
return err
}
// Properties - Get the properties of an AWS AppSync GraphQL API
func (f *AppSyncGraphqlAPI) Properties() types.Properties {
properties := types.NewProperties()
for key, value := range f.tags {
properties.SetTag(aws.String(key), value)
}
properties.Set("Name", f.name)
properties.Set("APIID", f.apiID)
return properties
}
func (f *AppSyncGraphqlAPI) String() string {
return *f.apiID
}