
    U                     P   S r SSKJr  SSKJr  SSKJr  SSKrSSKrSSKJr  SSK	J
r
  Sr " S	 S
\5      r " S S\5      r " S S\5      r " S S\5      r " S S\5      r " S S\5      r " S S\5      r " S S\5      r " S S\5      r " S S\5      r " S S\5      rS rg) z?Classes for cloud/file references yielded by storage iterators.    )absolute_import)division)unicode_literalsN)errors)resource_util_NOT_SUPPORTED_DO_NOT_DISPLAYc                   J    \ rS rSrSrSrS rS rS rS r	S r
\S	 5       rS
rg)Resource   a  Base class for a reference to one fully expanded iterator result.

This allows polymorphic iteration over wildcard-iterated URLs.  The
reference contains a fully expanded URL string containing no wildcards and
referring to exactly one entity (if a wildcard is contained, it is assumed
this is part of the raw string and should never be treated as a wildcard).

Each reference represents a Bucket, Object, or Prefix.  For filesystem URLs,
Objects represent files and Prefixes represent directories.

The metadata_object member contains the underlying object as it was retrieved.
It is populated by the calling iterator, which may only request certain
fields to reduce the number of server requests.

For filesystem and prefix URLs, metadata_object is not populated.

Attributes:
  TYPE_STRING (str): String representing the resource's content type.
  storage_url (StorageUrl): A StorageUrl object representing the resource.
resourcec                     Xl         g)zInitialize the Resource object.

Args:
  storage_url_object (StorageUrl): A StorageUrl object representing the
      resource.
Nstorage_url)selfstorage_url_objects     Flib/googlecloudsdk/command_lib/storage/resources/resource_reference.py__init__Resource.__init__6   s
     *    c                     [         R                  " [        R                  " SU R                  R
                  4SU R                  4/5      5      $ )z&Formats resource for printing as JSON.urltype)r   configured_json_dumpscollectionsOrderedDictr   
url_stringTYPE_STRINGr   s    r   get_json_dumpResource.get_json_dump?   sJ    ..D$$//0T%%&!
 	 r   c                 .    U R                   R                  $ N)r   r   r   s    r   __repr__Resource.__repr__G   s     &&&r   c                 l    [        XR                  5      =(       a    U R                  UR                  :H  $ r"   )
isinstance	__class__r   )r   others     r   __eq__Resource.__eq__M   s,    5..) 	.E---r   c                     [        S5      e)Nz is_container must be overridden.NotImplementedErrorr   s    r   is_containerResource.is_containerS   s    
@
AAr   c                     g)z+Returns whether this resource is a symlink.F r   s    r   
is_symlinkResource.is_symlinkV   s     r   r   N)__name__
__module____qualname____firstlineno____doc__r   r   r   r#   r)   r.   propertyr2   __static_attributes__r1   r   r   r
   r
      s<    ( +*'B  r   r
   c                   2    \ rS rSrSrSr\S 5       rS rSr	g)CloudResource\   a)  For Resource classes with CloudUrl's.

Attributes:
  TYPE_STRING (str): String representing the resource's content type.
  scheme (storage_url.ProviderPrefix): Prefix indicating what cloud provider
      hosts the bucket.
  storage_url (StorageUrl): A StorageUrl object representing the resource.
cloud_resourcec                 .    U R                   R                  $ r"   )r   schemer   s    r   r@   CloudResource.schemeg   s    """r   c                     0 $ )a=  Returns provider specific formatting for the acl fields.

Provider specific resource classses can override this method to return
provider specific formatting for acl fields. If not overriden, acl values
are displayed as-is if present.

Returns:
  Dictionary with acl fields as key and corresponding formatted values.
r1   r   s    r   get_formatted_aclCloudResource.get_formatted_aclk   s	     Ir   r1   N)
r4   r5   r6   r7   r8   r   r9   r@   rC   r:   r1   r   r   r<   r<   \   s%     !+# #
r   r<   c                      ^  \ rS rSrSrSr                 SU 4S jjr\S 5       r\S 5       r	\S 5       r
U 4S jrS	 rS
rU =r$ )BucketResourcex   a
  Class representing a bucket.

Warning: After being run through through output formatter utils (e.g. in
`shim_format_util.py`), these fields may all be strings.

Attributes:
  TYPE_STRING (str): String representing the resource's content type.
  storage_url (StorageUrl): A StorageUrl object representing the bucket.
  name (str): Name of bucket.
  scheme (storage_url.ProviderPrefix): Prefix indicating what cloud provider
    hosts the bucket.
  acl (dict|CloudApiError|None): ACLs dict or predefined-ACL string for the
    bucket. If the API call to fetch the data failed, this can be an error
    string.
  cors_config (dict|CloudApiError|None): CORS configuration for the bucket.
    If the API call to fetch the data failed, this can be an error string.
  creation_time (datetime|None): Bucket's creation time in UTC.
  default_event_based_hold (bool|None): Prevents objects in bucket from being
    deleted. Currently GCS-only but needed for generic copy logic.
  default_storage_class (str|None): Default storage class for objects in
    bucket.
  etag (str|None): HTTP version identifier.
  labels (dict|None): Labels for the bucket.
  lifecycle_config (dict|CloudApiError|None): Lifecycle configuration for
    bucket. If the API call to fetch the data failed, this can be an error
    string.
  location (str|None): Represents region bucket was created in.
    If the API call to fetch the data failed, this can be an error string.
  logging_config (dict|CloudApiError|None): Logging configuration for bucket.
    If the API call to fetch the data failed, this can be an error string.
  metadata (object|dict|None): Cloud-provider specific data type for holding
    bucket metadata.
  metageneration (int|None): The generation of the bucket's metadata.
  requester_pays (bool|CloudApiError|None): "Requester pays" status of bucket.
    If the API call to fetch the data failed, this can be an error string.
  retention_period (int|None): Default time to hold items in bucket before
    before deleting in seconds. Generated from retention_policy.
  retention_policy (dict|None): Info about object retention within bucket.
  retention_policy_is_locked (bool|None): True if a retention policy is
    locked.
  update_time (str|None): Bucket's update time.
  versioning_enabled (bool|CloudApiError|None): Whether past object versions
    are saved. If the API call to fetch the data failed, this can be an error
    string.
  website_config (dict|CloudApiError|None): Website configuration for bucket.
    If the API call to fetch the data failed, this can be an error string.
cloud_bucketc                    > [         [        U ]  U5        X l        X0l        X@l        XPl        X`l        Xpl        Xl	        Xl
        Xl        Xl        Xl        Xl        Xl        Xl        UU l        UU l        UU l        g6Initializes resource. Args are a subset of attributes.N)superrF   r   aclcors_configcreation_timedefault_event_based_holddefault_storage_classetaglabelslifecycle_configlocationlogging_configmetadatametagenerationrequester_paysretention_policyupdate_timeversioning_enabledwebsite_config)r   r   rM   rN   rO   rP   rQ   rR   rS   rT   rU   rV   rX   rW   rY   rZ   r[   r\   r]   r'   s                      r   r   BucketResource.__init__   s|    ( 
.$();<H"&$<!!6IK,M(M((,"D0D(Dr   c                 .    U R                   R                  $ r"   r   bucket_namer   s    r   nameBucketResource.name       '''r   c                     g r"   r1   r   s    r   retention_periodBucketResource.retention_period        r   c                     g r"   r1   r   s    r   retention_policy_is_locked)BucketResource.retention_policy_is_locked   rh   r   c                   > [         [        U ]  U5      =(       GaB    U R                  UR                  :H  =(       Ga!    U R                  UR                  :H  =(       Ga     U R
                  UR
                  :H  =(       Ga    U R                  UR                  :H  =(       Ga    U R                  UR                  :H  =(       Ga    U R                  UR                  :H  =(       Ga|    U R                  UR                  :H  =(       Ga[    U R                  UR                  :H  =(       Ga:    U R                  UR                  :H  =(       Ga    U R                  UR                  :H  =(       a    U R                  UR                  :H  =(       a    U R                  UR                  :H  =(       a    U R                  UR                  :H  =(       a    U R                  UR                  :H  =(       ay    U R                   UR                   :H  =(       aY    U R"                  UR"                  :H  =(       a9    U R$                  UR$                  :H  =(       a    U R&                  UR&                  :H  $ r"   )rL   rF   r)   rM   rN   rO   rP   rQ   rR   rU   rS   rT   rV   rW   rX   rY   rZ   r[   r\   r]   r   r(   r'   s     r   r)   BucketResource.__eq__   s   .$.u5 8 8HH		!8 8&*&6&6%:K:K&K8 8%"5"558 8 ))U-K-KK8 8 &&%*E*EE	8 8
 II#8 8
 )-(G8 8 KK5<<'8 8 !!U%;%;;8 8 MMU^^+8 5#7#778 MMU^^+8 5#7#778 5#7#778 !!U%;%;;8  1 118 ##u'?'??8  5#7#77!9r   c                     gNTr1   r   s    r   r.   BucketResource.is_container       r   )rM   rN   rO   rP   rQ   rR   rS   rT   rU   rV   rW   rX   rY   rZ   r[   r\   r]   )NNNNNNNNNNNNNNNNN)r4   r5   r6   r7   r8   r   r   r9   rb   rf   rj   r)   r.   r:   __classcell__r'   s   @r   rF   rF   x   s    .^ + !(,%) $""" $"&"%%)N ( (    9& r   rF   c                      ^  \ rS rSrSrSr                         SU 4S jjr\S 5       r\S 5       r	\S 5       r
\S 5       rU 4S	 jrS
 rS rSrU =r$ )ObjectResource   aO
  Class representing a cloud object confirmed to exist.

Warning: After being run through through output formatter utils (e.g. in
`shim_format_util.py`), these fields may all be strings.

Attributes:
  TYPE_STRING (str): String representing the resource's type.
  storage_url (StorageUrl): A StorageUrl object representing the object.
  scheme (storage_url.ProviderPrefix): Prefix indicating what cloud provider
    hosts the object.
  bucket (str): Bucket that contains the object.
  name (str): Name of object.
  generation (str|None): Generation (or "version") of the underlying object.
  acl (dict|str|None): ACLs dict or predefined-ACL string for the objects. If
    the API call to fetch the data failed, this can be an error string.
  cache_control (str|None): Describes the object's cache settings.
  component_count (int|None): Number of components, if any.
  content_disposition (str|None): Whether the object should be displayed or
    downloaded.
  content_encoding (str|None): Encodings that have been applied to the object.
  content_language (str|None): Language used in the object's content.
  content_type (str|None): A MIME type describing the object's content.
  custom_time (str|None): A timestamp in RFC 3339 format specified by the user
    for an object. Currently, GCS-only, but not in provider-specific class
    because generic daisy chain logic uses the field.
  crc32c_hash (str|None): Base64-encoded digest of crc32c hash.
  creation_time (datetime|None): Time the object was created.
  custom_fields (dict|None): Custom key-value pairs set by users.
  decryption_key_hash_sha256 (str|None): Digest of a customer-supplied
    encryption key.
  encryption_algorithm (str|None): Encryption algorithm used for encrypting
    the object if CSEK is used.
  etag (str|None): HTTP version identifier.
  event_based_hold (bool|None): Event based hold information for the object.
    Currently, GCS-only, but left generic because can affect copy logic.
  kms_key (str|None): Resource identifier of a Google-managed encryption key.
  md5_hash (str|None): Base64-encoded digest of md5 hash.
  metadata (object|dict|None): Cloud-specific metadata type.
  metageneration (int|None): Generation object's metadata.
  noncurrent_time (datetime|None): Noncurrent time value for the object.
  retention_expiration (datetime|None): Retention expiration information.
  size (int|None): Size of object in bytes (equivalent to content_length).
  storage_class (str|None): Storage class of the bucket.
  temporary_hold (bool|None): Temporary hold information for the object.
  update_time (datetime|None): Time the object was updated.
cloud_objectc                 n  > [         [        U ]  U5        X l        X0l        X@l        XPl        X`l        Xpl        Xl	        Xl
        Xl        Xl        Xl        Xl        Xl        Xl        UU l        UU l        UU l        UU l        UU l        UU l        UU l        UU l        UU l        UU l        UU l        grJ   )rL   rv   r   rM   cache_controlcomponent_countcontent_dispositioncontent_encodingcontent_languagecontent_typecrc32c_hashrO   custom_fieldscustom_timedecryption_key_hash_sha256encryption_algorithmrR   event_based_holdkms_keymd5_hashrX   rW   noncurrent_timeretention_expirationsizestorage_classtemporary_holdr[   )r   r   rM   rz   r{   r|   r}   r~   r   r   rO   r   r   r   r   rR   r   r   r   rW   rX   r   r   r   r   r   r[   r'   s                              r   r   ObjectResource.__init__'  s    8 
.$();<H&*2,,$"&&"&@# 4I,DDLDM(DDM*D 4DDI&D(D"Dr   c                 .    U R                   R                  $ r"   r`   r   s    r   bucketObjectResource.bucket^  rd   r   c                 .    U R                   R                  $ r"   r   resource_namer   s    r   rb   ObjectResource.nameb      )))r   c                 .    U R                   R                  $ r"   )r   
generationr   s    r   r   ObjectResource.generationf  s    &&&r   c                     U R                   (       a  [        R                  U R                   ;  a  gU R                   [        R                     R                  5       S:H  $ )z)Returns whether this object is a symlink.Ftrue)r   r   SYMLINK_METADATA_KEYlowerr   s    r   r2   ObjectResource.is_symlinkj  sK     --T5G5GG===>DDF&Pr   c                   > [         [        U ]  U5      =(       Ga)    U R                  UR                  :H  =(       Ga    U R                  UR                  :H  =(       Ga    U R
                  UR
                  :H  =(       Ga    U R                  UR                  :H  =(       Ga    U R                  UR                  :H  =(       Ga    U R                  UR                  :H  =(       Gac    U R                  UR                  :H  =(       GaB    U R                  UR                  :H  =(       Ga!    U R                  UR                  :H  =(       Ga     U R                  UR                  :H  =(       Ga    U R                  UR                  :H  =(       Ga    U R                  UR                  :H  =(       Ga    U R                  UR                  :H  =(       Ga|    U R                   UR                   :H  =(       Ga[    U R"                  UR"                  :H  =(       Ga:    U R$                  UR$                  :H  =(       Ga    U R&                  UR&                  :H  =(       a    U R(                  UR(                  :H  =(       a    U R*                  UR*                  :H  =(       a    U R,                  UR,                  :H  =(       a    U R.                  UR.                  :H  =(       ay    U R0                  UR0                  :H  =(       aY    U R2                  UR2                  :H  =(       a9    U R4                  UR4                  :H  =(       a    U R6                  UR6                  :H  $ r"   )rL   rv   r)   rM   rz   r{   r|   r}   r~   r   r   rO   r   r   r   r   rR   r   r   r   rW   rX   r   r   r   r   r   r[   rm   s     r   r)   ObjectResource.__eq__v  s   nd*51 	. 	.dhh%))6K 	. 	.e111	. 	. 5 55	. 	. 	  E$=$==	. 	. 	!7!77		. 	.
 	!7!77	. 	. 	U///	. 	. 	E---	. 	. 	e111	. 	. 	e111	. 	. 	E---	. 	. 	''5+K+KK	. 	. 	!!U%?%??	. 	. 			UZZ	. 	. 	!7!77	. 	. 	%	. 	. +/--5>>*I	.  	'!	." 	u333#	.$ 	 5 55%	.& 	!!U%?%??'	.( 			UZZ)	.* 	e111+	., 	u333-	.. 	E---1/r   c                     gNFr1   r   s    r   r.   ObjectResource.is_container      r   c                     [         er"   r,   r   s    r   is_encryptedObjectResource.is_encrypted  s    
r   )rM   rz   r{   r|   r}   r~   r   r   rO   r   r   r   r   rR   r   r   r   rW   rX   r   r   r   r   r   r[   )NNNNNNNNNNNNNNNNNNNNNNNNN)r4   r5   r6   r7   r8   r   r   r9   r   rb   r   r2   r)   r.   r   r:   rs   rt   s   @r   rv   rv      s    -\ + !##' $ $ !!*.$( $"#$(!"55#n ( ( * * ' ' 	 	/6 r   rv   c                   6   ^  \ rS rSrSrSrU 4S jrS rSrU =r	$ )PrefixResourcei  zClass representing a  cloud object.

Attributes:
  TYPE_STRING (str): String representing the resource's content type.
  storage_url (StorageUrl): A StorageUrl object representing the prefix.
  prefix (str): A string representing the prefix.
prefixc                 8   > [         [        U ]  U5        X l        g)zInitialize the PrefixResource object.

Args:
  storage_url_object (StorageUrl): A StorageUrl object representing the
      prefix.
  prefix (str): A string representing the prefix.
N)rL   r   r   r   )r   r   r   r'   s      r   r   PrefixResource.__init__  s     
.$();<Kr   c                     grp   r1   r   s    r   r.   PrefixResource.is_container  rr   r   )r   )
r4   r5   r6   r7   r8   r   r   r.   r:   rs   rt   s   @r   r   r     s     +	 r   r   c                   x   ^  \ rS rSrSrSr    S
U 4S jjr\S 5       r\S 5       r	\S 5       r
U 4S jrS	rU =r$ )ManagedFolderResourcei  z$Class representing a managed folder.managed_folderc                 p   > [         [        U ]  XR                  5        X l        X0l        X@l        XPl        g r"   )rL   r   r   r   create_timerW   rX   r[   r   r   r   rW   rX   r[   r'   s         r   r   ManagedFolderResource.__init__  s7     

/<< #M("r   c                 .    U R                   R                  $ r"   r`   r   s    r   r   ManagedFolderResource.bucket  rd   r   c                     gr   r1   r   s    r   r2    ManagedFolderResource.is_symlink      r   c                 .    U R                   R                  $ r"   r   r   s    r   rb   ManagedFolderResource.name  r   r   c                 j  > [         [        U ]  U5      =(       a    U R                  UR                  :H  =(       ay    U R                  UR                  :H  =(       aY    U R
                  UR
                  :H  =(       a9    U R                  UR                  :H  =(       a    U R                  UR                  :H  $ r"   )rL   r   r)   r   r   rW   rX   r[   rm   s     r   r)   ManagedFolderResource.__eq__  s    #T1%8 	2 1 11	2 1 11	2 MMU^^+	2 5#7#77		2
  1 11r   r   rW   rX   r[   NNNNr4   r5   r6   r7   r8   r   r   r9   r   r2   rb   r)   r:   rs   rt   s   @r   r   r     sd    , +
 #  ( (   * * r   r   c                   x   ^  \ rS rSrSrSr    S
U 4S jjr\S 5       r\S 5       r	\S 5       r
U 4S jrS	rU =r$ )FolderResourcei  zClass representing a folder.folderc                 p   > [         [        U ]  XR                  5        X l        X0l        X@l        XPl        g r"   )rL   r   r   r   r   rW   rX   r[   r   s         r   r   FolderResource.__init__  s6     
.$(<< #M("r   c                 .    U R                   R                  $ r"   r`   r   s    r   r   FolderResource.bucket  rd   r   c                     gr   r1   r   s    r   r2   FolderResource.is_symlink  r   r   c                 .    U R                   R                  $ r"   r   r   s    r   rb   FolderResource.name  r   r   c                 j  > [         [        U ]  U5      =(       a    U R                  UR                  :H  =(       ay    U R                  UR                  :H  =(       aY    U R
                  UR
                  :H  =(       a9    U R                  UR                  :H  =(       a    U R                  UR                  :H  $ r"   )rL   r   r)   r   r   rW   rX   r[   rm   s     r   r)   FolderResource.__eq__  s    nd*51 	2 1 11	2 1 11	2 MMU^^+	2 5#7#77		2
  1 11r   r   r   r   rt   s   @r   r   r     sd    $+
 #  ( (   * * r   r   c                   Z   ^  \ rS rSrSrSrS	U 4S jjrS r\S 5       r	\S 5       r
SrU =r$ )
FileObjectResourcei	  a  Wrapper for a filesystem file.

Attributes:
  TYPE_STRING (str): String representing the resource's content type.
  size (int|None): Size of local file in bytes or None if pipe or stream.
  storage_url (StorageUrl): A StorageUrl object representing the resource.
  md5_hash (bytes): Base64-encoded digest of MD5 hash.
  is_symlink (bool|None): Whether this file is known to be a symlink.
file_objectc                 D   > [         [        U ]  U5        X l        X0l        grJ   )rL   r   r   r   _is_symlink)r   r   r   r2   r'   s       r   r   FileObjectResource.__init__  s    	
d,-?@M!r   c                     gr   r1   r   s    r   r.   FileObjectResource.is_container  r   r   c                     U R                   R                  (       a  g[        R                  R	                  U R                   R
                  5      $ )z,Returns file size or None if pipe or stream.N)r   	is_streamospathgetsizer   r   s    r   r   FileObjectResource.size  s5     !!77??4++99::r   c                     U R                   c8  [        R                  R                  U R                  R
                  5      U l         U R                   $ )z'Returns whether this file is a symlink.)r   r   r   islinkr   r   r   s    r   r2   FileObjectResource.is_symlink%  s=     (8(8(F(FGdr   )r   r   )NN)r4   r5   r6   r7   r8   r   r   r.   r9   r   r2   r:   rs   rt   s   @r   r   r   	  sA     +" ; ;  r   r   c                   P   ^  \ rS rSrSrSU 4S jjr\S 5       r\S 5       rSr	U =r
$ )FileSymlinkPlaceholderResourcei-  zdA file to a symlink that should be preserved as a placeholder.

Attributes:
  Refer to super class.
c                 .   > [         [        U ]  XS5        g)rK   TN)rL   r   r   )r   r   r   r'   s      r   r   'FileSymlinkPlaceholderResource.__init__4  s    	
($8dr   c                     [        [        R                  " U R                  R                  5      R                  S5      5      $ )zEReturns the length of the symlink target to be used as a placeholder.zutf-8)lenr   readlinkr   r   encoder   s    r   r   #FileSymlinkPlaceholderResource.size:  s/     r{{4++99:AA'JKKr   c                     grp   r1   r   s    r   r2   )FileSymlinkPlaceholderResource.is_symlink?  s    r   r1   r"   )r4   r5   r6   r7   r8   r   r9   r   r2   r:   rs   rt   s   @r   r   r   -  s7     L L  r   r   c                   "    \ rS rSrSrSrS rSrg)FileDirectoryResourceiD  z$Wrapper for a File system directory.file_directoryc                     grp   r1   r   s    r   r.   "FileDirectoryResource.is_containerH  rr   r   r1   Nr4   r5   r6   r7   r8   r   r.   r:   r1   r   r   r   r   D  s    , +r   r   c                   "    \ rS rSrSrSrS rSrg)UnknownResourceiL  z0Represents a resource that may or may not exist.unknownc                 .    [         R                  " S5      e)Nz6Unknown whether or not UnknownResource is a container.)r   ValueCannotBeDeterminedErrorr   s    r   r.   UnknownResource.is_containerP  s    

-
-@B Br   r1   Nr   r1   r   r   r   r   L  s    8+Br   r   c                     [        U [        5      (       a  U R                  R                  5       $ U R	                  5       $ )z@Returns if resource is a known or unverified container resource.)r&   r   r   	is_bucketr.   )r   s    r   !is_container_or_has_container_urlr   U  s3    /**))++				  r   )r8   
__future__r   r   r   r   r   "googlecloudsdk.command_lib.storager   ,googlecloudsdk.command_lib.storage.resourcesr   NOT_SUPPORTED_DO_NOT_DISPLAYobjectr
   r<   rF   rv   r   r   r   r   r   r   r   r   r1   r   r   <module>r      s    F &  '  	 5 F  ? :v :zH 8{] {|_] _D] 2)N )X)^ )X! !H%7 .H Bh B!r   