From 2bd22d5e5c0cf6a4011b3c08a5b1c25e2e6c75bd Mon Sep 17 00:00:00 2001 From: Philipp Trulson Date: Thu, 31 Aug 2023 13:44:24 +0200 Subject: [PATCH] Improve listing of cloudcontrol resources (#1096) --- dev/list-cloudcontrol/main.go | 117 ++++++++++++++++++---------------- 1 file changed, 62 insertions(+), 55 deletions(-) diff --git a/dev/list-cloudcontrol/main.go b/dev/list-cloudcontrol/main.go index d61c3b078..b70780967 100644 --- a/dev/list-cloudcontrol/main.go +++ b/dev/list-cloudcontrol/main.go @@ -34,67 +34,74 @@ func main() { mapping := resources.GetCloudControlMapping() in := &cloudformation.ListTypesInput{ - Type: aws.String(cloudformation.RegistryTypeResource), - Visibility: aws.String(cloudformation.VisibilityPublic), - ProvisioningType: aws.String(cloudformation.ProvisioningTypeFullyMutable), - } + Type: aws.String(cloudformation.RegistryTypeResource), + Visibility: aws.String(cloudformation.VisibilityPublic), - err = cf.ListTypesPagesWithContext(ctx, in, func(out *cloudformation.ListTypesOutput, _ bool) bool { - if out == nil { - return true - } - - for _, summary := range out.TypeSummaries { - if summary == nil { - continue - } - - typeName := aws.StringValue(summary.TypeName) - color.New(color.Bold).Printf("%-55s", typeName) - if !strings.HasPrefix(typeName, "AWS::") { - color.HiBlack("does not have a valid prefix") - continue - } - - describe, err := cf.DescribeType(&cloudformation.DescribeTypeInput{ - Type: aws.String(cloudformation.RegistryTypeResource), - TypeName: aws.String(typeName), - }) - if err != nil { - color.New(color.FgRed).Println(err) - continue - } - - var schema CFTypeSchema - err = json.Unmarshal([]byte(aws.StringValue(describe.Schema)), &schema) - if err != nil { - color.New(color.FgRed).Println(err) - continue - } + Filters: &cloudformation.TypeFilters{ + TypeNamePrefix: aws.String("AWS::"), + }, + } - _, canList := schema.Handlers["list"] - if !canList { - color.New(color.FgHiBlack).Println("does not support list") - continue + // Immutable objects don't have an `update` option, but can still be removed + for _, provisioningType := range []string{cloudformation.ProvisioningTypeFullyMutable, cloudformation.ProvisioningTypeImmutable} { + in.ProvisioningType = &provisioningType + err = cf.ListTypesPagesWithContext(ctx, in, func(out *cloudformation.ListTypesOutput, _ bool) bool { + if out == nil { + return true } - resourceName, exists := mapping[typeName] - if exists && resourceName == typeName { - fmt.Print("is only covered by ") - color.New(color.FgGreen, color.Bold).Println(resourceName) - continue - } else if exists { - fmt.Print("is also covered by ") - color.New(color.FgBlue, color.Bold).Println(resourceName) - continue + for _, summary := range out.TypeSummaries { + if summary == nil { + continue + } + + typeName := aws.StringValue(summary.TypeName) + color.New(color.Bold).Printf("%-55s", typeName) + if !strings.HasPrefix(typeName, "AWS::") { + color.HiBlack("does not have a valid prefix") + continue + } + + describe, err := cf.DescribeType(&cloudformation.DescribeTypeInput{ + Type: aws.String(cloudformation.RegistryTypeResource), + TypeName: aws.String(typeName), + }) + if err != nil { + color.New(color.FgRed).Println(err) + continue + } + + var schema CFTypeSchema + err = json.Unmarshal([]byte(aws.StringValue(describe.Schema)), &schema) + if err != nil { + color.New(color.FgRed).Println(err) + continue + } + + _, canList := schema.Handlers["list"] + if !canList { + color.New(color.FgHiBlack).Println("does not support list") + continue + } + + resourceName, exists := mapping[typeName] + if exists && resourceName == typeName { + fmt.Print("is only covered by ") + color.New(color.FgGreen, color.Bold).Println(resourceName) + continue + } else if exists { + fmt.Print("is also covered by ") + color.New(color.FgBlue, color.Bold).Println(resourceName) + continue + } + + color.New(color.FgYellow).Println("is not configured") } - color.New(color.FgYellow).Println("is not configured") + return true + }) + if err != nil { + logrus.Fatal(err) } - - return true - }) - if err != nil { - logrus.Fatal(err) } }