Set user credentials attached to the current kernel and optionally the project & account name to the `gcloud` CLI. Example usage: client = UserSecretsClient() client.set_gcloud_credentials(project="my-gcp-project", account="me@my-org.com") !gcloud ai-pla
(self, project=None, account=None)
| 84 | raise |
| 85 | |
| 86 | def set_gcloud_credentials(self, project=None, account=None): |
| 87 | """Set user credentials attached to the current kernel and optionally the project & account name to the `gcloud` CLI. |
| 88 | |
| 89 | Example usage: |
| 90 | client = UserSecretsClient() |
| 91 | client.set_gcloud_credentials(project="my-gcp-project", account="me@my-org.com") |
| 92 | |
| 93 | !gcloud ai-platform jobs list |
| 94 | """ |
| 95 | creds = self.get_gcloud_credential() |
| 96 | creds_path = self._write_credentials_file(creds) |
| 97 | |
| 98 | subprocess.run(['gcloud', 'config', 'set', 'auth/credential_file_override', creds_path]) |
| 99 | |
| 100 | if project: |
| 101 | os.environ['GOOGLE_CLOUD_PROJECT'] = project |
| 102 | subprocess.run(['gcloud', 'config', 'set', 'project', project]) |
| 103 | |
| 104 | if account: |
| 105 | os.environ['GOOGLE_ACCOUNT'] = account |
| 106 | subprocess.run(['gcloud', 'config', 'set', 'account', account]) |
| 107 | |
| 108 | def set_tensorflow_credential(self, credential): |
| 109 | """Sets the credential for use by Tensorflow""" |