Skip to content

Commit

Permalink
internal/keyvaluetags: Generate Ec2UpdateTags
Browse files Browse the repository at this point in the history
Updated via:

```console
$ make gen
```
  • Loading branch information
bflad committed Oct 1, 2019
1 parent 9b45620 commit 8b88f68
Show file tree
Hide file tree
Showing 3 changed files with 91 additions and 8 deletions.
59 changes: 51 additions & 8 deletions aws/internal/keyvaluetags/generators/updatetags/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ var serviceNames = []string{
"directoryservice",
"docdb",
"dynamodb",
"ec2",
"ecr",
"ecs",
"efs",
Expand Down Expand Up @@ -100,14 +101,16 @@ func main() {
ServiceNames: serviceNames,
}
templateFuncMap := template.FuncMap{
"ClientType": keyvaluetags.ServiceClientType,
"TagFunction": ServiceTagFunction,
"TagInputIdentifierField": ServiceTagInputIdentifierField,
"TagInputResourceTypeField": ServiceTagInputResourceTypeField,
"TagInputTagsField": ServiceTagInputTagsField,
"Title": strings.Title,
"UntagFunction": ServiceUntagFunction,
"UntagInputTagsField": ServiceUntagInputTagsField,
"ClientType": keyvaluetags.ServiceClientType,
"TagFunction": ServiceTagFunction,
"TagInputIdentifierField": ServiceTagInputIdentifierField,
"TagInputIdentifierRequiresSlice": ServiceTagInputIdentifierRequiresSlice,
"TagInputResourceTypeField": ServiceTagInputResourceTypeField,
"TagInputTagsField": ServiceTagInputTagsField,
"Title": strings.Title,
"UntagFunction": ServiceUntagFunction,
"UntagInputRequiresTagType": ServiceUntagInputRequiresTagType,
"UntagInputTagsField": ServiceUntagInputTagsField,
}

tmpl, err := template.New("updatetags").Funcs(templateFuncMap).Parse(templateBody)
Expand Down Expand Up @@ -168,11 +171,19 @@ func {{ . | Title }}UpdateTags(conn {{ . | ClientType }}, identifier string{{ if
if removedTags := oldTags.Removed(newTags); len(removedTags) > 0 {
input := &{{ . }}.{{ . | UntagFunction }}Input{
{{- if . | TagInputIdentifierRequiresSlice }}
{{ . | TagInputIdentifierField }}: aws.StringSlice([]string{identifier}),
{{- else }}
{{ . | TagInputIdentifierField }}: aws.String(identifier),
{{- end }}
{{- if . | TagInputResourceTypeField }}
{{ . | TagInputResourceTypeField }}: aws.String(resourceType),
{{- end }}
{{- if . | UntagInputRequiresTagType }}
{{ . | UntagInputTagsField }}: removedTags.IgnoreAws().{{ . | Title }}Tags(),
{{- else }}
{{ . | UntagInputTagsField }}: aws.StringSlice(removedTags.Keys()),
{{- end }}
}
_, err := conn.{{ . | UntagFunction }}(input)
Expand All @@ -184,7 +195,11 @@ func {{ . | Title }}UpdateTags(conn {{ . | ClientType }}, identifier string{{ if
if updatedTags := oldTags.Updated(newTags); len(updatedTags) > 0 {
input := &{{ . }}.{{ . | TagFunction }}Input{
{{- if . | TagInputIdentifierRequiresSlice }}
{{ . | TagInputIdentifierField }}: aws.StringSlice([]string{identifier}),
{{- else }}
{{ . | TagInputIdentifierField }}: aws.String(identifier),
{{- end }}
{{- if . | TagInputResourceTypeField }}
{{ . | TagInputResourceTypeField }}: aws.String(resourceType),
{{- end }}
Expand Down Expand Up @@ -214,6 +229,8 @@ func ServiceTagFunction(serviceName string) string {
return "AddTagsToResource"
case "docdb":
return "AddTagsToResource"
case "ec2":
return "CreateTags"
case "efs":
return "CreateTags"
case "elasticache":
Expand Down Expand Up @@ -268,6 +285,8 @@ func ServiceTagInputIdentifierField(serviceName string) string {
return "ResourceId"
case "docdb":
return "ResourceName"
case "ec2":
return "Resources"
case "efs":
return "FileSystemId"
case "elasticache":
Expand Down Expand Up @@ -321,6 +340,16 @@ func ServiceTagInputIdentifierField(serviceName string) string {
}
}

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

// ServiceTagInputTagsField determines the service tagging tags field.
func ServiceTagInputTagsField(serviceName string) string {
switch serviceName {
Expand Down Expand Up @@ -356,6 +385,8 @@ func ServiceUntagFunction(serviceName string) string {
return "RemoveTagsFromResource"
case "docdb":
return "RemoveTagsFromResource"
case "ec2":
return "DeleteTags"
case "efs":
return "DeleteTags"
case "elasticache":
Expand Down Expand Up @@ -389,6 +420,16 @@ func ServiceUntagFunction(serviceName string) string {
}
}

// ServiceUntagInputRequiresTagType determines if the service untagging requires full Tag type.
func ServiceUntagInputRequiresTagType(serviceName string) string {
switch serviceName {
case "ec2":
return "yes"
default:
return ""
}
}

// ServiceUntagInputTagsField determines the service untagging tags field.
func ServiceUntagInputTagsField(serviceName string) string {
switch serviceName {
Expand All @@ -398,6 +439,8 @@ func ServiceUntagInputTagsField(serviceName string) string {
return "TagKeyList"
case "datasync":
return "Keys"
case "ec2":
return "Tags"
case "glue":
return "TagsToRemove"
default:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ import (
"github.com/aws/aws-sdk-go/service/directoryservice"
"github.com/aws/aws-sdk-go/service/docdb"
"github.com/aws/aws-sdk-go/service/dynamodb"
"github.com/aws/aws-sdk-go/service/ec2"
"github.com/aws/aws-sdk-go/service/ecr"
"github.com/aws/aws-sdk-go/service/ecs"
"github.com/aws/aws-sdk-go/service/efs"
Expand Down Expand Up @@ -146,6 +147,8 @@ func ServiceClientType(serviceName string) string {
funcType = reflect.TypeOf(docdb.New)
case "dynamodb":
funcType = reflect.TypeOf(dynamodb.New)
case "ec2":
funcType = reflect.TypeOf(ec2.New)
case "ecr":
funcType = reflect.TypeOf(ecr.New)
case "ecs":
Expand Down
37 changes: 37 additions & 0 deletions aws/internal/keyvaluetags/update_tags_gen.go

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

0 comments on commit 8b88f68

Please sign in to comment.