
    b                     &   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  SBS jrSBS jrSBS jrSBS jrSBS jrSBS jrSBS jrSBS jrSBS jrSCS jrSBS jrSBS jrSBS jrS rS rS rSBS jr SBS jr! SBS\RD                  S\#S S4S! jjr$S" r%S# r&S$ r'S% r(S& r)S' r*SBS( jr+S) r,SDS* jr-SES+ jr. SFS, jr/S- r0S. r1S/ r2S0 r3S1 r4S2 r5S3 r6S4 r7S5 r8S6 r9S7 r:S8 r;S9 r<S: r=S; r>S< r?SGS=\@S>\@4S? jjrAS@ rBSHSA jrCg)Iz$Shared resource arguments and flags.    )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(   2   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   AddLocationr/   :   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   AddReplicationPolicyFiler4   B   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   AddKmsKeyNamer9   N   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   AddSetKmsKeyNamer>   W   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   AddRemoveCmekrE   a   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   AddReplicaLocationrI   k   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   r.   r   	help_textr   s        r   	AddSecretrN   t   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'   r-   s       r   
AddVersionrS      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 )NrP   z_Numeric secret version {} or a configured alias (including 'latest' to use the latest version).r   r#   rQ   r-   s       r   AddVersionOrAliasrU      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   typerD   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.rY   zremove-topicszREMOVE-TOPICSz1List of Pub/Sub topics to remove from the secret.zclear-topicsrA   z)Clear all Pub/Sub topics from the secret.rC   N)	add_groupr   r   r   r[   r\   r   groups     r   AddUpdateTopicsGrouprd      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[        R                  " SSS9S9  g)z4Add flags for specifying replication policy updates.TzReplication update.r_   r@   FrA   rB   rC   zCMEK Update.r   r;   r<   r=   r   r*   rG   rH   zThis flag is not available in this universe. Specifying a location for replica updates is only for user-managed multi-replication, which is not supported.defaultuniverse_helpN)ra   r   r   r   UniverseHelpTextr   rc   subgroups      r   AddUpdateReplicationGrouprm      s    


,A

B%&=	  ? __._1(
&
Q	  	 U# ''<<
  r   c                    U R                  SSS9nUR                  [        SS5      S[        R                  " SSS	9S
9  UR                  SS9nUR                  [        SS5      S[        R                  " SSS	9S
9  UR                  [        SS5      SSS
9  UR                  [        SS5      [        R
                  S[        R                  " 5       [        R                  " SSS	9S9  g)z?Add flags for specifying replication policy on secret creation.TzReplication policy.r_   r1   Fr2   r3   zWThis flag is not available in this universe. User-managed replication is not supported.rg   r   zInline replication arguments.rf   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.zThe type of replication policy to apply to this secret. In this universe, only "automatic" is supported. User-managed replication is not available.r6   r7   r8   	locationsLOCATIONzKComma-separated list of locations in which the secret should be replicated.)rD   r   rZ   r   N)ra   r   r   r   rj   r\   r[   rk   s      r   AddCreateReplicationPolicyGrouprr      s    

,A

B%*E2'''4F  	 __"A_B(
%u-''J&	  	 'F  H e$%% ''+F  
	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   rZ   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.r_   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-ttlFrA   z8If set, removes the version destroy TTL from the secret.rC   N)ra   r   r   r   rw   r   r   r   rc   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.r_   regional-kms-key-namezREGIONAL-KMS-KEY-NAMEz*regional kms key name for regional secret.r   zremove-regional-kms-key-nameFrA   z%If set, removes the regional kms key.rC   Nra   r   r   rz   s       r   AddUpdateRegionalKmsKeyr   4  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.r_   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.Nr   rb   s     r   AddCreateExpirationGroupr   O  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   r_   r   Fr   r   r   r   r   r   zremove-expirationrA   zAIf set, removes scheduled expiration from secret (if it had one).rC   Nr   rb   s     r   AddUpdateExpirationGroupr   _  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.r_   next-rotation-time1Timestamp at which to send rotation notification.rf   rotation-period=Duration of time (in seconds) between rotation notifications.Nr   rb   s     r   AddCreateRotationGroupr   t  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   r_   r   r   rf   zremove-next-rotation-timerA   z8Remove timestamp at which to send rotation notification.rC   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.Nr   rb   s     r   AddUpdateRotationGroupr     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.rD   r   Nr   r   r,   r   rD   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~   r7   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_inactiveTrK   requiredhiddenN)	r   MultitypeResourceSpecrL   GetRegionalSecretResourceSpecr	   r$   r
   !MultitypeResourcePresentationSpecr'   )r   r.   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   TrP   r   N	r   r   rR   GetRegionalVersionResourceSpecr	   r$   r
   r   r'   r   r.   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   TrP   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    rM   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   7  s&    		2	2
:!,f 5 
 r   c                  J    [         R                  " SS[        R                  S9$ )NrK   The secret of the {resource}.r    rM   	completerr   r   secrets_completersSecretsCompleterr#   r   r   GetSecretAttributeConfigr   C  s$    		2	2/"33
5 5r   c                  J    [         R                  " SS[        R                  S9$ )z1Returns the attribute config for regional secret.rK   r   r   r   r#   r   r    GetRegionalSecretAttributeConfigr   J  s$    		2	2/"33
 r   c                  4    [         R                  " SSSS0SS9$ )NrP   The version of the {resource}.r   r    r   r   r#   r   r   GetVersionAttributeConfigr   S  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.rP   r   r   r    r   r   r#   r   r   !GetRegionalVersionAttributeConfigr   [  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&   h  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+   q  s-    			<#,.*,
. .r   c            	      T    [         R                  " SSSS[        5       [        5       S9$ )Nsecretmanager.projects.secretsrK   secretsF)r   r   r   r   	secretsIdr   )r   r   r   r   r#   r   r   rL   rL   {  s-    			:#(**,
. .r   c            
      f    [         R                  " SSSS[        5       [        5       [	        5       S9$ )N'secretmanager.projects.secrets.versionsrP   F)r   r   r   
versionsIdr   r   )r   r   r   r   r   r#   r   r   rR   rR     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 versionrP   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
rY   )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  )D__doc__googlecloudsdk.callioper   r   r    googlecloudsdk.calliope.conceptsr   r   "googlecloudsdk.command_lib.secretsr   r   (googlecloudsdk.command_lib.util.conceptsr	   r
   googlecloudsdk.corer   r   r   r(   r/   r4   r9   r>   rE   rI   rN   rS   rU   r]   rd   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+   rL   rR   r   r   r   r   r   strr  r  r  r#   r   r   <module>r!     sZ   + 0 ( 4 5 6 O D G )$$	($$:,B-	`"4 00 		63 P*	N?6		
B8 -@3"	5"....
"
s  2"/r   