U
    
ڲg                     @   sf   d Z zddlmZ W n ek
r0   edY nX ddlmZ dZdejddd	ZG d
d dZ	dS )zFirebase Cloud Storage module.

This module contains utilities for accessing Google Cloud Storage buckets associated with
Firebase apps. This requires the ``google-cloud-storage`` Python module.
    )storageznFailed to import the Cloud Storage library for Python. Make sure to install the "google-cloud-storage" module.)_utilsZ_storageN)returnc                 C   s   t |ttj}|| S )ao  Returns a handle to a Google Cloud Storage bucket.

    If the name argument is not provided, uses the 'storageBucket' option specified when
    initializing the App. If that is also not available raises an error. This function
    does not make any RPC calls.

    Args:
      name: Name of a cloud storage bucket (optional).
      app: An App instance (optional).

    Returns:
      google.cloud.storage.Bucket: A handle to the specified bucket.

    Raises:
      ValueError: If a bucket name is not specified either via options or method arguments,
          or if the specified bucket name is not a valid string.
    )r   Zget_app_service_STORAGE_ATTRIBUTE_StorageClientfrom_appbucket)nameappclient r   :/tmp/pip-unpacked-wheel-p0r7i5ii/firebase_admin/storage.pyr   !   s    r   c                   @   s.   e Zd ZdZdd Zedd Zd	ddZdS )
r   z-Holds a Google Cloud Storage client instance.c                 C   s   t j||d| _|| _d S )N)credentialsproject)r   ZClient_client_default_bucket)selfr   r   default_bucketr   r   r   __init__:   s    z_StorageClient.__init__c                 C   s$   |j  }|jd}t||j|S )NZstorageBucket)Z
credentialget_credentialoptionsgetr   Z
project_id)clsr
   r   r   r   r   r   r   >   s    
z_StorageClient.from_appNc                 C   sJ   |dk	r|n| j }|dkr"td|r0t|ts>td|| j|S )z7Returns a handle to the specified Cloud Storage Bucket.NzStorage bucket name not specified. Specify the bucket name via the "storageBucket" option when initializing the App, or specify the bucket name explicitly when calling the storage.bucket() function.zKInvalid storage bucket name: "{0}". Bucket name must be a non-empty string.)r   
ValueError
isinstancestrformatr   r   )r   r	   Zbucket_namer   r   r   r   F   s    z_StorageClient.bucket)N)__name__
__module____qualname____doc__r   classmethodr   r   r   r   r   r   r   7   s
   
r   )NN)
r    Zgoogle.cloudr   ImportErrorZfirebase_adminr   r   ZBucketr   r   r   r   r   r   <module>   s   