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

Auth Wrapper #1174

Merged
merged 6 commits into from
Feb 10, 2020
Merged

Auth Wrapper #1174

merged 6 commits into from
Feb 10, 2020

Conversation

ben-toogood
Copy link
Contributor

No description provided.

service.go Outdated
@@ -38,10 +39,14 @@ func newService(opts ...Option) Service {
options.Client = wrapper.FromService(serviceName, options.Client)
options.Client = wrapper.TraceCall(serviceName, trace.DefaultTracer, options.Client)

// parse command line flags
cmd.Init()
Copy link
Contributor Author

Choose a reason for hiding this comment

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

@asim I needed to do cmd.Init so that the auth package would be initialised with the necessary flags, e.g. excluded endpoints, public key etc. I've tested this and it's working well, but it feels like this shouldn't be here. Can you think of any potential problems I may have missed?

Copy link
Member

Choose a reason for hiding this comment

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

You cannot do this here. Flags are parsed when calling cmd.Init. This will violate the users expectation. When we do NewService our expectation is that this is just a clean simple initialisation which anyone can use without the flag parsing. If you do service.Init there is the knowledge that this will parse flags. It will also barf in the runtime anywhere we've used NewService. Since that execution occurs inside an existing cli parser.

It doesn't look like the auth wrapper needs those things outside of the interface so the assumption being when service.Init is called these things will be initialisation by config/cmd in the default auth interface. In the micro runtime this would end up being preinitialised since its already done that cmd.Init call.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I thought this also, but when I tested it the auth was noop, despite adding the auth flag. I checked this again when the wrapper was called upon request, and the same was true then.

Copy link
Member

Choose a reason for hiding this comment

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

Fixed. Unfortunately I can now remember why this problem occurs. We've moved from setting defaults to setting the values in the service itself. cmd.Init sets defaults and service.Init sets the values in the service itself.

I've fixed by creating a lazy loading function that returns the auth interface from service.options. It probably pushes us to clearly define what the expected behaviour is. Ideally service.Init should only set its only values rather than defaults in different packages and we should make use of our own internal values set in the options.

@ben-toogood ben-toogood requested a review from asim February 7, 2020 14:17
auth/options.go Outdated Show resolved Hide resolved
config/cmd/cmd.go Outdated Show resolved Hide resolved
util/wrapper/wrapper.go Outdated Show resolved Hide resolved
@ben-toogood
Copy link
Contributor Author

@asim thanks for fixing the cmd.Init bug. I've tested this morning and all is looking good now, can you please let me know if you're happy to merge.

@asim
Copy link
Member

asim commented Feb 10, 2020

LGTM will merge

@asim asim merged commit 4401c12 into master Feb 10, 2020
@asim asim deleted the auth-wrapper branch February 10, 2020 08:26
@ben-toogood ben-toogood restored the auth-wrapper branch February 11, 2020 11:16
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