This repository was archived by the owner on Dec 22, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
PMI-753: Read Google auth credentials from environment variables #12
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,8 @@ | ||
| AWS_PROFILE=verify-audit-billing-dev | ||
| RP_REPORT_OUTPUT_BUCKET=govukverify-hub-integration-billing-reports | ||
| PIWIK_API_TOKEN=<your-Piwik-API-token> | ||
| GOOGLE_AUTH_PRIVATE_KEY_ID=<your-Google-auth-private-key-id> | ||
| # GOOGLE_AUTH_PRIVATE_KEY=(cannot be set in `.env.`, must be defined in shell) | ||
| GOOGLE_AUTH_CLIENT_EMAIL=<your-Google-auth-client-email> | ||
| GOOGLE_AUTH_CLIENT_ID=<your-Google-auth-client-ID> | ||
| GOOGLE_AUTH_CLIENT_CERT_URL=<your-Google-auth-client-cert-URL> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,35 @@ | ||
| import json | ||
| import os | ||
| import pygsheets | ||
| import tempfile | ||
|
|
||
| from performance.env import check_get_env | ||
| from performance import prod_config as config | ||
|
|
||
|
|
||
| def get_pygsheets_client(): | ||
| google_auth_private_key_id = os.getenv('GOOGLE_AUTH_PRIVATE_KEY_ID') | ||
| if not google_auth_private_key_id: | ||
| return pygsheets.authorize(service_file=config.GSHEETS_CREDENTIALS_FILE) | ||
|
|
||
| creds = { | ||
| "type": "service_account", | ||
| "project_id": "verify-performance", | ||
| "private_key_id": google_auth_private_key_id, | ||
| # Private key cannot be set in `.env` at the moment and must therefore be defined in the | ||
| # shell when running locally. | ||
| "private_key": check_get_env('GOOGLE_AUTH_PRIVATE_KEY'), | ||
| "client_email": check_get_env('GOOGLE_AUTH_CLIENT_EMAIL'), | ||
| "client_id": check_get_env('GOOGLE_AUTH_CLIENT_ID'), | ||
| "auth_uri": "https://accounts.google.com/o/oauth2/auth", | ||
| "token_uri": "https://oauth2.googleapis.com/token", | ||
| "auth_provider_x509_cert_url": "https://www.googleapis.com/oauth2/v1/certs", | ||
| "client_x509_cert_url": check_get_env('GOOGLE_AUTH_CLIENT_CERT_URL') | ||
| } | ||
| temp = tempfile.NamedTemporaryFile(delete=False, mode="w+t") | ||
| temp.write(json.dumps(creds)) | ||
| temp.close() | ||
| try: | ||
| return pygsheets.authorize(service_file=temp.name) | ||
| finally: | ||
| os.unlink(temp.name) | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.