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

[Tech Debt]: Migrate AutoFlex ResourcePrefix workflow to an option #37266

Open
jar-b opened this issue May 3, 2024 · 1 comment
Open

[Tech Debt]: Migrate AutoFlex ResourcePrefix workflow to an option #37266

jar-b opened this issue May 3, 2024 · 1 comment
Labels
flex Pertains to FLatteners and EXpanders. technical-debt Addresses areas of the codebase that need refactoring or redesign.

Comments

@jar-b
Copy link
Member

jar-b commented May 3, 2024

Description

#36437 introduced the concept of option functions to AutoFlex.

AutoFlex also has a special case of field name matching which allows for a "resource prefix" to be specified in cases where multiple field names from an AWS struct will have an expected prefix. This optional resource prefix is currently passed into the flex.Expand or flex.Flatten function via a context value:

	resp.Diagnostics.Append(flex.Flatten(context.WithValue(ctx, flex.ResourcePrefix, ResNameIntent), out, &data)...)

Now that we have option functions, this workflow can be migrated to a formal, documented AutoFlex option to make it more discoverable for contributors outside the core team.

// AutoFlexOptions stores configurable options for an auto-flattener or expander.
type AutoFlexOptions struct {
        // Other stuff...

	// resourcePrefix specifies a common prefix which may be applied to one or more fields on an AWS data structure
	resourcePrefix string
}

func (o *AutoFlexOptions) SetResourcePrefix(s string) {
	o.resourcePrefix = s
}

Once implemented, the appropriate flex function can be called with the new option.

	opt := []AutoFlexOptionsFunc{
		func(opts *AutoFlexOptions) {
			opts.SetResourcePrefix(ResNameIntent)
		},
	}

         resp.Diagnostics.Append(flex.Flatten(ctx, out, &data, opt...)...)

References

Would you like to implement a fix?

None

@jar-b jar-b added technical-debt Addresses areas of the codebase that need refactoring or redesign. flex Pertains to FLatteners and EXpanders. labels May 3, 2024
Copy link

github-actions bot commented May 3, 2024

Community Note

Voting for Prioritization

  • Please vote on this issue by adding a 👍 reaction to the original post to help the community and maintainers prioritize this request.
  • Please see our prioritization guide for information on how we prioritize.
  • 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.

Volunteering to Work on This Issue

  • If you are interested in working on this issue, please leave a comment.
  • If this would be your first contribution, please review the contribution guide.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
flex Pertains to FLatteners and EXpanders. technical-debt Addresses areas of the codebase that need refactoring or redesign.
Projects
None yet
Development

No branches or pull requests

1 participant