
    Q                     t   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rSrSrSr\" 5       rS rS rS rS rS rS rS rS r S r!S r"S r#S r$S r%S r&S r'S  r(S! r)S" r*S# r+S$ r,S% r-S& r.S' r/S( r0S) r1S* r2S+ r3S, r4S- r5S. r6S/ r7S0 r8S1 r9g)2z*Shared flags for Cloud Workflows commands.    )apis)arg_parsers)base)
exceptions)concepts)deps)labels_util)map_util)concept_parsers)
properties)filesNzR^projects/[^/]+/locations/[^/]+/keyRings/[a-zA-Z0-9_-]+/cryptoKeys/[a-zA-Z0-9_-]+$zKMS key name should match projects/{project}/locations/{location}/keyRings/{keyring}/cryptoKeys/{cryptokey} and only contain characters from the valid character set for a KMS key.   c                      [         R                  " S[        R                  " [        R
                  " S5      5      /SS9$ )z4Builds an AttributeConfig for the location resource.locationzworkflows/locationzYCloud location for the {resource}.  Alternatively, set the property [workflows/location].)namefallthroughs	help_text)r    ResourceParameterAttributeConfigr   PropertyFallthroughr   
FromString     1lib/googlecloudsdk/command_lib/workflows/flags.pyLocationAttributeConfigr   ,   s=    		2	2

"
":#8#89M#N
OC	
 	r   c                  ,    [         R                  " SSS9$ )z4Builds an AttributeConfig for the workflow resource.workflowzWorkflow for the {resource}.r   r   r   r   r   r   r   WorkflowAttributeConfigr   :   s    		2	2!?
 r   c                  ,    [         R                  " SSS9$ )z5Builds an AttributeConfig for the execution resource.	executionzExecution for the {resource}.r   r   r   r   r   ExecutionAttributeConfigr"   A   s    		2	2"A
 r   c                  n    [         R                  " SS[         R                  [        5       [	        5       S9$ )z0Builds a ResourceSpec for the workflow resource.z&workflows.projects.locations.workflowsr   )resource_name
projectsIdlocationsIdworkflowsId)r   ResourceSpec DEFAULT_PROJECT_ATTRIBUTE_CONFIGr   r   r   r   r   GetWorkflowResourceSpecr*   H   s0    			.::)+)+
 r   c            	          [         R                  " SS[         R                  [        5       [	        5       [        5       S9$ )z1Builds a ResourceSpec for the execution resource.z:workflowexecutions.projects.locations.workflows.executionsr!   )r$   r%   r'   r&   executionsId)r   r(   r)   r   r   r"   r   r   r   GetExecutionResourceSpecr-   S   s6    			B::)+)++-
 r   c                     [         R                  R                  S[        5       SR	                  U5      SS9R                  U 5        g)zAdd a resource argument for a Cloud Workflows workflow.

Args:
  parser: the parser for the command.
  verb: str, the verb to describe the resource, such as 'to update'.
r   zName of the workflow {}.TrequiredN)r   ConceptParserForResourcer*   formatAddToParserparserverbs     r   AddWorkflowResourceArgr8   _   sC     ++ ''-	 , 
 Kr   c                     [         R                  R                  S[        5       SR	                  U5      SS9R                  U 5        g)zAdd a resource argument for a Cloud Workflows execution.

Args:
  parser: the parser for the command.
  verb: str, the verb to describe the resource, such as 'to update'.
r!   zName of the execution {}.Tr/   N)r   r1   r2   r-   r3   r4   r5   s     r   AddExecutionResourceArgr:   n   sC     ++ !((.	 , 
 Kr   c                 $    U R                  SSS9  g)z5Adds argument for specifying source for the workflow.--sourcezLocation of a workflow source code to deploy. Required on first deployment. Location needs to be defined as a path to a local file with the source code.helpNadd_argumentr6   s    r   AddSourceArgrB   }   s    "  r   c                 $    U R                  SSS9  g)z9Adds argument for specifying description of the workflow.z--descriptionz*The description of the workflow to deploy.r=   Nr?   rA   s    r   AddDescriptionArgrD      s    H  r   c                 $    U R                  SSS9  g)zBAdds argument for specifying service account used by the workflow.z--service-accountzThe service account that should be used as the workflow identity. "projects/PROJECT_ID/serviceAccounts/" prefix may be skipped from the full resource name, in that case "projects/-/serviceAccounts/" is prepended to the service account ID.r=   Nr?   rA   s    r   AddServiceAccountArgrF      s    5  r   c                 $    U R                  SSS9  g)zJAdds argument for specifying the data that will be passed to the workflow.z--datazIJSON string with data that will be passed to the workflow as an argument.r=   Nr?   rA   s    r   
AddDataArgrH      s      r   c                 ^    [         R                  " SSSSSS.SSS	9nUR                  U 5        g
)@Adds argument for specifying the logging level for an execution.--call-log-levelNo logging level specified.ELog all calls to subworkflows or library functions and their results./Log when a call is stopped due to an exception.Perform no call logging.nonelog-all-callslog-errors-onlyzlog-none0Level of call logging to apply during execution.rQ   choiceshelp_strdefaultNr   ChoiceArgumentr4   r6   	log_levels     r   AddLoggingArgr]      sD    !!/ O0 B) r   c                 \    [         R                  " SSSSS.SSS9nUR                  U 5        g	)
zJAdds argument for specifying the execution history level for an execution.--execution-history-level%No execution history level specified.z'Enable execution history basic feature.z*Enable execution history detailed feature.rQ   zexecution-history-basiczexecution-history-detailedz5Level of execution history to apply during execution.rQ   rU   NrY   r6   execution_history_levels     r   AddExecutionHistoryLevelArgrd      s?     //!97 ; G %%f-r   c                 (    U R                  SSSSS9  g)zBAdds an argument for determining whether to backlog the execution.z.--disable-concurrency-quota-overflow-buffering
store_trueFzIf set, the execution will not be backlogged when the concurrency quota is exhausted. Backlogged executions start when the concurrency quota becomes available.)actionrX   r>   Nr?   rA   s    r   AddDisableOverflowBufferArgrh      s#    61  	r   c                 \    [         R                  " SSSSS.SSS9nUR                  U 5        g	)
rJ   rK   rO   rM   rN   )rQ   rR   rS   rT   rQ   rU   NrY   r[   s     r   AddBetaLoggingArgrj      sA    !!, O B) r   c                 ^    [         R                  " SSSSSS.SSS	9nUR                  U 5        g
)z>Adds argument for specifying the logging level for a workflow.rK   rL   rM   rN   rO   rP   z;Level of call logging to apply by default for the workflow.rQ   rU   NrY   r[   s     r   AddWorkflowLoggingArgrl      sD    !!/ O0 M) r   c           	          / SQn[         R                  " SS[        R                  " 5       [        R                  SR                  U5      S9nUR                  U 5        g)z5Adds argument for specifying the tags for a workflow.)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=marketingz--tags	KEY=VALUE
)metavartyperg   r>   N)r   Argumentr   ArgDictUpdateActionjoinr4   )r6   
help_partstagss      r   AddWorkflowTagsArgrx     sP    * 
 %%99Z 
$ 6r   c                     U R                  S5      (       a_  [        U S5      nU(       d  gU" [        [        R                  " U5      5       VVs/ s H  u  pEUR                  XES9PM     snnS9Ul        ggs  snnf )z4Sets --tags for the workflow based on the arguments.rw   NkeyvalueadditionalProperties)IsSpecifiedgetattrsortedsix	iteritemsAdditionalPropertyrw   )argsr   tags_messagerw   r{   r|   s         r   SetWorkflowsTagsArgr     st    	f4 D  t!45775JC 	''C'=577 8HM 
77s   A7
c                 \    [         R                  " SSSSS.SSS9nUR                  U 5        g	)
zI"Adds argument for specifying the execution history level for a workflow.r_   r`   zEnable basic execution history.z^Enable detailed execution history, including expected iterations and in-scope variable values.ra   z5Level of execution history to apply for the workflow.rQ   rU   NrY   rb   s     r   #AddWorkflowExecutionHistoryLevelArgr     s?     //!9/:	 G %%f-r   c                 :    U b  Xl         UR                  S5        gg)a@  Sets --call-log-level for the workflow based on the arguments.

Also updates updated_fields accordingly.

Args:
  loglevel: Parsed callLogLevel to be set on the workflow.
  workflow: The workflow in which to set the call-log-level.
  updated_fields: A list to which the call-log-level field will be added if
    needed.
NcallLogLevel)r   append)loglevelr   updated_fieldss      r   SetWorkflowLoggingArgr   3  s#     $.) r   c                 :    U b  Xl         UR                  S5        gg)as  Sets --execution-history-level for the workflow based on the arguments.

Also updates updated_fields accordingly.

Args:
  execution_history_level: Parsed executionHistoryLevel to be set
  on the workflow.
  workflow: The workflow in which to set the execution-history-level.
  updated_fields: A list to which the execution-history-level field will
  be added if needed.
NexecutionHistoryLevel)r   r   )rc   r   r   s      r   #SetWorkflowExecutionHistoryLevelArgr   C  s$     (%<"12 )r   c                     U R                  SSS9nUR                  S[        R                  " [        [
        5      SS9  UR                  SSSS	9  g
)zjAdds flags for configuring the CMEK key.

Args:
  parser: The flag parser used for the specified command.
T)mutexhiddenz	--kms-keya          Sets the user managed KMS crypto key used to encrypt the new Workflow
        Revision and the Executions associated with it.

        The KMS crypto key name should match the pattern
        `projects/${PROJECT}/locations/${LOCATION}/keyRings/${KEYRING}/cryptoKeys/${CRYPTOKEY}`
        where ${PROJECT} is the project, ${LOCATION} is the location of the key
        ring, and ${KEYRING} is the key ring that contains the ${CRYPTOKEY}
        crypto key.
      )rq   r>   z--clear-kms-keyrf   z        Creates the new Workflow Revision and its associated Executions without
        the KMS key specified on the previous revision.
      rg   r>   N)	add_groupr@   r   RegexpValidator_KEY_NAME_PATTERN_KEY_NAME_ERROR)r6   kmskey_groups     r   AddKmsKeyFlagsr   V  se     !!T!:,&&'8/J	
   
  r   c                     U R                  S5      (       d  U R                  S5      (       a6  U R                  (       a  SOU R                  Ul        UR	                  S5        gg)a  Sets KMS key for the workflow based on the arguments.

Also update updated_fields accordingly.

Args:
  args: Args passed to the command.
  workflow: The workflow in which to set the KMS key.
  updated_fields: A list to which the KMS key field will be added if needed.
kms_keyclear_kms_keyNcryptoKeyName)r   r   r   r   r   r   r   r   s      r   	SetKmsKeyr   u  sO     
i  D$4$4_$E$E%)%7%7TT\\H/* %Fr   c           	      
   U R                  SSSS9nUR                  S[        R                  " [        [        [
        S9[        R                  SSS	9  UR                  S
S[        R                  " [        [        S9SS9  UR                  SSSS9  UR                  SS[        R                  [        R                  " [        S9SS9  UR                  S[        R                  " [        [        S9[        R                  SSS	9  g)z>Adds flags for configuring user-defined environment variables.TFag          Flags to configure user-defined environment variables for a
        workflow.

        Keys can't be empty strings and can't start with `GOOGLE`
        or `WORKFLOWS`. We recommend that environment variable keys consist
        solely of uppercase letters, digits, and underscores (`_`), and that
        they don't begin with a digit. Consider prefixing your user-defined
        environment variables with a unique key to avoid conflicts with other
        variables.

        If your value contains commas, prefix the mapping with a different
        delimiter character enclosed between `^` (example 1). Use special
        characters in your shell with caution as they might not work as
        intended or need escaping (example 2 escapes a `$` in Bash).

        Example 1: --set-env-vars ^@^KEY1=ONE,VALUE,WITH,COMMAS@KEY2=VALUE2

        Example 2: --set-env-vars ^$^KEY1=VALUE1\$KEY2=VALUE,WITH,COMMAS,TOO

        A maximum of 20 user-defined environment variables can be defined.
        Each definition string (`KEY=value`) is limited to 4 KiB.
        All keys and values are converted to strings.
      )r   r   r>   z--set-env-vars)key_type
value_type
max_lengthrn   a(          Sets environment variables for the workflow based on a comma-separated
        list of key-value pairs. Will overwrite a workflow's existing
        environment variables.

        Example:
        gcloud workflows deploy ${workflow_name} --set-env-vars policy=global,retry_count=5
      )rq   rg   rp   r>   z--env-vars-file	FILE_PATH)r   r   a          Sets environment variables for the workflow to those stored in a local
        YAML file at the given path. All existing environment variables are
        removed before the new environment variables are added.

        Example:
        gcloud workflows deploy ${workflow_name} --env-vars-file=/path/to/env_vars.yaml

        Inside env_vars.yaml:

        policy: global

        retry_count: 5 # Service converts this to string "5"
      )rp   rq   r>   z--clear-env-varsrf   z        Clears all user-defined environment variables previously set for the
        workflow.

        Example:
        gcloud workflows deploy ${workflow_name} --clear-env-vars
      r   z--remove-env-varsKEY)element_typez        Removes user-defined environment variables from a workflow based
        on a list of environment variable keys to be removed.

        Example:
        gcloud workflows deploy ${workflow_name} --remove-env-vars policy,retry_count...
      )rp   rg   rq   r>   z--update-env-varsz        Updates existing or adds new user-defined environment variables based
        on a comma-separated list of key-value pairs.

        Example:
        gcloud workflows deploy ${workflow_name} --update-env-vars policy=regional,retry_count=2
      N)
r   r@   r   rs   strUSER_ENV_VARS_LIMITrt   r
   ArgDictFileArgList)r6   userenvvars_groups     r   AddUserEnvVarsFlagsr     s%   &&
 ' :   (
 %%
 ! &   =
	 ! $   
 ! 
   %%C0
 !    <%%
 ! r   c                 J    U R                   R                  R                  5       $ )z)Get and validate execution from the args.)CONCEPTSr!   Parser   s    r   ParseExecutionr     s    		 	 	&	&	((r   c                     [         R                  " SS5      R                  n[        R                  " XR
                  R                  5      $ )z0Get and validate execution labels from the args.workflowexecutionsv1)r   GetClientInstanceMESSAGES_MODULEr	   ParseCreateArgs	ExecutionLabelsValue)r   messagess     r   ParseExecutionLabelsr     s8    ##$8$?OO(		$	$T+=+=+I+I	JJr   c                 J    U R                   R                  R                  5       $ )z(Get and validate workflow from the args.)r   r   r   r   s    r   ParseWorkflowr     s    				%	%	''r   c                     U R                   (       a8   [        R                  " U R                   5      Ul        UR                  S5        gg! [        R                   a    [
        R                  " SS5      ef = f)aG  Set source for the workflow based on the arguments.

Also update updated_fields accordingly.
Currently only local source file is supported.

Args:
  args: Args passed to the command.
  workflow: The workflow in which to set the source configuration.
  updated_fields: A list to which an appropriate source field will be added.
r<   zspecified file does not exist.sourceContentsN)sourcer   ReadFileContentsr   MissingFileErrorr   BadArgumentExceptionr   r   s      r   	SetSourcer     sm     
[[ % 6 6t{{ Ch
 *+  !! ++
6 s   %A ,A7c                 d    U R                   b#  U R                   Ul         UR                  S5        gg)a  Set description for the workflow based on the arguments.

Also update updated_fields accordingly.

Args:
  args: Args passed to the command.
  workflow: The workflow in which to set the description.
  updated_fields: A list to which a description field will be added if needed.
Ndescription)r   r   r   s      r   SetDescriptionr     s1     
!++H-( "r   c                     U R                   bI  SnU R                   R                  S5      (       d  SnX0R                   -   Ul        UR                  S5        gg)a&  Set service account for the workflow based on the arguments.

Also update updated_fields accordingly.

Args:
  args: Args passed to the command.
  workflow: The workflow in which to set the service account.
  updated_fields: A list to which a service_account field will be added if
    needed.
N z	projects/zprojects/-/serviceAccounts/serviceAccount)service_account
startswithr   r   )r   r   r   prefixs       r   SetServiceAccountr   %  sV     
%F**;77,f$';';;H*+ &r   c                 :    U b  Xl         UR                  S5        gg)aP  Set labels for the workflow based on the arguments.

Also update updated_fields accordingly.

Args:
  labels: Labels parsed as string to be set on the workflow, or None in case
    the field shouldn't be set.
  workflow: The workflow in which to set the labels.
  updated_fields: A list to which a labels field will be added if needed.
Nlabels)r   r   )r   r   r   s      r   	SetLabelsr   8  s"     O(# r   c                 R    U c  gU [         L a  SOU Ul        UR                  S5        g)a<  Sets user-defined environment variables.

Also updates updated_fields accordingly.

Args:
  env_vars: Parsed environment variables to be set on the workflow.
  workflow: The workflow in which to set the User Envrionment Variables.
  updated_fields: A list to which the userEnvVars field will be added if
    needed.
NuserEnvVars)CLEAR_ENVIRONMENTr   r   )env_varsr   r   s      r   SetUserEnvVarsr   H  s-     
!)->!>H(&r   c                 ,   U c  g[         R                  " SS5      R                  R                  R                  nU" [        U R                  5       5       VVs/ s H  u  pEUR                  XES9PM     snnS9Ul        UR                  S5        gs  snnf )a?  Updates user-defined environment variables.

Also updates updated_fields accordingly.

Args:
  env_vars: Parsed environment variables to be set on the workflow.
  workflow: The workflow in which to set the User Envrionment Variables.
  updated_fields: A list to which the userEnvVars field will be added if
    needed.
N	workflowsr   rz   r}   r   )
r   r   r   WorkflowUserEnvVarsValuer   itemsr   r   r   )r   r   r   env_vars_clsr{   r|   s         r   UpdateUserEnvVarsr   Y  s     
''
 OHH--  & #8>>#344jc 
)
)c
)
?4( &s   B
):__doc__googlecloudsdk.api_lib.utilr   googlecloudsdk.callioper   r   r    googlecloudsdk.calliope.conceptsr   r   $googlecloudsdk.command_lib.util.argsr	   r
   (googlecloudsdk.command_lib.util.conceptsr   googlecloudsdk.corer   googlecloudsdk.core.utilr   r   r   r   r   objectr   r   r   r"   r*   r-   r8   r:   rB   rD   rF   rH   r]   rd   rh   rj   rl   rx   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   <module>r      s    1 - / ( . 5 1 < 9 D * * 
" 
2 
  H 		
 &.& $ &$	8.(* 3&>+jZ)
K(
,*),&$ '"'r   