
    Q                        d Z ddlmZ ddlmZ ddlmZ ddlmZ ddlmZ ddlm	Z	 ddl
Z
g d	Z G d
 de	j                        Z G d de	j                        Z G d de	j                        Z G d de	j                        Z G d de      Z G d de      Z G d de      Z G d de      Z	 	 	 	 	 	 	 ddZd Zd Zd Zy)z$API Library for gcloud tasks queues.    )absolute_import)division)unicode_literals)encoding)
list_pager)
exceptionsN)httpTarget.headerOverrideshttpTarget.httpMethod)httpTarget.oauthToken.serviceAccountEmailhttpTarget.oauthToken.scope(httpTarget.oidcToken.serviceAccountEmailhttpTarget.oidcToken.audiencehttpTarget.uriOverridec                       e Zd ZdZy)"CreatingPullAndAppEngineQueueErrorzEError for when attempt to create a queue as both pull and App Engine.N__name__
__module____qualname____doc__     *lib/googlecloudsdk/api_lib/tasks/queues.pyr   r   &   s    Mr   r   c                       e Zd ZdZy)"CreatingHttpAndAppEngineQueueErrorzOError for when attempt to create a queue with both http and App Engine targets.Nr   r   r   r   r   r   *   s    Wr   r   c                       e Zd ZdZy)NoFieldsSpecifiedErrorz?Error for when calling a patch method with no fields specified.Nr   r   r   r   r   r   .   s    Gr   r   c                       e Zd ZdZy)RequiredFieldsMissingErrorzKError for when calling a patch method when a required field is unspecified.Nr   r   r   r   r   r   2   s    Sr   r   c                   H    e Zd ZdZd Zd ZddZd Zd Zd Z	d	 Z
d
 Zd Zy)
BaseQueues1Client for queues service in the Cloud Tasks API.c                      || _         || _        y N)messagesqueues_service)selfr%   r&   s      r   __init__zBaseQueues.__init__9   s    DM(Dr   c                     | j                   j                  |j                               }| j                  j	                  |      S Nname)r%   +CloudtasksProjectsLocationsQueuesGetRequestRelativeNamer&   Getr'   	queue_refrequests      r   r/   zBaseQueues.Get=   sA    mmGG##% H G ""7++r   Nc                     | j                   j                  |j                               }t        j                  | j
                  |||dd      S )N)parentqueuespageSize)
batch_sizelimitfieldbatch_size_attribute)r%   ,CloudtasksProjectsLocationsQueuesListRequestr.   r   YieldFromListr&   )r'   
parent_refr8   	page_sizer2   s        r   ListzBaseQueues.ListC   sU    mmHH&&( I G ##' r   c                     | j                   j                  |j                               }| j                  j	                  |      S r*   )r%   .CloudtasksProjectsLocationsQueuesDeleteRequestr.   r&   Deleter0   s      r   rB   zBaseQueues.DeleteP   A    mmJJ##% K G %%g..r   c                     | j                   j                  |j                               }| j                  j	                  |      S r*   )r%   -CloudtasksProjectsLocationsQueuesPurgeRequestr.   r&   Purger0   s      r   rF   zBaseQueues.PurgeV   A    mmII##% J G $$W--r   c                     | j                   j                  |j                               }| j                  j	                  |      S r*   )r%   -CloudtasksProjectsLocationsQueuesPauseRequestr.   r&   Pauser0   s      r   rJ   zBaseQueues.Pause\   rG   r   c                     | j                   j                  |j                               }| j                  j	                  |      S r*   )r%   .CloudtasksProjectsLocationsQueuesResumeRequestr.   r&   Resumer0   s      r   rM   zBaseQueues.Resumeb   rC   r   c                     | j                   j                  |j                               }| j                  j	                  |      S )N)resource)r%   4CloudtasksProjectsLocationsQueuesGetIamPolicyRequestr.   r&   GetIamPolicyr0   s      r   rQ   zBaseQueues.GetIamPolicyh   sD    JJ++- 	K 	
 
 ++G44r   c                     | j                   j                  |j                         | j                   j                  |            }| j                  j                  |      S )N)policy)rO   setIamPolicyRequest)r%   4CloudtasksProjectsLocationsQueuesSetIamPolicyRequestr.   SetIamPolicyRequestr&   SetIamPolicy)r'   r1   rS   r2   s       r   rW   zBaseQueues.SetIamPolicyp   s_    JJ++- $ A A !B ! 	K 	
  ++G44r   )Nd   )r   r   r   r   r(   r/   r?   rB   rF   rJ   rM   rQ   rW   r   r   r   r!   r!   6   s2    9),/../5	5r   r!   c                   @    e Zd ZdZ	 	 	 	 	 ddZ	 	 	 	 	 	 	 	 	 	 	 ddZy)Queuesr"   Nc                    ||f}t        |D 	cg c]  }	|	dnd
 c}	      dkD  rAt        dj                  t        j                  |      t        j                  |                  | j
                  j                  |j                         |||||      }
| j
                  j                  |j                         |
      }| j                  j                  |      S c c}	w )9Prepares and sends a Create request for creating a queue.   r   FAttempting to send multiple queue target types simultaneously: {} , {})r,   retryConfig
rateLimitsappEngineRoutingOverridestackdriverLoggingConfig
httpTargetr4   queue)sumr   formatsix	text_typer%   Queuer.   .CloudtasksProjectsLocationsQueuesCreateRequestr&   Create)r'   r=   r1   retry_configrate_limitsapp_engine_routing_overridestackdriver_logging_confighttp_targettargetsxre   r2   s               r   rl   zQueues.Create   s     +K8G
w7w!AA%w781<.&mm78mmK(  MM##% !<!;   E mmJJ&&( K G %%g..) 8s   Cc                 N   t        |||g      s)|s'd|vr#t        |||	|
|||gt        |      rt        d      | j                  j                  |j                               }|||_        |||_        |2t        |      r | j                  j                         |_        n||_        |||_        t        | j                  |||||	|
|||
       dj                  |      }| j                  j                  |j                         ||      }| j                   j#                  |      S )9Prepares and sends a Patch request for modifying a queue.ra   *Must specify at least one field to update.r+   ,r,   re   
updateMask)any_NeitherUpdateNorClearhttp_target_update_masks_listr   r%   rj   r.   r_   r`   _IsEmptyConfigAppEngineRoutingra   rb   _GenerateHttpTargetUpdateMaskjoin-CloudtasksProjectsLocationsQueuesPatchRequestr&   Patch)r'   r1   updated_fieldsrm   rn   ro   rp   http_uri_overridehttp_method_overridehttp_header_overridehttp_oauth_email_overridehttp_oauth_scope_overridehttp_oidc_email_overridehttp_oidc_audience_overridere   update_maskr2   s                    r   r   zQueues.Patch   sT   " k+EFG *(>"""''&) (
 %8
 	
 MMY%;%;%=>E&e$e".	3	4)-)G)G)I&)D&!-'Ae$ "!! # ((>*KmmII##%U{ J G $$W--r   NNNNN)NNNNNNNNNNNr   r   r   r   rl   r   r   r   r   rZ   rZ   |   sE    9 "&!% /L "&!% $ $#"&I.r   rZ   c                   H    e Zd ZdZ	 	 	 	 	 	 ddZ	 	 	 	 	 	 	 	 	 	 	 	 	 	 ddZy)
BetaQueuesr"   Nc	                 
   |duxr |j                   du}	|du}
|	rC|
rAt        dj                  t        j                  |      t        j                  |                  |
r0| j
                  j                  |j                         |||||      }n/| j
                  j                  |j                         |||||      }| j
                  j                  |j                         |      }| j                  j                  |      S )r\   Nr^   )r,   r_   r`   rb   typerc   )r,   r_   r`   appEngineHttpQueuerb   r   rd   )ra   r   rg   rh   ri   r%   rj   r.   rk   r&   rl   )r'   r=   r1   rm   rn   app_engine_http_queuerp   
queue_typerq   is_app_engine_target_setis_http_target_setre   r2   s                r   rl   zBetaQueues.Create   s   " 	T) 	G!::$F 
 %D0$6.&mm12CMM+4N  mm!!%%'" #=  " e mm!!%%'" 2#= " e mmJJ&&( K G %%g..r   c                    |	r|	|	j                   k7  rd}	t        |||||g      s2t        |gdg|      r#t        |
||||||gt        |      rt	        d      | j
                  j                  |j                         |	      }|||_        |||_	        |||_
        |||_        |||_        |Lt        |      r | j
                  j                         |_        n!| j
                  j                  |      |_        t!        | j
                  |||
||||||
       dj#                  |      }| j
                  j%                  |j                         ||      }| j&                  j)                  |      S )ru   Nra   rv   )r,   r   ra   rw   rx   )PULLrz   r{   r|   r   r%   rj   r.   r_   r`   taskTtltombstoneTtlrb   r}   AppEngineHttpQueuer   r   r   r   r&   r   )r'   r1   r   rm   rn   ro   task_ttltask_tombstone_ttlrp   r   r   r   r   r   r   r   r   re   r   r2   s                       r   r   zBetaQueues.Patch&  s   , jJOO3j"  
 &
'%
&

 #""''&) (
 %8
 	
 MMY%;%;%=JOE&e$eem%-e!-'Ae$".	3	4#'==#C#C#E #'==#C#C%@ $D $
 
 "!! # ((>*KmmII##%U{ J G $$W--r   )NNNNNN)NNNNNNNNNNNNNNr   r   r   r   r   r      sQ    9  !%4/t "&!% $ $#"&#b.r   r   c                   >    e Zd ZdZ	 	 	 	 	 ddZ	 	 	 	 	 	 	 	 	 	 ddZy)AlphaQueuesr"   Nc                 *   ||f}t        |D 	cg c]  }	|	dnd
 c}	      dkD  rAt        dj                  t        j                  |      t        j                  |                  |||f}t        |D 	cg c]  }	|	dnd
 c}	      dkD  rt        d      | j                  j                  |j                         |||||      }
| j                  j                  |j                         |
      }| j                  j                  |      S c c}	w c c}	w )r\   r]   r   r^   z=Attempting to send multiple queue target types simultaneously)r,   r_   r`   
pullTargetappEngineHttpTargetrc   rd   )rf   r   rg   rh   ri   r   r%   rj   r.   rk   r&   rl   )r'   r=   r1   rm   rn   pull_targetapp_engine_http_targetrq   rr   rs   re   r2   s               r   rl   zAlphaQueues.Create  s.    &{3G
w7w!AA%w781<.&mm23S]];5O  2K@G
w7w!AA%w781<.
I  MM##% 2   E mmJJ&&( K G %%g..1 8 8s   D4Dc                    t        ||g      s2t        |gdg|      r#t        ||||	|
||gt        |      rt        d      | j                  j                  |j                               }|||_        |||_        |Lt        |      r | j                  j                         |_        n!| j                  j                  |      |_        t        | j                  ||||||	|
||
       dj                  |      }| j                  j                  |j                         ||      }| j                  j!                  |      S )ru   ra   rv   r+   r   rw   rx   )rz   r{   r|   r   r%   rj   r.   r_   r`   r}   AppEngineHttpTargetr   r   r   r   r&   r   )r'   r1   r   rm   rn   ro   r   r   r   r   r   r   r   re   r   r2   s                   r   r   zAlphaQueues.Patch  si   " k*+ 
 &
'%
&

 #""''&) (
 %8
 	
 MMY%;%;%=>E&e$e".	3	4$(MM$E$E$G!$(MM$E$E%@ %F %
! "!! # ((>*KmmII##%U{ J G $$W--r   r   )
NNNNNNNNNNr   r   r   r   r   r     sB    9 !%/V "& $ $#"&L.r   r   c
                    t        |      r3| j                         }
d|v r||
_        d|v r||
_        d|v rv|g |
_        nlg }|D ]^  }| j                  | j                  |j                  j                  |j                  j                              }|j                  |       ` ||
_        d|v sd|v r7d|vs||t        d	      |
|d|
_        n| j                  ||
      |
_        d|v sd|v r7d|vs||	t        d      |
|	d|
_        n| j                  ||	      |
_        t!        |
      rdn|
|_        yy)zDA helper function to generate update mask given the override config.r   r
   r	   N)keyvalue)headerr   r   zTOauth service account email (http-oauth-service-account-email-override) must be set.)serviceAccountEmailscoper   r   zROidc service account email (http-oidc-service-account-email-override) must be set.)r   audience)_HttpTargetNeedsUpdate
HttpTargeturiOverride
httpMethodheaderOverridesHeaderOverrideHeaderr   r   r   appendr   
oauthToken
OAuthToken	oidcToken	OidcTokenr}   rc   )r%   re   r   r   r   r   r   r   r   r   rq   headers_listhoheader_overrides                 r   r   r     s    N+%%'K>1 1k.03k#~5		%&(#&B$33__biioo_N 4 / 

o
.	 '
 '3# 	4~E(N: 
5N	J
#
+'3 )H
 	

 $
+'/!%!)!4!4 9+ "5 "
 	3nD*n< 
4>	I
"
*)5(G
 	

 #
*)1 $ ( 2 2 80 !3 !

  .k:tES ,r   c                 &    t         D ]  }|| v s y y)NTF)r|   )r   masks     r   r   r   ^  s    +d~ , 
r   c                 V    t        d | D              xr t        fd|D               S )Nc              3   $   K   | ]  }|d u  
 y wr$   r   ).0items     r   	<genexpr>z)_NeitherUpdateNorClear.<locals>.<genexpr>g  s     4mdTT\ms   c              3   &   K   | ]  }|v  
 y wr$   r   )r   r   available_maskss     r   r   z)_NeitherUpdateNorClear.<locals>.<genexpr>g  s      A*7$do-s   )allrz   )update_valuesr   update_fieldss    ` r   r{   r{   f  s6    	4m4	4 
S A*7A > : r   c                 f    | yt        j                  |       }t        |j                                S )NT)r   MessageToDictrz   values)configconfig_dicts     r   r}   r}   l  s1    ^&&v.+##%&	&&r   )NNNNNNN)r   
__future__r   r   r   apitools.base.pyr   r   googlecloudsdk.corer   rh   r|   InternalErrorr   r   Errorr   r   objectr!   rZ   r   r   r   r   r{   r}   r   r   r   <module>r      s    + &  ' % ' * 
! N)A)A NX)A)A XHZ-- HT!1!1 TC5 C5Ln.Z n.b[. [.|v.* v.z ""! $WLt'r   