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

client: functional opts for constructor #54

Merged
merged 7 commits into from
Dec 21, 2021

Conversation

thepwagner
Copy link
Collaborator

Update the client package to prefer NewClient() with functional options.

This removes the need for multiple constructors (we were up to 3):

This removes the need for SetFooBar() post-construction intializers (we were up to 2):

The highest risk change here is to the voucher-client binary, where getVoucherClient() is refactored to build []client.Options and fall-through.

Related

@thepwagner thepwagner requested a review from rxbchen December 16, 2021 19:26
@thepwagner thepwagner self-assigned this Dec 16, 2021
@rxbchen rxbchen requested a review from lynnsh December 16, 2021 19:45
Copy link
Collaborator

@rxbchen rxbchen left a comment

Choose a reason for hiding this comment

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

LGTM!

v2/client/client.go Outdated Show resolved Hide resolved
Copy link
Collaborator

@lynnsh lynnsh left a comment

Choose a reason for hiding this comment

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

I like the idea of functional options! I have a comment about NewAuthClient but otherwise it looks good.
I was also wondering if the new token client config should be in cmd/config instead, for consistency? And calling it defaultclient might be a bit misleading?

v2/client/client.go Outdated Show resolved Hide resolved
@thepwagner thepwagner changed the base branch from voucher-client-user-agent to main December 20, 2021 14:59
@thepwagner thepwagner marked this pull request as draft December 20, 2021 15:00
@thepwagner thepwagner marked this pull request as ready for review December 20, 2021 16:27
@thepwagner thepwagner requested a review from lynnsh December 20, 2021 16:27
Copy link
Collaborator

@lynnsh lynnsh left a comment

Choose a reason for hiding this comment

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

Looks great! I just have a small comment.

@@ -1,25 +1,22 @@
package main
package client
Copy link
Collaborator

Choose a reason for hiding this comment

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

A nitpick, but it might be possible to confuse Google's idtoken library used by WithIDTokenAuth with this file. Maybe it should be called default_idtoken/default_token to match it with WithDefaultTokenAuth?

@thepwagner thepwagner force-pushed the client-functional-opts branch from 8a91a18 to 2e2e7d5 Compare December 21, 2021 13:09
@thepwagner thepwagner merged commit b296cb6 into grafeas:main Dec 21, 2021
@thepwagner thepwagner deleted the client-functional-opts branch December 21, 2021 13:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants