Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

keyvaluetags: Add support for 'ListTags' with pagination methods #10834

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions aws/internal/keyvaluetags/generators/listtags/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -104,3 +104,28 @@ The field name of the tags from the tag listing must be updated. Add an entry wi
case "cloudhsmv2":
return "TagList"
```

### Pagination

Some AWS services can return multiple pages of results when listing tags. Support for paged results in the AWS Go SDK is implemented in one of two ways.

#### [Pagination Methods](https://docs.aws.amazon.com/sdk-for-go/v1/developer-guide/making-requests.html#using-pagination-methods)

The AWS Go SDK has a `ListTagsForResourcePages()` API. Add an entry within the `ServiceListTagsHasPaginationFunction()` function of the generator.
For example:

```go
case "cloudhsmv2":
return "yes"
```

#### Pagination Tokens

The AWS Go SDK `ListTagsForResourceInput` structure has a _NextToken_ member and the `ListTagsForResourceOutput` structure has a _NextToken_ member.
Add an entry within the `ServiceListTagsPaginationTokens()` function of the generator.
For example:

```go
case "route53resolver":
return &PaginationTokens{InputToken: "NextToken", OutputToken: "NextToken"}
```
128 changes: 128 additions & 0 deletions aws/internal/keyvaluetags/generators/listtags/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,10 +103,12 @@ func main() {
templateFuncMap := template.FuncMap{
"ClientType": keyvaluetags.ServiceClientType,
"ListTagsFunction": ServiceListTagsFunction,
"ListTagsHasPaginationFunction": ServiceListTagsHasPaginationFunction,
"ListTagsInputIdentifierField": ServiceListTagsInputIdentifierField,
"ListTagsInputIdentifierRequiresSlice": ServiceListTagsInputIdentifierRequiresSlice,
"ListTagsInputResourceTypeField": ServiceListTagsInputResourceTypeField,
"ListTagsOutputTagsField": ServiceListTagsOutputTagsField,
"ListTagsPaginationTokens": ServiceListTagsPaginationTokens,
"Title": strings.Title,
}

Expand Down Expand Up @@ -172,13 +174,48 @@ func {{ . | Title }}ListTags(conn {{ . | ClientType }}, identifier string{{ if .
{{- end }}
}

{{- if . | ListTagsHasPaginationFunction }}
tags := New(nil)

err := conn.{{ . | ListTagsFunction }}Pages(input, func (page *{{ . }}.{{ . | ListTagsFunction }}Output, isLast bool) bool {
tags = tags.Merge({{ . | Title }}KeyValueTags(page.{{ . | ListTagsOutputTagsField }}))

return !isLast
})

if err != nil {
return New(nil), err
}

return tags, nil
{{- else if $tokens := . | ListTagsPaginationTokens }}
tags := New(nil)

for {
output, err := conn.{{ . | ListTagsFunction }}(input)

if err != nil {
return New(nil), err
}

tags = tags.Merge({{ . | Title }}KeyValueTags(output.{{ . | ListTagsOutputTagsField }}))

if output.{{ $tokens.OutputToken }} == nil {
break
}
input.{{ $tokens.InputToken }} = output.{{ $tokens.OutputToken }}
}

return tags, nil
{{- else }}
output, err := conn.{{ . | ListTagsFunction }}(input)

if err != nil {
return New(nil), err
}

return {{ . | Title }}KeyValueTags(output.{{ . | ListTagsOutputTagsField }}), nil
{{- end }}
}
{{- end }}
`
Expand Down Expand Up @@ -233,6 +270,97 @@ func ServiceListTagsFunction(serviceName string) string {
}
}

// ServiceListTagsHasPaginationFunction determines if there is a service tagging pagination function.
func ServiceListTagsHasPaginationFunction(serviceName string) string {
switch serviceName {
case "acmpca":
return "yes"
case "appmesh":
return "yes"
case "backup":
return "yes"
case "cloudhsmv2":
return "yes"
case "codepipeline":
return "yes"
case "datasync":
return "yes"
case "organizations":
return "yes"
case "sagemaker":
return "yes"
case "storagegateway":
return "yes"
case "transfer":
return "yes"
default:
return ""
}
}

type PaginationTokens struct {
InputToken string
OutputToken string
}

// ServiceListTagsPaginationTokens returns any pagination tokens.
func ServiceListTagsPaginationTokens(serviceName string) *PaginationTokens {
switch serviceName {
case "acmpca":
return &PaginationTokens{InputToken: "NextToken", OutputToken: "NextToken"}
case "appmesh":
return &PaginationTokens{InputToken: "NextToken", OutputToken: "NextToken"}
case "athena":
return &PaginationTokens{InputToken: "NextToken", OutputToken: "NextToken"}
case "backup":
return &PaginationTokens{InputToken: "NextToken", OutputToken: "NextToken"}
case "cloudhsmv2":
return &PaginationTokens{InputToken: "NextToken", OutputToken: "NextToken"}
case "cloudtrail":
return &PaginationTokens{InputToken: "NextToken", OutputToken: "NextToken"}
case "codecommit":
return &PaginationTokens{InputToken: "NextToken", OutputToken: "NextToken"}
case "codedeploy":
return &PaginationTokens{InputToken: "NextToken", OutputToken: "NextToken"}
case "codepipeline":
return &PaginationTokens{InputToken: "NextToken", OutputToken: "NextToken"}
case "configservice":
return &PaginationTokens{InputToken: "NextToken", OutputToken: "NextToken"}
case "datasync":
return &PaginationTokens{InputToken: "NextToken", OutputToken: "NextToken"}
case "dax":
return &PaginationTokens{InputToken: "NextToken", OutputToken: "NextToken"}
case "directoryservice":
return &PaginationTokens{InputToken: "NextToken", OutputToken: "NextToken"}
case "dynamodb":
return &PaginationTokens{InputToken: "NextToken", OutputToken: "NextToken"}
case "efs":
return &PaginationTokens{InputToken: "Marker", OutputToken: "NextMarker"}
case "fsx":
return &PaginationTokens{InputToken: "NextToken", OutputToken: "NextToken"}
case "iot":
return &PaginationTokens{InputToken: "NextToken", OutputToken: "NextToken"}
case "kms":
return &PaginationTokens{InputToken: "Marker", OutputToken: "NextMarker"}
case "opsworks":
return &PaginationTokens{InputToken: "NextToken", OutputToken: "NextToken"}
case "organizations":
return &PaginationTokens{InputToken: "NextToken", OutputToken: "NextToken"}
case "route53resolver":
return &PaginationTokens{InputToken: "NextToken", OutputToken: "NextToken"}
case "sagemaker":
return &PaginationTokens{InputToken: "NextToken", OutputToken: "NextToken"}
case "transfer":
return &PaginationTokens{InputToken: "NextToken", OutputToken: "NextToken"}
case "waf":
return &PaginationTokens{InputToken: "NextMarker", OutputToken: "NextMarker"}
case "wafregional":
return &PaginationTokens{InputToken: "NextMarker", OutputToken: "NextMarker"}
default:
return nil
}
}

// ServiceListTagsInputIdentifierField determines the service tag identifier field.
func ServiceListTagsInputIdentifierField(serviceName string) string {
switch serviceName {
Expand Down
Loading