| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1,3 +1,11 @@ | |||
| 1 | + """UserSecret client classes. | ||
| 2 | + | ||
| 3 | + This library adds support for communicating with the UserSecrets service, | ||
| 4 | + currently used for retrieving an access token for supported integrations | ||
| 5 | + (ie. BigQuery). | ||
| 6 | + | ||
| 7 | + """ | ||
| 8 | + | ||
| 1 | 9 | import json | |
| 2 | 10 | import os | |
| 3 | 11 | import urllib.request | |
@@ -17,7 +25,7 @@ class BackendError(Exception): | |||
| 17 | 25 | ||
| 18 | 26 | class UserSecretsClient(): | |
| 19 | 27 | GET_USER_SECRET_ENDPOINT = '/requests/GetUserSecretRequest' | |
| 20 | - BIGQUERY_PURPOSE_VALUE = 1 | ||
| 28 | + BIGQUERY_TARGET_VALUE = 1 | ||
| 21 | 29 | ||
| 22 | 30 | def __init__(self): | |
| 23 | 31 | url_base_override = os.getenv(_KAGGLE_URL_BASE_ENV_VAR_NAME) | |
@@ -39,22 +47,12 @@ def _make_get_request(self, request_body): | |||
| 39 | 47 | response_json = json.loads(response.read()) | |
| 40 | 48 | return response_json | |
| 41 | 49 | ||
| 42 | - def get_user_secret(self, secret_label: str): | ||
| 43 | - request_body = { | ||
| 44 | - 'SecretLabel': secret_label | ||
| 45 | - } | ||
| 46 | - response_json = self._make_get_request(request_body) | ||
| 47 | - if 'Secret' not in response_json: | ||
| 48 | - raise BackendError( | ||
| 49 | - 'Unexpected response from the service.') | ||
| 50 | - return response_json['Secret'] | ||
| 51 | - | ||
| 52 | 50 | def get_bigquery_access_token(self): | |
| 53 | 51 | request_body = { | |
| 54 | - 'Purpose': self.BIGQUERY_PURPOSE_VALUE | ||
| 52 | + 'Target': self.BIGQUERY_TARGET_VALUE | ||
| 55 | 53 | } | |
| 56 | 54 | response_json = self._make_get_request(request_body) | |
| 57 | 55 | if 'Secret' not in response_json: | |
| 58 | 56 | raise BackendError( | |
| 59 | - 'Unexpected response from UserSecrets service.') | ||
| 57 | + 'Unexpected response from the service.') | ||
| 60 | 58 | return response_json['Secret'] | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -86,14 +86,4 @@ def call_get_access_token(): | |||
| 86 | 86 | secret_response = client.get_bigquery_access_token() | |
| 87 | 87 | self.assertEqual(secret_response, secret) | |
| 88 | 88 | self._test_client(call_get_access_token, | |
| 89 | - '/requests/GetUserSecretRequest?Purpose=1', secret) | ||
| 90 | - | ||
| 91 | - def test_get_user_secret_succeeds(self): | ||
| 92 | - secret = '5678' | ||
| 93 | - | ||
| 94 | - def call_get_access_token(): | ||
| 95 | - client = UserSecretsClient() | ||
| 96 | - secret_response = client.get_user_secret('MY_SECRET') | ||
| 97 | - self.assertEqual(secret_response, secret) | ||
| 98 | - self._test_client( | ||
| 99 | - call_get_access_token, '/requests/GetUserSecretRequest?SecretLabel=MY_SECRET', secret) | ||
| 89 | + '/requests/GetUserSecretRequest?Target=1', secret) | ||
| Back | FazBrowse Home | New Git URL |
0 commit comments