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

fields: parse tagged fields in struct values and apply secrets to them #80

Merged
merged 1 commit into from
Oct 12, 2023

Conversation

creachadair
Copy link
Member

Given a pointer to a struct with specially-tagged fields, use reflection to
locate these fields and plumb secrets from a setec.Store into them.

@creachadair creachadair force-pushed the mjf/plugtype branch 6 times, most recently from 54a9141 to 9646968 Compare October 7, 2023 21:59
}
defer st.Close()

// Apply the requested secrets to the fields.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hm, having it as a separate package makes for an unfortunate 3-step dance to discover, register, then install the secrets. But I can't think of a better way that doesn't pull reflect sadness into the main setec client library...

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Based on our discussion in Slack, I reworked this a bit along that suggestion.

fields/fields.go Outdated Show resolved Hide resolved
@creachadair creachadair marked this pull request as ready for review October 11, 2023 23:25
// tagged name, separated with a slash ("/").
//
// See [Fields] for a description of the struct tags and types recognized.
func ParseFields(v any, namePrefix string) (*Fields, error) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Deliberately still exported? The example seems to point to usage that doesn't require the machinery to be exposed. Or are we keeping it as an alternative way to do this?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I left it exported so that you can still apply secrets to a struct even if that struct isn't available when the store is constructed. I reworked the examples and the docs to focus on the pre-declared case, but in some of our existing use we wouldn't be able to do this, because we don't get the struct until later.

Given a pointer to a struct with specially-tagged fields, use reflection to
locate these fields and plumb secrets from a setec.Store into them.
@creachadair creachadair merged commit 1f77e93 into main Oct 12, 2023
1 check passed
@creachadair creachadair deleted the mjf/plugtype branch October 12, 2023 01:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants