
                  
       t   S r SSKJr  SSKJr  SSKJr  SSKrSSKJr  SSK	J
r  SSKJ
r  SSKJ
r  SSKJ
r  SSKJr  SSKJr  SS	KJr  SS
KJr  SR/                  SR1                  \" \R4                   V s/ s H  o R6                  PM     sn 5      5      5      rSqS\S\4S jr S r!S r"SS jr#SS jr$gs  sn f )z5Returns correct API client instance for user command.    )absolute_import)division)unicode_literalsN)errorsclient)storage_url)log)
propertiesz-Invalid provider. Valid provider prefixes: {}z, bucket_namereturnc                 R   U(       a  U [         R                  R                  :w  a  g[        R                  " 5       n UR                  U5      nUR                  S:H  $ ! [        R                   a5  n[        USS5      nUS;   a  [        R                  " SX5         SnAge SnAff = f)z7Returns true if the given bucket is a GCS zonal bucket.Fzonestatus_codeN)i  i  i  z.Failed to get storage layout for bucket %s: %s)r	   ProviderPrefixGCSgcs_json_client
JsonClientget_storage_layoutlocationTypecloud_api_errorsCloudApiErrorgetattrr
   debug)providerr   
api_clientstorage_layouter   s         1lib/googlecloudsdk/api_lib/storage/api_factory.py_is_gcs_zonal_bucketr    0   s    	K$>$>$B$BB))+*
22;?N&&&00		'	' 

!]D1Ko%	ii
:K 	

s   A B&1*B! B!!B&c                    U [         R                  R                  :X  Gar  U(       a(  [        R                  " S5        SSKJn  UR                  $ [        R                  R                  R                  R                  5       (       dX  [        R                  R                  R                  R                  5       [        R                  R                   R"                  :X  a&  [        R                  " S5        [$        R&                  $ [        R                  R                  R(                  R                  5       (       aG  [        R                  R                  R*                  R                  5       (       a  [,        R.                  $ [0        R2                  $ U [         R                  R4                  :X  a  [6        R8                  $ [:        R<                  " [>        5      e)aM  Returns a CloudApi subclass corresponding to the requested provider.

Args:
  provider (storage_url.ProviderPrefix): Cloud provider prefix.
  is_zonal_bucket (bool): Whether the bucket is a zonal bucket.

Returns:
  An appropriate CloudApi subclass.

Raises:
  Error: If provider is not a cloud scheme in storage_url.ProviderPrefix.
z2Using gRPC Bidi Streaming client for zonal bucket.r   r   z%Using gRPC client with JSON Fallback.) r	   r   r   r
   r   6googlecloudsdk.api_lib.storage.gcs_grpc_bidi_streamingr   GcsGrpcBidiStreamingClientr   VALUESstorageuse_grpc_if_availableGetBoolpreferred_apiGetStoragePreferredApiGRPC_WITH_JSON_FALLBACKvaluegcs_grpc_clientGrpcClientWithJsonFallbackgs_xml_access_key_idgs_xml_secret_access_keygcs_xml_client	XmlClientr   r   S3s3_xml_clientS3XmlClientr   Error _INVALID_PROVIDER_PREFIX_MESSAGE)r   is_zonal_bucketgrpc_bidi_streaming_clients      r   _get_api_classr:   E   s8    ++///	iiDEm'BBB   66>>@@!!//335))AAGG	H 
ii78777!!66::<<%%>>BBDD%%%%%%;--000$$$
,,7
88    c                 H    U(       a  U R                    S3$ U R                    $ )zGReturns the thread local storage key for the given provider and bucket._zonal)r,   )r   r8   s     r   _get_thread_local_storage_keyr>   r   s$    nnV$$NNr;   c                    [        X5      n[        R                  R                  R                  R                  5       (       aC  [        (       d  [        R                  " 5       q[        [        [        X5      S5      nU(       a  U$ [        X5      nU" 5       n[        R                  R                  R                  R                  5       (       a  [        [        [        X5      U5        U$ )a-  Returns thread local API instance based on provider and bucket(if available).

Uses thread local storage to make sure only one instance of an API exists
per thread per provider + bucket type.

Args:
  provider (storage_url.ProviderPrefix): Cloud provider prefix.
  bucket_name (str): Name of the bucket. If available, the API client will be
    chosen based on the bucket type as well. Currently only supported for GCS.

Returns:
  CloudApi client object for the arguments.

Raises:
  Error: If provider is not a cloud scheme in storage_url.ProviderPrefix.
N)r    r   r$   r%   use_threading_localr'   _cloud_api_thread_local_storage	threadinglocalr   r>   r:   setattr)r   r   r8   r   	api_classs        r   get_apirF   y   s    . )?/22::<<**(1(9%'%h@J
 X7){*22::<<'%h@ 
r;   c                 D    [        U [        X5      5      nUR                  $ )a  Gets the capabilities of a cloud provider.

Args:
  provider (storage_url.ProviderPrefix): Cloud provider prefix.
  bucket_name (str): Name of the bucket. If available, the API client will be
    chosen based on the bucket type as well. Currently only supported for GCS.

Returns:
  The CloudApi.capabilities attribute for the requested provider.

Raises:
  Error: If provider is not a cloud scheme in storage_url.ProviderPrefix.
)r:   r    capabilities)r   r   rE   s      r   get_capabilitiesrI      s'     $X;) 
		r;   )N)%__doc__
__future__r   r   r   rB   googlecloudsdk.api_lib.storager   r   'googlecloudsdk.api_lib.storage.gcs_grpcr   r-   'googlecloudsdk.api_lib.storage.gcs_jsonr   &googlecloudsdk.api_lib.storage.gcs_xmlr1   %googlecloudsdk.api_lib.storage.s3_xmlr4   "googlecloudsdk.command_lib.storager	   googlecloudsdk.corer
   r   formatjoinsortedVALID_CLOUD_SCHEMESr,   r7   rA   strboolr    r:   r>   rF   rI   )schemes   0r   <module>rZ      s    < '  '  E M M K I 5 : # * 4::		{/N/NO/NVLL/NOP	
 ! #' 
 
 
**9Z/d K Ps   5B5