Skip to content
This repository has been archived by the owner on Mar 20, 2018. It is now read-only.

Refactor auth code to ease transition to google-auth #135

Merged
merged 7 commits into from
Nov 2, 2016

Conversation

theacodes
Copy link

note This changes several public API methods.

@theacodes
Copy link
Author

/cc @bjwatson

@codecov-io
Copy link

codecov-io commented Nov 1, 2016

Current coverage is 98.21% (diff: 100%)

Merging #135 into master will increase coverage by 0.16%

@@             master       #135   diff @@
==========================================
  Files             8          8          
  Lines           616        616          
  Methods           0          0          
  Messages          0          0          
  Branches          0          0          
==========================================
+ Hits            604        605     +1   
+ Misses           12         11     -1   
  Partials          0          0          

Powered by Codecov. Last update 0750185...7dfd9bd

Copy link
Contributor

@geigerj geigerj left a comment

Choose a reason for hiding this comment

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

Thanks for doing this! I like how nicely create_stub cleaned up.

ignored.
service_path: The domain name of the API remote host.
service_port: The port on which to connect to the remote host.
credentials: The credentials for this request.
Copy link
Contributor

Choose a reason for hiding this comment

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

Could you clarify the difference between credentials and ssl_credentials in the docstring?

Copy link
Author

Choose a reason for hiding this comment

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

Done.

@@ -31,19 +31,49 @@

from __future__ import absolute_import

import grpc
Copy link
Contributor

Choose a reason for hiding this comment

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

There is a design restriction on gax not to import grpc in any module except google.gax.grpc. (The intention is that when we support alternative transports, we should only need to switch out a single module.) Let's move secure_authorized_channel to grpc for this reason. gax should also not expose any methods that are grpc-specific in its public interface, so let's make secure_authorized_channel "private".

Copy link
Author

Choose a reason for hiding this comment

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

So this is here because eventually I'll defer most of this to google-auth - (see this PR - you'll notice a similar secure_authorized_channel function).

I can move this into grpc, but at that point I might as well just delete the auth file altogether - it will provide no discernible value. Which would you like?

Copy link
Author

Choose a reason for hiding this comment

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

Actually - I think I'm going to shove this into _grpc_oauth2client.py, so that I can add _grpc_google_auth.py with the same interface.

Copy link
Contributor

Choose a reason for hiding this comment

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

That makes sense. Let's just get rid of the auth module altogether. If I recall correctly, we only created it to begin with because oauth2client didn't provide the generic auth function; since google-auth is going to do that, we shouldn't expose the functionality on the gax surface.

Copy link
Contributor

Choose a reason for hiding this comment

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

Sorry, posted that comment before I saw yours. Moving it to a private module SGTM.

_fake_create_stub, self.FAKE_SERVICE_PATH, self.FAKE_PORT,
metadata_transformer=lambda x: tuple())
self.assertFalse(auth.called)
self.assertFalse(secure_authorized_channel.called)
Copy link
Contributor

Choose a reason for hiding this comment

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

You should pass these variables as parameters to grpc.create_stub; otherwise this doesn't actually test anything.

Copy link
Author

Choose a reason for hiding this comment

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

I'm not sure what you mean here?

Copy link
Contributor

Choose a reason for hiding this comment

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

(see above)

Copy link
Author

Choose a reason for hiding this comment

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

Still not sure what you mean here.

Copy link
Contributor

Choose a reason for hiding this comment

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

Sorry, I misread this. Disregard this comment.

_fake_create_stub, service_path=self.FAKE_SERVICE_PATH,
service_port=self.FAKE_PORT, credentials=credentials)

self.assertFalse(get_default_credentials.called)
Copy link
Contributor

@geigerj geigerj Nov 2, 2016

Choose a reason for hiding this comment

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

get_default_credentials is an unused variable, so a meaningless assertion?

Copy link
Author

Choose a reason for hiding this comment

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

This ensures that default credentials are not used when explicit credentials are specified.

Copy link
Contributor

Choose a reason for hiding this comment

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

You haven't executed any code that references get_default_credentials at the point that you make the assertion that it hasn't been called; it's clear from the syntax alone that it hasn't been called. This is only meaningful if you pass it somehow to grpc.create_stub as a parameter.

Copy link
Author

Choose a reason for hiding this comment

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

create_stub has a branch that calls get_default_credentials, this assert ensures that branch was not executed.

Copy link
Contributor

Choose a reason for hiding this comment

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

Sorry, I misread this. Disregard this comment.

Copy link
Author

Choose a reason for hiding this comment

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

:) I thought I had caught the dumb for second. :D

from grpc import RpcError, StatusCode
from . import auth
from . import _grpc_oauth2client
Copy link
Contributor

Choose a reason for hiding this comment

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

think this file accidentally got left out of the commit

Copy link
Author

Choose a reason for hiding this comment

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

Yeah, fixed. I also did away with the use of closures and went with @dhermes' suggestion of using a class like we do in google-auth.

@@ -0,0 +1,94 @@
# Copyright 2015, Google Inc.
Copy link
Contributor

Choose a reason for hiding this comment

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

Cool. So this file goes away entirely once googleapis/google-auth-library-python#67 is merged, right?

Copy link
Author

Choose a reason for hiding this comment

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

It'll stay around until we formally deprecate oauth2client. I'll also be adding another module named _grpc_google_auth.py that'll be a very small interface to google.auth.

Copy link
Contributor

@geigerj geigerj left a comment

Choose a reason for hiding this comment

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

Please update docs/index.rst -- that should fix the Travis failure. Otherwise LGTM

@theacodes
Copy link
Author

Please update docs/index.rst

Done.

@theacodes
Copy link
Author

Travis is green. ✨

@geigerj geigerj merged commit 8c5fd0d into googleapis:master Nov 2, 2016
@theacodes
Copy link
Author

Thanks @geigerj! Can I get your review over at googleapis/google-auth-library-python#67? Once we merge that I can send another PR for _grpc_google_auth.py.

@theacodes theacodes deleted the auth-refactor branch November 2, 2016 22:17
@geigerj
Copy link
Contributor

geigerj commented Nov 2, 2016

Will do!

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants