MCPcopy Create free account
hub / github.com/Kaggle/docker-python / KaggleKernelCredentials

Class KaggleKernelCredentials

patches/kaggle_gcp.py:48–78  ·  view source on GitHub ↗

Custom Credentials used to authenticate using the Kernel's connected OAuth account. Example usage: client = bigquery.Client(project='ANOTHER_PROJECT', credentials=KaggleKernelCredentials())

Source from the content-addressed store, hash-verified

46 GcpTarget.AUTOML in self.integrations
47
48class KaggleKernelCredentials(credentials.Credentials):
49 """Custom Credentials used to authenticate using the Kernel's connected OAuth account.
50 Example usage:
51 client = bigquery.Client(project='ANOTHER_PROJECT',
52 credentials=KaggleKernelCredentials())
53 """
54 def __init__(self, target=GcpTarget.BIGQUERY):
55 super().__init__()
56 self.target = target
57
58 def refresh(self, request):
59 try:
60 client = UserSecretsClient()
61 if self.target == GcpTarget.BIGQUERY:
62 self.token, self.expiry = client.get_bigquery_access_token()
63 elif self.target == GcpTarget.GCS:
64 self.token, self.expiry = client._get_gcs_access_token()
65 elif self.target == GcpTarget.CLOUDAI:
66 self.token, self.expiry = client._get_cloudai_access_token()
67 except ConnectionError as e:
68 logging.error(f"Connection error trying to refresh access token: {e}")
69 print("There was a connection error trying to fetch the access token. "
70 f"Please ensure internet is on in order to use the {self.target.service} Integration.")
71 raise RefreshError('Unable to refresh access token due to connection error.') from e
72 except Exception as e:
73 logging.error(f"Error trying to refresh access token: {e}")
74 if (not get_integrations().has_integration(self.target)):
75 logging.error(f"No {self.target.service} integration found.")
76 print(
77 f"Please ensure you have selected a {self.target.service} account in the Notebook Add-ons menu.")
78 raise RefreshError('Unable to refresh access token.') from e
79
80class KaggleKernelWithProjetCredentials(KaggleKernelCredentials):
81 """ Wrapper Kaggle Credentials with quota_project_id.

Callers 14

init_bigqueryFunction · 0.90
monkeypatch_bqFunction · 0.90
init_gcsFunction · 0.90
init_translation_v2Function · 0.90
init_translation_v3Function · 0.90
init_natural_languageFunction · 0.90
init_ucaipFunction · 0.90
init_video_intelligenceFunction · 0.90
init_visionFunction · 0.90
test_default_targetMethod · 0.90

Calls

no outgoing calls