
    ^                     J   S r SSKJr  SSKJr  SSKJr  SSKJr  SSKJr  SSKJr  SSK	J
r
  SS	K	Jr  SS
KJr  SSKJr  SSKJr  SSKJr  SES jrSES jrSES jrSES jrSES jrSES jrSES jrSES jrSES jrSFS jrSES jrSES jrSES jr S r!S r"S r#SES jr$SES  jr% SES!\RL                  S"\'S#S4S$ jjr(S% r)S& r*S' r+S( r,S) r-S* r.SES+ jr/S, r0SGS- jr1SHS. jr2 SIS/ jr3S0 r4S1 r5S2 r6S3 r7S4 r8S5 r9S6 r:S7 r;S8 r<S9 r=S: r>S; r?S< r@S= rAS> rBS? rCSJS@\DSA\D4SB jjrESC rFSKSD jrGg)Lz$Shared resource arguments and flags.    )absolute_import)division)unicode_literals)arg_parsers)base)parser_arguments)concepts)	multitype)
completers)concept_parsers)presentation_specs)	resourcesc                 D    U R                   " [        SU5      4SSS.UD6  g )Nz	data-filePATHz]File path from which to read secret data. Set this to "-" to read the secret data from stdin.metavarhelpadd_argument
_ArgOrFlagparser
positionalkwargss      .lib/googlecloudsdk/command_lib/secrets/args.pyAddDataFiler   #   s1    j)*
 	    c                 D    U R                   " [        SU5      4SSS.UD6  g )Nzout-filezOUT-FILE-PATHz~File path to which secret data is written. If this flag is not provided secret data will be written to stdout in UTF-8 format.r   r   r   s      r   
AddOutFiler   ,   s2    Z(N
 	r   c                     [         R                  R                  " S[        SU5      [	        5       SS.UD6R                  U 5        g )NprojectzThe project ID.nameresource_spec
group_help )r   ConceptParserForResourcer   GetProjectResourceSpecAddToParserr   s      r   
AddProjectr+   5   sD    ++ i,*," 		 F#r   c                     [         R                  R                  " S[        SU5      [	        5       SR                  U5      S.UD6R                  U 5        g )NlocationzThe location {}.r"   r&   )r   r'   r(   r   GetLocationResourceSpecformatr*   r   purposer   r   s       r   AddLocationr2   =   sO    ++ j*-+-#**73 		 F#r   c                 D    U R                   " [        SU5      4SSS.UD6  g )Nreplication-policy-fileREPLICATION-POLICY-FILEJSON or YAML file to use to read the replication policy. The file must conform to https://cloud.google.com/secret-manager/docs/reference/rest/v1/projects.secrets#replication.Set this to "-" to read from stdin.r   r   r   s      r   AddReplicationPolicyFiler7   E   s2    *J7'0	 	r   c                 D    U R                   " [        SU5      4SSS.UD6  g )Nkms-key-nameKMS-KEY-NAMEyGlobal KMS key with which to encrypt and decrypt the secret. Only valid for secrets with an automatic replication policy.r   r   r   s      r   AddKmsKeyNamer<   Q   s2    ,F
 	r   c                 D    U R                   " [        SU5      4SSS.UD6  g )Nset-kms-keySET-KMS-KEYENew KMS key with which to encrypt and decrypt future secret versions.r   r   r   s      r   AddSetKmsKeyNamerA   Z   s/    
+
Q	 	r   c                 D    U R                   " [        SU5      4SSS.UD6  g )Nremove-cmek
store_truetRemove customer managed encryption key so that future versions will be encrypted by a Google managed encryption key.actionr   r   r   s      r   AddRemoveCmekrH   d   s1    
+=	 	r   c                 D    U R                   " [        SU5      4SSS.UD6  g )Nr-   REPLICA-LOCATIONdLocation of replica to update. For secrets with automatic replication policies, this can be omitted.r   r   r   s      r   AddReplicaLocationrL   n   s1    Z( 9
 	r   Nc                     Uc  SR                  U5      n[        R                  R                  " S[	        SU5      [        5       US.UD6R                  U 5        g)a)  Add secret resource argument to the parser.

Args:
  parser: The parser to add the argument to.
  purpose: The purpose of the secret, used to generate the help text.
  positional: Whether the argument is positional.
  help_text: The help text to use for the argument.
  **kwargs: Extra arguments.
NzThe secret {}.secretr"   r&   )r/   r   r'   r(   r   GetSecretResourceSpecr*   )r   r1   r   	help_textr   s        r   	AddSecretrQ   w   s\      ''0I++ h
+)+ 		
 Kr   c                     [         R                  R                  " S[        SU5      [	        5       SR                  U5      S.UD6R                  U 5        g )NversionzNumeric secret version {}.r"   r&   r   r'   r(   r   GetVersionResourceSpecr/   r*   r0   s       r   
AddVersionrV      sO    ++ i,*,.66w? 		 F#r   c                     [         R                  R                  " S[        SU5      [	        5       SR                  U5      S.UD6R                  U 5        g )NrS   z_Numeric secret version {} or a configured alias (including 'latest' to use the latest version).r"   r&   rT   r0   s       r   AddVersionOrAliasrX      sM    ++ i,*,
mw 	 F#r   c                     U R                   " [        SU5      4S[        R                  " 5       [        R                  SS.UD6  g )NtopicsTOPICSz2List of Pub/Sub topics to configure on the secret.r   typerG   r   )r   r   r   ArgListUpdateActionr   s      r   	AddTopicsr`      sD    :& %%@ 	r   c                 R   U R                  SSS9nUR                  [        SS5      S[        R                  " 5       [        R
                  SS9  UR                  [        S	S5      S
[        R                  " 5       [        R
                  SS9  UR                  [        SS5      SSS9  g)z2Add flags for specifying topics on secret updates.TzTopics.mutexr   z
add-topicsFz
ADD-TOPICSz,List of Pub/Sub topics to add to the secret.r\   zremove-topicszREMOVE-TOPICSz1List of Pub/Sub topics to remove from the secret.zclear-topicsrD   z)Clear all Pub/Sub topics from the secret.rF   N)	add_groupr   r   r   r^   r_   r   groups     r   AddUpdateTopicsGrouprg      s     

I

6%u% %%:  = %( %%?  B '7  :r   c                     U R                  SSS9nUR                  [        SS5      SSS9  UR                  S	S
9nUR                  [        SS5      SSS9  UR                  [        SS5      SSS9  g)z4Add flags for specifying replication policy updates.TzReplication update.rb   rC   FrD   rE   rF   zCMEK Update.r   r>   r?   r@   r   r-   rJ   rK   Nrd   r   r   r   rf   subgroups      r   AddUpdateReplicationGrouprm      s    


,A

B%&=	  ? __._1(
&
Q	  	 U# 9  ;r   c                 `   U R                  SSS9nUR                  [        SS5      SSS9  UR                  S	S
9nUR                  [        SS5      SSS9  UR                  [        SS5      SSS9  UR                  [        SS5      [        R                  S[        R
                  " 5       SS9  g)z?Add flags for specifying replication policy on secret creation.TzReplication policy.rb   r4   Fr5   r6   r   zInline replication arguments.ri   zreplication-policyPOLICYzThe type of replication policy to apply to this secret. Allowed values are "automatic" and "user-managed". If user-managed then --locations must also be provided.r9   r:   r;   	locationsLOCATIONzKComma-separated list of locations in which the secret should be replicated.)rG   r   r]   r   N)rd   r   r   r   r_   r^   rk   s      r   AddCreateReplicationPolicyGrouprr      s     

,A

B%*E2'0	  2 __"A_B(
%u-1  3 'F  H e$%%   r   c                 l    U R                   " [        SU5      4S[        R                  " 5       SS.UD6  g)z?Add flags for specifying version destroy ttl on secret creates.version-destroy-ttlVERSION-DESTROY-TTLa8  Secret Version Time To Live (TTL) after destruction request. For secret with TTL>0, version destruction does not happen immediately on calling destroy; instead, the version goes to a disabled state and destruction happens after the TTL expires. See `$ gcloud topic datetimes` for information on duration formats.r   r]   r   N)r   r   r   Durationr   s      r   AddCreateVersionDestroyTTLrx      s?    &
3#!P 	r   c                     U R                  SSS9nUR                  " [        SU5      4S[        R                  " 5       SS.UD6  UR                  " [        SS	5      4S
SS.UD6  g)z?Add flags for specifying version destroy ttl on secret updates.TzVersion destroy ttl.rb   rt   ru   a)  Secret Version TTL after destruction request. For secret with TTL>0, version destruction does not happen immediately on calling destroy; instead, the version goes to a disabled state and destruction happens after the TTL expires. See `$ gcloud topic datetimes` for information on duration formats.rv   zremove-version-destroy-ttlFrD   z8If set, removes the version destroy TTL from the secret.rF   N)rd   r   r   r   rw   r   r   r   rf   s       r   AddUpdateVersionDestroyTTLr{     s    


,B

C%&
3#!P 	 -u5E 		r   r   r   returnc                     U R                  SSS9nUR                  " [        SU5      4SSS.UD6  UR                  " [        SS	5      4S
SS.UD6  g)zAdd flags for specifying regional cmek on secret updates.

Args:
    parser: Given argument parser.
    positional : Whether the argument is positional.
    **kwargs: Extra arguments.
Tzregional kms key.rb   regional-kms-key-namezREGIONAL-KMS-KEY-NAMEz*regional kms key name for regional secret.r   zremove-regional-kms-key-nameFrD   z%If set, removes the regional kms key.rF   Nrj   rz   s       r   AddUpdateRegionalKmsKeyr     sx     

,?

@%(*5%7 		 /72 		r   c                     U R                  SSS9nUR                  [        SS5      SSS9  UR                  [        S	S5      S
SS9  g)z6Add flags for specifying expiration on secret creates.TExpiration.rb   expire-timeFEXPIRE-TIME6Timestamp at which to automatically delete the secret.r   ttlTTLhDuration of time (in seconds) from the running of the command until the secret is automatically deleted.Nrj   re   s     r   AddCreateExpirationGroupr   :  sd     

M

:%&D  G 1	  3r   c                     U R                  SSS9nUR                  [        SS5      SSS9  UR                  [        S	S5      S
SS9  UR                  [        SS5      SSS9  g)z7Add flags for specifying expiration on secret updates..Tr   rb   r   Fr   r   r   r   r   r   zremove-expirationrD   zAIf set, removes scheduled expiration from secret (if it had one).rF   Nrj   re   s     r   AddUpdateExpirationGroupr   J  s     

M

:%&D  G 1	  3 $e,
M	  Pr   c                     U R                  SSS9nUR                  [        SS5      SS9  UR                  [        SS5      SS9  g	)
z4Add flags for specifying rotation on secret creates.F	Rotation.rb   next-rotation-time1Timestamp at which to send rotation notification.ri   rotation-period=Duration of time (in seconds) between rotation notifications.Nrj   re   s     r   AddCreateRotationGroupr   _  s_     

[

9%%u-?  B "E*K  Nr   c                 .   U R                  SSS9nUR                  [        SS5      SS9  UR                  [        SS5      SS	S
9  UR                  [        SS5      SS9  UR                  [        SS5      SSS
9  UR                  [        SS5      SSS
9  g)z5Add flags for specifying rotation on secret updates..Fr   rb   r   r   ri   zremove-next-rotation-timerD   z8Remove timestamp at which to send rotation notification.rF   r   r   zremove-rotation-periodzVIf set, removes the rotation period, cancelling all rotations except for the next one.zremove-rotation-schedulez.If set, removes rotation policy from a secret.Nrj   re   s     r   AddUpdateRotationGroupr   k  s     

[

9%%u-?  B ,e4F  I "E*K  N )51%	  	 +U3<  ?r   c                 T    U R                  [        SS5      SSR                  US9S9  g)z0Add flag for specifying the current secret etag.etagFETAGzCurrent entity tag (ETag) of the secret. If specified, the secret is {action} only if the ETag provided matches the current secret's ETag.rG   r   Nr   r   r/   r   rG   s     r   AddSecretEtagr     s5     	f  r   c                 T    U R                  [        SS5      SSR                  US9S9  g)z8Add flag for specifying the current secret version etag.r   Fr   zCurrent entity tag (ETag) of the secret version. If specified, the version is {action} only if the ETag provided matches the current version's ETag.r   r   Nr   r   s     r   AddVersionEtagr     s5     	f  r   c                 D    U R                   " [        SU5      4SSS.UD6  g)z2Add flag for specifying the regional KMS key name.r~   r:   z_Regional KMS key with which to encrypt and decrypt the secret. Only valid for regional secrets.r   Nr   r   s      r   AddRegionalKmsKeyNamer     s2    (*5(	 	r   c                 r    U(       a   U R                  5       R                  SS5      $ SR                  U 5      $ )zReturns the argument name in resource argument format or flag format.

Args:
    name (str): name of the argument
    positional (bool): whether the argument is positional

Returns:
    arg (str): the argument or flag
-_z--{})upperreplacer/   )r#   r   s     r   r   r     s/     ::<S))	t	r   c           
          [         R                  " S[        5       [        5       4SS0UD6n[        R
                  " [        R                  " SUUSSS9/5      R                  U 5        g)a  Adds a secret resource.

Secret resource can be global secret or regional secret. If command has
"--location" then regional secret will be created or else global secret will
be created.
Regionl secret - projects/<project>/locations/<location>/secrets/<secret>
Global secret - projects/<project>/secrets/<secret>

Args:
    parser: given argument parser
    purpose: help text
    **kwargs: extra arguments
zglobal or regional secretallow_inactiveTrN   requiredhiddenN)	r
   MultitypeResourceSpecrO   GetRegionalSecretResourceSpecr   r'   r   !MultitypeResourcePresentationSpecr*   )r   r1   r   secret_or_region_secret_specs       r   AddGlobalOrRegionalSecretr     sv     "+!@!@!#%" 	"
 	" ::

&
!  [r   c           
          [         R                  " S[        5       [        5       4SS0UD6n[        R
                  " [        R                  " SUUSSS9/5      R                  U 5        g)zwAdds a version resource.

Args:
    parser: given argument parser
    purpose: help text
    **kwargs: extra arguments
!global or regional secret versionr   TrS   r   N	r
   r   rU   GetRegionalVersionResourceSpecr   r'   r   r   r*   r   r1   r   global_or_region_version_specs       r   AddGlobalOrRegionalVersionr     sv     #,"A"A)$&# 	#
 	# ::

'
!  [r   c           
          [         R                  " S[        5       [        5       4SS0UD6n[        R
                  " [        R                  " SUUSSS9/5      R                  U 5        g)zAdds a version resource or alias.

Args:
    parser: given argument parser
    purpose: help text
    **kwargs: extra arguments
r   r   TrS   r   Nr   r   s       r   !AddGlobalOrRegionalVersionOrAliasr     sv     #,"A"A)$&# 	#
 	# ::

'
!  [r   c                  "    [         R                  $ )N)r	    DEFAULT_PROJECT_ATTRIBUTE_CONFIGr&   r   r   GetProjectAttributeConfigr     s    		2	22r   c                  4    [         R                  " SSSS0SS9$ )Nr-   zThe location of the {resource}.	fieldMaskr#   r#   rP   completion_request_paramscompletion_id_fieldr	    ResourceParameterAttributeConfigr&   r   r   GetLocationAttributeConfigr     s&    		2	21!,f 5 	
" "r   c                  4    [         R                  " SSSS0SS9$ )z3Returns the attribute config for location resource.r-   z.[EXPERIMENTAL] The location of the {resource}.r   r#   r   r   r&   r   r   "GetLocationResourceAttributeConfigr   "  s&    		2	2
:!,f 5 
 r   c                  J    [         R                  " SS[        R                  S9$ )NrN   The secret of the {resource}.r#   rP   	completerr	   r   secrets_completersSecretsCompleterr&   r   r   GetSecretAttributeConfigr   .  s$    		2	2/"33
5 5r   c                  J    [         R                  " SS[        R                  S9$ )z1Returns the attribute config for regional secret.rN   r   r   r   r&   r   r    GetRegionalSecretAttributeConfigr   5  s$    		2	2/"33
 r   c                  4    [         R                  " SSSS0SS9$ )NrS   The version of the {resource}.r   r#   r   r   r&   r   r   GetVersionAttributeConfigr   >  s&    		2	20!,f 5 	
" "r   c                  4    [         R                  " SSSS0SS9$ )z9Returns the attribute config for regional secret version.rS   r   r   r#   r   r   r&   r   r   !GetRegionalVersionAttributeConfigr   F  s&    		2	20!,f 5 	
 r   c                  B    [         R                  " SSSS[        5       S9$ )Nzsecretmanager.projectsr!   projectsF)resource_collectionresource_nameplural_namedisable_auto_completers
projectsId)r	   ResourceSpecr   r&   r   r   r)   r)   S  s'    			2#*,
. .r   c            	      T    [         R                  " SSSS[        5       [        5       S9$ )Nz secretmanager.projects.locationsr-   rp   F)r   r   r   r   locationsIdr   )r	   r   r   r   r&   r   r   r.   r.   \  s-    			<#,.*,
. .r   c            	      T    [         R                  " SSSS[        5       [        5       S9$ )Nsecretmanager.projects.secretsrN   secretsF)r   r   r   r   	secretsIdr   )r	   r   r   r   r&   r   r   rO   rO   f  s-    			:#(**,
. .r   c            
      f    [         R                  " SSSS[        5       [        5       [	        5       S9$ )N'secretmanager.projects.secrets.versionsrS   F)r   r   r   
versionsIdr   r   )r	   r   r   r   r   r&   r   r   rU   rU   p  s3    			/#*,(**,
. .r   c            
      f    [         R                  " SSSS[        5       [        5       [	        5       S9$ )z.Returns the resource spec for regional secret.z(secretmanager.projects.locations.secretszregional secretr   F)r   r   r   r   r   r   r   )r	   r   r   r   r   r&   r   r   r   r   {  s3    			D%#02*,46
 r   c                  x    [         R                  " SSSS[        5       [        5       [	        5       [        5       S9$ )z6Returns the resource spec for regional secret version.1secretmanager.projects.locations.secrets.versionszregional versionrS   F)r   r   r   r   r   r   r   r   )r	   r   r   r   r   r   r&   r   r   r   r     s9    			M&#2402*,46	
 	r   c                 >    [         R                  R                  U SS9$ )Nr   
collectionr   REGISTRYParserefs    r   ParseSecretRefr     s&    				!	!	6 
" 
 r   c                 >    [         R                  R                  U SS9$ )Nr   r   r   r   s    r   ParseVersionRefr     s&    				!	!	? 
" 
 r   c                 >    [         R                  R                  U SS9$ )zParses regional section version into 'secretmanager.projects.locations.secrets.versions' format .

Args:
  ref: resource name of regional secret version.
Returns:
  Parsed secret version.
r   r   r   r   s    r   ParseRegionalVersionRefr     s(     
			!	!	I 
" 
 r   r   api_versionc                    ^ ^ UU 4S jnU$ )a-  Returns a function which turns a resource into a uri.

Example:
  class List(base.ListCommand):
    def GetUriFunc(self):
      return MakeGetUriFunc(self)

Args:
  collection: A command instance.
  api_version: api_version to be displayed.

Returns:
  A function which can be returned in GetUriFunc.
c                    > [         R                  R                  5       nUR                  ST5        UR	                  U R
                  TS9nUR                  5       $ )Nsecretmanagerr   )r   r   CloneRegisterApiByNamer   r#   SelfLink)resourceregistryparsedr   r   s      r   _GetUriMakeGetUriFunc.<locals>._GetUri  sJ    !!'')H<^^HMMj^AF??r   r&   )r   r   r   s   `` r   MakeGetUriFuncr     s      
.r   c            	          / SQn [         R                  " SS[        R                  " 5       [        R                  SR                  U 5      S9$ )z(Makes the base.Argument for --tags flag.)z%List of tags KEY=VALUE pairs to bind.zEach item must be expressed asz4`<tag-key-namespaced-name>=<tag-value-short-name>`.
z?Example: `123/environment=production,123/costCenter=marketing`
z--tagsz	KEY=VALUE
r\   )r   Argumentr   ArgDictr_   join)
help_partss    r   
GetTagsArgr    sC    * 
 %%99Z 
 r   c                     [        X5      nU(       d  gU" [        UR                  5       5       VVs/ s H  u  pEUR                  XES9PM     snnS9$ s  snnf )zMakes the tags message object.N)keyvalue)additionalProperties)getattrsorteditemsAdditionalProperty)argstags_messagetags_arg_nametagsr	  r
  s         r   GetTagsFromArgsr    sZ    		%$		tzz|,,.,*# %%#%;,,. 
/ / ,.s   A
)F) FN)zcreate a secret)zcreate a version)zcreate a version alias)v1)r  )H__doc__
__future__r   r   r   googlecloudsdk.callioper   r   r    googlecloudsdk.calliope.conceptsr	   r
   "googlecloudsdk.command_lib.secretsr   r   (googlecloudsdk.command_lib.util.conceptsr   r   googlecloudsdk.corer   r   r   r+   r2   r7   r<   rA   rH   rL   rQ   rV   rX   r`   rg   rm   rr   rx   r{   ArgumentInterceptorboolr   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r)   r.   rO   rU   r   r   r   r   r   strr   r  r  r&   r   r   <module>r!     s`   + &  ' / ( 4 5 6 O D G )$$	($$:,;.D"4 00 		63 P*	N?6		
B8 -@3"	5"....
"
s  2"/r   