
    5                       d Z ddlmZ ddlmZ ddlmZ ddlZddlZddlZddlZddl	m
Z ddl	mZ ddl	mZ dd	lmZ dd
lmZ ddlmZ ddlmZ ddlmZ ddlmZ ddlmZ ddlmZ ddlmZ ddlmZ ddlmZ ddlm Z  dd
lmZ! ddlm"Z" ddlm#Z# ddlm$Z$ ddlm%Z% ddlm&Z& ddlm'Z' ddl(m)Z) ddl(m*Z* ddl+m,Z, ddl+m-Z- ddl.m
Z/ ddl.m0Z0 dd l.m1Z1 dd!l.m2Z2 dd"l3m4Z4 dd#l5m6Z6 ddl7Z7dd$l8m9Z9  ejt                          d%Z;d&e;z  Z<ejz                  j|                  d'ejz                  j~                  d(iZ@d) ZAd* ZB G d+ d,e2j                        ZDd- ZEd. ZF G d/ d0ej                        ZH G d1 d2ej                        ZJy)3zClient for interacting with Google Cloud Storage.

Implements CloudApi for the GCS JSON API. Example functions include listing
buckets, uploading objects, and setting lifecycle conditions.
    )absolute_import)division)unicode_literalsN)
exceptions)
list_pager)transfer)	cloud_api)errors)gcs_iam_util)headers_util)download)
error_util)metadata_util)patch_apitools_messages)upload)apis)waiter)encryption_util)	gzip_util)operations_util)
posix_util)storage_url)tracker_file_util)user_request_args_factory)gcs_resource_reference)resource_reference)	copy_util)download_util)log)
properties)requests)
transports)scaled_integer)urllibi   i   JSON_API_V1NONEc           
         t         j                  j                  j                  j	                         }|r|j                  dd      }nt        j                  d      }dj                  |t         j                  j                  j                  j	                         | j                  t        j                  j                  | j                  j                  d      d            }| j                   r|dj                  | j                         z   S |S )	zGGenerates link https://cloud.google.com/storage/docs/request-endpoints.zstorage/v1/ zhttps://storage.googleapis.com/z){}download/storage/{}/b/{}/o/{}?alt=mediazutf-8   ~)safez&generation={})r    VALUESapi_endpoint_overridesstorageGetreplace	core_apisUniversifyAddressformatjson_api_versionbucketr$   parsequotenameencode
generation)object_resourcecustom_endpointbase
url_strings       5lib/googlecloudsdk/api_lib/storage/gcs_json/client.py_get_download_linkr?   Q   s    %%<<DDHHJ/""="5D&&'HID:AA
00446 ll--44W=DI* (//0J0JKKK	    c                     | j                   r| j                   j                  }nt        |       }d|| j                  |d}t	        j
                  |      S )a  Generates download serialization data for Apitools.

  Args:
    object_resource (resource_reference.ObjectResource): Used to get metadata.
    progress (int): Represents how much of download is complete.

  Returns:
    JSON string for use with Apitools.
  F)auto_transferprogress
total_sizeurl)metadata	mediaLinkr?   sizejsondumps)r:   rC   download_linkserialization_dicts       r>   get_download_serialization_datarM   f   sT     #,,66M&7M#((	 
&	''r@   c                   8     e Zd ZdZ fdZ	 	 	 	 ddZd Z xZS )_StorageStreamResponseHandlerzBHandler for writing the streaming response to the download stream.c                 F   t         t        |   d       d| _        i | _        d| _        d| _        d| _        t        j                  t        j                  j                  j                  j                               | _        t!        t"        | j                        | _        y)z4Initializes response handler for requests downloads.T)
use_streamN)r   )superrO   __init___stream
_digesters_processed_bytes_progress_callback_sizer#   ParseIntegerr    r+   r-   download_chunk_sizer.   _chunk_sizemax#MINIMUM_PROGRESS_CALLBACK_THRESHOLD_progress_callback_thresholdself	__class__s    r>   rS   z&_StorageStreamResponseHandler.__init__   s    	
'747HDLDOD"DDJ%22!!5599;=D ),,O,0,<,<)>D%r@   c                     || _         || _        ||ni | _        || _        || _        || _        | j                  | _        y)a  Updates the stream handler with destination information.

    The download_http_client object is stored on the gcs_api object. This allows
    resusing the same http_client when the gcs_api is cached using
    threading.local, which improves performance.
    Since this same object gets used for multiple downloads, we need to update
    the stream handler with the current active download's destination.

    Args:
      stream (stream): Local stream to write downloaded data to.
      size (int): The amount of data in bytes to be downloaded.
      digesters (dict<HashAlgorithm, hashlib object> | None): For updating hash
        digests of downloaded objects on the fly.
      download_strategy (DownloadStrategy): Indicates if user wants to retry
        download on failures.
      processed_bytes (int): For keeping track of how much progress has been
        made.
      progress_callback (func<int>): Accepts processed_bytes and submits
        progress info for aggregation.
    N)rT   rX   rU   _download_strategyrV   rW   _start_byte)r`   streamrH   	digestersdownload_strategyprocessed_bytesprogress_callbacks          r>   update_destination_infoz5_StorageStreamResponseHandler.update_destination_info   sF    6 DLDJ#,#8ibDO/D+D/D,,Dr@   c                 "   | j                   t        j                  d      d}d}	 |j                  | j                        }|r	 | j                   j                  |       | j                  j!                         D ]  }|j#                  |        | xj$                  t'        |      z  c_        |t'        |      z  }| j(                  rd|| j*                  k\  rU| j)                  | j$                         || j*                  z
  }n*| j(                  r|r| j)                  | j$                         n| j$                  | j,                  z
  }| j.                  |k7  rI|sFdj1                  | j.                  |      }t        j2                  |       t5        j6                  |      y y # t        $ re}|j                  t        j                  k(  rB| j                  t        j                  j                  u rt        j                  d       d}Y d }~ڂ d }~ww xY w)NzStream was not found.Fr   Tz4Writing to download stream raised broken pipe error.z:Download not completed. Target size={}, downloaded data={})rT   command_errorsErrorreadr[   writeOSErrorerrnoEPIPErc   r	   DownloadStrategyONE_SHOTr   inforU   valuesupdaterV   lenrW   r^   rd   rX   r2   debugcloud_errorsRetryableApiError)	r`   source_streamdestination_pipe_is_broken"bytes_since_last_progress_callbackdataehash_objecttotal_downloaded_datamessages	            r>   handlez$_StorageStreamResponseHandler.handle   s   ||  !899 "')*&
 0 01d		
,,

T
"  ??113K


T
" 4 	T**c$i7*##(J--).

!
!$"7"7
80//0 - ""'I

!
!$"7"7
89 < !11D4D4DDzz**3M G
M
Mjj/1  
ii**733 4N*5  	gg$%%)C)C)L)LLHHKL)-&
	s   F   	H)AH	H		H)NNr   N)__name__
__module____qualname____doc__rS   rj   r   __classcell__ra   s   @r>   rO   rO   }   s$    J>& )-04./04"-H.4r@   rO   c                     | rT| t         j                  k7  rA| j                  t        j                  j
                  k(  rd| j                  | j                  dS i S )NAES256)zx-goog-encryption-algorithmzx-goog-encryption-keyzx-goog-encryption-key-sha256)r   CLEARtyper   KeyTypeCSEKkeysha256)r   s    r>   _get_encryption_headersr      sM    	c.444	hh/))...'/!$(+

 
 
)r@   c                 <   t         j                  j                  j                  j	                         }| j
                  j                  j                  d      }|y |j                  j                  d|      |_        |j                  j                  d|      |_
        y )NInsertv1)r    r+   r-   r3   r.   objects_upload_configsgetsimple_pathr/   resumable_path)clientapi_versioninsert_configs      r>   )_update_api_version_for_uploads_if_neededr      s    !!))::>>@+..0044X>-
+77??
K-!.!=!=!E!E
K"-r@   c                   <    e Zd ZdZ ej
                  dd      Zd Zy)CloudStorageLroPollerzPoller for Storage LROs.r-   r   c                 V   	 t        j                  |j                        \  }}| j                  j                  ||      }| j                  j                  |      S # t        j                  $ r9 t        j                  d       t        j                  d|j                   d      w xY w)z
Overrides.zWe could not wait for the operation to complete because the required data was incorrect. The operation may still have completed in the background. Please check if the operation has completed before retrying.z3Invalid operation data initiated for this command: z=. Please check if command completed in the background before r4   operationId)r   %get_operation_bucket_and_id_from_namer7   rl   rm   r   warningrz   GcsApiError	_MESSAGES"StorageBucketsOperationsGetRequestoperation_servicer.   )r`   operation_refr4   operation_idrequests        r>   PollzCloudStorageLroPoller.Poll  s    

?
?   fl$ nn??< @ G !!%%g..!  	kk $$  ! "   s   "A AB(N)r   r   r   r   r0   GetMessagesModuler   r    r@   r>   r   r      s     )i)))T:)/r@   r   c                   P    e Zd ZdZej
                  j                  ej
                  j                  ej
                  j                  ej
                  j                  ej
                  j                  ej
                  j                  ej
                  j                  ej
                  j                  hZdZ fdZej$                  d        Zd Zd Zd Zd Z ej2                         d	        Z ej2                         d
        Z ej2                         d        Z ej2                         d        Z ej2                         d        Z ej2                         d        Z ej2                         d        Z  ej2                         ejB                  jD                  fd       Z# ej2                         d        Z$ ej2                         dejB                  jD                  dfd       Z% ej2                         d        Z&ejB                  jD                  ddfdZ' ej2                         	 	 dEd       Z( ej2                         d        Z) ej2                         ejB                  jD                  fd       Z* ej2                         d        Z+ ej2                         d        Z, ej2                         d        Z- ej2                         d        Z.ddejB                  j^                  fdZ0 ej2                         d        Z1 ej2                         	 	 dFd        Z2 ej2                         	 	 	 dGd!       Z3 ej2                         d"        Z4 ej2                         ddejj                  jl                  dd#dfd$       Z7 ej2                         dHd%       Z8 ej2                         ddejB                  jD                  dfd&       Z9ddejB                  jD                  d'ddejt                  jv                  dfd(Z< ej2                         ejB                  jD                  ddfd)       Z= ej2                         	 dHd*       Z> ej2                         ddddej~                  j                  fd+       ZA ej2                         d,        ZB ej2                         d-        ZC ej2                         d.        ZD ej2                         d/        ZEdHd0ZF ej2                         d1        ZG ej2                         dId2       ZH ej2                         d3        ZI ej2                         d4        ZJdFd5ZK ej2                         d6        ZL ej2                         dFd7       ZM ej2                         dddej                  j                  fd8       ZP ej2                         d9        ZQ ej2                         d:        ZR ej2                         d;        ZS ej2                         dHd<       ZT ej2                         d=        ZU ej2                         d>        ZVdHd?ZW ej2                         d@        ZX ej2                         dA        ZY ej2                         	 	 	 	 	 dJdB       ZZ ej2                         dC        Z[ ej2                         dD        Z\ xZ]S )K
JsonClientz$Client for Google Cloud Storage API.    c                 b   t         t        |           t        j                  dd      | _        t        | j
                         d| j
                  _        t        j                         | j
                  _
        t        j                  dd      | _        t               | _        d | _        d | _        y )Nr-   r   T)rR   r   rS   r0   GetClientInstancer   r   (overwrite_transfer_urls_with_client_baser   get_additional_header_dictadditional_http_headersr   messagesrO   _stream_response_handler_download_http_client_upload_http_clientr_   s    r>   rS   zJsonClient.__init__/  s    	*d$&--i>DK-dkk:;?DKK8//1 	KK' //	4@DM$A$CD!!%D#Dr@   c              #      K   |rI| j                   j                  j                         }| j                   j                  j                  |       d  |r| j                   _        y y wN)r   r   copyrw   )r`   headersold_headerss      r>   !_apitools_request_headers_contextz,JsonClient._apitools_request_headers_context>  sP     KK77<<>k
kk))009	,7dkk) s   A%A'c                 6    | j                  t        |            S r   )r   r   )r`   r   s     r>   _encryption_headers_contextz&JsonClient._encryption_headers_contextG  s    112I#2NOOr@   c                 \   i }t        |j                  dd       }|j                  t        |             t        |j                  dd       }|rP|j                  t
        j                  j                  k(  r)|j                  d|j                  |j                  d       | j                  |      S )Nencryption_keydecryption_keyr   )z'x-goog-copy-source-encryption-algorithmz!x-goog-copy-source-encryption-keyz(x-goog-copy-source-encryption-key-sha256)getattrresource_argsrw   r   r   r   r   r   r   r   r   )r`   request_configadditional_headersr   r   s        r>   ,_encryption_headers_for_rewrite_call_contextz7JsonClient._encryption_headers_for_rewrite_call_contextJ  s    ^99;K!#N5nEF^99;K!#N.--1H1H1M1MM5=/=/A/A6D6K6K! 	
 112DEEr@   c                    	 |t         j                  vrt        j                  d      	 |j
                  }|t         j                  j                  k(  r|j                  S |j                  S # t        $ r t        j                  d      w xY w)a  Generate query projection from fields_scope.

    Args:
      fields_scope (FieldsScope): Used to determine projection to return.
      message_class (object): Apitools message object that contains a projection
        enum.

    Returns:
      projection (ProjectionValueValuesEnum): Determines if ACL properties
          should be returned.

    Raises:
      Error: The fields_scope isn't recognized.
    zInvalid fields_scope.)	r	   FieldsScoperl   rm   	TypeErrorProjectionValueValuesEnumFULLfullnoAcl)r`   fields_scopemessage_classprojection_enums       r>   _get_projectionzJsonClient._get_projectionZ  s    :	Y22	2""#:;; 
3 $==Oy,,111!!!     :  !899:s   'A+ +B
c                 4    |r|j                   j                  S y)zGet source path from source_resource.

    Args:
      source_resource (FileObjectResource|None): Contains the
        source StorageUrl. Can be None if source is pure stream.

    Returns:
      (str|None) Source path.
    N)r   versionless_url_string)r`   source_resources     r>   _get_source_pathzJsonClient._get_source_patht  s     ((???r@   c                    | j                   j                  ||||      }| j                  dt        j                         j
                  i      5  | j                  j                  j                  |      }ddd       |S # 1 sw Y   S xY w)See super class.)r4   zoneadmissionPolicyttlx-goog-gcs-idempotency-tokenN)	r   AnywhereCacher   uuiduuid4hexr   anywhereCachesr   )r`   bucket_namer   admission_policyr   r   	operations          r>   create_anywhere_cachez JsonClient.create_anywhere_cache  s     mm))(	 * G 
	/	/	')9)9:
 ++,,33G<i
 	
    &A??B	c                     | j                   j                  ||      }| j                  j                  j	                  |       yr   r4   anywhereCacheIdN)r   #StorageAnywhereCachesDisableRequestr   r   Disabler`   r   anywhere_cache_idr   s       r>   disable_anywhere_cachez!JsonClient.disable_anywhere_cache  s>     mm??) @ G 	KK&&w/r@   c                     | j                   j                  ||      }t        j                  | j                  j
                  j                  |            S )r   r   )r   StorageAnywhereCachesGetRequestr   )get_anywhere_cache_resource_from_metadatar   r   r.   r   s       r>   get_anywhere_cachezJsonClient.get_anywhere_cache  sP     mm;;) < G BB""&&w/ r@   c              #     K   | j                   j                  |t        j                  d      }t	        j
                  | j                  j                  |t        j                  d      }	 |D ]  }t        j                  |        y# t        j                  $ rA}t        j                  t        j                  |t         j"                               Y d}~yd}~ww xY ww)r   N)r4   pageSize	pageTokenr   )
batch_sizebatch_size_attribute)r    StorageAnywhereCachesListRequestr	   NUM_ITEMS_PER_LIST_PAGEr   YieldFromListr   r   r   r   apitools_exceptions	HttpErrorcore_exceptionsreraiserz   translate_errorr   ERROR_TRANSLATION)r`   r   r   anywhere_cache_iteratoranywhere_cacher   s         r>   list_anywhere_cacheszJsonClient.list_anywhere_caches  s      mm<<22 = G )66""44'	3.EE
 	
 4 (( 

&
&q**F*F
G s0   A(C!+B
 	C!
C7CC!CC!c                    | j                   j                  ||||      }| j                  dt        j                         j
                  i      5  | j                  j                  j                  |      }ddd       |S # 1 sw Y   S xY w)r   )r4   r   r   r   r   N)	r   r   r   r   r   r   r   r   Update)r`   r   r   r   r   r   r   s          r>   patch_anywhere_cachezJsonClient.patch_anywhere_cache  s     mm)))(	 * G 
	/	/	')9)9:
 ++,,33G<i
 	
 r   c                     | j                   j                  ||      }| j                  j                  j	                  |       yr   )r   !StorageAnywhereCachesPauseRequestr   r   Pauser   s       r>   pause_anywhere_cachezJsonClient.pause_anywhere_cache  s=     mm==) > G 	KK$$W-r@   c                     | j                   j                  ||      }| j                  j                  j	                  |       yr   )r   "StorageAnywhereCachesResumeRequestr   r   Resumer   s       r>   resume_anywhere_cachez JsonClient.resume_anywhere_cache  s=     mm>>) ? G 	KK%%g.r@   c                    | j                  || j                  j                        }| j                  j                  |j                  j
                        }t        j                  ||       t        |dd      }| j                  j                  |t        |dd      t        j                  j                  j                  j                         |      }| j                  j                  j!                  |      }t        j"                  |      S )r   r7   r   Nenable_per_object_retention)r4   enableObjectRetentionproject
projection)r   r   StorageBucketsInsertRequestBucketr   r   r   *update_bucket_metadata_from_request_configr   r    r+   corer  	GetOrFailr   bucketsr   !get_bucket_resource_from_metadata)	r`   bucket_resourcer   r   r  bucket_metadatar   r   created_bucket_metadatas	            r>   create_bucketzJsonClient.create_bucket  s     %%l&*mm&O&OQJ mm**((44 + 6O<<) NOTBMmm77%8$
 !!&&..88: 8 G #kk1188A::! !r@   c                     | j                   j                  ||j                        }| j                  j                  j                  |       y)r   r4   ifMetagenerationMatchN)r   StorageBucketsDeleteRequest!precondition_metageneration_matchr   r   Delete)r`   r   r   r   s       r>   delete_bucketzJsonClient.delete_bucket  sD     mm77,NN 8 PG
 	KKw'r@   NFc                    | j                  || j                  j                        }| j                  j                  ||||rdnd      }| j                  j                  j                  |      }t        j                  |      S )r   TN)r4   r9   r  softDeleted)r   r   StorageBucketsGetRequestr   r   r.   r   r!  )r`   r   r9   r   soft_deletedr  r   rF   s           r>   
get_bucketzJsonClient.get_bucket  s{     %%dmm<<J mm44(Dd 5 G {{""&&w/H::8DDr@   c                     | j                   j                  d      }| j                  j                  j	                  | j                   j                  |t        j                        |      S )r   bindings,etagfields)r4   optionsRequestedPolicyVersionglobal_params)r   StandardQueryParametersr   r   GetIamPolicy!StorageBucketsGetIamPolicyRequestr   IAM_POLICY_VERSION)r`   r   r8  s      r>   get_bucket_iam_policyz JsonClient.get_bucket_iam_policy-  sl     MM99 : M ;;++77*6*I*I 	8 	
 $ ,  r@   c              #     K   | j                  || j                  j                        }| j                  j                  t        j                  j
                  j                  j                         ||rdnd|      }d}|t        j                  j                  k(  r| j                  j                  d      }t        j                  | j                  j                  |t        j                   |      }	 |D ]  }t#        j$                  |        y# t&        j(                  $ rA}	t+        j,                  t/        j0                  |	t2        j4                               Y d}	~	yd}	~	ww xY ww)r   TN)r  r  r.  prefixzitems/name,nextPageTokenr4  )r   r8  )r   r   StorageBucketsListRequestr    r+   r  r  r  r	   r   SHORTr9  r   r   r   r   r   r   r!  r  r  r  r  rz   r  r   r  )
r`   r   r0  r?  r  r   r8  bucket_iterr4   r   s
             r>   list_bucketszJsonClient.list_buckets;  s0     %%dmm==J mm55!!&&..88:(Dd 6 G My,,222mm;;+ < m **44#	K&==fEE  (( 

&
&q**F*F
G s0   C0E)3D E)E&%7E!E)!E&&E)c                    |&| j                   j                  j                  |      }| j                   j                  |||      }| j                   j                  ||      }| j                  j
                  j                  |      S )See CloudApi class.)dataLocations)destinationLocation destinationCustomPlacementConfigvalidateOnly)r4   relocateBucketRequest)r   RelocateBucketRequest%DestinationCustomPlacementConfigValueStorageBucketsRelocateRequestr   r   Relocate)r`   r   destination_location#destination_custom_placement_configvalidate_onlyr   relocate_requests          r>   relocate_bucketzJsonClient.relocate_bucketa  s     +6,0MM,O,O,u,u; -v -) mm110)L" 2 G
 }}BB' C  ;;''(899r@   c                    |j                   xs |j                  }| j                  j                  |j                  j
                  |      }t        j                  | j                  j                  j                  |            S )Nr'  )r*  metagenerationr   (StorageBucketsLockRetentionPolicyRequestr   r   r   r!  r   r   LockRetentionPolicy)r`   r"  r   metageneration_preconditionr   s        r>   lock_bucket_retention_policyz'JsonClient.lock_bucket_retention_policyx  s{     	88 	*))   mmDD**669 E G :://8 r@   c                    | j                  || j                  j                        }t        |dd      xs t	        j
                  |j                        }t	        j                  ||       t	        j                  |      }|j                  r8|j                  d   t        j                  k(  r|j                  d       g |_	        |j                  r.|j                  t	        j                  |j                               |j                  rF|j                  d       t        | j                  j                  j                   |j                        }nd}|j"                  rF|j                  d       t        | j                  j                  j$                  |j"                        }nd}| j                  j                  |j                  j&                  |||j(                  ||      }	| j*                  j-                  |      5  t	        j.                  | j*                  j0                  j3                  |	            cddd       S # 1 sw Y   yxY w)r   rF   Nr   defaultObjectAclacl)r4   bucketResourcer  r(  predefinedAclpredefinedDefaultObjectAcl)r   r   StorageBucketsPatchRequestr   r   get_apitools_metadata_from_urlr   r  get_cleared_bucket_fieldsr[  PRIVATE_DEFAULT_OBJECT_ACLappendipFilterextendget_cleared_ip_filter_fieldspredefined_acl_stringPredefinedAclValueValuesEnum$predefined_default_object_acl_string)PredefinedDefaultObjectAclValueValuesEnumr   r*  r   IncludeFieldsr!  r   Patch)
r`   r"  r   r   r  rF   cleared_fieldspredefined_aclpredefined_default_object_aclapitools_requests
             r>   patch_bucketzJsonClient.patch_bucket  s    %%dmm>>J 
D9 44''	
 
 <<. #<<^LN!!%%a(334 ./"$h 

4
4X5F5F
G
 ++E"
--
2
2
O
O

.
.0n n::./&-
--
2
244

=
='?#
 '+#}}??**66,NN$#@ @ B 
	"	">	2<<
++


#
#$4
57 
3	2	2s    8IIc                     | j                   j                  j                  | j                  j	                  ||            S )r   )r4   policy)r   r   SetIamPolicyr   !StorageBucketsSetIamPolicyRequest)r`   r   rt  s      r>   set_bucket_iam_policyz JsonClient.set_bucket_iam_policy  s=     ;;++77v 	8 	/0 0r@   c                    | j                   j                  t        j                  j                  j
                  j                         |      }t        j                  | j                  j                  j                  |            S )r   )	projectIdserviceAccountEmail)r   $StorageProjectsHmacKeysCreateRequestr    r+   r  r  r  r   GcsHmacKeyResourcer   projects_hmacKeysCreate)r`   service_account_emailr   s      r>   create_hmac_keyzJsonClient.create_hmac_key  sl     mm@@##((00::<1 A 3G "44%%,,W57 7r@   c                     | j                   j                  t        j                  j                  j
                  j                         |      }| j                  j                  j                  |       y)r   ry  accessIdN)
r   $StorageProjectsHmacKeysDeleteRequestr    r+   r  r  r  r   r}  r+  )r`   	access_idr   s      r>   delete_hmac_keyzJsonClient.delete_hmac_key  sY     mm@@##((00::< A G 	KK!!((1r@   c                    | j                   j                  t        j                  j                  j
                  j                         |      }| j                  j                  j                  |      }t        j                  |      S )r   r  )r   !StorageProjectsHmacKeysGetRequestr    r+   r  r  r  r   r}  r.   r   r|  )r`   r  r   responses       r>   get_hmac_keyzJsonClient.get_hmac_key  sk     mm==##((00::< > G {{,,009H!44X>>r@   c              #     K   |t         j                  j                  k(  rt        j                  d      |t         j                  j
                  k(  rd}n| j                  j                  d      }| j                  j                  ||t        j                  j                  j                  j                               }t        j                  || j                   j"                  |t         j$                        }	 |D ]  }t'        j(                  |        y# t*        j,                  $ rA}t/        j0                  t3        j4                  |t6        j8                               Y d}~yd}~ww xY ww)r   zHMAC keys do not have ACLs.Nz7items(accessId,state,serviceAccountEmail),nextPageTokenr4  )rz  showDeletedKeysry  )r8  servicer   r   )r	   r   NO_ACLrl   rm   r   r   r9  "StorageProjectsHmacKeysListRequestr    r+   r  r  r  r   r   r   r}  r   r   r|  r  r  r  r  rz   r  r   r  )	r`   r  show_deleted_keysr   r8  r   	hmac_iterhmac_keyr   s	            r>   list_hmac_keyszJsonClient.list_hmac_keys  s8     y,,333  
') )y,,111mmm;;J < Lm mm>>1)##((00::< ? G ((#--44	II($77AA  (( I

&
&q**F*F
GI IIs0   C8E1;D E1E.-7E)$E1)E..E1c                 l   | j                   j                  |j                        }|r||_        | j                   j	                  t
        j                  j                  j                  j                         ||      }t        j                  | j                  j                  j                  |            S )r   )state)ry  hmacKeyMetadatar  )r   HmacKeyMetadatavalueetag$StorageProjectsHmacKeysUpdateRequestr    r+   r  r  r  r   r|  r   r}  r  )r`   r  r  r  updated_metadatar   s         r>   patch_hmac_keyzJsonClient.patch_hmac_key  s     }}445;;4G"mm@@##((00::<( A G "44%%,,W57 7r@   c                 z   |st        j                  d      t        |      | j                  kD  r8t        j                  dj	                  t        |      | j                              g }|D ]  }| j
                  j                  j                  |j                  j                        }|j                  j                  &t        |j                  j                        }	|	|_
        |j                  |        t        j                  |j                        }
t        |d   dd      r?t        j                   |d   j"                  |
|t        j$                  j&                        }n|
}t        j(                  ||||t        j$                  j&                         | j
                  j                  ||	      }| j
                  j+                  ||j                  j,                  |j                  j                  |j.                  |j0                  
      }|j2                  rc|j2                  j4                  }|rK|t6        j8                  k7  r8|j:                  t<        j>                  j@                  k(  r|jB                  |_"        |jF                  9t        | j
                  j*                  jH                  |jF                        |_%        t        |j2                  dd      }| jM                  |      5  t        jN                  | jP                  jR                  jU                  |            cddd       S # 1 sw Y   yxY w),See CloudApi class for function doc strings.z/Compose requires at least one component object.z4Compose was called with {} objects. The limit is {}.r  Nr   rF   )method_type)attributes_resourceposix_to_setr  )sourceObjectsdestination)composeRequestdestinationBucketdestinationObjectifGenerationMatchr(  r   )+rz   r   rx   MAX_OBJECTS_PER_COMPOSE_CALLr2   r   ComposeRequestSourceObjectsValueListEntryr   resource_namer9   intrd  r   ra  r   copy_object_metadatarF   
MethodTypeOBJECT_COMPOSE*update_object_metadata_from_request_configStorageObjectsComposeRequestr   precondition_generation_matchr*  r   r   r   r   r   r   r   CMEKr   
kmsKeyNamerh  'DestinationPredefinedAclValueValuesEnumdestinationPredefinedAclr   !get_object_resource_from_metadatar   r   Compose)r`   source_resourcesdestination_resourcer   original_source_resourcer  source_messagessourcesource_messager9   base_destination_metadatafinal_destination_metadatacompose_request_payloadcompose_requestr   s                  r>   compose_objectszJsonClient.compose_objects  s    $$
;= = t@@@$$
@
G
G"#T%F%FHI I O"}}33OO!!// P 1n				&	&	2++667
$.!^, # !. L L((!*"J5#0#E#E
1

&
&(A
m&>&>&M&M$O  $= <<"4!!,,;; #mm::%3M ; O mm@@..::FF.::HH(FF,NN A PO ##%33BBn

5;;
;


!8!8!=!=
=%3%7%7"++718
--
4
422

.
.20o.
 ^99;K!#N		)	).	9<<
++


%
%o
68 
:	9	9s   /8L11L:c                    t        |dd      }|st        j                  |j                        }|j                  r#t        j
                  |j                  |||      }t        j                  |||t        j                  j                         |j                  r5t        | j                  j                  j                  |j                        }nd}|j                  d}	nt        |j                        }	t        j                   |j                  t        j"                  j$                  |j                        }
t        j&                  ||||      }t        j(                  |
|      }|rt+        j,                  d       nt+        j,                  d       t/        j0                  t2        j4                  j6                  j8                  j;                               }| j=                  |      5  	 | j                  j                  |j                  j>                  |j                  j@                  |j                  j>                  |j                  j@                  ||	tC        jD                  |      |jF                  |||	      }t        |jH                  d
d      }|rK|tJ        jL                  k7  r8|jN                  tP        jR                  jT                  k(  r|jV                  |_,        | jZ                  j\                  j_                  |      }|j`                  }|r ||       |jb                  rn|s|jd                  }|jf                  t/        j0                  t2        j4                  j6                  jh                  j;                               k\  r!t        jj                  |
||jd                         	 ddd       t        jl                  |
       t        jn                  jp                        S # 1 sw Y   =xY w)r   rF   N)should_deep_copyr  r  )
source_url)r   z#Found rewrite token. Resuming copy.z3No rewrite token found. Starting copy from scratch.)sourceBucketsourceObjectr  r  objectsourceGenerationr  r(  r  rewriteTokenmaxBytesRewrittenPerCallr   )9r   r   ra  r   rF   r  r  r  OBJECT_REWRITErh  r   StorageObjectsRewriteRequestr  r9   r  r   get_tracker_file_pathTrackerFileTypeREWRITE,hash_gcs_rewrite_parameters_for_tracker_file#get_rewrite_token_from_tracker_filer   ry   r#   rY   r    r+   r-   copy_chunk_sizer.   r   r   r  r   get_generation_match_valuer*  r   r   r   r   r   r   r  r   destinationKmsKeyNamer   r   RewritetotalBytesRewrittendoner  rH   resumable_thresholdwrite_rewrite_tracker_filedelete_tracker_filer  resource)r`   r   r  r   r  ri   should_deep_copy_metadatadestination_metadataro  source_generationtracker_file_pathrewrite_parameters_hashresume_rewrite_tokenmax_bytes_per_callr   r   rewrite_responserh   s                     r>   copy_objectzJsonClient.copy_objectb  sr    ##7TJ*II

*
*,*??

"
"

4	6
 <<!!,,;;	 ++
--
4
422

.
.0n
 n!!)o889)??(())11"..0
 	FF  )		
  	==6	8  	ii56	iiEF'44!!115579		:	:>	J--<<(44@@(44BB2>>JJ2>>LL'.'BB "0..%3-%7 = 9 !((*:DB7===?#:#:#?#??
 +9*<*<'
';;..66w?*>>
O
,  
#!1!>!>
!!^%@%@'';;??A&C C88!#: --/O B E 
KX ))*;<::!!# #[ 
K	Js   ,GO--O6c                 &   |j                   t        |j                         }nd}| j                  j                  |j                  |j
                  ||j                  |j                        }| j                  j                  j                  |       y)r   N)r4   r  r9   r  r(  )r9   r  r   StorageObjectsDeleteRequestr   r  r  r*  r   r   r+  )r`   
object_urlr   r9   r   s        r>   delete_objectzJsonClient.delete_object  s     (z,,-jjmm77%%''(FF,NN 8 PG 	KKw'r@   r   c
                 B   t        j                  ||      ryt        ||      }
t        j                  j                  ||
t        j                  j                  j                  j                         | j                        }|	|j                  dz
  }n|	}| j                  j                  |||z
  dz   ||||       | j                  &t!        j"                  d| j                        | _        | j                  |_        | j                  j&                  }|rd|d<   t)        |j*                  dd      }|j-                  t/        |             |t0        j2                  j4                  k(  rt7        j8                  |||	|	      }|S t7        j:                  ||||	|	      }|S )
r   N)num_retriesr      )re   rH   rf   rg   rh   ri   )response_encodingresponse_handlergzipzaccept-encodingr   )
start_byteend_byter   )r   (return_and_report_if_nothing_to_downloadrM   apitools_transferDownloadFromDatar    r+   r-   max_retriesGetIntr   rH   r   rj   r   r"   GetApitoolsTransport
bytes_httpr   r   r   rw   r   r	   rs   rt   r   launchlaunch_retriable)r`   cloud_resourcedownload_streamr   rf   do_not_decompressrg   ri   r  r  serialization_dataapitools_downloadcalculated_end_byter   r   server_reported_encodings                   r>   download_objectzJsonClient.download_object  s    ==) 8
$)22;;%%--99@@B{{	 <  *//!3$!!99 :-1+"+ :  !!)#-#B#B 88$:d  $(#=#= <<.4*+^99;K!#N5nEFI66???!)
/	"1 $# "*!:!:

/"1 $#r@   c                     |rt        |      }| j                  j                  d      }| j                  j                  j                  | j                  j                  |||      |      S )r   r3  r4  )r4   r  r9   r7  )r  r   r9  r   r   r:  !StorageObjectsGetIamPolicyRequest)r`   r   object_namer9   r8  s        r>   get_object_iam_policyz JsonClient.get_object_iam_policy+  sp     z?jMM99 :  M;;++77{z 	8 	K# , % %r@   c           
         |rt        |      }| j                  || j                  j                        }d}|t        j
                  j                  k(  r| j                  j                  d      }t        t        |dd      dd      }	| j                  |	      5  | j                  j                  j                  | j                  j                  |||||rdnd      |      }
ddd       t        j                  
      S # 1 sw Y   xY w)	r   Nzbucket,name,size,generationr4  r   r   T)r4   r  r9   r  r.  r7  )r  r   r   StorageObjectsGetRequestr	   r   rA  r9  r   r   r   r   r.   r   r  )r`   r   r  r   r9   r   r0  r  r8  r   object_metadatas              r>   get_object_metadatazJsonClient.get_object_metadata8  s     z?j%%l&*mm&L&LNJMy,,222mm;;. < m 68H$PN		)	).	9++//
--
0
0  ##".$D 1  & 0 
o 
: ::?KK 
:	9s   A
C??DTc
              #     K   | j                  || j                  j                        }
d}|t        j                  j
                  k(  r| j                  j                  d      }n|t        j                  j                  k(  ru| j                  j                  dj                  t        j                  t        j                  t        j                  t        j                  t        j                              }d}|t        j                  j                   u rdnd}|t        j                  j"                  u rdnd}	 | j                  j                  |||||
|t        j$                  |||	
      }	 | j&                  j(                  j+                  ||      }|j<                  }|j>                  s5|j@                  s)|r'|r%tC        jD                  dj                  |             y|j>                  D ]   }||_#        tI        jJ                  |       " |j@                  D ]I  }tM        jN                  tQ        jR                  tP        jT                  jV                  ||	      |
       K |sy4# t,        j.                  $ rB}t1        j2                  t5        j6                  |t8        j:                               Y d}~)d}~ww xY ww)r   Nz=prefixes,items/name,items/size,items/generation,nextPageTokenr4  zprefixes,items/name,items/etag,items/size,items/generation,items/storageClass,items/timeCreated,items/metadata/{},items/metadata/{},items/metadata/{},items/metadata/{},items/metadata/{},items/crc32c,items/md5Hash,nextPageToken,items/kmsKeyNameT)
r4   r?  	delimiterversionsr  r   
maxResultsincludeFoldersAsPrefixesr.  filterr7  a  Received empty list response. However, a next page token is available. Rerun with `--exhaustive --next-page-token={}` to pick up where you left off and exhaustively search all objects. Making numerous LIST API calls can be expensive, and additional objects are not guaranteed exist.)schemer   r  )r?  ),r   r   StorageObjectsListRequestr	   r   rA  r9  RSYNCr2   r   ATIME_METADATA_KEYGID_METADATA_KEYMODE_METADATA_KEYMTIME_METADATA_KEYUID_METADATA_KEYObjectStateLIVE_AND_NONCURRENTSOFT_DELETEDr   r   r   Listr  r  r  r  rz   r  r   r  nextPageTokenitemsprefixesr   r   r4   r   r  r   PrefixResourcer   CloudUrlProviderPrefixGCS)r`   r   r?  r  r   halt_on_empty_responseinclude_folders_as_prefixesnext_page_tokenobject_statelist_filterr  r8  list_resultlive_and_noncurrentr0  rq  r   r  prefix_strings                      r>   list_objectszJsonClient.list_objects_  s     %%l&*mm&M&MOJMy,,222mm;;P < m 
..44	4mm;;!
 F++))**++)) < m  K 900DDD 	  	 5 5 B BB  @@&#66#>" A Kkk))..M / 
 $11o  K$8$8$@
 f_%	
 	 )../!,== 	 / '//- //  "1155'+- !" 	" 0 s & !** K((J,H,HI	K 	KKs1   E+K.'I. CK.K7J>8K>KKc                 &   |rt        |      }d}|j                  r4t        | j                  j                  j
                  |j                        }| j                  || j                  j                        }	|j                  xs t        j                  |j                        }
t        j                  |
||t        j                  j                         | j                  j	                  |||
||j                  |j                  |j                   ||		      }| j"                  j%                  t        j&                  |            5  | j"                  j(                  j+                  |      }ddd       t        j,                        S # 1 sw Y   xY w)r   Nr  )	r4   r  objectResourcer9   r  r(  overrideUnlockedRetentionr^  r  )r  rh  r   r   StorageObjectsPatchRequestri  r   rF   r   ra  r   r  r  OBJECT_PATCHr  r*  override_unlocked_retentionr   rl  get_cleared_object_fieldsr   rm  r  )r`   r   r  r:   r   r   r9   r  ro  r  r  r   r  s                r>   patch_object_metadataz JsonClient.patch_object_metadata  sd    z?jN++
--
2
2
O
O

.
.n
 %%dmm>>J &.. 44''	
  <<!!,,99	 mm66&(FF,NN"0"L"L$ 7 
G 
	"	"//?
 ,,227;
 ::;KLL	
 
s   &FFc                     |rt        |      }| j                  j                  j                  | j                  j                  ||||            S )r   )r4   r  r9   rt  )r  r   r   ru  r   !StorageObjectsSetIamPolicyRequest)r`   r   r  rt  r9   s        r>   set_object_iam_policyz JsonClient.set_object_iam_policy  sP     z?j;;++77!	 	8 	 r@   c	                    | j                   t        j                  d      | _         | j                  |      }	t	        j
                  |j                  |	      }
|
r$t        j                  dj                  |	             |t        j                  j                  k(  r(t        j                  | | j                   |||
|||      }n|t        j                  j                  k(  r*t        j                   | | j                   |||
|||||
      }ns|t        j                  j"                  k(  r(t        j$                  | | j                   |||
|||      }n.t'        j(                  dj                  |j*                              t-        |j.                  dd      }	 | j1                  |      5  |j3                         }ddd       tK        jL                        S # 1 sw Y   xY w# t4        j6                  t4        j8                  f$ rc}t;        j<                  d	j                  t?        |      t@        jB                  jD                  jF                  jI                                     d}~ww xY w)
r  NzObject data is not displayed to keep the log output clean. Set log_http_show_request_body property to True to print the body of this request.)redact_request_body_reasonz+Using compressed transport encoding for {}.)r  r   )r  r  r   tracker_callbackzInvalid upload strategy: {}.r   z{}
 This likely occurred because the file being uploaded changed size between resumable upload attempts. If this error persists, try deleting the tracker files present in {})'r   r"   r  r   r   should_gzip_in_flightgzip_settingsr   ru   r2   r	   UploadStrategySIMPLEr   SimpleUpload	RESUMABLEResumableUpload	STREAMINGStreamingUploadrl   rm   r  r   r   r   runr  StreamExhaustedTransferErrorrz   ResumableUploadAbortErrorstrr    r+   r-   tracker_files_directoryr.   r   r  )r`   r|   r  r   r  r   r  r=  upload_strategysource_pathr>  uploaderr   rF   errors                  r>   upload_objectzJsonClient.upload_object  s?    '!+!@!@'")d ''8K%;;$$k3 	hh
7
>
>{
KM)22999$$


"
"



#)	h 
I44>>	>''


"
"



#/)+h 
I44>>	>''


"
"



#)	h   !?!F!F


"! " " ^99;K!#NH++N;<<> < ::8DD <; 	++)) 	H 2255;V%j''??CCE6GH H		Hs1   G! 'G8G! GG! !#I'AI""I'c                     | j                   j                  ||      }| j                  j                  j	                  |      }t        j                  |      S )r  r4   r7   )r   ManagedFolderr   managedFoldersr   r   )get_managed_folder_resource_from_metadata)r`   r   managed_folder_namefolder_messager  s        r>   create_managed_folderz JsonClient.create_managed_folderf  sP     ]]00!4 1 N {{))00@HBB8LLr@   c                     | j                   j                  ||      }| j                  j                  j	                  |       y)r  r4   managedFolderN)r   "StorageManagedFoldersDeleteRequestr   rU  r+  )r`   r   rW  delete_requests       r>   delete_managed_folderz JsonClient.delete_managed_foldero  s>     ]]EE*= F N 	KK%%n5r@   c                     | j                   j                  j                  | j                  j	                  ||            }t        j                  |      S )r  r[  )r   rU  r.   r   StorageManagedFoldersGetRequestr   rV  )r`   r   rW  r  s       r>   get_managed_folderzJsonClient.get_managed_folderw  sN     {{))--55.A 	6 	
H
 BB8LLr@   c                     | j                   j                  d      }| j                  j                  j	                  | j                   j                  ||      |      S )r  r3  r4  r[  r7  )r   r9  r   rU  r:  (StorageManagedFoldersGetIamPolicyRequest)r`   r   rW  r8  s       r>   get_managed_folder_iam_policyz(JsonClient.get_managed_folder_iam_policy  sf     MM99 : M ;;%%22>>.A 	? 	
 $	 3  r@   c              #     K   	 t        j                  | j                  j                  | j                  j                  ||      ddd      D ]  }t        j                  |        y# t        j                  $ rQ}t        j                  t        j                  |t        j                  t        j                                Y d}~yd}~ww xY ww)r  )r4   r?    r   r!  r   r   fieldstatus_code_getterN)r   r   r   rU  r    StorageManagedFoldersListRequestr   rV  r  r  r  r  rz   r  r   r  get_status_code)r`   r   r?  folderr   s        r>   list_managed_folderszJsonClient.list_managed_folders  s     ,,
++
$
$
--
8
8  9  )	& EEfMM	 (( 

&
&**!+!;!; s0   CA%A* )C*C=AC	C	CCc                     | j                   j                  j                  | j                  j	                  |||            S )r  )r4   r\  rt  )r   rU  ru  r   (StorageManagedFoldersSetIamPolicyRequest)r`   r   rW  rt  s       r>   set_managed_folder_iam_policyz(JsonClient.set_managed_folder_iam_policy  s@    
 ;;%%22>>.A& 	? 	
 r@   c                     | j                   j                  ||      }| j                   j                  |||      }| j                  j                  j                  |      }t        j                  |      S )r  rS  )r4   rn  	recursive)r   FolderStorageFoldersInsertRequestr   foldersr   r   !get_folder_resource_from_metadata)r`   r   folder_nameis_recursivern  insert_folder_request_messager  s          r>   create_folderzJsonClient.create_folder  sm     ]]!!;!GF$(MM$M$M6\ %N %! {{""))*GHH::8DDr@   c                     | j                   j                  ||      }| j                  j                  j	                  |       y)r  r4   rn  N)r   StorageFoldersDeleteRequestr   rw  r+  )r`   r   ry  delete_folder_requests       r>   delete_folderzJsonClient.delete_folder  s?     !MMEE; F  	KK45r@   c                     | j                   j                  j                  | j                  j	                  ||            }t        j                  |      S )r  r~  )r   rw  r.   r   StorageFoldersGetRequestr   rx  )r`   r   ry  r  s       r>   
get_folderzJsonClient.get_folder  sM     {{""&&..{ 	/ 	
H
 ::8DDr@   c              #     K   	 t        j                  | j                  j                  | j                  j                  |||      ddd      D ]  }t        j                  |        y# t        j                  $ rQ}t        j                  t        j                  |t        j                  t        j                                Y d}~yd}~ww xY ww)r  )r4   r  r?  rg  r   r!  rh  rj  N)r   r   r   rw  r   StorageFoldersListRequestr   rx  r  r  r  r  rz   r  r   r  rm  )r`   r   r  r?  rn  r   s         r>   list_folderszJsonClient.list_folders  s     ,,
++


--
1
1 ! 2 
 )
& ==fEE
 (( 

&
&**!+!;!; s0   CA&A+ *C+C>AC
C
CCc                     | j                   j                  |||      }| j                  j                  j	                  |      S )r  )r4   sourceFolderdestinationFolder)r   StorageFoldersRenameRequestr   rw  Rename)r`   r   source_folder_namedestination_folder_namerename_folder_requests        r>   rename_folderzJsonClient.rename_folder  sF    
 !MMEE'1 F 
 ;;%%&;<<r@   c                 2   |r|}nJ|rt        j                  |      }n2t        j                  j                  j
                  j                         }| j                  j                  j                  | j                  j                  |            j                  S )#See CloudApi class for doc strings.)ry  )six	text_typer    r+   r  r  r  r   projects_serviceAccountr.   r   'StorageProjectsServiceAccountGetRequestemail_address)r`   
project_idproject_numberproject_identifiers       r>   get_service_agentzJsonClient.get_service_agent  s|     %	==8%,,1199CCE;;..22==( 	> 	*++8=9r@   c                    |j                         st        j                  d      | j                  j	                  |t
        |         }|rg }|j                         D ]E  \  }	}
|j                  | j                  j                  j                  j                  |	|
             G | j                  j                  j                  |      |_
        |r|D cg c]  }|j                   c}|_        |r||_        | j                  j                  j!                  | j                  j#                  |j$                  |t&        j(                  j*                  j,                  j/                                     S c c}w )r  zDCreate notification configuration endpoint accepts only bucket URLs.)topicpayload_format)r   r  )additionalPropertiesr4   notificationuserProject)	is_bucketrl   InvalidUrlErrorr   Notification0_NOTIFICATION_PAYLOAD_FORMAT_KEY_TO_API_CONSTANTr!  rd  CustomAttributesValueAdditionalPropertycustom_attributesr  event_typesobject_name_prefixr   notificationsr   !StorageNotificationsInsertRequestr   r    r+   r  r  r  )r`   rE   pubsub_topicr  r  r  r  notification_configurationadditional_propertiesr   r  
event_types               r>   !create_notification_configurationz,JsonClient.create_notification_configuration  sj    ==?**
P  "&!;!;G "< "  )//1*#u$$MM&&<<OOu P &	( 2
 --
$
$
:
:#8 ; : !2 -80-8z*

[0 , 6H 3;;$$++77??3"))..66@@B 	8 	DE E0s   E6c                 D   |j                         st        j                  d      | j                  j                  j                  | j                  j                  |j                  |t        j                  j                  j                  j                                      y)r  zDDelete notification configuration endpoint accepts only bucket URLs.r  N)r  rl   r  r   r  r+  r   !StorageNotificationsDeleteRequestr   r    r+   r  r  r  r`   rE   notification_ids      r>   !delete_notification_configurationz,JsonClient.delete_notification_configuration%  s~     ==?**
P  	KK$$77??("))..66@@B 	8 	DEr@   c                 B   |j                         st        j                  d      | j                  j                  j                  | j                  j                  |j                  |t        j                  j                  j                  j                                     S )r  zAGet notification configuration endpoint accepts only bucket URLs.r  )r  rl   r  r   r  r.   r   StorageNotificationsGetRequestr   r    r+   r  r  r  r  s      r>   get_notification_configurationz)JsonClient.get_notification_configuration2  s     ==?**
M  ;;$$((44??("))..66@@B 	5 	DE Er@   c              #   t  K   |j                         st        j                  d      | j                  j                  j                  | j                  j                  |j                  t        j                  j                  j                  j                                     }|j                  D ]  }|  yw)r  zCList notification configurations endpoint accepts only bucket URLs.)r4   r  N)r  rl   r  r   r  r  r   StorageNotificationsListRequestr   r    r+   r  r  r  r!  )r`   rE   r  r  s       r>    list_notification_configurationsz+JsonClient.list_notification_configurations?  s      ==?**
O  {{((--55??"))..66@@B 	6 	DEH '/nn"&& '5s   B6B8c                     | j                   j                  |t        |      dz   nd      }| j                   j                  |||      }| j                  j
                  j                  |      S )rE  Ns)r   )%advanceRelocateBucketOperationRequestr4   r   )r   %AdvanceRelocateBucketOperationRequestrK  4StorageBucketsOperationsAdvanceRelocateBucketRequestr   
operationsAdvanceRelocateBucket)r`   r   r   r   )advance_relocate_bucket_operation_requestr   s         r>   advance_relocate_bucketz"JsonClient.advance_relocate_bucketN  ss     	;;"%/C3t 	< 	
 .
 mmPP.W  Q G
 ;;!!77@@r@   c                     | j                   j                  j                  | j                  j	                  ||             y)rE  r   N)r   r  Cancelr   %StorageBucketsOperationsCancelRequestr`   r   r   s      r>   cancel_operationzJsonClient.cancel_operation]  s9     	KK!!;;$ 	< 	
r@   c                     | j                   j                  j                  | j                  j	                  ||            S )rE  r   )r   r  r.   r   r   r  s      r>   get_operationzJsonClient.get_operationg  s>     ;;!!%%88$ 	9 	
 r@   c              #   f  K   | j                   j                  ||      }t        j                  | j                  j
                  |dd      }	 |D ]  }|  y# t        j                  $ rA}t        j                  t        j                  |t        j                               Y d}~yd}~ww xY ww)rE  )r4   r  r   r  )r   ri  N)r   #StorageBucketsOperationsListRequestr   r   r   r  r  r  r  r  rz   r  r   r  )r`   r   server_side_filterr   operation_iteratorr   r   s          r>   list_operationszJsonClient.list_operationsq  s     mm??! @ G $11'	)) *(( 

&
&q**F*F
G s0   AB1A B1B.-7B)$B1)B..B1c           
      t   |j                   r|j                   j                  }nd}| j                  j                  j	                  | j
                  j                  |j                  |t        |j                        |j                  |j                  |j                              }t        j                  |      S )rE  N)r4   copySourceAclr9   r  r(  r  )r   preserve_aclr   r   Restorer   StorageObjectsRestoreRequestr   r  r9   r  r*  r  r   r  )r`   rE   r   r  r  s        r>   restore_objectzJsonClient.restore_object  s     ###11>>llkk))1122??&3>>*,JJ@@$$ 	3 		
O ::?KKr@   c                 H   |j                         st        j                  d      |j                  st        j                  d      | j                  j
                  j                  | j                  j                  |j                  t        |j                                    S )rE  z1Restore bucket endpoint accepts only bucket URLs.z.Restore bucket endpoint requires a generation.)r4   r9   )r  rl   r  r9   r   r   r  r   StorageBucketsRestoreRequestr   r  )r`   rE   s     r>   restore_bucketzJsonClient.restore_bucket  s     ==?**
=  >>**
:  ;;&&22??3>>* 	3 	
 r@   c	                    |j                   r|j                   j                  }	nd}	| j                  dt        j                         j
                  i      5  | j                  j                  j                  | j                  j                  |j                  | j                  j                  ||	|||||                  }
ddd       |
S # 1 sw Y   
S xY w)rE  Nr   )allowOverwriter  createdAfterTimecreatedBeforeTime
matchGlobssoftDeletedAfterTimesoftDeletedBeforeTime)r4   bulkRestoreObjectsRequest)r   r  r   r   r   r   r   r   BulkRestorer    StorageObjectsBulkRestoreRequestr   BulkRestoreObjectsRequest)r`   
bucket_urlobject_globsr   allow_overwritecreated_after_timecreated_before_timedeleted_after_timedeleted_before_timer  r   s              r>   bulk_restore_objectszJsonClient.bulk_restore_objects  s     ###11>>ll		/	/	')9)9:
 ++%%11
--
8
8++(,(O(O!0 ,#5$7)'9(; )P ) 9 i
" #
" s   A+C

Cc                     | j                   j                  |      }| j                  j                  j	                  |      S )r  )r4   )r   %StorageBucketsGetStorageLayoutRequestr   r   GetStorageLayout)r`   r   storage_layout_requests      r>   get_storage_layoutzJsonClient.get_storage_layout  s<     	;;;;O  ;;//0FGGr@   c                 p    t        | j                  j                  d       }t        j                  ||      S )r  c                     | j                   S r   r  )refs    r>   <lambda>z/JsonClient.wait_for_operation.<locals>.<lambda>  s    SXXr@   )r   r   r  r   WaitFor)r`   r   pollers      r>   wait_for_operationzJsonClient.wait_for_operation  s1     #!5F >>&-00r@   )NF)NN)NNFr   )F)FNNNN)^r   r   r   r   r	   
CapabilityCOMPOSE_OBJECTS"DAISY_CHAIN_SEEKABLE_UPLOAD_STREAM
ENCRYPTIONMANAGED_FOLDERSFOLDERSSTORAGE_LAYOUTRESUMABLE_UPLOADSLICED_DOWNLOADcapabilitiesr  rS   
contextlibcontextmanagerr   r   r   r   r   r   $catch_http_error_raise_gcs_api_errorr   r   r   r	  r  r  r  r   r  r%  r,  r1  r=  rC  rS  rY  rr  rw  r  r  r  rA  r  r  r  r  r  rs   rC  r  r	  r  r  LIVEr/  r7  r:  r@  rA  rQ  rY  r_  rb  re  ro  rr  r|  r  r  r  r  r  NotificationPayloadFormatJSONr  r  r  r  r  r  r  r  r  r  r  r  r  r   r   s   @r>   r   r     ss   , **==%%**""))++**	, "$$ 8 8PF !4 3:224 5 3:224
0 5
0 3:224 5 3:224 56 3:224 5( 3:224. 5. 3:224/ 5/ 3:224 "+!6!6!=!=! 5!4 3:224( 5( 3:224 ((//E 5E, 3:224 5 ((//	$L 3:224
 +/: 5:, 3:224 5 3:224
 ((//	?7 5?7B 3:2240 50 3:2247 57 3:2242 52 3:224? 5? 26"+"7"7"="=IB 3:224
7 5
7 3:224  $G8 5G8R 3:224  %m# 5m#^ 3:224( 5($ 3:224
 !%(-(1(B(B(L(L(,!"#C$ 5C$J 3:224
% 5
% 3:224
 ((//$L 5$LR ((//!"&((--gR 3:224 ((//6M 56Mp 3:224
 (,	 5 3:224 ..55RE 5REh 3:224M 5M 3:2246 56 3:224M 5M 3:224
 5
. 3:224 5 3:224E 5E 3:2246 56 3:224E 5E0 3:224	= 5	= 3:224
9 5
9 3:224
 88==%E 5%EN 3:224
E 5
E 3:224
E 5
E 3:224' 5' 3:224A 5A 3:224 5 3:224 5( 3:224L 5L* 3:224 5& 3:224 " 5"H 3:224H 5H 3:2241 51r@   r   )Kr   
__future__r   r   r   r  rq   rI   r   apitools.base.pyr   r  r   r   r  googlecloudsdk.api_lib.storager	   r
   rz   r   r   'googlecloudsdk.api_lib.storage.gcs_jsonr   r   r   r   r   googlecloudsdk.api_lib.utilr   r0   r   "googlecloudsdk.command_lib.storager   rl   r   r   r   r   r   r   ,googlecloudsdk.command_lib.storage.resourcesr   r   +googlecloudsdk.command_lib.storage.tasks.cpr   r   googlecloudsdk.corer  r   r    r!   googlecloudsdk.core.credentialsr"   googlecloudsdk.core.utilr#   r  	six.movesr$   patchKBr]   r	  r
  r&   r  r?   rM   ResponseHandlerrO   r   r   CloudOperationPollerNoResourcesr   CloudApir   r   r@   r>   <module>r     s%   '  '     > ' : 4 A 7 7 < > A K : 9 . > G 8 > 9 : @ H O K A E = # * ( 6 3 
      
 
&)Bh # '',,m'',,f4 0*(.e4H$<$< e4P	/FBB /BG1## G1r@   