Skip to content

Commit

Permalink
No public description
Browse files Browse the repository at this point in the history
PiperOrigin-RevId: 554952229
  • Loading branch information
colaboratory-team committed Aug 8, 2023
1 parent f68ac97 commit d4607f1
Showing 1 changed file with 23 additions and 4 deletions.
27 changes: 23 additions & 4 deletions google/colab/_userdata.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,34 @@
"""API to access user secrets."""

from google.colab._message import blocking_request as BlockingRequest
from google.colab import _message


def Get(*args):
class NotebookAccessError(Exception):
"""Exception thrown then the current notebook doesn't have access to the requested secret."""

def __init__(self, key):
super().__init__(f'Notebook does not have access to secret {key}')


def Get(key):
"""Fetchets the value for specified secret keys.
Args:
*args: identifiers for the secret to fetch.
key: Identifier of the secret to fetch.
Returns:
Stored secret
Raises:
NotebookAccessError: If the notebook does not have access to the requested
secret.
"""
return BlockingRequest('GetSecret', request={'keys': args}, timeout_sec=None)
resp = _message.blocking_request(
'GetSecret', request={'key': key}, timeout_sec=None
)
access = resp.get('access', False)
if not access:
# TODO(b/294619193): Open the user secrets pane so that they can grant
# access.
raise NotebookAccessError(key)
return resp.get('payload', '')

0 comments on commit d4607f1

Please sign in to comment.