forked from rebuy-de/aws-nuke
-
Notifications
You must be signed in to change notification settings - Fork 0
/
appmesh-virtualgateway.go
85 lines (73 loc) · 1.89 KB
/
appmesh-virtualgateway.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
78
79
80
81
82
83
84
85
package resources
import (
"github.com/aws/aws-sdk-go/aws/session"
"github.com/aws/aws-sdk-go/service/appmesh"
"github.com/dngferreira/aws-nuke/v2/pkg/types"
)
type AppMeshVirtualGateway struct {
svc *appmesh.AppMesh
meshName *string
virtualGatewayName *string
}
func init() {
register("AppMeshVirtualGateway", ListAppMeshVirtualGateways)
}
func ListAppMeshVirtualGateways(sess *session.Session) ([]Resource, error) {
svc := appmesh.New(sess)
resources := []Resource{}
// Get Meshes
var meshNames []*string
err := svc.ListMeshesPages(
&appmesh.ListMeshesInput{},
func(page *appmesh.ListMeshesOutput, lastPage bool) bool {
for _, mesh := range page.Meshes {
meshNames = append(meshNames, mesh.MeshName)
}
return true
},
)
if err != nil {
return nil, err
}
// List VirtualGateways per Mesh
var vgs []*appmesh.VirtualGatewayRef
for _, meshName := range meshNames {
err = svc.ListVirtualGatewaysPages(
&appmesh.ListVirtualGatewaysInput{
MeshName: meshName,
},
func(page *appmesh.ListVirtualGatewaysOutput, lastPage bool) bool {
for _, vg := range page.VirtualGateways {
vgs = append(vgs, vg)
}
return lastPage
},
)
if err != nil {
return nil, err
}
}
// Create the resources
for _, vg := range vgs {
resources = append(resources, &AppMeshVirtualGateway{
svc: svc,
meshName: vg.MeshName,
virtualGatewayName: vg.VirtualGatewayName,
})
}
return resources, nil
}
func (f *AppMeshVirtualGateway) Remove() error {
_, err := f.svc.DeleteVirtualGateway(&appmesh.DeleteVirtualGatewayInput{
MeshName: f.meshName,
VirtualGatewayName: f.virtualGatewayName,
})
return err
}
func (f *AppMeshVirtualGateway) Properties() types.Properties {
properties := types.NewProperties()
properties.
Set("MeshName", f.meshName).
Set("Name", f.virtualGatewayName)
return properties
}