
    d                     (   S r SSKJr  SSKJr  SSKJr  SSK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 rS rS rS9S jrS rS rS:S jrS r\R4                  R6                  SS4S jrS r\R4                  R6                  SS4S jrS rS r S r!S r"S;S jr#S r$S r%S  r&S! r'S<S" jr(S# r)S$ r*S% r+S& r,S' r-\R4                  R6                  4S( jr.S) r/S* r0S+ r1S, r2S- r3S. r4S/ r5S0 r6S<S1 jr7S2 r8S=S3 jr9S4 r:S5 r;S6 r<S7 r=S8 r>g)>z0Utilities for flags for `gcloud tasks` commands.    )absolute_import)division)unicode_literalsN)tasks)apis)arg_parsers)base)	constants)	arg_utilsc                 f   [         R                  " SSSS9n[         R                  " SSS9n[         R                  " SS	S9n[         R                  " S
SS9n[         R                  " SS9nUR                  U5        UR                  U5        UR                  U5        [         R                  " SSSSS9n[         R                  " SS9nUR                  U5        [         R                  " SSS9nUR                  U5        UR                  U5        UR	                  U 5        UR	                  U 5        g)zAdd flags for CMEK Update.z--kms-key-namezFully qualified identifier for the key or just the key ID. The latter requires that the --kms-keyring and --kms-project flags be provided too.Thelprequiredz--kms-keyringz4            KMS keyring of the KMS key.
            r   
--location?            Google Cloud location for the KMS key.
            z--kms-projectz>            Google Cloud project for the KMS key.
            z$Flags for Updating CMEK Resource keyz--clear-kms-key
store_truezDisables CMEK for Cloud Tasks in the specified location by clearing the Cloud KMS cryptokey from the Cloud Tasks project and CMEK configuration.)actionr   r   z%Flags for clearing CMEK Resource key.z,Flags for Clearing or Updating CMEK Resource)r   mutexN)r	   ArgumentArgumentGroupAddArgumentAddToParser)	parserkms_key_name_argkms_keyring_argkms_location_argkms_project_argcmek_update_groupclear_kms_key_name_flagcmek_clear_groupcmek_clear_update_groups	            -lib/googlecloudsdk/command_lib/tasks/flags.pyAddCmekConfigResourceFlagr$      sF    ]]  MM/ ]] MM/ ((1  0100 !MM	 ''2 67 !..9 %%&67%%&78v&%%f-    c                 R    [         R                  " SSSS9nUR                  U 5        g)zAdd flags for CMEK Describe.r   Tr   r   r   Nr	   r   r   )r   r   s     r#   DescribeCmekConfigResourceFlagr)   a   s.     ]] v&r%   c                 j    [         R                  " SSR                  U5      S9R                  U 5        g )NqueuezThe queue {}.

r   r	   r   formatr   r   verbs     r#   AddQueueResourceArgr0   o   s*    --188>?KKr%   TFc                 f    U(       a  SOSn[         R                  " SX1S9nUR                  U 5        g )NzThe queue the tasks belong to.zThe queue the task belongs to.z--queuer   r(   )r   r   plural_tasksdescriptionarguments        r#   AddQueueResourceFlagr5   u   s0      2&F ]]9;J(
vr%   c                 V    Sn[         R                  " SUSS9nUR                  U 5        g )Nz'The task ID for the task being created.z	--task-idFr   r(   )r   r3   r4   s      r#   AddTaskIdFlagr7   |   s'    :+]];[5I(
vr%   c                 ~    [         R                  " SSR                  U5      S9R                  U 5        [	        U SS9  g )NtaskzThe task {}.

r   Fr   )r	   r   r-   r   r5   r.   s     r#   AddTaskResourceArgsr;      s3    --%,,T244?K4Gv.r%   c                 \    Uc  Sn[         R                  " SSX!S9nUR                  U 5        g )NzThe location where we want to manage the queue or task. If not specified, uses the location of the current project's App Engine app if there is an associated app.r   F)hiddenr   r   r(   )r   r   helptextr4   s       r#   AddLocationFlagr?      s8    	- 
 ]]5xD(
vr%   c                 H    [        5        H  nUR                  U 5        M     g N)_PullQueueFlagsr   r   flags     r#   AddCreatePullQueueFlagsrE      s    dV  r%   c                 <   U[         R                  R                  :X  a  [        5       nO;[	        U5      nU[         R                  R
                  :X  a  U(       d  [        U 5        U(       a  U[        5       -  n[        U SS9  U H  nUR                  U 5        M     g)z%Creates flags related to Push queues.T)is_email_requiredN)
r	   ReleaseTrackALPHA_AlphaPushQueueFlags_PushQueueFlagsBETAAddQueueTypeFlag_HttpPushQueueFlags_AddHttpTargetAuthFlagsr   r   release_trackapp_engine_queue
http_queueflagsrD   s         r#   AddCreatePushQueueFlagsrU      s|     d''--- "EM*E))... 	 ""EFd;dV r%   c                 <    [        5        H  n[        X5        M     g rA   )rB   _AddFlagAndItsClearEquivalentrC   s     r#   AddUpdatePullQueueFlagsrX      s    d!$/  r%   c                 2   U[         R                  R                  :X  a  [        5       nO;[	        U5      nU[         R                  R
                  :X  a  U(       d  [        U 5        U(       a  U[        5       [        5       -   -  nU H  n[        XP5        M     g)z%Updates flags related to Push queues.N)
r	   rH   rI   rJ   rK   rL   rM   rN   rO   rW   rP   s         r#   AddUpdatePushQueueFlagsrZ      sw     d''--- "EM*E))...  	 "%<%>>>Ed!$/ r%   c                     [         R                  " SS9nUR                  U 5        UR                  [        U 5      5        UR	                  U5        g )NT)r   )r	   r   r   _EquivalentClearFlagr   )rD   r   update_groups      r#   rW   rW      sB    ##$/,4 /566"r%   c                     U R                   R                  SS5      n[        R                  " USSR	                  U R                   5      S9nU$ )Nz--z--clear-r   z,      Clear the field corresponding to `{}`.r   r   )namereplacer	   r   r-   )rD   r`   
clear_flags      r#   r\   r\      sG    			4	,$}}
< '006tyy0AC* 
r%   c                 L    [         R                  " SSS9R                  U 5        g )Npolicy_filez2      JSON or YAML file containing the IAM policy.r   r(   r   s    r#   AddPolicyFileFlagrf      s    -- %6 77B{67Jr%   c                 l    [         R                  " SSSR                  U5      S9R                  U 5        g )N--schedule-timeTzy      The task's current schedule time. This restriction is to check that the
      caller is {} the correct task.
      r'   r,   r.   s     r#   AddTaskLeaseScheduleTimeFlagri      s/    --$
 &,
 $F+r%   c                 b    Uc  Sn[         R                  " SS[        US9R                  U 5        g )NzrThe number of seconds for the desired new lease duration, starting from now. The maximum lease duration is 1 week.z--lease-durationT)r   typer   )r	   r   intr   )r   r>   s     r#   AddTaskLeaseDurationFlagrm      s0    KH--"T*{62r%   c                 v    [         R                  " S[        S[         R                  SS9R	                  U 5        g )Nz--limiti  zc      The maximum number of tasks to lease. The maximum that can be requested is
      1000.
      )rk   defaultcategoryr   )r	   r   rl   LIST_COMMAND_FLAGSr   re   s    r#   AddMaxTasksToLeaseFlagrr      s.    --c4$2I2I

 ;vr%   c                 `    [         R                  " S[        5       SSS9R                  U 5        g )Nz--typepushz{      Specifies the type of queue. Only available options are 'push' and
      'pull'. The default option is 'push'.
      )rk   ro   r   )r	   r   _GetQueueTypeArgValidatorr   re   s    r#   rM   rM      s+    --$&
	 ;vr%   c                 f    U R                  5       nUR                  SSS9  UR                  SSSS9  g )N--tagz      A tag to filter each task to be leased. If a task has the tag and the
      task is available to be leased, then it is listed and leased.
      r   z--oldest-tagr   zf      Only lease tasks which have the same tag as the task with the oldest
      schedule time.
      r_   add_mutually_exclusive_groupadd_argument)r   tag_filter_groups     r#   AddFilterLeasedTasksFlagr|     sF    88: /
  | K
 r%   c                     [        U SS9  [        5       R                  U 5        [        5        H  nUR                  U 5        M     [	        U S5        g)z8Add flags needed for creating a pull task to the parser.Tr:   N)r5   _GetTaskIdFlagr   _PullTaskFlags_AddPayloadFlagsrC   s     r#   AddCreatePullTaskFlagsr     sB    v-v&dV 64 r%   c                     [        U SS9  [        5       R                  U 5        U(       a
  [        5       O	[	        5       nU H  nUR                  U 5        M     [        X5        g)z>Add flags needed for creating a App Engine task to the parser.Tr:   N)r5   r~   r   _AlphaAppEngineTaskFlags_AppEngineTaskFlagsr   )r   is_alpharT   rD   s       r#   AddCreateAppEngineTaskFlagsr     sN    v-v&(0
"
$6I6K%dV 6$r%   c                     [        U SS9  [        5       R                  U 5        [        5        H  nUR                  U 5        M     [	        U 5        [        U 5        g)z8Add flags needed for creating a HTTP task to the parser.Tr:   N)r5   r~   r   _HttpTaskFlagsr   _AddAuthFlagsrC   s     r#   AddCreateHttpTaskFlagsr   &  sH    v-v&dV 6r%   c            	          [         R                  " S[        R                  " S[        R
                  SS9SS9[         R                  " SSS	9/$ )
Nz--max-attemptsT)	unlimitedzJ          The maximum number of attempts per task in the queue.
          rk   r   z--max-retry-durationai            The time limit for retrying a failed task, measured from when the task
          was first run. Once the `--max-retry-duration` time has passed and the
          task has been attempted --max-attempts times, no further attempts will
          be made and the task will be deleted.

          Must be a string that ends in 's', such as "5s".
          r   )r	   r   r   
BoundedIntsysmaxsize r%   r#   rB   rB   0  sL    
mm
%%b#++F mm
 	
 r%   c                  `   [        5       [        R                  " S[        SS9[        R                  " SSS9[        R                  " SSS9[        R                  " S	[        R
                  " [        5       S
SSS 0S9SSR                  SR                  [        R                  5      5      S9/-   $ )Nz--max-doublingsa            The time between retries will double maxDoublings times.

          A tasks retry interval starts at minBackoff, then doubles maxDoublings
          times, then increases linearly, and finally retries retries at
          intervals of maxBackoff up to maxAttempts times.

          For example, if minBackoff is 10s, maxBackoff is 300s, and
          maxDoublings is 3, then the a task will first be retried in 10s. The
          retry interval will double three times, and then increase linearly by
          2^3 * 10s. Finally, the task will retry at intervals of maxBackoff
          until the task has been attempted maxAttempts times. Thus, the
          requests will retry at 10s, 20s, 40s, 80s, 160s, 240s, 300s, 300s.
          r   z--min-backoffz          The minimum amount of time to wait before retrying a task after it
          fails. Must be a string that ends in 's', such as "5s".
          r   z--max-backoffz          The maximum amount of time to wait before retrying a task after it
          fails. Must be a string that ends in 's', such as "5s".
          z--routing-override      :key_type
min_length
max_length	operators	KEY:VALUEz          If provided, the specified App Engine route is used for all tasks
          in the queue, no matter what is set is at the task-level.

          KEY must be at least one of: [{}]. Any missing keys will use the
          default.
          , rk   metavarr   )rB   r	   r   rl   r   ArgDict!_GetAppEngineRoutingKeysValidatorr-   joinr
   APP_ENGINE_ROUTING_KEYSr   r%   r#   _BasePushQueueFlagsr   G  s    		
mm
" mm
 mm
 mm
""8:d	%
  fTYYy@@ABD=- -
 -r%   c                      [        5       [        R                  " S[        SS9[        R                  " S[        SS9/-   $ )Nz!--max-tasks-dispatched-per-secondT          The maximum rate at which tasks are dispatched from this queue.
          r   z--max-concurrent-tasks            The maximum number of concurrent tasks that Cloud Tasks allows to
          be dispatched for this queue. After this threshold has been reached,
          Cloud Tasks stops dispatching tasks until the number of outstanding
          requests decreases.
          )r   r	   r   floatrl   r   r%   r#   rJ   rJ   x  sG    		
mm
- mm
"" 
 r%   c            
      .   [         R                  " S[        R                  " [	        5       SSSS 0S9SSR                  SR                  [        R                  5      5      S	9[         R                  " S
SS9[         R                  " SSS[        5       SS9/$ )Nz--http-uri-overrider      r   r   r   ag            If provided, the specified HTTP target URI override is used for all
          tasks in the queue depending on what is set as the mode.
          Allowed values for mode are: ALWAYS, IF_NOT_EXISTS. If not set, mode
          defaults to ALWAYS.

          KEY must be at least one of: [{}]. Any missing keys will use the
          default.
          r   r   z--http-method-overridez          If provided, the specified HTTP method type override is used for
          all tasks in the queue, no matter what is set at the task-level.
          r   z--http-header-overrideHEADER_FIELD: HEADER_VALUEappenda!            If provided, the specified HTTP headers override the existing
          headers for all tasks in the queue.
          If a task has a header with the same Key as a queue-level header
          override, then the value of the task header will be overriden with
          the value of the queue-level header. Otherwise, the queue-level
          header will be added to the task headers.
          Header values can contain commas. This flag can be repeated.
          Repeated header fields will have their values overridden.
          r   r   rk   r   )
r	   r   r   r    _GetHttpUriOverrideKeysValidatorr-   r   r
   HTTP_URI_OVERIDE_KEYS_GetHeaderArgValidatorr   r%   r#   rN   rN     s    
mm
""79d	%
  fTYYy>>?@!B" mm
" mm
".%'	1' 'r%   c                 N   [        5       [        R                  " S[        SS9[        R                  " S[        SS9/-   nU [        R
                  R                  :X  d  U [        R
                  R                  :X  a)  UR                  [        R                  " S[        SS95        U$ )z$Returns flags needed by push queues.z--max-dispatches-per-secondr   r   z--max-concurrent-dispatchesr   z--log-sampling-ratioz        Specifies the fraction of operations to write to Cloud Logging.
        This field may contain any value between 0.0 and 1.0, inclusive. 0.0 is
        the default and means that no operations are logged.
        )	r   r	   r   r   rl   rH   rL   GAr   )rQ   rT   s     r#   rK   rK     s    


mm
' mm
'# %" d'',,,ARARAUAU0U	LL  
,r%   c                  D    [        5       [        R                  " SSS9/-   $ )Nrw   zC          An optional label used to group similar tasks.
          r   )_CommonTaskFlagsr	   r   r   r%   r#   r   r     s*    		
mmG #  
 r%   c            
          [        5       [        R                  " SSS9[        R                  " SSS[        5       SS9/-   $ )	Nz--methodzm          The HTTP method to use for the request. If not specified, "POST" will
          be used.
          r   z--headerr   r   z          An HTTP request header. Header values can contain commas. This flag
          can be repeated. Repeated header fields will have their values
          overridden.
          r   )r   r	   r   r   r   r%   r#   _BasePushTaskFlagsr     sK    		
mmJ &  mmJ(D#*@*B 
 r%   c                  F    [        5       [        R                  " SSSS9/-   $ )N--urlTz          The full URL path that the request will be sent to. This string must
          begin with either "http://" or "https://".
          r'   )r   r	   r   r   r%   r#   r   r     s,    		
mmGd 2 ! 
 r%   c                      [        5       [        R                  " S[        R                  " [        5       SSSS 0S9SSR                  SR                  [        R                  5      5      S	9/-   $ )
Nz	--routingr   r   r   r   r   z          The route to be used for this task. KEY must be at least one of:
          [{}]. Any missing keys will use the default.

          Routing can be overridden by the queue-level `--routing-override`
          flag.
          r   r   )
r   r	   r   r   r   r   r-   r   r
   r   r   r%   r#   _BaseAppEngineTaskFlagsr     sl    		
mm
"",M,O./A.14[:  fTYYy@@ABD! 
 r%   c                  D    [        5       [        R                  " SSS9/-   $ )Nr   z          The relative URL of the request. Must begin with "/" and must be a
          valid HTTP relative URL. It can contain a path and query string
          arguments. If not specified, then the root path "/" will be used.
          r   r   r	   r   r   r%   r#   r   r   	  s*    	 	"
mmG # & 
 r%   c                  D    [        5       [        R                  " SSS9/-   $ )Nz--relative-uriz          The relative URI of the request. Must begin with "/" and must be a
          valid HTTP relative URI. It can contain a path and query string
          arguments. If not specified, then the root path "/" will be used.
          r   r   r   r%   r#   r   r     s+    	 	"
mm$ , & 
 r%   c                  0    [         R                  " SSSSS9$ )Nr9   TASK_ID?a4        The task to create.

      If not specified then the system will generate a random unique task
      ID. Explicitly specifying a task ID enables task de-duplication. If a
      task's ID is identical to that of an existing task or a task that was
      deleted or completed recently then the call will fail.

      Because there is an extra lookup cost to identify duplicate task
      names, tasks created with IDs have significantly increased latency.
      Using hashed strings for the task ID or for the prefix of the task ID
      is recommended.
      )r   nargsr   r	   r   r   r%   r#   r~   r~     s!    	
	
 r%   c                  .    [         R                  " SSS9/$ )Nrh   z}          The time when the task is scheduled to be first attempted. Defaults to
          "now" if not specified.
          r   r   r   r%   r#   r   r   1  s     
mm% - 
 r%   c                     U R                  5       nU(       a!  UR                  SSS9  UR                  SSS9  g
UR                  SSS9  UR                  SS	S9  g
)z"Adds either payload or body flags.z--payload-contentzR            Data payload used by the task worker to process the task.
            r   z--payload-filezn            File containing data payload used by the task worker to process the
            task.
            z--body-contentzT            HTTP Body data sent to the task worker processing the task.
            z--body-filezp            File containing HTTP body data sent to the task worker processing
            the task.
            Nrx   )r   r   payload_groups      r#   r   r   :  s|    557-2 :  / 7 
 / 7  } 4 r%   c                     U R                  SS9nUR                  SS9nUR                  SSSS9  UR                  SS	S9  UR                  S
S9nUR                  SSSS9  UR                  SSS9  g)Add flags for http auth.zx            How the request sent to the target when executing the task should be
            authenticated.
            r   OpenId Connectz--oidc-service-account-emailTu              The service account email to be used for generating an OpenID
            Connect token to be included in the request sent to the target when
            executing the task. The service account must be within the same
            project as the queue. The caller must have
            'iam.serviceAccounts.actAs' permission for the service account.
            r'   z--oidc-token-audience              The audience to be used when generating an OpenID Connect token to
            be included in the request sent to the target when executing the
            task. If not specified, the URI specified in the target will be
            used.
            OAuth2z--oauth-service-account-emailt              The service account email to be used for generating an OAuth2 access
            token to be included in the request sent to the target when
            executing the task. The service account must be within the same
            project as the queue. The caller must have
            'iam.serviceAccounts.actAs' permission for the service account.
            z--oauth-token-scope              The scope to be used when generating an OAuth2 access token to be
            included in the request sent to the target when executing the task.
            If not specified, 'https://www.googleapis.com/auth/cloud-platform'
            will be used.
            N)ry   add_argument_grouprz   )r   
auth_group
oidc_groupoauth_groups       r#   r   r   O  s    22 92 * ,,2B,C*84    1 9  --8-<+:T!   0 8 r%   c                 $   [         R                  " SSS9n[         R                  " SS9n[         R                  " SUSS9nUR                  U5        [         R                  " S	S
S9nUR                  U5        [         R                  " SS9n[         R                  " SUSS9nUR                  U5        [         R                  " SSS9nUR                  U5        UR                  U5        UR                  U5        U b  UR	                  U 5        XEXx/$ )r   Tz            If specified, all `Authorization` headers in the HttpRequest.headers
            field will be overridden for any tasks executed on this queue.
            )r   r   r   r   z*--http-oidc-service-account-email-overrider   r'   z#--http-oidc-token-audience-overrider   r   z+--http-oauth-service-account-email-overrider   z!--http-oauth-token-scope-overrider   )r	   r   r   r   r   )	r   rG   r   r   oidc_email_argoidc_token_argr   oauth_email_argoauth_scope_args	            r#   rO   rO   u  s   !!* !!'78*==2 	. (==+. (""1+MM3 	/ /*MM)/ /*$%6"
/	KKr%   c                      [         R                  " S SR                  SR                  [        R
                  5      5      5      $ )Nc                 (    U [         R                  ;   $ rA   )r
   r   ks    r#   <lambda>3_GetAppEngineRoutingKeysValidator.<locals>.<lambda>  s    Y666r%   4Only the following keys are valid for routing: [{}].r   )r   CustomFunctionValidatorr-   r   r
   r   r   r%   r#   r   r     s8    		,	,6<CC
))I55
68
9 9r%   c                      [         R                  " S SR                  SR                  [        R
                  5      5      5      $ )Nc                 (    U [         R                  ;   $ rA   )r
   r   r   s    r#   r   2_GetHttpUriOverrideKeysValidator.<locals>.<lambda>  s    Y444r%   r   r   )r   r   r-   r   r
   r   r   r%   r#   r   r     s8    		,	,4<CC
))I33
46
7 7r%   c                      [         R                  " S SR                  SR                  [        R
                  5      5      5      $ )Nc                 (    U [         R                  ;   $ rA   )r
   VALID_QUEUE_TYPESr   s    r#   r   +_GetQueueTypeArgValidator.<locals>.<lambda>  s    Y000r%   z/Only the following queue types are valid: [{}].r   )r   r   r-   r   r
   r   r   r%   r#   ru   ru     s8    		,	,07>>
))I//
02
3 3r%   c                  0    [         R                  " SS5      $ )Nz^(\S+):(.+)$z2Must be of the form: "HEADER_FIELD: HEADER_VALUE".)r   RegexpValidatorr   r%   r#   r   r     s    		$	$K
M Mr%   c           	          [         R                  " S[        R                  " [        R
                  [        R                  " U 5      5      R                  R                  SSS9$ )Nz--response-viewbasiczTask response view.)ro   help_str)	r   ChoiceEnumMapperr   GetMessagesModuletasks_api_libAPI_NAMEApiVersionFromReleaseTrack0CloudtasksProjectsLocationsQueuesTasksGetRequestResponseViewValueValuesEnum)rQ   s    r#   GetTaskResponseViewMapperr     sU    		#	#


 
 

2
2 ON""$
& &r%   )TF)FNrA   )F)NF)?__doc__
__future__r   r   r   r   googlecloudsdk.api_libr   r   googlecloudsdk.api_lib.utilr   googlecloudsdk.callioper   r	    googlecloudsdk.command_lib.tasksr
   $googlecloudsdk.command_lib.util.apisr   r$   r)   r0   r5   r7   r;   r?   rE   rH   r   rU   rX   rZ   rW   r\   rf   ri   rm   rr   rM   r|   r   r   r   rB   r   rJ   rN   rK   r   r   r   r   r   r   r~   r   r   r   rO   r   r   ru   r   r   r   r%   r#   <module>r      sF   7 &  ' 
 9 , / ( 6 :?.D'/	 ##&&	00 ##&&	0.#K
,3	!%..b((V #'"3"3"6"6 > $(*#L;L|973M
	&r%   