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

Migrating the Python Admin SDK to google-auth Library #19

Merged
merged 6 commits into from
May 5, 2017

Conversation

hiranya911
Copy link
Contributor

Up until now we have been using the oauth2client library for handling Google credentials. But this library is now deprecated and the new google-auth library is available as a replacement. This PR migrates the SDK to this new library. In addition to the credential related code changes, the migration also allows us to get rid of all the JWT encoding/decoding code that we had to write in the previous implementation. The new library has much better support for JWT processing than the old oauth2client.

[API proposal for this is currently under review]

Copy link

@wilhuff wilhuff left a comment

Choose a reason for hiding this comment

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

Mostly LGTM.

except client.ApplicationDefaultCredentialsError as error:
raise ValueError('Failed to initialize a certificate credential from file "{0}". '
'Caused by: "{1}"'.format(file_path, error))
self._g_credential = service_account.Credentials.from_service_account_info(json_data)
Copy link

Choose a reason for hiding this comment

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

It would appear that any exception thrown from this method will no longer have the filename in the error message, which is useful. Could you wrap this in a try/except similar to the previous version?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

client_id = json_data.get('client_id')
client_secret = json_data.get('client_secret')
refresh_token = json_data.get('refresh_token')
self._g_credential = credentials.Credentials(
Copy link

Choose a reason for hiding this comment

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

This similarly loses file information for error messages.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The Credentials constructor does not raise any errors. So I've implemented some error handling in our init method to check for the required JSON keys, and raise a ValueError with the file name in the error message.

@@ -3,7 +3,7 @@
"project_id": "mock-project-id",
"private_key_id": "mock-key-id-1",
"private_key": "-----BEGIN RSA PRIVATE KEY-----\nMIIEpAIBAAKCAQEAwJENcRev+eXZKvhhWLiV3Lz2MvO+naQRHo59g3vaNQnbgyduN/L4krlr\n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E+OBvfkGGBtw22S\nLesx6sWf99Ov58+x4Q0U5dpxL0Lb7d2Z+2Dtp+Z4jXFjNeeI4ae/qG/LOR/b0pE0J5F415ap\n7Mpq5v89vepUtrkCgYAjMXytu4v+q1Ikhc4UmRPDrUUQ1WVSd+9u19yKlnFGTFnRjej86hiw\nH3jPxBhHra0a53EgiilmsBGSnWpl1WH4EmJz5vBCKUAmjgQiBrueIqv9iHiaTNdjsanUyaWw\njyxXfXl2eI80QPXh02+8g1H/pzESgjK7Rg1AqnkfVH9nrwKBgQDJVxKBPTw9pigYMVt9iHrR\niCl9zQVjRMbWiPOc0J56+/5FZYm/AOGl9rfhQ9vGxXZYZiOP5FsNkwt05Y1UoAAH4B4VQwbL\nqod71qOcI0ywgZiIR87CYw40gzRfjWnN+YEEW1qfyoNLilEwJB8iB/T+ZePHGmJ4MmQ/cTn9\nxpdLXA==\n-----END RSA PRIVATE KEY-----",
"client_email": "mock-email@mock-project.iam.gserviceaccount.com",
"client_id": "1234567890",
Copy link

Choose a reason for hiding this comment

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

It doesn't seem right that you have client_id in a file named tests/data/no_client_id_service_account.json.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Renamed to no_client_email_service_account.json

@@ -1,159 +0,0 @@
# Copyright 2017 Google Inc.
Copy link

Choose a reason for hiding this comment

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

nice!

@hiranya911
Copy link
Contributor Author

Made the suggested changes.

Copy link

@wilhuff wilhuff left a comment

Choose a reason for hiding this comment

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

LGTM

@wilhuff wilhuff assigned hiranya911 and unassigned wilhuff May 4, 2017
@hiranya911 hiranya911 merged commit b29ddb6 into io-2017 May 5, 2017
@hiranya911 hiranya911 deleted the hkj-auth-migration branch May 5, 2017 00:05
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