Skip to content

Commit b161c43

Browse files
committed
Merge branch 'main' into oreilly-main
2 parents 9f72e61 + 2bd22d5 commit b161c43

21 files changed

+498
-119
lines changed

dev/list-cloudcontrol/main.go

Lines changed: 62 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -34,67 +34,74 @@ func main() {
3434
mapping := resources.GetCloudControlMapping()
3535

3636
in := &cloudformation.ListTypesInput{
37-
Type: aws.String(cloudformation.RegistryTypeResource),
38-
Visibility: aws.String(cloudformation.VisibilityPublic),
39-
ProvisioningType: aws.String(cloudformation.ProvisioningTypeFullyMutable),
40-
}
37+
Type: aws.String(cloudformation.RegistryTypeResource),
38+
Visibility: aws.String(cloudformation.VisibilityPublic),
4139

42-
err = cf.ListTypesPagesWithContext(ctx, in, func(out *cloudformation.ListTypesOutput, _ bool) bool {
43-
if out == nil {
44-
return true
45-
}
46-
47-
for _, summary := range out.TypeSummaries {
48-
if summary == nil {
49-
continue
50-
}
51-
52-
typeName := aws.StringValue(summary.TypeName)
53-
color.New(color.Bold).Printf("%-55s", typeName)
54-
if !strings.HasPrefix(typeName, "AWS::") {
55-
color.HiBlack("does not have a valid prefix")
56-
continue
57-
}
58-
59-
describe, err := cf.DescribeType(&cloudformation.DescribeTypeInput{
60-
Type: aws.String(cloudformation.RegistryTypeResource),
61-
TypeName: aws.String(typeName),
62-
})
63-
if err != nil {
64-
color.New(color.FgRed).Println(err)
65-
continue
66-
}
67-
68-
var schema CFTypeSchema
69-
err = json.Unmarshal([]byte(aws.StringValue(describe.Schema)), &schema)
70-
if err != nil {
71-
color.New(color.FgRed).Println(err)
72-
continue
73-
}
40+
Filters: &cloudformation.TypeFilters{
41+
TypeNamePrefix: aws.String("AWS::"),
42+
},
43+
}
7444

75-
_, canList := schema.Handlers["list"]
76-
if !canList {
77-
color.New(color.FgHiBlack).Println("does not support list")
78-
continue
45+
// Immutable objects don't have an `update` option, but can still be removed
46+
for _, provisioningType := range []string{cloudformation.ProvisioningTypeFullyMutable, cloudformation.ProvisioningTypeImmutable} {
47+
in.ProvisioningType = &provisioningType
48+
err = cf.ListTypesPagesWithContext(ctx, in, func(out *cloudformation.ListTypesOutput, _ bool) bool {
49+
if out == nil {
50+
return true
7951
}
8052

81-
resourceName, exists := mapping[typeName]
82-
if exists && resourceName == typeName {
83-
fmt.Print("is only covered by ")
84-
color.New(color.FgGreen, color.Bold).Println(resourceName)
85-
continue
86-
} else if exists {
87-
fmt.Print("is also covered by ")
88-
color.New(color.FgBlue, color.Bold).Println(resourceName)
89-
continue
53+
for _, summary := range out.TypeSummaries {
54+
if summary == nil {
55+
continue
56+
}
57+
58+
typeName := aws.StringValue(summary.TypeName)
59+
color.New(color.Bold).Printf("%-55s", typeName)
60+
if !strings.HasPrefix(typeName, "AWS::") {
61+
color.HiBlack("does not have a valid prefix")
62+
continue
63+
}
64+
65+
describe, err := cf.DescribeType(&cloudformation.DescribeTypeInput{
66+
Type: aws.String(cloudformation.RegistryTypeResource),
67+
TypeName: aws.String(typeName),
68+
})
69+
if err != nil {
70+
color.New(color.FgRed).Println(err)
71+
continue
72+
}
73+
74+
var schema CFTypeSchema
75+
err = json.Unmarshal([]byte(aws.StringValue(describe.Schema)), &schema)
76+
if err != nil {
77+
color.New(color.FgRed).Println(err)
78+
continue
79+
}
80+
81+
_, canList := schema.Handlers["list"]
82+
if !canList {
83+
color.New(color.FgHiBlack).Println("does not support list")
84+
continue
85+
}
86+
87+
resourceName, exists := mapping[typeName]
88+
if exists && resourceName == typeName {
89+
fmt.Print("is only covered by ")
90+
color.New(color.FgGreen, color.Bold).Println(resourceName)
91+
continue
92+
} else if exists {
93+
fmt.Print("is also covered by ")
94+
color.New(color.FgBlue, color.Bold).Println(resourceName)
95+
continue
96+
}
97+
98+
color.New(color.FgYellow).Println("is not configured")
9099
}
91100

92-
color.New(color.FgYellow).Println("is not configured")
101+
return true
102+
})
103+
if err != nil {
104+
logrus.Fatal(err)
93105
}
94-
95-
return true
96-
})
97-
if err != nil {
98-
logrus.Fatal(err)
99106
}
100107
}

pkg/types/properties.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,21 @@ func (p Properties) SetTagWithPrefix(prefix string, tagKey *string, tagValue int
8585
return p.Set(keyStr, tagValue)
8686
}
8787

88+
func (p Properties) SetPropertyWithPrefix(prefix string, propertyKey string, propertyValue interface{}) Properties {
89+
keyStr := strings.TrimSpace(propertyKey)
90+
prefix = strings.TrimSpace(prefix)
91+
92+
if keyStr == "" {
93+
return p
94+
}
95+
96+
if prefix != "" {
97+
keyStr = fmt.Sprintf("%s:%s", prefix, keyStr)
98+
}
99+
100+
return p.Set(keyStr, propertyValue)
101+
}
102+
88103
func (p Properties) Get(key string) string {
89104
value, ok := p[key]
90105
if !ok {

pkg/types/properties_test.go

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,3 +161,41 @@ func TestPropertiesSetTagWithPrefix(t *testing.T) {
161161
})
162162
}
163163
}
164+
165+
func TestPropertiesSetPropertiesWithPrefix(t *testing.T) {
166+
cases := []struct {
167+
name string
168+
prefix string
169+
key string
170+
value interface{}
171+
want string
172+
}{
173+
{
174+
name: "empty",
175+
prefix: "",
176+
key: "OwnerID",
177+
value: aws.String("123456789012"),
178+
want: `[OwnerID: "123456789012"]`,
179+
},
180+
{
181+
name: "nonempty",
182+
prefix: "igw",
183+
key: "OwnerID",
184+
value: aws.String("123456789012"),
185+
want: `[igw:OwnerID: "123456789012"]`,
186+
},
187+
}
188+
189+
for _, tc := range cases {
190+
t.Run(tc.name, func(t *testing.T) {
191+
p := types.NewProperties()
192+
193+
p.SetPropertyWithPrefix(tc.prefix, tc.key, tc.value)
194+
have := p.String()
195+
196+
if tc.want != have {
197+
t.Errorf("'%s' != '%s'", tc.want, have)
198+
}
199+
})
200+
}
201+
}

resources/apprunner-connection.go

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
package resources
2+
3+
import (
4+
"github.com/aws/aws-sdk-go/aws/session"
5+
"github.com/aws/aws-sdk-go/service/apprunner"
6+
"github.com/rebuy-de/aws-nuke/v2/pkg/types"
7+
)
8+
9+
type AppRunnerConnection struct {
10+
svc *apprunner.AppRunner
11+
ConnectionArn *string
12+
ConnectionName *string
13+
}
14+
15+
func init() {
16+
register("AppRunnerConnection", ListAppRunnerConnections)
17+
}
18+
19+
func ListAppRunnerConnections(sess *session.Session) ([]Resource, error) {
20+
svc := apprunner.New(sess)
21+
resources := []Resource{}
22+
23+
params := &apprunner.ListConnectionsInput{}
24+
25+
for {
26+
resp, err := svc.ListConnections(params)
27+
if err != nil {
28+
return nil, err
29+
}
30+
31+
for _, item := range resp.ConnectionSummaryList {
32+
resources = append(resources, &AppRunnerConnection{
33+
svc: svc,
34+
ConnectionArn: item.ConnectionArn,
35+
ConnectionName: item.ConnectionName,
36+
})
37+
}
38+
39+
if resp.NextToken == nil {
40+
break
41+
}
42+
43+
params.NextToken = resp.NextToken
44+
}
45+
46+
return resources, nil
47+
}
48+
49+
func (f *AppRunnerConnection) Remove() error {
50+
_, err := f.svc.DeleteConnection(&apprunner.DeleteConnectionInput{
51+
ConnectionArn: f.ConnectionArn,
52+
})
53+
54+
return err
55+
}
56+
57+
func (f *AppRunnerConnection) Properties() types.Properties {
58+
properties := types.NewProperties()
59+
properties.Set("ConnectionArn", f.ConnectionArn)
60+
properties.Set("ConnectionName", f.ConnectionName)
61+
return properties
62+
}

resources/apprunner-service.go

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
package resources
2+
3+
import (
4+
"github.com/aws/aws-sdk-go/aws/session"
5+
"github.com/aws/aws-sdk-go/service/apprunner"
6+
"github.com/rebuy-de/aws-nuke/v2/pkg/types"
7+
)
8+
9+
type AppRunnerService struct {
10+
svc *apprunner.AppRunner
11+
ServiceArn *string
12+
ServiceId *string
13+
ServiceName *string
14+
}
15+
16+
func init() {
17+
register("AppRunnerService", ListAppRunnerServices)
18+
}
19+
20+
func ListAppRunnerServices(sess *session.Session) ([]Resource, error) {
21+
svc := apprunner.New(sess)
22+
resources := []Resource{}
23+
24+
params := &apprunner.ListServicesInput{}
25+
26+
for {
27+
resp, err := svc.ListServices(params)
28+
if err != nil {
29+
return nil, err
30+
}
31+
32+
for _, item := range resp.ServiceSummaryList {
33+
resources = append(resources, &AppRunnerService{
34+
svc: svc,
35+
ServiceArn: item.ServiceArn,
36+
ServiceId: item.ServiceId,
37+
ServiceName: item.ServiceName,
38+
})
39+
}
40+
41+
if resp.NextToken == nil {
42+
break
43+
}
44+
45+
params.NextToken = resp.NextToken
46+
}
47+
48+
return resources, nil
49+
}
50+
51+
func (f *AppRunnerService) Remove() error {
52+
_, err := f.svc.DeleteService(&apprunner.DeleteServiceInput{
53+
ServiceArn: f.ServiceArn,
54+
})
55+
56+
return err
57+
}
58+
59+
func (f *AppRunnerService) Properties() types.Properties {
60+
properties := types.NewProperties()
61+
properties.Set("ServiceArn", f.ServiceArn)
62+
properties.Set("ServiceId", f.ServiceId)
63+
properties.Set("ServiceName", f.ServiceName)
64+
return properties
65+
}

resources/cloudwatch-rum.go

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
package resources
2+
3+
import (
4+
"github.com/aws/aws-sdk-go/aws/session"
5+
"github.com/aws/aws-sdk-go/service/cloudwatchrum"
6+
"github.com/rebuy-de/aws-nuke/v2/pkg/types"
7+
)
8+
9+
type CloudWatchRumApp struct {
10+
svc *cloudwatchrum.CloudWatchRUM
11+
appmonitorname *string
12+
id *string
13+
state *string
14+
}
15+
16+
func init() {
17+
register("CloudWatchRUMApp", ListCloudWatchRumApp)
18+
}
19+
20+
func ListCloudWatchRumApp(sess *session.Session) ([]Resource, error) {
21+
svc := cloudwatchrum.New(sess)
22+
resources := []Resource{}
23+
24+
params := &cloudwatchrum.ListAppMonitorsInput{}
25+
26+
for {
27+
output, err := svc.ListAppMonitors(params)
28+
if err != nil {
29+
return nil, err
30+
}
31+
32+
for _, appEntry := range output.AppMonitorSummaries {
33+
resources = append(resources, &CloudWatchRumApp{
34+
svc: svc,
35+
appmonitorname: appEntry.Name,
36+
id: appEntry.Id,
37+
state: appEntry.State,
38+
})
39+
}
40+
41+
if output.NextToken == nil {
42+
break
43+
}
44+
45+
params.NextToken = output.NextToken
46+
}
47+
48+
return resources, nil
49+
}
50+
51+
func (f *CloudWatchRumApp) Remove() error {
52+
53+
_, err := f.svc.DeleteAppMonitor(&cloudwatchrum.DeleteAppMonitorInput{
54+
Name: f.appmonitorname,
55+
})
56+
57+
return err
58+
}
59+
60+
func (f *CloudWatchRumApp) Properties() types.Properties {
61+
properties := types.NewProperties()
62+
properties.Set("Name", *f.appmonitorname)
63+
properties.Set("ID", *f.id)
64+
properties.Set("State", *f.state)
65+
66+
return properties
67+
}
68+
69+
func (f *CloudWatchRumApp) String() string {
70+
return *f.appmonitorname
71+
}

0 commit comments

Comments
 (0)