示例#1
0
def create_gs_key_async(filename, rpc=None):
    """Asynchronously creates an encoded key for a Google Cloud Storage file.

  It is safe to persist this key for future use.

  Args:
    filename: The file name of the Google Cloud Storage object for which you
        want to create the key.
    rpc: Optional UserRPC object.

  Returns:
    A UserRPC whose result will be a string as returned by `create_gs_key()`.

  Raises:
    TypeError: If `filename` is not a string.
    ValueError: If `filename` is not in the format
        `/gs/bucket_name/object_name`.
  """

    if not isinstance(filename, basestring):
        raise TypeError('filename must be str: %s' % filename)
    if not filename.startswith(GS_PREFIX):
        raise ValueError('filename must start with "/gs/": %s' % filename)
    if not '/' in filename[4:]:
        raise ValueError('filename must use the format '
                         '"/gs/bucket_name/object_name": %s' % filename)

    request = blobstore_service_pb.CreateEncodedGoogleStorageKeyRequest()
    response = blobstore_service_pb.CreateEncodedGoogleStorageKeyResponse()

    request.set_filename(filename)

    return _make_async_call(rpc, 'CreateEncodedGoogleStorageKey', request,
                            response, _get_result_hook,
                            lambda rpc: rpc.response.blob_key())
示例#2
0
def create_gs_key_async(filename, rpc=None):
    """Create an encoded key for a google storage file - async version.

  The created blob key will include short lived access token using the
  application's service account for authorization.

  This blob key should not be stored permanently as the access token will
  expire.

  Args:
    filename: The filename of the google storage object to create the
      key for.
    rpc: Optional UserRPC object.

  Returns:
    A UserRPC whose result will be a str as returned by create_gs_key.

  Raises:
    TypeError: If filename is not a string.
    ValueError: If filename is not in the format '/gs/bucket_name/object_name'
  """

    if not isinstance(filename, basestring):
        raise TypeError('filename must be str: %s' % filename)
    if not filename.startswith('/gs/'):
        raise ValueError('filename must start with "/gs/": %s' % filename)
    if not '/' in filename[4:]:
        raise ValueError('filename must have the format '
                         '"/gs/bucket_name/object_name": %s' % filename)

    request = blobstore_service_pb.CreateEncodedGoogleStorageKeyRequest()
    response = blobstore_service_pb.CreateEncodedGoogleStorageKeyResponse()

    request.set_filename(filename)

    return _make_async_call(rpc, 'CreateEncodedGoogleStorageKey', request,
                            response, _get_result_hook,
                            lambda rpc: rpc.response.blob_key())
示例#3
0
def create_gs_key_async(filename, rpc=None):
  """Create an encoded key for a google storage file - async version.

  It is safe to persist this key for future use.

  Args:
    filename: The filename of the google storage object to create the
      key for.
    rpc: Optional UserRPC object.

  Returns:
    A UserRPC whose result will be a string as returned by create_gs_key.

  Raises:
    TypeError: If filename is not a string.
    ValueError: If filename is not in the format '/gs/bucket_name/object_name'
  """

  if not isinstance(filename, six.string_types):
    raise TypeError('filename must be str: %s' % filename)
  if not filename.startswith(GS_PREFIX):
    raise ValueError('filename must start with "/gs/": %s' % filename)
  if not '/' in filename[4:]:
    raise ValueError('filename must have the format '
                     '"/gs/bucket_name/object_name": %s' % filename)

  request = blobstore_service_pb.CreateEncodedGoogleStorageKeyRequest()
  response = blobstore_service_pb.CreateEncodedGoogleStorageKeyResponse()

  request.set_filename(filename)

  return _make_async_call(rpc,
                          'CreateEncodedGoogleStorageKey',
                          request,
                          response,
                          _get_result_hook,
                          lambda rpc: rpc.response.blob_key())