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

internal/keyvaluetags: Generate Context-Aware Functions #16346

Closed
bflad opened this issue Nov 20, 2020 · 3 comments
Closed

internal/keyvaluetags: Generate Context-Aware Functions #16346

bflad opened this issue Nov 20, 2020 · 3 comments
Labels
enhancement Requests to existing resources that expand the functionality or scope. provider Pertains to the provider itself, rather than any interaction with AWS. stale Old or inactive issues managed by automation, if no further action taken these will get closed.

Comments

@bflad
Copy link
Contributor

bflad commented Nov 20, 2020

Community Note

  • Please vote on this issue by adding a 👍 reaction to the original issue to help the community and maintainers prioritize this request
  • Please do not leave "+1" or other comments that do not add relevant new information or questions, they generate extra noise for issue followers and do not help prioritize the request
  • If you are interested in working on this issue or have submitted a pull request, please leave a comment

Description

Note: Do not implement this until after version 3.17.0 release

The generators in internal/keyvaluetags are tailored to our current AWS Go SDK receiver method usage without context.Context. While we do not have a specific need for it today, as we continue our experimentation with end-to-end resource context handling, we will eventually come across the need to pass through the context to AWS Go SDK calls provided by this functionality. Ideally the generators should create both context and non-context functions, in a DRY fashion.

Adding something like the below for each of the templates should hopefully be on the right track:

// Code generated by generators/listtags/main.go; DO NOT EDIT.

package keyvaluetags

import (
	"context"

	"github.com/aws/aws-sdk-go/aws"
{{- range .ServiceNames }}
	"github.com/aws/aws-sdk-go/service/{{ . }}"
{{- end }}
)
{{ range .ServiceNames }}

// {{ . | 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 . | TagResourceTypeField }}, resourceType string{{ end }}) (KeyValueTags, error) {
	return {{ . | Title }}ListTagsWithContext(context.Background(), identifier{{ if . | TagResourceTypeField }}, resourceType{{ end }})
}

// {{ . | Title }}ListTagsWithContext 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 }}ListTagsWithContext(ctx context.Context, conn {{ . | ClientType }}, identifier string{{ if . | TagResourceTypeField }}, resourceType string{{ end }}) (KeyValueTags, error) {
	input := &{{ . | TagPackage  }}.{{ . | ListTagsFunction }}Input{
		{{- if . | ListTagsInputFilterIdentifierName }}
		Filters: []*{{ . | TagPackage  }}.Filter{
			{
				Name:   aws.String("{{ . | ListTagsInputFilterIdentifierName }}"),
				Values: []*string{aws.String(identifier)},
			},
		},
		{{- else }}
		{{- if . | ListTagsInputIdentifierRequiresSlice }}
		{{ . | ListTagsInputIdentifierField }}: aws.StringSlice([]string{identifier}),
		{{- else }}
		{{ . | ListTagsInputIdentifierField }}: aws.String(identifier),
		{{- end }}
		{{- if . | TagResourceTypeField }}
		{{ . | TagResourceTypeField }}:         aws.String(resourceType),
		{{- end }}
		{{- end }}
	}

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

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

	return {{ . | Title }}KeyValueTags(output.{{ . | ListTagsOutputTagsField }}{{ if . | TagTypeIdentifierField }}, identifier{{ if . | TagResourceTypeField }}, resourceType{{ end }}{{ end }}), nil
}
{{- end }}

References

@bflad bflad added enhancement Requests to existing resources that expand the functionality or scope. provider Pertains to the provider itself, rather than any interaction with AWS. labels Nov 20, 2020
@github-actions
Copy link

Marking this issue as stale due to inactivity. This helps our maintainers find and focus on the active issues. If this issue receives no comments in the next 30 days it will automatically be closed. Maintainers can also remove the stale label.

If this issue was automatically closed and you feel this issue should be reopened, we encourage creating a new issue linking back to this one for added context. Thank you!

@github-actions github-actions bot added the stale Old or inactive issues managed by automation, if no further action taken these will get closed. label Nov 10, 2022
@ewbankkit
Copy link
Contributor

Implemented in #25238.

@github-actions
Copy link

I'm going to lock this issue because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues.
If you have found a problem that seems similar to this, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Dec 12, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
enhancement Requests to existing resources that expand the functionality or scope. provider Pertains to the provider itself, rather than any interaction with AWS. stale Old or inactive issues managed by automation, if no further action taken these will get closed.
Projects
None yet
Development

No branches or pull requests

2 participants