Skip to content

Commit

Permalink
internal/keyvaluetags: Implement support for additional tag informati…
Browse files Browse the repository at this point in the history
…on, fix nil value panics, implement autoscaling service tags

Reference: #12368
Reference: #13808
  • Loading branch information
bflad committed Aug 20, 2020
1 parent 83b895a commit cdf7229
Show file tree
Hide file tree
Showing 12 changed files with 1,403 additions and 78 deletions.
19 changes: 11 additions & 8 deletions aws/internal/keyvaluetags/generators/createtags/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,10 @@ func main() {
"TagInputCustomValue": keyvaluetags.ServiceTagInputCustomValue,
"TagInputIdentifierField": keyvaluetags.ServiceTagInputIdentifierField,
"TagInputIdentifierRequiresSlice": keyvaluetags.ServiceTagInputIdentifierRequiresSlice,
"TagInputResourceTypeField": keyvaluetags.ServiceTagInputResourceTypeField,
"TagInputTagsField": keyvaluetags.ServiceTagInputTagsField,
"TagPackage": keyvaluetags.ServiceTagPackage,
"TagResourceTypeField": keyvaluetags.ServiceTagResourceTypeField,
"TagTypeIdentifierField": keyvaluetags.ServiceTagTypeIdentifierField,
"Title": strings.Title,
}

Expand Down Expand Up @@ -133,25 +134,27 @@ func isResourceTimeoutError(err error) bool {
// {{ . | Title }}CreateTags creates {{ . }} service tags for new resources.
// The identifier is typically the Amazon Resource Name (ARN), although
// it may also be a different identifier depending on the service.
func {{ . | Title }}CreateTags(conn {{ . | ClientType }}, identifier string{{ if . | TagInputResourceTypeField }}, resourceType string{{ end }}, tagsMap interface{}) error {
func {{ . | Title }}CreateTags(conn {{ . | ClientType }}, identifier string{{ if . | TagResourceTypeField }}, resourceType string{{ end }}, tagsMap interface{}) error {
tags := New(tagsMap)
{{- if . | TagFunctionBatchSize }}
for _, tags := range tags.Chunks({{ . | TagFunctionBatchSize }}) {
{{- end }}
input := &{{ . | TagPackage }}.{{ . | TagFunction }}Input{
{{- if not ( . | TagTypeIdentifierField ) }}
{{- if . | TagInputIdentifierRequiresSlice }}
{{ . | TagInputIdentifierField }}: aws.StringSlice([]string{identifier}),
{{ . | TagInputIdentifierField }}: aws.StringSlice([]string{identifier}),
{{- else }}
{{ . | TagInputIdentifierField }}: aws.String(identifier),
{{ . | TagInputIdentifierField }}: aws.String(identifier),
{{- end }}
{{- if . | TagResourceTypeField }}
{{ . | TagResourceTypeField }}: aws.String(resourceType),
{{- end }}
{{- if . | TagInputResourceTypeField }}
{{ . | TagInputResourceTypeField }}: aws.String(resourceType),
{{- end }}
{{- if . | TagInputCustomValue }}
{{ . | TagInputTagsField }}: {{ . | TagInputCustomValue }},
{{ . | TagInputTagsField }}: {{ . | TagInputCustomValue }},
{{- else }}
{{ . | TagInputTagsField }}: tags.IgnoreAws().{{ . | Title }}Tags(),
{{ . | TagInputTagsField }}: tags.IgnoreAws().{{ . | Title }}Tags(),
{{- end }}
}
Expand Down
19 changes: 15 additions & 4 deletions aws/internal/keyvaluetags/generators/gettag/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import (
const filename = `get_tag_gen.go`

var serviceNames = []string{
"autoscaling",
"dynamodb",
"ec2",
"ecs",
Expand All @@ -38,9 +39,11 @@ func main() {
"ClientType": keyvaluetags.ServiceClientType,
"ListTagsFunction": keyvaluetags.ServiceListTagsFunction,
"ListTagsInputFilterIdentifierName": keyvaluetags.ServiceListTagsInputFilterIdentifierName,
"ListTagsInputResourceTypeField": keyvaluetags.ServiceListTagsInputResourceTypeField,
"ListTagsOutputTagsField": keyvaluetags.ServiceListTagsOutputTagsField,
"TagPackage": keyvaluetags.ServiceTagPackage,
"TagResourceTypeField": keyvaluetags.ServiceTagResourceTypeField,
"TagTypeAdditionalBoolFields": keyvaluetags.ServiceTagTypeAdditionalBoolFields,
"TagTypeIdentifierField": keyvaluetags.ServiceTagTypeIdentifierField,
"Title": strings.Title,
}

Expand Down Expand Up @@ -97,7 +100,11 @@ import (
// This function will optimise the handling over {{ . | Title }}ListTags, if possible.
// The identifier is typically the Amazon Resource Name (ARN), although
// it may also be a different identifier depending on the service.
func {{ . | Title }}GetTag(conn {{ . | ClientType }}, identifier string{{ if . | ListTagsInputResourceTypeField }}, resourceType string{{ end }}, key string) (bool, *string, error) {
{{- if or ( . | TagTypeIdentifierField ) ( . | TagTypeAdditionalBoolFields) }}
func {{ . | Title }}GetTag(conn {{ . | ClientType }}, identifier string{{ if . | TagResourceTypeField }}, resourceType string{{ end }}, key string) (bool, *TagData, error) {
{{- else }}
func {{ . | Title }}GetTag(conn {{ . | ClientType }}, identifier string{{ if . | TagResourceTypeField }}, resourceType string{{ end }}, key string) (bool, *string, error) {
{{- end }}
{{- if . | ListTagsInputFilterIdentifierName }}
input := &{{ . | TagPackage }}.{{ . | ListTagsFunction }}Input{
Filters: []*{{ . | TagPackage }}.Filter{
Expand All @@ -118,16 +125,20 @@ func {{ . | Title }}GetTag(conn {{ . | ClientType }}, identifier string{{ if . |
return false, nil, err
}
listTags := {{ . | Title }}KeyValueTags(output.{{ . | ListTagsOutputTagsField }})
listTags := {{ . | Title }}KeyValueTags(output.{{ . | ListTagsOutputTagsField }}{{ if . | TagTypeIdentifierField }}, identifier{{ if . | TagResourceTypeField }}, resourceType{{ end }}{{ end }})
{{- else }}
listTags, err := {{ . | Title }}ListTags(conn, identifier{{ if . | ListTagsInputResourceTypeField }}, resourceType{{ end }})
listTags, err := {{ . | Title }}ListTags(conn, identifier{{ if . | TagResourceTypeField }}, resourceType{{ end }})
if err != nil {
return false, nil, err
}
{{- end }}
{{ if or ( . | TagTypeIdentifierField ) ( . | TagTypeAdditionalBoolFields) }}
return listTags.KeyExists(key), listTags.KeyTagData(key), nil
{{- else }}
return listTags.KeyExists(key), listTags.KeyValue(key), nil
{{- end }}
}
{{- end }}
`
16 changes: 9 additions & 7 deletions aws/internal/keyvaluetags/generators/listtags/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ var serviceNames = []string{
"appstream",
"appsync",
"athena",
"autoscaling",
"backup",
"cloud9",
"cloudfront",
Expand Down Expand Up @@ -133,9 +134,10 @@ func main() {
"ListTagsInputFilterIdentifierName": keyvaluetags.ServiceListTagsInputFilterIdentifierName,
"ListTagsInputIdentifierField": keyvaluetags.ServiceListTagsInputIdentifierField,
"ListTagsInputIdentifierRequiresSlice": keyvaluetags.ServiceListTagsInputIdentifierRequiresSlice,
"ListTagsInputResourceTypeField": keyvaluetags.ServiceListTagsInputResourceTypeField,
"ListTagsOutputTagsField": keyvaluetags.ServiceListTagsOutputTagsField,
"TagPackage": keyvaluetags.ServiceTagPackage,
"TagResourceTypeField": keyvaluetags.ServiceTagResourceTypeField,
"TagTypeIdentifierField": keyvaluetags.ServiceTagTypeIdentifierField,
"Title": strings.Title,
}

Expand Down Expand Up @@ -189,7 +191,7 @@ import (
// {{ . | Title }}ListTags lists {{ . }} service tags.
// The identifier is typically the Amazon Resource Name (ARN), although
// 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) {
func {{ . | Title }}ListTags(conn {{ . | ClientType }}, identifier string{{ if . | TagResourceTypeField }}, resourceType string{{ end }}) (KeyValueTags, error) {
input := &{{ . | TagPackage }}.{{ . | ListTagsFunction }}Input{
{{- if . | ListTagsInputFilterIdentifierName }}
Filters: []*{{ . | TagPackage }}.Filter{
Expand All @@ -200,12 +202,12 @@ func {{ . | Title }}ListTags(conn {{ . | ClientType }}, identifier string{{ if .
},
{{- else }}
{{- if . | ListTagsInputIdentifierRequiresSlice }}
{{ . | ListTagsInputIdentifierField }}: aws.StringSlice([]string{identifier}),
{{ . | ListTagsInputIdentifierField }}: aws.StringSlice([]string{identifier}),
{{- else }}
{{ . | ListTagsInputIdentifierField }}: aws.String(identifier),
{{ . | ListTagsInputIdentifierField }}: aws.String(identifier),
{{- end }}
{{- if . | ListTagsInputResourceTypeField }}
{{ . | ListTagsInputResourceTypeField }}: aws.String(resourceType),
{{- if . | TagResourceTypeField }}
{{ . | TagResourceTypeField }}: aws.String(resourceType),
{{- end }}
{{- end }}
}
Expand All @@ -216,7 +218,7 @@ func {{ . | Title }}ListTags(conn {{ . | ClientType }}, identifier string{{ if .
return New(nil), err
}
return {{ . | Title }}KeyValueTags(output.{{ . | ListTagsOutputTagsField }}), nil
return {{ . | Title }}KeyValueTags(output.{{ . | ListTagsOutputTagsField }}{{ if . | TagTypeIdentifierField }}, identifier{{ if . | TagResourceTypeField }}, resourceType{{ end }}{{ end }}), nil
}
{{- end }}
`
Loading

0 comments on commit cdf7229

Please sign in to comment.