Skip to content

Commit

Permalink
Keyvaluetags - add support for elbv2, acm, acmpca & resourcegroups (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
DrFaust92 authored and bflad committed Nov 4, 2019
1 parent 1bb5073 commit d4b69da
Show file tree
Hide file tree
Showing 5 changed files with 289 additions and 6 deletions.
44 changes: 38 additions & 6 deletions aws/internal/keyvaluetags/generators/listtags/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import (
const filename = `list_tags_gen.go`

var serviceNames = []string{
"acm",
"acmpca",
"amplify",
"appmesh",
Expand Down Expand Up @@ -47,6 +48,7 @@ var serviceNames = []string{
"elasticache",
"elasticbeanstalk",
"elasticsearchservice",
"elbv2",
"firehose",
"fsx",
"glue",
Expand All @@ -71,6 +73,7 @@ var serviceNames = []string{
"organizations",
"qldb",
"rds",
"resourcegroups",
"route53resolver",
"sagemaker",
"securityhub",
Expand All @@ -96,12 +99,13 @@ func main() {
ServiceNames: serviceNames,
}
templateFuncMap := template.FuncMap{
"ClientType": keyvaluetags.ServiceClientType,
"ListTagsFunction": ServiceListTagsFunction,
"ListTagsInputIdentifierField": ServiceListTagsInputIdentifierField,
"ListTagsInputResourceTypeField": ServiceListTagsInputResourceTypeField,
"ListTagsOutputTagsField": ServiceListTagsOutputTagsField,
"Title": strings.Title,
"ClientType": keyvaluetags.ServiceClientType,
"ListTagsFunction": ServiceListTagsFunction,
"ListTagsInputIdentifierField": ServiceListTagsInputIdentifierField,
"ListTagsInputIdentifierRequiresSlice": ServiceListTagsInputIdentifierRequiresSlice,
"ListTagsInputResourceTypeField": ServiceListTagsInputResourceTypeField,
"ListTagsOutputTagsField": ServiceListTagsOutputTagsField,
"Title": strings.Title,
}

tmpl, err := template.New("listtags").Funcs(templateFuncMap).Parse(templateBody)
Expand Down Expand Up @@ -156,7 +160,11 @@ import (
// it may also be a different identifier depending on the service.
func {{ . | Title }}ListTags(conn {{ . | ClientType }}, identifier string{{ if . | ListTagsInputResourceTypeField }}, resourceType string{{ end }}) (KeyValueTags, error) {
input := &{{ . }}.{{ . | ListTagsFunction }}Input{
{{- if . | ListTagsInputIdentifierRequiresSlice }}
{{ . | ListTagsInputIdentifierField }}: aws.StringSlice([]string{identifier}),
{{- else }}
{{ . | ListTagsInputIdentifierField }}: aws.String(identifier),
{{- end }}
{{- if . | ListTagsInputResourceTypeField }}
{{ . | ListTagsInputResourceTypeField }}: aws.String(resourceType),
{{- end }}
Expand All @@ -176,6 +184,8 @@ func {{ . | Title }}ListTags(conn {{ . | ClientType }}, identifier string{{ if .
// ServiceListTagsFunction determines the service tagging function.
func ServiceListTagsFunction(serviceName string) string {
switch serviceName {
case "acm":
return "ListTagsForCertificate"
case "acmpca":
return "ListTags"
case "backup":
Expand All @@ -190,6 +200,8 @@ func ServiceListTagsFunction(serviceName string) string {
return "DescribeTags"
case "elasticsearchservice":
return "ListTags"
case "elbv2":
return "DescribeTags"
case "firehose":
return "ListTagsForDeliveryStream"
case "glue":
Expand All @@ -204,6 +216,8 @@ func ServiceListTagsFunction(serviceName string) string {
return "ListTags"
case "redshift":
return "DescribeTags"
case "resourcegroups":
return "GetTags"
case "sagemaker":
return "ListTags"
case "workspaces":
Expand All @@ -216,6 +230,8 @@ func ServiceListTagsFunction(serviceName string) string {
// ServiceListTagsInputIdentifierField determines the service tag identifier field.
func ServiceListTagsInputIdentifierField(serviceName string) string {
switch serviceName {
case "acm":
return "CertificateArn"
case "acmpca":
return "CertificateAuthorityArn"
case "athena":
Expand All @@ -240,6 +256,8 @@ func ServiceListTagsInputIdentifierField(serviceName string) string {
return "ResourceName"
case "elasticsearchservice":
return "ARN"
case "elbv2":
return "ResourceArns"
case "firehose":
return "DeliveryStreamName"
case "fsx":
Expand All @@ -262,6 +280,8 @@ func ServiceListTagsInputIdentifierField(serviceName string) string {
return "ResourceName"
case "redshift":
return "ResourceName"
case "resourcegroups":
return "Arn"
case "ssm":
return "ResourceId"
case "storagegateway":
Expand All @@ -277,6 +297,16 @@ func ServiceListTagsInputIdentifierField(serviceName string) string {
}
}

// ServiceTagInputIdentifierRequiresSlice determines if the service tagging resource field requires a slice.
func ServiceListTagsInputIdentifierRequiresSlice(serviceName string) string {
switch serviceName {
case "elbv2":
return "yes"
default:
return ""
}
}

// ServiceListTagsInputResourceTypeField determines the service tagging resource type field.
func ServiceListTagsInputResourceTypeField(serviceName string) string {
switch serviceName {
Expand Down Expand Up @@ -304,6 +334,8 @@ func ServiceListTagsOutputTagsField(serviceName string) string {
return "ResourceTags"
case "elasticsearchservice":
return "TagList"
case "elbv2":
return "TagDescriptions[0].Tags"
case "neptune":
return "TagList"
case "rds":
Expand Down
40 changes: 40 additions & 0 deletions aws/internal/keyvaluetags/generators/updatetags/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ import (
const filename = `update_tags_gen.go`

var serviceNames = []string{
"acm",
"acmpca",
"amplify",
"apigateway",
"apigatewayv2",
Expand Down Expand Up @@ -50,6 +52,7 @@ var serviceNames = []string{
"eks",
"elasticache",
"elasticsearchservice",
"elbv2",
"emr",
"firehose",
"fsx",
Expand Down Expand Up @@ -78,6 +81,7 @@ var serviceNames = []string{
"ram",
"rds",
"redshift",
"resourcegroups",
"route53resolver",
"secretsmanager",
"securityhub",
Expand Down Expand Up @@ -223,6 +227,10 @@ func {{ . | Title }}UpdateTags(conn {{ . | ClientType }}, identifier string{{ if
// ServiceTagFunction determines the service tagging function.
func ServiceTagFunction(serviceName string) string {
switch serviceName {
case "acm":
return "AddTagsToCertificate"
case "acmpca":
return "TagCertificateAuthority"
case "databasemigrationservice":
return "AddTagsToResource"
case "datapipeline":
Expand All @@ -239,6 +247,8 @@ func ServiceTagFunction(serviceName string) string {
return "AddTagsToResource"
case "elasticsearchservice":
return "AddTags"
case "elbv2":
return "AddTags"
case "emr":
return "AddTags"
case "firehose":
Expand All @@ -253,6 +263,8 @@ func ServiceTagFunction(serviceName string) string {
return "AddTagsToResource"
case "redshift":
return "CreateTags"
case "resourcegroups":
return "Tag"
case "sagemaker":
return "AddTags"
case "ssm":
Expand All @@ -269,6 +281,10 @@ func ServiceTagFunction(serviceName string) string {
// ServiceTagInputIdentifierField determines the service tag identifier field.
func ServiceTagInputIdentifierField(serviceName string) string {
switch serviceName {
case "acm":
return "CertificateArn"
case "acmpca":
return "CertificateAuthorityArn"
case "athena":
return "ResourceARN"
case "cloudhsmv2":
Expand All @@ -295,6 +311,8 @@ func ServiceTagInputIdentifierField(serviceName string) string {
return "ResourceName"
case "elasticsearchservice":
return "ARN"
case "elbv2":
return "ResourceArns"
case "emr":
return "ResourceId"
case "firehose":
Expand Down Expand Up @@ -325,6 +343,8 @@ func ServiceTagInputIdentifierField(serviceName string) string {
return "ResourceName"
case "redshift":
return "ResourceName"
case "resourcegroups":
return "Arn"
case "secretsmanager":
return "SecretId"
case "ssm":
Expand All @@ -347,6 +367,8 @@ func ServiceTagInputIdentifierRequiresSlice(serviceName string) string {
switch serviceName {
case "ec2":
return "yes"
case "elbv2":
return "yes"
default:
return ""
}
Expand Down Expand Up @@ -379,6 +401,10 @@ func ServiceTagInputResourceTypeField(serviceName string) string {
// ServiceUntagFunction determines the service untagging function.
func ServiceUntagFunction(serviceName string) string {
switch serviceName {
case "acm":
return "RemoveTagsFromCertificate"
case "acmpca":
return "UntagCertificateAuthority"
case "databasemigrationservice":
return "RemoveTagsFromResource"
case "datapipeline":
Expand All @@ -395,6 +421,8 @@ func ServiceUntagFunction(serviceName string) string {
return "RemoveTagsFromResource"
case "elasticsearchservice":
return "RemoveTags"
case "elbv2":
return "RemoveTags"
case "emr":
return "RemoveTags"
case "firehose":
Expand All @@ -409,6 +437,8 @@ func ServiceUntagFunction(serviceName string) string {
return "RemoveTagsFromResource"
case "redshift":
return "DeleteTags"
case "resourcegroups":
return "Untag"
case "sagemaker":
return "DeleteTags"
case "ssm":
Expand All @@ -425,6 +455,10 @@ func ServiceUntagFunction(serviceName string) string {
// ServiceUntagInputRequiresTagType determines if the service untagging requires full Tag type.
func ServiceUntagInputRequiresTagType(serviceName string) string {
switch serviceName {
case "acm":
return "yes"
case "acmpca":
return "yes"
case "ec2":
return "yes"
default:
Expand All @@ -435,6 +469,10 @@ func ServiceUntagInputRequiresTagType(serviceName string) string {
// ServiceUntagInputTagsField determines the service untagging tags field.
func ServiceUntagInputTagsField(serviceName string) string {
switch serviceName {
case "acm":
return "Tags"
case "acmpca":
return "Tags"
case "backup":
return "TagKeyList"
case "cloudhsmv2":
Expand All @@ -445,6 +483,8 @@ func ServiceUntagInputTagsField(serviceName string) string {
return "Tags"
case "glue":
return "TagsToRemove"
case "resourcegroups":
return "Keys"
default:
return "TagKeys"
}
Expand Down
54 changes: 54 additions & 0 deletions aws/internal/keyvaluetags/list_tags_gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit d4b69da

Please sign in to comment.