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

Add google.auth.oauth2client - helpers for oauth2client migration #70

Merged
merged 2 commits into from
Nov 3, 2016

Conversation

theacodes
Copy link
Contributor

Resolves #38

@dhermes please let me know what you think about exposing this as google.auth.oauth2client, and feel free to suggest a better name (oauth2client_compat?)

@theacodes theacodes added this to the 1.0.0 milestone Nov 2, 2016
@@ -0,0 +1,133 @@
# Copyright 2015 Google Inc.

This comment was marked as spam.

This comment was marked as spam.

import oauth2client.service_account
_HAS_OAUTH2CLIENT = True
except ImportError: # pragma: NO COVER
_HAS_OAUTH2CLIENT = False

This comment was marked as spam.

This comment was marked as spam.



def _convert_oauth2_credentials(credentials):
"""Converts to :class:`google.oauth2.credentials.Credentials`."""

This comment was marked as spam.

This comment was marked as spam.



def _convert_service_account_credentials(credentials):
"""Converts to :class:`google.oauth2.service_account.Credentials`."""

This comment was marked as spam.

This comment was marked as spam.

def _convert_service_account_credentials(credentials):
"""Converts to :class:`google.oauth2.service_account.Credentials`."""
info = credentials.serialization_data
info['token_uri'] = credentials.token_uri

This comment was marked as spam.

This comment was marked as spam.

google.auth.credentials.Credentials: The converted credentials.

Raises:
EnvironmentError: If oauth2client is not installed.

This comment was marked as spam.

This comment was marked as spam.

if not _HAS_OAUTH2CLIENT:
raise EnvironmentError(
'oauth2client is not installed and is required in order to convert'
'credentials.')

This comment was marked as spam.

This comment was marked as spam.

return _CLASS_CONVERSION_MAP[credentials_class](credentials)
except KeyError:
raise ValueError(
'Unable to convert {} to a google-auth credentials class.'.format(

This comment was marked as spam.

This comment was marked as spam.

@@ -56,7 +56,7 @@
},
'BASIC': {
'method-rgx': '[a-z_][a-z0-9_]{2,40}$',
'function-rgx': '[a-z_][a-z0-9_]{2,40}$',
'function-rgx': '[a-z_][a-z0-9_]{2,45}$',

This comment was marked as spam.

This comment was marked as spam.



def test_import_has_app_engine(mock_oauth2client_gae_imports):
reload_module(_oauth2client)

This comment was marked as spam.

This comment was marked as spam.

@dhermes
Copy link
Contributor

dhermes commented Nov 2, 2016

please let me know what you think about exposing this as google.auth.oauth2client, and feel free to suggest a better name (oauth2client_compat?)

The very first thing I thought when I saw the first file (docs/reference/google.auth.oauth2client.rst) was: "aw man why is it public?"

My reflex says make it non-public.

  • If you make it non-public, the name is less relevant. _oauth2client is fine
  • If you make it public, I prefer oauth2client_compat

@theacodes
Copy link
Contributor Author

If I make it non-public, how would I expose the 'convert' function?

On Tue, Nov 1, 2016, 8:04 PM Danny Hermes notifications@github.com wrote:

please let me know what you think about exposing this as
google.auth.oauth2client, and feel free to suggest a better name (
oauth2client_compat?)

The very first thing I thought when I saw the first file (
docs/reference/google.auth.oauth2client.rst) was: "aw man why is it
public?"

My reflex says make it non-public.

  • If you make it non-public, the name is less relevant. _oauth2client
    is fine
  • If you make it public, I prefer oauth2client_compat


You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
#70 (comment),
or mute the thread
https://github.com/notifications/unsubscribe-auth/AAPUcxBZ0vUtS_R-wv3SZoB32zj9oXKKks5q5_2ygaJpZM4KmzNC
.

@dhermes
Copy link
Contributor

dhermes commented Nov 2, 2016

If I make it non-public, how would I expose the convert function?

Just force the non-public module to show up in the Sphinx generated docs and then put a big warning in the module docstring that the module is intentionally non-public and not intended for typical users / new users. Then let them eat cake import the non-public module.

@theacodes
Copy link
Contributor Author

@dhermes I'm rather just leave it out of the docs in that case. Cool with you?

@dhermes
Copy link
Contributor

dhermes commented Nov 2, 2016

@jonparrott I suppose it's cool with me, though you should still have very good and useful docstrings (especially the module docstring).

@theacodes
Copy link
Contributor Author

(especially the module docstring).

Anything you'd add to the module docstring?

@dhermes
Copy link
Contributor

dhermes commented Nov 2, 2016

Essentially

put a big warning in the module docstring that the module is intentionally non-public and not intended for typical users / new users

Copy link
Contributor Author

@theacodes theacodes left a comment

Choose a reason for hiding this comment

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

@dhermes I've made it private and addressed all comments.

@@ -0,0 +1,133 @@
# Copyright 2015 Google Inc.

This comment was marked as spam.

import oauth2client.service_account
_HAS_OAUTH2CLIENT = True
except ImportError: # pragma: NO COVER
_HAS_OAUTH2CLIENT = False

This comment was marked as spam.



def _convert_oauth2_credentials(credentials):
"""Converts to :class:`google.oauth2.credentials.Credentials`."""

This comment was marked as spam.



def _convert_service_account_credentials(credentials):
"""Converts to :class:`google.oauth2.service_account.Credentials`."""

This comment was marked as spam.

def _convert_service_account_credentials(credentials):
"""Converts to :class:`google.oauth2.service_account.Credentials`."""
info = credentials.serialization_data
info['token_uri'] = credentials.token_uri

This comment was marked as spam.

google.auth.credentials.Credentials: The converted credentials.

Raises:
EnvironmentError: If oauth2client is not installed.

This comment was marked as spam.

if not _HAS_OAUTH2CLIENT:
raise EnvironmentError(
'oauth2client is not installed and is required in order to convert'
'credentials.')

This comment was marked as spam.

return _CLASS_CONVERSION_MAP[credentials_class](credentials)
except KeyError:
raise ValueError(
'Unable to convert {} to a google-auth credentials class.'.format(

This comment was marked as spam.

@@ -56,7 +56,7 @@
},
'BASIC': {
'method-rgx': '[a-z_][a-z0-9_]{2,40}$',
'function-rgx': '[a-z_][a-z0-9_]{2,40}$',
'function-rgx': '[a-z_][a-z0-9_]{2,45}$',

This comment was marked as spam.



def test_import_has_app_engine(mock_oauth2client_gae_imports):
reload_module(_oauth2client)

This comment was marked as spam.

@theacodes
Copy link
Contributor Author

@dhermes you've approved, but I changed a lot since, care to take another look? ("No" is also acceptable as this is a completely private module)

@theacodes theacodes merged commit a896d2a into master Nov 3, 2016
@theacodes theacodes deleted the oauth2client-converter branch November 3, 2016 06:42
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.

None yet

2 participants