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

Commit

Permalink
Improve listing of cloudcontrol resources (#1096)
Browse files Browse the repository at this point in the history
  • Loading branch information
der-eismann authored Aug 31, 2023
1 parent 5560ce3 commit 2bd22d5
Showing 1 changed file with 62 additions and 55 deletions.
117 changes: 62 additions & 55 deletions dev/list-cloudcontrol/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}

0 comments on commit 2bd22d5

Please sign in to comment.