-
Notifications
You must be signed in to change notification settings - Fork 957
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for setting the GCS credential
Set the credential for both the TPU and the local notebook. https://b.corp.google.com/issues/158133824
- Loading branch information
1 parent
ad4d638
commit c703d33
Showing
2 changed files
with
53 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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 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,37 @@ | ||
import unittest | ||
|
||
import os | ||
import tensorflow_gcs_config | ||
from unittest.mock import patch | ||
from test.support import EnvironmentVarGuard | ||
from kaggle_secrets import UserSecretsClient | ||
|
||
class TestTensorflowCredentials(unittest.TestCase): | ||
|
||
@patch('tensorflow_gcs_config.configure_gcs') | ||
def test_set_tensorflow_credential(self, mock_configure_gcs): | ||
credential = '{"client_id":"fake_client_id",' \ | ||
'"client_secret":"fake_client_secret",' \ | ||
'"refresh_token":"not a refresh token",' \ | ||
'"type":"authorized_user"}'; | ||
|
||
env = EnvironmentVarGuard() | ||
env.set('HOME', '/tmp') | ||
env.set('GOOGLE_APPLICATION_CREDENTIALS', '') | ||
|
||
# These need to be set to make UserSecretsClient happy, but aren't | ||
# pertinent to this test. | ||
env.set('KAGGLE_USER_SECRETS_TOKEN', 'foobar') | ||
env.set('KAGGLE_KERNEL_INTEGRATIONS', 'AUTOML') | ||
|
||
user_secrets = UserSecretsClient() | ||
user_secrets.set_tensorflow_credential(credential) | ||
|
||
credential_path = '/tmp/gcloud_credential.json' | ||
self.assertEqual( | ||
credential_path, os.environ['GOOGLE_APPLICATION_CREDENTIALS']) | ||
with open(credential_path, 'r') as f: | ||
saved_cred = f.read() | ||
self.assertEqual(credential, saved_cred) | ||
|
||
mock_configure_gcs.assert_called_with(credentials=credential) |