-
Notifications
You must be signed in to change notification settings - Fork 3
feat: fetch user by email #263
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
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it's okay. Could benefit from a little clean up before merging but seems correct at glance
| return | ||
| } | ||
| createAPITokenRequest.ExpiresAt = &expire | ||
| createAPITokenRequest.SetExpiresAt(expire) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What happened here? Did our API change? Is this now optional?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
v0.6.0 of the generated API client provides setter helpers for optional fields like expiresAt, and using the helper preserves the behaviour of the previous pointer assignment: Unleash/unleash-server-api-go@87392b0#diff-4f4e55d02e361836eb5485af7002e491e934b9742cfea3df8bcce513bf3c81d9R87-R89
| } | ||
| user = apiUser | ||
|
|
||
| if emailProvided { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Struggling a bit with the nesting here. Not sure but I think flattening this if statement may help to make this monster a bit more readble. Tempted to say the conditions for the if statement can just be a single well named function because I also can't spot at a glance what this case represents
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
f9f3dee should flatten this a bit :D
|
|
||
| // Read refreshes the Terraform state with the latest data. | ||
| func (d *userDataSource) Read(ctx context.Context, req datasource.ReadRequest, resp *datasource.ReadResponse) { | ||
| tflog.Debug(ctx, "Preparing to read user data source") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This could really benefit from being broken up into smaller functions, this beast is over a hundred lines long now. At a quick glance I see 3 responsibilities here:
- An initial quick check of the config to check for an early exit
- Fetching a user by whatever property
- Converting that data into a terraform response
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agree: 435f130 should make it more readable
| idProvided := !config.Id.IsNull() && config.Id.ValueString() != "" | ||
| emailProvided := !config.Email.IsNull() && config.Email.ValueString() != "" | ||
|
|
||
| if !idProvided && !emailProvided { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's a shame to do this check at runtime, a config validator might let us push this to plan time. Something like this?
func (d *userDataSource) ConfigValidators(_ context.Context) []datasource.ConfigValidator {
return []datasource.ConfigValidator{
datasourcevalidator.AtLeastOneOf(
path.MatchRoot("id"),
path.MatchRoot("email"),
),
}
}
No idea if this will work on our version of tf, it's based off a quick search
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Interesting! Let me dig into it
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, this requires terraform-plugin-framework-validators dependency... I'm validating the approach
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@sighphyre wdyt of this: #265
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yaaas queen
About the changes
Adds the ability to search for a user by email when using the user data source. This simplifies referring to a user when their ID is unknown.
Fixes #253