
    D                       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rSSKrSSKrSSK	r	SSK
r
SSK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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%  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,J0r0  SSK,J1r1  SSK,J2r2  SS K,J3r3  SS!K,J4r4  SS"K5J6r6  SS#K5J7r7  SS	K8Jr  SS$K8J9r9  SS%K8J:r:  SS&K8J;r;  SS'K8J<r<  SS(K=J>r>  SS)K?J@r@  SS*KAJBrB  SSKCrCS+rDS,rES-rFS.rGS//rHS0rI " S1 S2\R                  5      rK\R                  SBS3 j5       rMS4 rN\R                  " S5S69 " S7 S8\.R                  5      5       rQ " S9 S:\.R                  5      rSS; rT\R                  " S5S69 " S< S=\.R                  5      5       rU\R                  " S5S69 " S> S?\.R                  5      5       rV " S@ SA\W5      rXg)CzGAllows you to write surfaces in terms of logical Serverless operations.    )absolute_import)division)print_function)unicode_literalsN)List)encoding)
exceptions)
list_pager)	condition)configuration)domain_mapping)	execution)global_methods)job)metric_names)revision)route)service)taskworker_pool)apis)apis_internal)waiter)base)iam_util)config_changes)messages_util)name_generator)
op_pollers)resource_name_conversion)stages)deployer)sources)log)metrics)
properties)	resources)progress_tracker)universe_descriptor)retryv1
   allUserszroles/run.invokerzrun.services.setIamPolicyzGsha256:fd2fdc0ac4a07f8d96ebe538566331e9da0f4bea069fb88de981cd8054b8cabcc                       \ rS rSrSrg)UnknownAPIErrorX    N)__name__
__module____qualname____firstlineno____static_attributes__r2       ;lib/googlecloudsdk/command_lib/run/serverless_operations.pyr0   r0   X   s    r8   r0   c              #   z  #    [         R                  " U R                  U R                  US9nU  nU R                  (       a  [         R
                  " U5      OSn[        R                  " UR                  UR                  UU R                  5       S9n[        UUU5      v   SSS5        g! , (       d  f       g= f7f)a  Provide a ServerlessOperations instance to use.

If we're using the GKE Serverless Add-on, connect to the relevant cluster.
Otherwise, connect to the right region of GSE.

Arguments:
  conn_context: a context manager that yields a ConnectionInfo and manages a
    dynamic context that makes connecting to serverless possible.
  already_activated_service: bool that should be true if we already checked if
    the run.googleapis.com service was enabled. If this is true, we skip
    prompting the user to enable the service because they should have already
    been prompted if the API wasn't activated.

Yields:
  A ServerlessOperations instance.
)skip_activation_promptN)check_response_funchttp_client)
r   GetClientInstanceapi_nameapi_versionsupports_one_platformCheckResponser   _GetClientInstance
HttpClientServerlessOperations)conn_contextalready_activated_service	op_client	conn_inforesponse_funcclients         r9   ConnectrL   \   s     2 $$6) y -- 	45  --) ++-F   ||s   -B;A2B*!	B;*
B84B;c                  L    SR                  S [        [        5       5       5      $ )zAReturn a random string with unlikely collision to use as a nonce. c              3   j   #    U  H)  n[         R                  " [        R                  5      v   M+     g 7fN)randomchoicestringascii_lowercase).0_s     r9   	<genexpr>_Nonce.<locals>.<genexpr>   s&      5IfmmF**++5Is   13)joinrange_NONCE_LENGTHr2   r8   r9   _Noncer\      s%    	 5:=5I 
 r8   T)frozenc                   *    \ rS rSr% Sr\\S'   S rSrg)_NewRevisionNonceChange   zEForces a new revision to get created by posting a random nonce label.noncec                     U R                   UR                  R                  [        R                  '   S UR                  l        U$ rP   )ra   templatelabelsr   NONCE_LABELnameselfresources     r9   Adjust_NewRevisionNonceChange.Adjust   s5    59ZZHX112!HOr8   r2   N	r3   r4   r5   r6   __doc__str__annotations__rj   r7   r2   r8   r9   r_   r_      s    M	*r8   r_   c                   ,   ^  \ rS rSrSrU 4S jrSrU =r$ )_NewRevisionForcingChange   zCForces a new revision to get created by changing the revision name.c                    > [         R                  UR                  R                  ;   a%  UR                  R                  [         R                  	 [        TU ]  U5      $ )zAdjust by revision name.)r   re   rc   rd   superrj   )rh   ri   	__class__s     r9   rj    _NewRevisionForcingChange.Adjust   sF    x00777



"
"8#7#7
87>(##r8   r2   )r3   r4   r5   r6   rm   rj   r7   __classcell__)ru   s   @r9   rq   rq      s    K$ $r8   rq   c                     SU ;   $ )z0Return true if the given image url is by-digest.z@sha256:r2   )urls    r9   	_IsDigestrz      s    	s	r8   c                   >    \ rS rSr% Sr\R                  \S'   S rSr	g)_SwitchToDigestChange   z4Switches the configuration from by-tag to by-digest.base_revisionc                     [        U R                  R                  5      (       a  U$ U R                  R                  (       d  U$ U R                  R                  UR                  l        U$ rP   )rz   r~   imageimage_digestrc   rg   s     r9   rj   _SwitchToDigestChange.Adjust   sQ    ##))**o**o"00==HOr8   r2   N)
r3   r4   r5   r6   rm   r   Revisionro   rj   r7   r2   r8   r9   r|   r|      s    <"""r8   r|   c                   *    \ rS rSr% Sr\\S'   S rSrg)_AddDigestToImageChange   z.Add image digest that comes from source build.r   c                     [        UR                  R                  5      (       a  U$ UR                  R                  S-   U R                  -   UR                  l        U$ )N@)rz   rc   r   r   rg   s     r9   rj   _AddDigestToImageChange.Adjust   sM    ""(())o&//55;d>O>OOHOr8   r2   Nrl   r2   r8   r9   r   r      s    6r8   r   c            
          \ rS rSrSrS r\S 5       rS rS r	SMS jr
S rS	 rS
 rS r\R                   R"                  4S jrS rS rS rS rS rS rS r SNS jrS rS rS rS rS rS\ RB                  S\"S\#RH                  S\%\&RN                     S\(4
S jr)                           SOS! jr*S" r+S# r,S$ r-S% r.\/R`                  " S&S'S(9S) 5       r1S* r2S+ r3S, r4S- r5S. r6 SPS/ jr7   SQS0 jr8 SRS1 jr9S2 r: SNS3 jr;S4 r<S5 r=        SSS6 jr>STS7 jr?STS8 jr@     SUS9 jrAS: rBS; rCS< rDS= rES> rFS? rGS@ rHSA rI    SVSB jrJSWSC jrKSD rLSE rMSF\(4SG jrNSH rOSI rPSJ rQSK rRSLrSg )XrE      zHClient used by Serverless to communicate with the actual Serverless API.c                     Xl         [        R                  R                  5       U l        U R                  R                  UR                  UR                  5        X0l        UR                  U l
        X l        g)a@  Inits ServerlessOperations with given API clients.

Args:
  client: The API client for interacting with Kubernetes Cloud Run APIs.
  conn_context: the connection context used to create this object.
  op_client: The API client for interacting with One Platform APIs. Or None
    if interacting with Cloud Run for Anthos.
N)_clientr(   REGISTRYClone	_registryRegisterApiByNamer?   r@   
_op_clientregion_region_conn_context)rh   rK   rF   rH   s       r9   __init__ServerlessOperations.__init__   s\     L''--/DNNN$$|77  O&&DL%r8   c                 .    U R                   R                  $ rP   )r   MESSAGES_MODULE)rh   s    r9   messages_module$ServerlessOperations.messages_module   s    <<'''r8   c                    U R                   nUR                  5       nUR                  US9n [        R                  " [
        R                  5         U R                  R                  R                  U5      nSSS5        [        R                  " WU5      $ ! , (       d  f       N%= f! [        R                   a   n[        R                  " U5         SnAgSnAf[        R                    a     gf = f)zlGet the revision.

Args:
  revision_ref: Resource, revision to get.

Returns:
  A revision.Revision object.
rf   N)r   RelativeName RunNamespacesRevisionsGetRequestr&   RecordDurationr   GET_REVISIONr   namespaces_revisionsGetr   r   api_exceptionsInvalidDataFromServerErrorserverless_exceptionsMaybeRaiseCustomFieldMismatchHttpNotFoundError)rh   revision_refmessagesrevision_namerequestresponsees          r9   GetRevision ServerlessOperations.GetRevision   s     ##H --/M77]7KG!!,";";<<<4488A =x22 =< 44 =99!<<++ s5   $B' &B7B' 
B$ B' 'C0;CC0/C0c                 $    UR                  5         g)z)Upload the code for the given deployable.N)UploadFiles)rh   
deployables     r9   UploadServerlessOperations.Upload   s    r8   c                 P    US:X  a  [         R                  " USSS9$ [         R                  " USUSS9$ ! [        R                   a\  nUR	                  5       nU(       a  UR                  5       OSnU(       a%  [        R                  " SR                  U5      5        UeSnAff = f)a0  Wait for a configuration to be ready in latest revision.

Args:
  poller: A ConditionPoller object.
  max_wait_ms: int, if not 0, passed to waiter.PollUntilDone.

Returns:
  A condition.Conditions object.

Raises:
  RetryException: Max retry limit exceeded.
  ConfigurationError: configuration failed to
r   Ni  )wait_ceiling_ms)max_wait_msr   zStill waiting: {})	r   PollUntilDoner+   RetryExceptionGetConditionsDescriptiveMessager%   errorformat)rh   pollerr   err
conditionsmsgs         r9   WaitForCondition%ServerlessOperations.WaitForCondition  s    		##FD$GG!!
$K   '')j 0:J))+tc			%,,S12is   5 5 B%	AB  B%c                    U R                   nUR                  UR                  5       S9n [        R                  " [
        R                  5         U R                  R                  R                  U5      nSSS5        WR                   Vs/ s H  n[        R                  " XR5      PM     sn$ ! , (       d  f       N?= fs  snf ! [        R                   a   n[        R                   " U5         SnAgSnAff = f)z&Returns all services in the namespace.parentN)r    RunNamespacesServicesListRequestr   r&   r   r   LIST_SERVICESr   namespaces_servicesr   itemsr   Servicer   r   r   r   rh   namespace_refr   r   r   itemr   s          r9   ListServices!ServerlessOperations.ListServices"  s    ##H77))+ 8 G=!!,"<"<=<<3388A >:B..I.$good-.II >=I44 =99!<<=;   $C &B.5C  B?+C .
B<8C C8C33C8c                    U R                   nUR                  UR                  5       S9n [        R                  " [
        R                  5         U R                  R                  R                  U5      nSSS5        WR                   Vs/ s H  n[        R                  " XR5      PM     sn$ ! , (       d  f       N?= fs  snf ! [        R                   a   n[        R                   " U5         SnAgSnAff = f)z,Returns all configurations in the namespace.r   N)r   &RunNamespacesConfigurationsListRequestr   r&   r   r   LIST_CONFIGURATIONSr   namespaces_configurationsr   r   r   Configurationr   r   r   r   r   s          r9   ListConfigurations'ServerlessOperations.ListConfigurations/  s    ##H==))+ > G=!!,"B"BC<<99>>wG D CK..BP$-
%
%d
5.  DC 44 =99!<<=r   c                    U R                   nUR                  UR                  5       S9n[        R                  " [
        R                  5         U R                  R                  R                  U5      nSSS5        WR                   Vs/ s H  n[        R                  " XR5      PM     sn$ ! , (       d  f       N?= fs  snf )z$Returns all routes in the namespace.r   N)r   RunNamespacesRoutesListRequestr   r&   r   r   LIST_ROUTESr   namespaces_routesr   r   r   Routerh   r   r   r   r   r   s         r9   
ListRoutesServerlessOperations.ListRoutes>  s    ##H55))+ 6 G 
		 8 8	9//44W=h 
:4<NNCNDEKK'NCC 
:	9C   &B-
 B>-
B;c                    U R                   nUR                  UR                  5       S9n [        R                  " [
        R                  5         U R                  R                  R                  U5      n[        R                  " XB5      sSSS5        $ ! , (       d  f       g= f! [        R                   a   n[        R                  " U5         SnAgSnAf[        R                    a     gf = f)<Return the relevant Service from the server, or None if 404.r   N)r   RunNamespacesServicesGetRequestr   r&   r   r   GET_SERVICEr   r   r   r   r   r   r   r   r   r   )rh   service_refr   service_get_requestservice_get_responser   s         r9   
GetServiceServerlessOperations.GetServiceH  s    ##H"BB%%' C 	!!,":":;#||??CC 
 3>	 <;;
 44 =99!<<++ ;   $B% ;B
	B% 
B"B% "B% %C.9CC.-C.c                    U R                   n[        R                  R                  R                  R                  SS9nSU SU R                   SU 3nU R                  R                  USS9n [        R                  " [        R                  5         [        R                  " U R                   U R                  R                   U R                  R"                  5      nU[$        R&                  R(                  :X  Ga!  UR+                  U5      n	U	R,                  (       aj  [.        R0                  " U	R,                  5      n
[.        R2                  " UR4                  U
5      n[6        R4                  " XR                   5      sSSS5        $ U	R8                  (       aj  [.        R0                  " U	R8                  5      n
[.        R2                  " UR4                  U
5      n[6        R4                  " XR                   5      sSSS5        $ U R;                  U5      sSSS5        $ [<        R>                  " X5      n	[.        R0                  " U	R,                  5      n
[.        R2                  " UR4                  U
5      n[6        R4                  " XR                   5      sSSS5        $ ! , (       d  f       g= f! [@        RB                   a   n[D        RF                  " U5         SnAgSnAf[@        RH                   a     gf = f)	r   Trequired	projects//locations//operations/!run.projects.locations.operations
collectionN)%r   r'   VALUEScoreprojectr   r   r   ParseRelativeNamer&   r   r   WAIT_OPERATIONr    WaitOperationPollerr   projects_locations_servicesprojects_locations_operationsr   ReleaseTrackALPHAPollr   r   MessageToPyValuePyValueToMessager   r   metadatar   r   r   r   r   r   r   r   )rh   operation_idr   release_trackr   r   op_nameop_refr   	operationas_dictas_pbr   s                r9   WaitService ServerlessOperations.WaitServiceZ  s7    ##H$$,,00$0?G
G9K~\,P  ^^--? . F!!,"="=>//  LL44LL66

 D--333kk&)) //	0B0BCG--h.>.>HE??5*>*>? ?> !!//	0B0BCG--h.>.>HE??5*>*>?% ?>( ??;/) ?>, **6:)--i.@.@A'++H,<,<gF%(<(<=3 ?>>6 44 =99!<<++ sc   .$J. C,J>	J. A1J9	J. J	J. A6J	J. 
J+'J. +J. .K7KK76K7c                    U R                   n[        US5      (       a@  U R                  R                  UR                  SUR
                  0SS9R                  5       nOUR                  5       nUR                  US9n [        R                  " [        R                  5         U R                  R                  R                  U5      nSSS5        [        R                   " WU5      $ ! , (       d  f       N%= f! ["        R$                   a   n[&        R(                  " U5         SnAgSnAf["        R*                   a     gf = f)zBReturn the relevant Configuration from the server, or None if 404.
servicesIdnamespacesIdzrun.namespaces.configurationsparamsr   r   N)r   hasattrr   Parser  r  r   %RunNamespacesConfigurationsGetRequestr&   r   r   GET_CONFIGURATIONr   r   r   r   r   r   r   r   r   r   )rh   service_or_configuration_refr   rf   configuration_get_requestconfiguration_get_responser   s          r9   GetConfiguration%ServerlessOperations.GetConfiguration  s   ##H+\::^^!!
&
1
1:GG 5 "  	  *668d ( N N !O !	!!,"@"@A%)\\%K%K%O%O%&
" B (()CXNN	 BA
 44 =99!<<++ s6   >$C8 "&C'C8 '
C51C8 8ED''E Ec                 $   U R                   n[        US5      (       a@  U R                  R                  UR                  SUR
                  0SS9R                  5       nOUR                  5       nUR                  US9n [        R                  " [        R                  5         U R                  R                  R                  U5      nSSS5        [        R                   " WU5      $ ! , (       d  f       N%= f! ["        R$                   a     gf = f)z:Return the relevant Route from the server, or None if 404.r  r  zrun.namespaces.routesr  r   N)r   r  r   r  r  r  r   RunNamespacesRoutesGetRequestr&   r   r   	GET_ROUTEr   r   r   r   r   r   r   )rh   service_or_route_refr   rf   route_get_requestroute_get_responses         r9   GetRouteServerlessOperations.GetRoute  s    ##H#\22^^!!

)
)2?? - "  	  "..0d >>D>I!!,"8"89!\\;;??
 : [[+X66	 :9
 ++ s*   >$C8 "&C'C8 '
C51C8 8DDc                    U R                   nUR                  5       nUR                  US9n [        R                  " [
        R                  5         U R                  R                  R                  U5        SSS5        g! , (       d  f       g= f! [        R                   a0    [        R                  " SR                  UR                  5      5      ef = f)zDelete the provided Service.

Args:
  service_ref: Resource, a reference to the Service to delete

Raises:
  ServiceNotFoundError: if provided service is not found.
r   N Service [{}] could not be found.)r   r   "RunNamespacesServicesDeleteRequestr&   r   r   DELETE_SERVICEr   r   Deleter   r   r   ServiceNotFoundErrorr   r  )rh   r   r   service_nameservice_delete_requests        r9   DeleteService"ServerlessOperations.DeleteService  s     ##H++-L%HH I !!,"="=>((//0FG ?>>++ !66
,
3
3K4J4J
K *   $B &B 7B  
B
B B ACc                    U R                   nUR                  5       nUR                  US9n [        R                  " [
        R                  5         U R                  R                  R                  U5        SSS5        g! , (       d  f       g= f! [        R                   a0    [        R                  " SR                  UR                  5      5      ef = f)zDelete the provided Revision.

Args:
  revision_ref: Resource, a reference to the Revision to delete

Raises:
  RevisionNotFoundError: if provided revision is not found.
r   Nz!Revision [{}] could not be found.)r   r   #RunNamespacesRevisionsDeleteRequestr&   r   r   DELETE_REVISIONr   r   r'  r   r   r   RevisionNotFoundErrorr   revisionsId)rh   r   r   r   r   s        r9   DeleteRevision#ServerlessOperations.DeleteRevision  s     ##H --/M:::NG!!,">">?))009 @??++ !77
-
4
4\5M5M
N r-  c                    U R                   nUR                  UR                  5       SR                  [        R
                  U5      S9n U R                  R                  R                  U5      nUR                   Vs/ s H  n[        R                  " Xc5      PM     sn$ s  snf ! [        R                   a   n[        R                  " U5         SnAgSnAff = f)z*Return all revisions with the given nonce.z{} = {})r   labelSelectorN)r   !RunNamespacesRevisionsListRequestr   r   r   re   r   r   r   r   r   r   r   r   r   )rh   r   ra   r   r   r   r   r   s           r9   GetRevisionsByNonce(ServerlessOperations.GetRevisionsByNonce  s    ##H88))+&&x';';UC 9 G=2277@h<DNNKNDh/NKKK44 =99!<<=s*   
3B% = B B%  B% %C9CCc           	         SnUR                   nU(       ar   [        R                  " U R                  R                  SUR
                  0SS9n[        R                  " X5      nUR                  [        R                  " XuSSS95      nU(       d  UR                  R                  [        R                   S5      nU(       aa    U R                  R	                  UR
                  SS	9n	[        R&                  " X	5      nUR                  [        R                  " XxSSS95      nU(       dS  UR(                  (       aB  U R                  R	                  UR(                  SUR
                  0SS9n
U R+                  U
5      nU$ ! [        R                   a     GNf = f! ["        R$                   a'    U R                  R	                  UR
                  S
S	9n	 Nf = f! [        R                   a     Nf = f)a  Return a Revision for use as the "base revision" for a change.

When making a change that should not affect the code running, the
"base revision" is the revision that we should lock the code to - it's where
we get the digest for the image to run.

Getting this revision:
  * If there's a name in the template metadata, use that
  * If there's a nonce in the revisonTemplate metadata, use that
  * If that query produces >1 or 0 after a short timeout, use
    the latestCreatedRevision in status.

Arguments:
  template: Revision, the revision template to get the base revision of. May
    have been derived from a Service.
  metadata: ObjectMeta, the metadata from the top-level object
  status: Union[ConfigurationStatus, ServiceStatus], the status of the top-
    level object.

Returns:
  The base revision of the configuration or None if not found by revision
    name nor nonce and latestCreatedRevisionName does not exist on the
    Service object.
Nr  zrun.namespaces.revisionsr  i  i  )sleep_msr   zrun.namespacesr   zrun.api.v1.namespaces)rf   	functoolspartialr   r  	namespacer    RevisionNameBasedPoller	GetResultr   r   r+   r   rd   getr   re   r(   InvalidCollectionExceptionNonceBasedRevisionPollerlatestCreatedRevisionNamer   )rh   rc   r  statusr~   base_revision_namerevision_ref_getterr   base_revision_noncer   r   s              r9   _GetBaseRevision%ServerlessOperations._GetBaseRevision  s   2 M!'//NN  "H$6$671

 33DN((  Sd
 $OO//0D0DdK		 NN00""/? 1 M 66tK& **""- 		)	)~~++,,"H$6$671 , 

 ((6K !!  55  NN00""/F 1 M ## 	
	sB   A1E= $F &;G =FF8GG GG G-,G-c                     [        UR                  R                  5      (       dT  U R                  UR                  UR                  UR
                  5      nU(       a  UR                  [        U5      5        ggg)zEMake config_changes include switch by-digest image if not so already.N)rz   rc   r   rI  r  rE  appendr|   )rh   servr   r~   s       r9   _EnsureImageDigest'ServerlessOperations._EnsureImageDigestC  s]    T]](())++
--m 
3MBC 
	 *r8   c                 
   U R                   n U(       a  [        R                  " XB5      nUR                  5       nUR	                  UR                  5       UU(       a  SOSS9n[        R                  " [        R                  5         U R                  R                  R                  U5      n	SSS5        [        R                  " W	U5      $ U(       d/  [        R                   " SR#                  UR$                  5      5      e[        R                  R'                  U R                  UR(                  5      n
UR$                  U
l        UR-                  5       R                  5       n[        R                  " X5      n
UR/                  U
R                  5       UU(       a  SOSS9n[        R                  " [        R0                  5         U R                  R                  R3                  U5      nSSS5        [        R                  " WU5      $ ! , (       d  f       GNf= f! , (       d  f       N7= f! [4        R6                   a   n[        R8                  " U5         SnAgSnAf[4        R:                   a4  n[<        R>                  " [        R@                  " U5      5         SnAgSnAf[4        RB                   Ga  n[D        RF                  " U5      n[I        URJ                  S5      (       a  SURJ                  RL                  ;   a  Ue[N        RP                  RR                  RT                  RW                  5       nSnUS	:X  au  [X        RZ                  " 5       nU Vs/ s H)  nS
R#                  UR*                  UR\                  5      PM+     Os  snf nnUSR#                  SR_                  U5      5      -  nOUS:X  a{  [X        R`                  " U Rb                  5      nU Rd                  U;  aJ  U Vs/ s H  nSR#                  U5      PM     Os  snf nnUSR#                  SR_                  U5      5      -  nOUS:X  a  US-  n[        Rf                  " U5      eSnAf[4        R@                   a  n[N        RP                  RR                  RT                  RW                  5       nUS:X  a  [<        R>                  " U5        [        Rh                  " U5      nSR_                  URj                   Vs/ s H  nUS   PM
     Os  snf sn5      nU(       d  URl                  n[        Rn                  " SR#                  [q        URj                  5      S:  a  SU5      5      eSU5      5      eSnAff = f)a
  Apply config_changes to the service.

Create it if necessary.

Arguments:
  service_ref: Reference to the service to create or update
  config_changes: list of ConfigChanger to modify the service with
  with_code: bool, True if the config_changes contains code to deploy. We
    can't create the service if we're not deploying code.
  serv: service.Service, For update the Service to update and for create
    None.
  dry_run: bool, if True only validate the change.

Returns:
  The Service object we created or modified.
allN)r   rf   dryRunr$  )r   r   rR  domain_detailsrun.googleapis.com"Deployment endpoint was not found.gkez
* {} in {}z Perhaps the provided cluster was invalid or does not have Cloud Run enabled. Pass the `--cluster` and `--cluster-location` flags or set the `run/cluster` and `run/cluster_location` properties to a valid cluster and zone and retry.
Available clusters:
{}
managed* {} The provided region was invalid. Pass the `--region` flag or set the `run/region` property to a valid region and retry.
Available regions:
{}
kubernetesz Perhaps the provided cluster was invalid or does not have Cloud Run enabled. Ensure in your kubeconfig file that the cluster referenced in the current context or the specified context is a valid cluster and retry.z

messagezError{}:
{}
   srN   )9r   config_changes_modWithChangesr   *RunNamespacesServicesReplaceServiceRequestMessager&   r   r   UPDATE_SERVICEr   r   ReplaceServicer   r   r   r(  r   r  Newr  rf   Parent"RunNamespacesServicesCreateRequestCREATE_SERVICECreater   r   r   HttpBadRequestErrorr	   reraise	HttpErrorr   api_lib_exceptionsHttpExceptionr  payloadrS  r'   r   runplatformr   r   ListClusterszonerY   ListRegionsr   r   DeploymentFailedErrorKubernetesExceptionParsercausesr   KubernetesErrorlen)rh   r   r   	with_coderM  dry_runr   	serv_nameserv_update_requpdatednew_servr   serv_create_reqraw_servicer   
parsed_errrq  	error_msgall_clusterscclustersall_regionsrregions	k8s_errorrw  s                             r9   _UpdateOrCreateService+ServerlessOperations._UpdateOrCreateServiceL  sR   & ##HY	!--dC,,.	"MMLLN$E$ N 

 ##L$?$?@LL44CC' A w11 %::0778N8NO  ??&&t||[5M5MN#..##%224%11(K"EE$$&#5 F 

 ##L$?$?@88??P+ A{H55/ A@* A@ 44 =99!<<-- =.88;<<++ &C%33A6j
*$$&6
7
7"j&8&8&G&GG""&&//335h6i	U	%224AMNAL''7NN(
 )/tyy/B(C	
	 y $00A<<{*/:;{!V]]1%{;';
) *0		'0B)C	) |#,	
	 "77	BB## ""&&//335h	Y	1'AA!Di{{)2B2BC2BQAiL2BCDf!11

!
!))*Q.c 46 s   A9H/ &H-H/ C;H/ &H-H/ 
HH/ 
H,(H/ /U,IU,5*J$$U,<B Q0NA&Q2PAQU,1A=U'.S>
=A*U''U,c                    Uc)  [         R                  " [        R                  " 5       SSS9nU R	                  U5      nU(       d/  [
        R                  " SR                  UR                  5      5      eU R                  XSU5      nU(       d  UR                  R                  5       (       a  U$ UR                  b  U(       a"  [        R                  " U R                  U5      n	O-[        R                  " U R                  UR                  UU5      n	[         R"                  " XUS9n
U R%                  U
5        U
R'                  5       nU$ )z"Update traffic splits for service.Tabortedinterruptableaborted_messager$  F)rM  )r)   NoOpStagedProgressTrackerr"   UpdateTrafficStagesr   r   r(  r   r  r  r   IsReadyr  r<  r=  r  r    ServiceConditionPollerr   GetResource)rh   r   r   trackerasyn
is_verboser  rM  updated_servgetterr   s              r9   UpdateTraffic"ServerlessOperations.UpdateTraffic  s%     ::

$
$
&#g
 ??;'D!66
,
3
3K4J4J
K  ..UDL 		 	 	(	(	*	*		"	"	*j""4??K@""%%	
 00
f F#'')lr8   c                     Ub  UR                   OSnSR                  [        US-   5      R                  S5      [        R
                  " 5       5      nUR                  S[        U5      5        g)z?Get a new revision forcing config change for the given service.Nr   z{}-{}r]     )
generationr   rn   zfillr   GenerateNameinsertrq   )rh   rM  r   curr_generationrevision_suffixs        r9   _AddRevisionForcingChange.ServerlessOperations._AddRevisionForcingChange  s[    )-)9dooqOnnOa &&q)>+F+F+HO !6GHr8   c                 L    UR                  [        R                  " U/S95        g)zEDelete the base image revision level annotation for source container.)deletesNrL  r_  BaseImagesAnnotationChange)rh   r   source_container_names      r9   "_DeleteRevisionBaseImageAnnotation7ServerlessOperations._DeleteRevisionBaseImageAnnotation  s&     55*+	
r8   c                 L    UR                  [        R                  " X20S95        g)aw  Replace the base image in the config changes with the rectified base image returned from build.

Args:
  config_changes: list, objects that implement Adjust().
  base_image_from_build: The base image from build to opt-in automatic build
    image updates.
  ingress_container_name: The name of the ingress container that is build
    from source. This could be empty string.
updatesNr  )rh   r   base_image_from_buildingress_container_names       r9   _ReplaceOrAddBaseImage+ServerlessOperations._ReplaceOrAddBaseImage  s&     55+C	
r8   c                     U(       aI  US   R                  S/ 5       H0  nUR                  S5      (       d  M  UR                  SS5      S   s  $    g)z,Get the function target from the build pack.r   envszGOOGLE_FUNCTION_TARGET==r]  N)rA  
startswithsplit)rh   packenv_vars      r9   _GetFunctionTargetFromBuildPack4ServerlessOperations._GetFunctionTargetFromBuildPack  sK    !W[[,'788sA&q)
) - r8   r  r   prefetchr   generate_namec                    SnUSS nU(       aD  [         R                  " [        R                  " UR	                  5       5      U R
                  5      nOUb  U R                  U5      nU(       a  U R                  Xg5        O"UR                  [        [        5       5      5        UR                  [        R                  5        UR                  S5        U R                  X'SUSS9  UR!                  [        R                  5        g)z0Validate the service in dry run before building.NzValidating Service...T)r{  )r   r   copydeepcopyrb  r   r   r  rL  r_   r\   
StartStager"   VALIDATE_SERVICEUpdateHeaderMessager  CompleteStage)rh   r  r   r  r   r  svcvalidate_config_changess           r9   "_ValidateServiceBeforeSourceDeploy7ServerlessOperations._ValidateServiceBeforeSourceDeploy  s     C,Q/OO
--((*
+T-A-Ac 
	 OOK(c 
$$SB$$%<VX%FGv../ 78dC    &112r8   Nc                 (	   USL=(       a    U(       + nU=(       d    U R                   n Uc5  [        R                  " [        R                  " USLUUSLUUSLUSLS9SSS9nUb  U(       a  UR                  [        R                  5        [        R                  " U5      (       a  UR                  S5        Un!ON[        R                  " UU UU[        R                  R                  SS9n"SU"l        [        R                  " U"5      n!UR                  [         R"                  " UU!0S	95        UR%                  [        R                  5        OU(       a  U R&                  R)                  U 5      n#U#   U R+                  XAXU5        [,        R.                  " UU
UUUUUU UUUUUUUUUU5      u  n$n%n&n'n(U$c
   SSS5        gU R1                  U5        U R3                  UU'UUUUU&U
U(U%UUS
9  UR                  [5        U$5      5        SSS5        U	c  Sn)O3U(       a  U R7                  U5      n)OU	=(       d    U R7                  U5      n)U(       a  Sn*O[9        S U 5       5      n*[         R:                  " U5      (       ac  U(       a  U R=                  U)U5        O"UR                  [?        [A        5       5      5        U)(       a   U*(       d  U(       d  U RC                  U)U5        U)(       aF  U)RD                  RF                  b/  [H        RJ                  " SRM                  URN                  5      5      eU RQ                  XU*U)U5      n+U RS                  XXt5        U RU                  UUU+U5        U(       Gd  U(       Gd  U+RV                  RY                  5       (       a  U+$ U+RZ                  b  U(       a"  [\        R^                  " U R6                  U5      n,O-[\        R^                  " U R`                  U+RZ                  UU5      n,[b        Rd                  " U,U[        Rf                  " U5      U+S9n-U Ri                  U-5        [j        Rl                  " U-Ro                  5       5       H  n.URq                  U.5        M     U-Rs                  5       n+U+$ ! , (       d  f       GN= f)a  Change the given service in prod using the given config_changes.

Ensures a new revision is always created, even if the spec of the revision
has not changed.

Args:
  service_ref: Resource, the service to release.
  config_changes: list, objects that implement Adjust().
  release_track: ReleaseTrack, the release track of a command calling this.
  tracker: StagedProgressTracker, to report on the progress of releasing.
  asyn: bool, if True, return without waiting for the service to be updated.
  allow_unauthenticated: bool, True if creating a hosted Cloud Run service
    which should also have its IAM policy set to allow unauthenticated
    access. False if removing the IAM policy to allow unauthenticated access
    from a service.
  multiregion_regions: The regions for a multi-region service.
  for_replace: bool, If the change is for a replacing the service from a
    YAML specification.
  prefetch: the service, pre-fetched for ReleaseService. `False` indicates
    the caller did not perform a prefetch; `None` indicates a nonexistent
    service.
  build_image: The build image reference to the build.
  build_pack: The build pack reference to the build.
  build_region: The region to use for the build, in case of multi-region.
  build_source: The build source reference to the build.
  repo_to_create: Optional
    googlecloudsdk.command_lib.artifacts.docker_util.DockerRepo defining a
    repository to be created.
  already_activated_services: bool. If true, skip activation prompts for
    services
  dry_run: bool. If true, only validate the configuration.
  generate_name: bool. If true, create a revision name, otherwise add nonce.
  delegate_builds: bool. If true, use the Build API to submit builds.
  base_image: The build base image to opt-in automatic build image updates.
  build_service_account: The service account to use to execute the build.
  deploy_from_source_container_name: The name of the ingress container that
    is deployed from source include build-from-source and zip deploy. This
    field could be an empty string.
  build_worker_pool:  The name of the Cloud Build custom worker pool that
    should be used to build the function.
  build_machine_type: The machine type from Cloud Build default pool to use
    for the build.
  build_env_vars: Dictionary of build env vars to send to submit build.
  enable_automatic_updates: If true, opt-in automatic build image updates.
    If false, opt-out automatic build image updates.
  is_verbose: Print verbose output. Forces polling instead of waiting.
  source_bucket: The existing bucket to use for source uploads. Leave it as
    None to create a new bucket.
  kms_key: The KMS key to use for the deployment.
  iap_enabled: If true, assign run.invoker access to IAP P4SA, if false,
    remove run.invoker access from IAP P4SA.
  skip_build: If true, skip the cloud build step.

Returns:
  service.Service, the service as returned by the server on the POST/PUT
   request to create/update the service.
N)include_validate_serviceinclude_upload_sourceinclude_buildinclude_create_repoinclude_iapTr  r  z+Using the source from the specified bucket.F)respect_gitignorer  )r   uploaded_sourceservice_accountr   build_env_vars
build_packbuild_idbuild_image
build_namebuild_base_image build_from_source_container_nameenable_automatic_updatesc              3   V   #    U  H  n[        U[        R                  5      v   M!     g 7frP   )
isinstancer_  ImageChange)rU   r  s     r9   rW   6ServerlessOperations.ReleaseService.<locals>.<genexpr>  s$      AOA*Q*66
7
7s   ')z0Service [{}] is in the process of being deleted.)dependenciesrM  ):r   r)   r  r"   ServiceStagesr  UPLOAD_SOURCEr$   IsGcsObjectr  r   ArchiveTypeTARr  GetGsutilUrirL  r_  SourcesAnnotationChanger  r   GetContextWithRegionOverrider  r#   CreateImage_ClearRunFunctionsAnnotations_AddRunFunctionsAnnotationsr   r   anyAdjustsTemplater  r_   r\   rN  r  deletionTimestampr   ru  r   r  r  _HandleAllowUnauthenticated
_HandleIapr   r  r  r<  r=  r  r    r  ServiceDependenciesr   run_conditionGetNonTerminalMessagesr   
AddWarningr  )/rh   r   r   r  r  r  allow_unauthenticatedmultiregion_regionsfor_replacer  r  r  build_regionbuild_sourcerepo_to_createalready_activated_servicesr{  r  delegate_builds
base_imagebuild_service_account!deploy_from_source_container_namebuild_worker_poolbuild_machine_typer  r  r  source_bucketkms_keyiap_enabled
skip_buildrequires_buildr   source_pathsourcenew_connr   r  r  r  r  rM  
with_imageupdated_servicer  r   r   s/                                                  r9   ReleaseService#ServerlessOperations.ReleaseService8  sZ   t "-@j.N)T\\F ::


#4/'5$0$<*"0"<%T1 #g J--.			\	*	*##9	
 ####
 !**62

4
48+F
 F001	##@@Hh//(M	
   &!$%
	
* 
C 8D 	**>:(()+1))!#!--N%= 	) 	
 	5lCDc d d	 __[)d55dj AO j 
	+	+N	;	; 

(
(~
>


 7 A
B
+> 
!
!$
7//;!77
<
C
C$$  11ZwO
 	$$,? 	OOKowG		#	#	+	+	-	-		%	%	-""4??K@""((	
 00

112EF	f F#55f6J6J6LM#3 N**,oo 8s   /AR=AR
Rc                    Ub  Ub  U R                  XX45      $ Ub|   UR                  [        R                  5        UR	                  [        R                  S5        U R                  UU[        [        5        UR                  [        R                  5        gg! [        R                   aO    SR                  U(       a  SOSU R                  UR                  S9nUR                  [        R                  US9   gf = f)zHandle SetIamPolicy call(s).NrN   zSetting IAM policy failed, try "gcloud beta run services {}-iam-policy-binding --region={region} --member=allUsers --role=roles/run.invoker {service}"addremover   r   warning_message)&_HandleMultiRegionAllowUnauthenticatedr  r"   SERVICE_IAM_POLICY_SETUpdateStageAddOrRemoveIamPolicyBinding"ALLOW_UNAUTH_POLICY_BINDING_MEMBER ALLOW_UNAUTH_POLICY_BINDING_ROLEr  r   rl  r   r   r  CompleteStageWithWarning)rh   r   r  r  r  r  s         r9   r  0ServerlessOperations._HandleAllowUnauthenticated9  s     (-@-L88
.A  (
6889F992>((!.,		
 	f;;< ) %% 
228&.H||#.. 39 3 	 	(())? 	) 	

s   A:B A C<;C<c           	         UR                  [        R                  5        SnU HN  n UR                  [        R                  SR	                  U5      5        U R                  UU[        [        US9  MP     U(       d   UR                  [        R                  5        gUR                  [        R                  US9  g! [        R                   a6    U(       d'  SR	                  U(       a  SOSUUR                  S9n M  XV-  n M  f = f)	z4Handle SetIamPolicy calls for Multi-Region Services.Nz Setting IAM policy for region {})region_overridezSetting IAM policy failed, try "gcloud beta run services {}-iam-policy-binding --region=[region] --member=allUsers --role=roles/run.invoker {service}" for regions: {region}r  r  r  r  )r  r"   r  r  r   r  r  r  r   rl  r  r  r  )rh   r   r  r  r  r  r   s          r9   r  ;ServerlessOperations._HandleMultiRegionAllowUnauthenticatedZ  s     v445O%$)).55f=	
 	((!.," 	) 	
 &6 F99:&&

'
' ' # %% $J v0%h%00  	  
#/$s   A
B<<?D>DDc                 l    [         R                  " 5       R                  nU(       a	  SU SU S3$ SU S3$ )a-  Returns the service agent for the given project.

For Universe Projects, the format will look like
service-{project_num}@gcp-sa-iap.{project_prefix}iam.gserviceaccount.com
FOR GDU format will look like
service-{project_num}@gcp-sa-iap.iam.gserviceaccount.com

Args:
  project_num: The project number.
zserviceAccount:service-z@gcp-sa-iap.z.iam.gserviceaccount.comz#@gcp-sa-iap.iam.gserviceaccount.com)r*   GetUniverseDomainDescriptorproject_prefix)rh   project_numr"  s      r9   GetServiceAgent$ServerlessOperations.GetServiceAgent  sG     	779HH  &{m<?OOghh$[M1TUUr8   c                 r   U R                  UR                  5      nUb   UR                  [        R                  5        UR                  [        R                  S5        U(       a  U R                  X5        OU R                  USU[        5        UR                  [        R                  5        gg! [        R                   aq  nU(       a  UR                  S:X  a  SnO/SR                  U(       a  SOSU R                  UUR                  S	9nUR!                  [        R                  US
9   SnAgSnAff = f)zHandle IAP changes.NrN   Fi  zIAP has not been successfully enabled. If this is the first time you're enabling IAP in this project, please wait a few minutes for the service agent to propagate, then try enabling IAP again on this service.zSetting IAM policy failed, try "gcloud run services {}-iam-policy-binding --region={region} --member={member} --role=roles/run.invoker {service}"r  r  )r   memberr   r  )r$  r>  r  r"   SERVICE_IAP_ENABLEr  _AddIamPolicyBindingWithRetryr  r  r  r   rl  status_coder   r   r  r  )rh   r   r  r  r  iap_service_agentr   r  s           r9   r  ServerlessOperations._HandleIap  s   ,,_-F-FG$
6445F55r:

,
,[
L

*
*.	 	f778  %% 
AMMS0" 55;V&%H*%00	 6< 6  	((%% 	) 	
+
s   BB1 1D6A'D11D6r-   i:  )max_retrialsr;  c                 2    U R                  USU[        5      $ )NT)r  r  )rh   r   r+  s      r9   r)  2ServerlessOperations._AddIamPolicyBindingWithRetry  s     ++T,.N r8   c                    U R                   nUR                  UR                  5       S9n [        R                  " [
        R                  5         U R                  R                  R                  U5      n[        R                  " XB5      sSSS5        $ ! , (       d  f       g= f! [        R                   a   n[        R                  " U5         SnAgSnAf[        R                    a     gf = f)?Return the relevant WorkerPool from the server, or None if 404.r   N)r   "RunNamespacesWorkerpoolsGetRequestr   r&   r   r   GET_WORKER_POOLr   namespaces_workerpoolsr   worker_pool_lib
WorkerPoolr   r   r   r   r   )rh   worker_pool_refr   worker_pool_get_requestworker_pool_get_responser   s         r9   GetWorkerPool"ServerlessOperations.GetWorkerPool  s    ##H&II))+ J 	!!,">">?#'<<#F#F#J#J#$
  ))*BM	 @??
 44 =99!<<++ r   c                    U R                   nUR                  UR                  5       S9n [        R                  " [
        R                  5         U R                  R                  R                  U5      nSSS5        WR                   Vs/ s H  n[        R                  " XR5      PM     sn$ ! , (       d  f       N?= fs  snf ! [        R                   a   n[        R                   " U5         SnAgSnAff = f)z(Returns all worker pools in the project.r   N)r   #RunNamespacesWorkerpoolsListRequestr   r&   r   r   LIST_WORKER_POOLSr   r4  r   r   r5  r6  r   r   r   r   )rh   project_refr   r   r   r   r   s          r9   ListWorkerPools$ServerlessOperations.ListWorkerPools  s    ##H::'') ; G=!!,"@"@A<<66;;GD B BJAO/
$
$T
4  BA 44 =99!<<=r   c                 6   Uc)  [         R                  " [        R                  " 5       SSS9nU R	                  U5      nU(       aF  UR
                  R                  b/  [        R                  " SR                  UR                  5      5      eU R                  XXe5      nU(       d(  U(       d!  UR                  R                  5       (       a  U$ UR                  c"  [        R                   " U R                  U5      nO+[        R                   " U R"                  UR                  5      n[$        R&                  " UUUS9n	U R)                  U	5        [*        R,                  " U	R/                  5       5       H  n
UR1                  U
5        M     U	R3                  5       nU$ )a#  Replace the given worker pool in prod using the given config_changes.

Args:
  worker_pool_ref: Resource, the worker pool to replace.
  config_changes: list, objects that implement Adjust().
  tracker: StagedProgressTracker, to report on the progress of releasing.
  asyn: bool, if True, return without waiting for the worker pool to be
    updated.
  dry_run: bool. If true, only validate the configuration.

Returns:
  worker_pool.WorkerPool, the worker pool as returned by the server on the
  POST/PUT request to create/update the worker pool.
Tr  r  z4Worker pool [{}] is in the process of being deleted.r   )r)   r  r"   WorkerPoolStagesr:  r  r  r   ru  r   workerpoolsId_UpdateOrCreateWorkerPoolr   r  r  r<  r=  WaitWorkerPoolr    WorkerPoolConditionPollerr   r  r  r   r  r  )rh   r7  r   r  r  r{  r   updated_worker_poolr  r   r   s              r9   ReplaceWorkerPool&ServerlessOperations.ReplaceWorkerPool  sh   ,  ::

!
!
##g
 $$_5K{++==I!77
@
G
G++  88 		'	'	/	/	1	1""''/  !3!3_Ef  


2??f 11'F
 	&!33F4H4H4JK L ,,.r8   c                    U R                   n[        R                  R                  R                  R                  SS9nSU SU R                   SU 3nU R                  R                  USS9n [        R                  " [        R                  5         [        R                  " U R                   U R                  R                   U R                  R"                  5      n[$        R&                  " Xe5      n[(        R*                  " UR,                  5      n[(        R.                  " UR0                  U5      n	[2        R0                  " XR                   5      sSSS5        $ ! , (       d  f       g= f! [4        R6                   a     gf = f)	r1  Tr   r   r   r   r   r   N)r   r'   r   r   r   r   r   r   r   r&   r   r   r   r    r   r   projects_locations_workerpoolsr   r   r   r   r  r   r  r6  r5  r   r   )
rh   r  r   r   r  r  r   r  r	  r
  s
             r9   rF  #ServerlessOperations.WaitWorkerPool$  s7   ##H$$,,00$0?G
G9K~\,P  ^^--? . F!!,"="=>//  LL77LL66

 ((8	++I,>,>?))(*=*=wG))%1E1EF ?>> ++ s1   .$E. CE	E. 
E+'E. +E. .FFc                    U R                   n U(       a  [        R                  " X25      nUR                  5       nUR	                  UR                  5       UU(       a  SOSS9n[        R                  " [        R                  5         U R                  R                  R                  U5      nSSS5        [        R                  " WU5      $ [        R                  R                  U R                  UR                   5      n	UR"                  U	l        UR'                  5       R                  5       n
[        R                  " X5      n	UR)                  U	R                  5       U
U(       a  SOSS9n[        R                  " [        R*                  5         U R                  R                  R-                  U5      nSSS5        [        R                  " WU5      $ ! , (       d  f       GN0= f! , (       d  f       N7= f! [.        R0                   a4  n[2        R4                  " [6        R8                  " U5      5         SnAgSnAf[.        R:                   a  n[<        R>                  " U5      n[A        URB                  S5      (       a  SURB                  RD                  ;   a  UeSn[F        RH                  " U RJ                  5      nU RL                  U;  aJ  U Vs/ s H  nSRO                  U5      PM     Os  snf nnUS	RO                  S
RQ                  U5      5      -  n[6        RR                  " U5      eSnAf[.        R8                   a   n[2        R4                  " U5         SnAgSnAff = f)zUpdate or create worker pool.rQ  N)
workerPoolrf   rR  )rO  r   rR  rS  rT  rU  rY  rZ  rW  )*r   r_  r`  r   0RunNamespacesWorkerpoolsReplaceWorkerPoolRequestrb  r&   r   r   UPDATE_WORKER_POOLr   r4  rI  r5  r6  re  r  rD  rf   rf  %RunNamespacesWorkerpoolsCreateRequestCREATE_WORKER_POOLri  r   rj  r	   rk  r   rl  r   rm  rn  r  ro  rS  r   rt  r   r   r   rY   ru  )rh   r7  r   r   r{  r   worker_pool_nameworker_pool_update_reqr~  new_worker_poolr   worker_pool_create_reqraw_worker_poolr   r  r  r  r  r  s                      r9   rE  .ServerlessOperations._UpdateOrCreateWorkerPool<  s    ##H<	(44
 +779EE&..0%!(d F  	 ##L$C$CDLL77II$' E ))'8<< *4488LL/66
  /<< '')668,88
 "*!O!O&..0#5 "P "

 ##L$C$CD LL??FF$/ E ))/8DD1 ED( ED
 -- =.88;<<++ C%33A6j
*$$&6
7
7"j&8&8&G&GG6i"..t?k	[	(-89[6==#[99' (.vdii.@'A		
	 "77	BB## su   A9G9 &G-G9 CG9 &G(7G9 
G% G9 (
G62G9 9M)*H<<M)BL2K21AL22M)	M$$M)c           
   #     #    U R                   nUR                  UR                  5       S9nU(       a  X&l         [        R
                  " U R                  R                  UUUSSSS9 H  n[        R                  " Xu5      v   M     g! [        R                   a   n[        R                  " U5         SnAgSnAff = f7f)a  List all executions for the given job.

Executions list gets sorted by job name, creation timestamp, and completion
timestamp.

Args:
  namespace_ref: Resource, namespace to list executions in
  label_selector: Optional[string], extra label selector to filter
    executions
  limit: Optional[int], max number of executions to list.
  page_size: Optional[int], number of executions to fetch at a time

Yields:
  Executions for the given surface
r   	continue_r  r[  limitr   r   r]  
batch_sizecurrent_token_attributenext_token_attributebatch_size_attributeN)r   "RunNamespacesExecutionsListRequestr   r6  r
   YieldFromListr   namespaces_executionsr   	Executionr   r   r   r   	rh   r   label_selectorr]  	page_sizer   r   resultr   s	            r9   ListExecutions#ServerlessOperations.ListExecutions  s     $ ##H99))+ : G ,=,,,,44"-8&& !!&33 44 =99!<<=s/   7B?AB B?B<B72B?7B<<B?c           
   #     #    U R                   nUR                  UR                  5       S9n/ nUb-  UR                  SR	                  [
        R                  US95        Ub>  SR	                  [
        R                  SR                  U5      S9n	UR                  U	5        U(       a  SR                  U5      Ul	         [        R                  " U R                  R                  UUUSS	S
S9 H  n
[
        R                  " X5      v   M     g! [        R                    a   n["        R$                  " U5         SnAgSnAff = f7f)a  List all tasks for the given execution.

Args:
  namespace_ref: Resource, namespace to list tasks in
  execution_name: str, The execution for which to list tasks.
  include_states: List[str], states of tasks to include in the list.
  limit: Optional[int], max number of tasks to list.
  page_size: Optional[int], number of tasks to fetch at a time

Yields:
  Executions for the given surface
r   Nz{label} = {name})labelrf   z{label} in ({states}),)rn  statesr[  r\  r]  r^  )r   RunNamespacesTasksListRequestr   rL  r   r   EXECUTION_LABELSTATE_LABELrY   r6  r
   rd  r   namespaces_tasksTaskr   r   r   r   )rh   r   execution_nameinclude_statesr]  ri  r   r   label_selectorsstatus_selectorrj  r   s               r9   	ListTasksServerlessOperations.ListTasks  s3    ( ##H44))+ 5 G O!

#
#((~ $ 
 !/66  .)A 7 o _-!hh7g=,,,,//"-8&& ii)) 44 =99!<<=s1   B:E=AD 
ED?D:5E:D??Ec           
   #   z  #    U R                   nUR                  UR                  5       S9nUb  X&l         [        R
                  " U R                  R                  UUUSSSS9 H  n[        R                  " Xu5      v   M     g! [        R                   a   n[        R                  " U5         SnAgSnAff = f7f)a  List all revisions for the given service.

Revision list gets sorted by service name and creation timestamp.

Args:
  namespace_ref: Resource, namespace to list revisions in
  label_selector: str, label selector for either a service or worker pool
    for which to list revisions.
  limit: Optional[int], max number of revisions to list.
  page_size: Optional[int], number of revisions to fetch at a time

Yields:
  Revisions for the given surface
r   Nr[  r\  r]  r^  )r   r7  r   r6  r
   rd  r   r   r   r   r   r   r   r   rg  s	            r9   ListRevisions"ServerlessOperations.ListRevisions  s     " ##H88))+ 9 G ! -=,,,,33"-8&& 11 44 =99!<<=s/   3B;AB B;B8B3.B;3B88B;c                    U R                   nUR                  UR                  5       S9n[        R                  " [
        R                  5         U R                  R                  R                  U5      nSSS5        WR                   Vs/ s H  n[        R                  " XR5      PM     sn$ ! , (       d  f       N?= fs  snf )zList all domain mappings.

Args:
  namespace_ref: Resource, namespace to list domain mappings in.

Returns:
  A list of domain mappings.
r   N)r   &RunNamespacesDomainmappingsListRequestr   r&   r   r   LIST_DOMAIN_MAPPINGSr   namespaces_domainmappingsr   r   r   DomainMappingr   s         r9   ListDomainMappings'ServerlessOperations.ListDomainMappings  s     ##H==))+ > G 
		 A A	B77<<WEh 
C BJAO$$T4  
C	Br   c                    U R                   n[        R                  R                  U R                  UR
                  5      nUR                  Ul        X&l        XFl	        U H  nUR                  U5      nM     UR                  UR                  5       UR                  5       R                  5       S9n[        R                   " ["        R$                  5          U R                  R&                  R)                  U5      n	[6        R8                  " S5         [:        R<                  " [>        R@                  " U 5      U5      n
SSS5        W
RB                  RE                  S5      nSnU(       a  URE                  S5      (       a  US   nU
RF                  (       ds  U
RH                  S   [        RJ                  :X  a3  [.        RL                  " SR3                  UR5                  5       5      5      e[.        R0                  " U=(       d    S	5      eU(       a  [N        RP                  RS                  U5        U
sSSS5        $ ! [*        R,                   a4    [.        R0                  " SR3                  UR5                  5       5      5      ef = f! , (       d  f       GNN= f! , (       d  f       O= f[        R                  " W	U5      $ )
aR  Create a domain mapping.

Args:
  domain_mapping_ref: Resource, domainmapping resource.
  service_name: str, the service to which to map domain.
  config_changes: list of ConfigChanger to modify the domainmapping with
  force_override: bool, override an existing mapping of this domain.

Returns:
  A domain_mapping.DomainMapping object.
)domainMappingr   z5Domain mapping to [{}] already exists in this region.zCreating...NReadyr\  reasonz3Domain mapping to [{}] is already in use elsewhere.z Could not create domain mapping.)*r   r   r  re  r   r  domainmappingsIdrf   
route_nameforce_overriderj   (RunNamespacesDomainmappingsCreateRequestrb  rf  r   r&   r   r   CREATE_DOMAIN_MAPPINGr  ri  r   HttpConflictErrorr   DomainMappingCreationErrorr   Namer)   ProgressTrackerr   r   r    !DomainMappingResourceRecordPollerr   rA  recordsready_condition'MAPPING_ALREADY_EXISTS_CONDITION_REASONDomainMappingAlreadyExistsErrorr%   rE  Print)rh   domain_mapping_refr)  r   r  r   new_mappingconfig_changer   r   mappingreadyr\  s                r9   CreateDomainMapping(ServerlessOperations.CreateDomainMapping  sI   & ##H ..22(55K *::K)!/'!((5k ( ??!))+!((*779 @ G 
		 B B	C
<<99@@I ++M:&&88>
 ;
   $$W-eg	599Y''	"__##H-EEF &EECJJ$))+ 
 $>>99
 	
 


!E 
D	C -- 
#>>CJJ"'')
 	

 ;: 
D	CH ''(;;s>   J%H;=J,J?C2J;AJJ
J	J
J&c                    U R                   nUR                  UR                  5       S9n[        R                  " [
        R                  5         U R                  R                  R                  U5        SSS5        g! , (       d  f       g= f)zXDelete a domain mapping.

Args:
  domain_mapping_ref: Resource, domainmapping resource.
r   N)
r   (RunNamespacesDomainmappingsDeleteRequestr   r&   r   r   DELETE_DOMAIN_MAPPINGr   r  r'  )rh   r  r   r   s       r9   DeleteDomainMapping(ServerlessOperations.DeleteDomainMapping`  sl     ##H??,,. @ G 
		 B B	C
ll,,33G< 
D	C	Cs   &A==
Bc                 H   U R                   nUR                  UR                  5       S9n[        R                  " [
        R                  5         U R                  R                  R                  U5      nSSS5        [        R                  " WU5      $ ! , (       d  f       N%= f)zGet a domain mapping.

Args:
  domain_mapping_ref: Resource, domainmapping resource.

Returns:
  A domain_mapping.DomainMapping object.
r   N)r   %RunNamespacesDomainmappingsGetRequestr   r&   r   r   GET_DOMAIN_MAPPINGr   r  r   r   r  )rh   r  r   r   r   s        r9   GetDomainMapping%ServerlessOperations.GetDomainMappingn  s     ##H<<,,. = G 
		 ? ?	@77;;GDh 
A''(;; 
A	@s   &B
B!c                 d   Uc-  [         R                  " [        R                  " USLU	SLS9SSS9nUbL  [        R
                  " UUUUU	UUU R                  U5	      u  n      nUc  gUR                  [        U5      5        U
(       + nU(       a  U R                  XXE5      $ U R                  XXE5      $ )a  Deploy to create a new Cloud Run Job or to update an existing one.

Args:
  job_ref: Resource, the job to create or update.
  config_changes: list, objects that implement Adjust().
  release_track: ReleaseTrack, the release track of a command calling this.
  tracker: StagedProgressTracker, to report on the progress of releasing.
  asyn: bool, if True, return without waiting for the job to be updated.
  build_image: The build image reference to the build.
  build_pack: The build pack reference to the build.
  build_source: The build source reference to the build.
  repo_to_create: Optional
    googlecloudsdk.command_lib.artifacts.docker_util.DockerRepo defining a
    repository to be created.
  prefetch: the job, pre-fetched for DeployJob. `None` indicates a
    nonexistent job so the job has to be created, else this is for an
    update.
  already_activated_services: bool. If true, skip activation prompts for
    services

Returns:
  A job.Job object.
N)r  r  Tr  r  )r)   r  r"   	JobStagesr#   r  r   rL  r   	CreateJob	UpdateJob)rh   job_refr   r  r  r  r  r  r  r  r  r  r   rV   	is_creates                  r9   	DeployJobServerlessOperations.DeployJob  s    J  ::


(4"0"< #g !)!5!5






$
,,

"lAq!Q 
	3LABI^^GWCC^^GWCCr8   c                 X   U R                   n[        R                  R                  U R                  UR                  5       R                  5       5      nUR                  5       Ul        UR                  5       R                  5       nU H  nUR                  U5      nM     UR                  UR                  5       US9n	Sn
[        R                  " [        R                  5          [        R                  " U R                  R                   R#                  U	5      U5      n
SSS5        U(       dX  [6        R8                  " U R:                  U5      n[<        R>                  " X5      nU RA                  U5        URC                  5       n
U
$ ! [$        R&                   a4    [(        R*                  " SR-                  UR                  5       5      5      e[$        R.                   a4  n[0        R2                  " [(        R4                  " U5      5         SnANSnAff = f! , (       d  f       GN= f)a5  Create a new Cloud Run Job.

Args:
  job_ref: Resource, the job to create.
  config_changes: list, objects that implement Adjust().
  tracker: StagedProgressTracker, to report on the progress of releasing.
  asyn: bool, if True, return without waiting for the job to be updated.

Returns:
  A job.Job object.
)r   r   NzJob [{}] already exists.)"r   r   Jobre  r   rf  r  rf   r   rj   RunNamespacesJobsCreateRequestrb  r&   r   r   
CREATE_JOBnamespaces_jobsri  r   r  r   ru  r   rj  r	   rk  rl  r<  r=  GetJobr    ConditionPollerr   r  )rh   r  r   r  r  r   new_jobr   r  create_requestcreated_jobr   r  r   s                 r9   r  ServerlessOperations.CreateJob  s    ##Hggkk$,,(8(=(=(?@G<<>GL^^**,F'$$W-g (<<OOf = N K			 7 7	8	?ggLL((//?
 
9   g6f))&:f
F#&&(k -- 
#99&--glln=
 	
 // ?0::1=>>? 
9	8s1   $H&:F		AH#*HHHH
H)c                    U R                   nU R                  U5      nUc3  [        R                  " SR	                  UR                  5       5      5      eU H  nUR                  U5      nM     UR                  UR                  5       UR                  5       S9nSn	[        R                  " [        R                  5          [        R                  " U R                   R"                  R%                  U5      U5      n	SSS5        U(       dX  [0        R2                  " U R                  U5      n[4        R6                  " X5      nU R9                  U5        UR;                  5       n	U	$ ! [&        R(                   a4  n
[*        R,                  " [        R.                  " U
5      5         Sn
A
NSn
A
ff = f! , (       d  f       N= f)a:  Update an existing Cloud Run Job.

Args:
  job_ref: Resource, the job to update.
  config_changes: list, objects that implement Adjust().
  tracker: StagedProgressTracker, to report on the progress of updating.
  asyn: bool, if True, return without waiting for the job to be updated.

Returns:
  A job.Job object.
NJob [{}] could not be found.)r   rf   )r   r  r   JobNotFoundErrorr   r  rj   "RunNamespacesJobsReplaceJobRequestrb  r   r&   r   r   
UPDATE_JOBr   r  r   r  
ReplaceJobr   rj  r	   rk  rl  r<  r=  r    r  r   r  )rh   r  r   r  r  r   
update_jobr  replace_requestreturned_jobr   r  r   s                r9   r  ServerlessOperations.UpdateJob  sk    ##HW%J!22
(
/
/
?  ( ''
3j (AA w';';'= B O L			 7 7	8?wwLL((33ODh
 
9   g6f))&:f
F#'')l // ?0::1=>>? 
9	8s0    F0:E%%F-9*F(#F0(F--F00
F>c                    U R                   nUR                  5       nU(       a  Xhl        UR                  UR	                  5       US9n	[
        R                  " [        R                  5          U R                  R                  R                  U	5      n
 SSS5        U(       a  ["        R$                  " W
U5      $ U R&                  R)                  W
R*                  R,                  SU
R*                  R.                  0SS9n[0        R2                  " U R4                  U5      nU(       a  ["        R6                  O["        R8                  nU R5                  U5      n[:        R<                  " UR>                  SS	9 H  nURA                  U5        M     [B        RD                  " UUU[F        RH                  " 5       S
9n U RK                  UU(       a  SOS5        U R5                  U5      $ ! [        R                   a-  nUR                  S:X  a  [        R                   " S5      eUeSnAff = f! , (       d  f       GN= f! [        RL                   a.    [        RL                  " S[N        RP                  " X_5      -   5      ef = f)a  Run a Cloud Run Job, creating an Execution.

Args:
  job_ref: Resource, the job to run
  tracker: StagedProgressTracker, to report on the progress of running
  wait: boolean, True to wait until the job is complete
  asyn: bool, if True, return without waiting for anything
  release_track: ReleaseTrack, the release track of a command calling this
  overrides: ExecutionOverrides to be applied for this run of a job

Returns:
  An Execution Resource in its state when RunJob returns.
)rf   runJobRequesti  zResource exhausted error. This may mean that too many executions are already running. Please wait until one completes before creating a new one.Nr  zrun.namespaces.executionsr  T)ignore_retry)r  r   zThe execution failed.))r   RunJobRequest	overridesRunNamespacesJobsRunRequestr   r&   r   r   RUN_JOBr   r  Runr   rl  r*  r   ru  r   rf  r   r  r  rf   r>  r<  r=  GetExecutionCOMPLETED_CONDITIONSTARTED_CONDITIONr  r  r   r  r    ExecutionConditionPollerr"   ExecutionDependenciesr   ExecutionFailedErrorr   GetExecutionCreatedMessage)rh   r  r  waitr  r  r  r   run_job_requestrun_requestexecution_messager   execution_refr  terminal_conditionexr   r   s                     r9   RunJobServerlessOperations.RunJob  s0   , ##H,,.O"+66!!#? 7 K 
		 4 4	5	 LL88<<[I 
6   !2H==NN((""'' 1 : : D DE. ) M
 t00-@F)-	%%93N3N  
		=	)B33
D  00113	F
FDDa8 ]++M %% ==C%;;5 
  
6	5H !55 !66
!44]GH s7   ,H*.%G&:H< &H':(H""H''H**
H9<AI>c                    U R                   nUR                  UR                  5       S9n [        R                  " [
        R                  5         U R                  R                  R                  U5      n[        R                  " XB5      sSSS5        $ ! , (       d  f       g= f! [        R                   a   n[        R                  " U5         SnAgSnAf[        R                    a     gf = f)z8Return the relevant Job from the server, or None if 404.r   N)r   RunNamespacesJobsGetRequestr   r&   r   r   GET_JOBr   r  r   r   r  r   r   r   r   r   )rh   r  r   get_requestjob_responser   s         r9   r  ServerlessOperations.GetJob^  s    ##H66!!# 7 K!!,"6"67||3377Dww|. 877 44 =99!<<++ r   c                    U R                   nUR                  UR                  5       S9n [        R                  " [
        R                  5         U R                  R                  R                  U5      n[        R                  " XB5      sSSS5        $ ! , (       d  f       g= f! [        R                   a   n[        R                  " U5         SnAgSnAf[        R                    a     gf = f)z9Return the relevant Task from the server, or None if 404.r   N)r   RunNamespacesTasksGetRequestr   r&   r   r   GET_TASKr   rt  r   r   ru  r   r   r   r   r   )rh   task_refr   r  task_responser   s         r9   GetTaskServerlessOperations.GetTaskn  s    ##H77""$ 8 K!!,"7"785599+Fyy1 988 44 =99!<<++ r   c                    U R                   nUR                  UR                  5       S9n [        R                  " [
        R                  5         U R                  R                  R                  U5      n[        R                  " XB5      sSSS5        $ ! , (       d  f       g= f! [        R                   a   n[        R                  " U5         SnAgSnAf[        R                    a     gf = f)z>Return the relevant Execution from the server, or None if 404.r   N)r   !RunNamespacesExecutionsGetRequestr   r&   r   r   GET_EXECUTIONr   re  r   r   rf  r   r   r   r   r   )rh   r  r   r  execution_responser   s         r9   r  !ServerlessOperations.GetExecution~  s    ##H<<'') = K!!,"<"<=!\\??CCKP""#5@ >== 44 =99!<<++ r   c                    U R                   nUR                  UR                  5       S9n [        R                  " [
        R                  5         U R                  R                  R                  U5      nUR                   Vs/ s H  n[        R                  " XR5      PM     snsSSS5        $ s  snf ! , (       d  f       g= f! [        R                   a   n[        R                   " U5         SnAgSnAff = f)z"Returns all jobs in the namespace.r   N)r   RunNamespacesJobsListRequestr   r&   r   r   	LIST_JOBSr   r  r   r   r   r  r   r   r   r   r   s          r9   ListJobsServerlessOperations.ListJobs  s    ##H33))+ 4 G=!!,"8"89<<//44W=4<NNCND'NC :9C :9 44 =99!<<=sG   $C 4B4 B/#B4%	C /B44
C>C C C9C44C9c                    U R                   nUR                  UR                  5       S9n [        R                  " [
        R                  5         U R                  R                  R                  U5        SSS5        g! , (       d  f       g= f! [        R                   a4    [        R                  " SR                  UR                  5       5      5      ef = f)zDelete the provided Job.

Args:
  job_ref: Resource, a reference to the Job to delete

Raises:
  JobNotFoundError: if provided job is not found.
r   Nr  )r   RunNamespacesJobsDeleteRequestr   r&   r   r   
DELETE_JOBr   r  r'  r   r   r   r  r   r  )rh   r  r   r   s       r9   	DeleteJobServerlessOperations.DeleteJob  s     ##H55!!# 6 G!!,"9"9:$$++G4 ;::++ !22
(
/
/
? *   $B &A>5B >
BB B ACc                    U R                   nUR                  UR                  5       S9n [        R                  " [
        R                  5         U R                  R                  R                  U5        SSS5        g! , (       d  f       g= f! [        R                   a4    [        R                  " SR                  UR                  5       5      5      ef = f)zDelete the provided Execution.

Args:
  execution_ref: Resource, a reference to the Execution to delete

Raises:
  ExecutionNotFoundError: if provided Execution is not found.
r   N"Execution [{}] could not be found.)r   $RunNamespacesExecutionsDeleteRequestr   r&   r   r   DELETE_EXECUTIONr   re  r'  r   r   r   ExecutionNotFoundErrorr   r  rh   r  r   r   s       r9   DeleteExecution$ServerlessOperations.DeleteExecution       ##H;;'') < G!!,"?"?@**11': A@@++ !88
.
5
5m6H6H6J
K r  c                    U R                   nUR                  UR                  5       S9n [        R                  " [
        R                  5         U R                  R                  R                  U5        SSS5        g! , (       d  f       g= f! [        R                   a4    [        R                  " SR                  UR                  5       5      5      ef = f)zCancel the provided Execution.

Args:
  execution_ref: Resource, a reference to the Execution to cancel

Raises:
  ExecutionNotFoundError: if provided Execution is not found.
r   Nr  )r   $RunNamespacesExecutionsCancelRequestr   r&   r   r   CANCEL_EXECUTIONr   re  Cancelr   r   r   r   r   r  r  s       r9   CancelExecution$ServerlessOperations.CancelExecution  r  r  c                     U R                   nUR                  [        R                  " U5      S9nU R                  R
                  R                  U5      nU$ )z$Gets the IAM policy for the service.)ri   )r   /RunProjectsLocationsServicesGetIamPolicyRequestsix	text_typer   r   GetIamPolicy)rh   r)  r   r   r   s        r9   _GetIamPolicy"ServerlessOperations._GetIamPolicy  sP    ##HFF|, G G ::GGPHOr8   c                    U R                   nU=(       d    U R                  n[        R                  " X5      nU R	                  U5      n	U(       ad  U(       a]  U(       a#  [
        R                  " UR                  XU5        O3[
        R                  " XU5      (       a  [
        R                  " XU5        UR                  [        R                  " U5      UR                  U	S9S9n
U R                  R                  R!                  U
5      nU$ )a  Add or remove the given IAM policy binding to the provided service.

If no members or role are provided, set the IAM policy to the current IAM
policy. This is useful for checking whether the authenticated user has
the appropriate permissions for setting policies.

Args:
  service_ref: str, The service to which to add the IAM policy.
  add_binding: bool, Whether to add to or remove from the IAM policy.
  member: str, One of the users for which the binding applies.
  role: str, The role to grant the provided members.
  region_override: str, The region to use instead of the configured region.

Returns:
  A google.iam.v1.TestIamPermissionsResponse.
)policy)ri   setIamPolicyRequest)r   r   r!   K8sToOnePlatformr  r   AddBindingToIamPolicyBindingBindingInPolicyRemoveBindingFromIamPolicy/RunProjectsLocationsServicesSetIamPolicyRequestr  r  SetIamPolicyRequestr   r   SetIamPolicy)rh   r   add_bindingr'  roler  r   r   oneplatform_servicer  r   rj  s               r9   r  0ServerlessOperations.AddOrRemoveIamPolicyBinding  s    0 ##H,F2CC  34F$	&&x'7'7N##FD99++FDAFF23$888G G G __88EEgNFMr8   c                    U R                   nU=(       d    U R                  n[        R                  " X5      nUR	                  [
        R                  " U5      UR                  [        S9S9nU R                  R                  R                  U5      n[        [        5      R                  [        UR                  5      5      $ )zBCheck if user has permission to set the iam policy on the service.)permissions)ri   testIamPermissionsRequest)r   r   r!   r  5RunProjectsLocationsServicesTestIamPermissionsRequestr  r  TestIamPermissionsRequestNEEDED_IAM_PERMISSIONSr   r   TestIamPermissionssetissubsetr"  )rh   r   r  r   r   r  r   r   s           r9   CanSetIamPolicyBinding+ServerlessOperations.CanSetIamPolicyBinding  s    ##H,F2CC LL23"*"D"D. #E #
 M G ||77JJH %&//H4H4H0IJJr8   c                     U R                  U5      n[        [        5      nUR                  U5        U R	                  XSUSS9  UR                  5         g)z:Validates starting service operation with provided config.T)rz  rM  r{  N)r   r   FAKE_IMAGE_DIGESTrL  r  pop)rh   r   r   rM  fake_validation_images        r9   _ValidateService%ServerlessOperations._ValidateService   sU    ??;'D34EF/0t$    r8   c                    UR                  [        R                  " [        R                  5      5        UR                  [        R                  " [        R
                  5      5        UR                  [        R                  " [        R                  5      5        UR                  [        R                  " [        R                  5      5        g)zCClear run functions annotations to the service before setting them.N)rL  r_  DeleteAnnotationChanger   3RUN_FUNCTIONS_SOURCE_LOCATION_ANNOTATION_DEPRECATED3RUN_FUNCTIONS_FUNCTION_TARGET_ANNOTATION_DEPRECATED-RUN_FUNCTIONS_IMAGE_URI_ANNOTATION_DEPRECATED1RUN_FUNCTIONS_ENABLE_AUTOMATIC_UPDATES_DEPRECATED)rh   r   s     r9   r  2ServerlessOperations._ClearRunFunctionsAnnotations*  s    11GG	

 11GG	

 11AA	

 11EE	
r8   r  c                    U(       a  [         R                  " U5      OSnU R                  U5      nSnU(       a  [        R                  " U5      nU(       a  US   R                  S5      OUn[        R                  U[        R                  U[        R                  U[        R                  U[        R                  U	[        R                  U[        R                  U[        R                  U[        R                  U(       a  SOS0	nU(       a  U R!                  UU
U5        OU R#                  X5        UR%                  S UR'                  5        5       5        U
(       a5  UR)                  [*        R,                  " [        R.                  U
5      5        gUR)                  [*        R0                  " [        R.                  5      5        g)z-Add run functions annotations to the service.Nr   r   truefalsec              3   \   #    U  H"  u  pUc  M
  [         R                  " X5      v   M$     g 7frP   )r_  SetAnnotationChange)rU   kvs      r9   rW   CServerlessOperations._AddRunFunctionsAnnotations.<locals>.<genexpr>p  s-      +DA 	5..q44+s   	,,)jsondumpsr  r$   r  rA  r   .RUN_FUNCTIONS_BUILD_SERVICE_ACCOUNT_ANNOTATION*RUN_FUNCTIONS_BUILD_WORKER_POOL_ANNOTATION'RUN_FUNCTIONS_BUILD_ENV_VARS_ANNOTATION!RUN_FUNCTIONS_BUILD_ID_ANNOTATION#RUN_FUNCTIONS_BUILD_NAME_ANNOTATION(RUN_FUNCTIONS_BUILD_IMAGE_URI_ANNOTATION.RUN_FUNCTIONS_BUILD_SOURCE_LOCATION_ANNOTATION.RUN_FUNCTIONS_BUILD_FUNCTION_TARGET_ANNOTATION,RUN_FUNCTIONS_BUILD_ENABLE_AUTOMATIC_UPDATESr  r  extendr   rL  r_  r=  RUN_FUNCTIONS_BUILD_BASE_IMAGEr3  )rh   r   r  r  r   r  r  r  r  r  r  r  r  build_env_vars_strfunction_targetr  	image_uriannotations_maps                     r9   r  0ServerlessOperations._AddRunFunctionsAnnotationsA  sq     8FN34:::FOK((9k.8
1!!'*kI>>::K779K11833Z88)>>>><<.FGO  
!!


* --
  #))+ 
 

0
0446F 

3
344r8   c                 Z    U R                  U5      nU H  nUR                  U5      nM     g)a  Apply config changes to Job resource to validate.

This is to replicate the same validation logic in `jobs/services update`.
Override attempts with types (out of string literals, secrets,
config maps) that are different from currently set value type will appear as
errors in the console.

Args:
  job_ref: Resource, job resource.
  config_changes: Job configuration changes from Overrides
N)r  rj   )rh   r  r   run_jobchanges        r9   ValidateConfigOverrides,ServerlessOperations.ValidateConfigOverrides  s*     kk'"G g&g !r8   c           	          U R                   R                  UUUU R                   R                  R                  UR                  5       5      S9$ )N)containerOverrides	taskCounttimeoutSecondspriorityTier)r   	OverridesPriorityTierValueValuesEnumupper)rh   taskstask_timeoutpriority_tiercontainer_overridess        r9   GetExecutionOverrides*ServerlessOperations.GetExecutionOverrides  sQ     )).#))33OO!
	 *  r8   c                 j    U R                   R                  UU=(       d    / U R                  U5      US9$ )N)rf   argsenv	clearArgs)r   ContainerOverride_GetEnvVarList)rh   rf   update_env_varsrg  
clear_argss        r9   MakeContainerOverride*ServerlessOperations.MakeContainerOverride  s;    11ZR0	 2  r8   c                     / nUbA  UR                  5        H-  u  p4UR                  U R                  R                  X4S95        M/     U$ )N)rf   value)r   rL  r   EnvVar)rh   env_varsenv_var_listrf   rq  s        r9   rk  #ServerlessOperations._GetEnvVarList  sH    L!)+$D0077T7OP *r8   )r   r   r   r   r   )r   F)NFNNFFNNNNNFFFFNNrN   NNNFFNNNF)rN   Nd   )NNrw  )Nrw  )NFNNNNNF)NF)NFFNN)TNNNrP   )Tr3   r4   r5   r6   rm   r   propertyr   r   r   r   r   r   r   r   r   r   GAr  r  r!  r+  r3  r8  rI  rN  r  r  r  r  r  r  r)   StagedProgressTrackerrS   r   r   r   r_  ConfigChangerboolr  r  r  r  r$  r  r+   RetryOnExceptionr)  r:  r@  rI  rF  rE  rk  rz  r}  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r	  r  r  r*  r0  r  r  rV  rd  rn  rk  r7   r2   r8   r9   rE   rE      s   P&$ ( (*<==D& 6:5F5F5I5I+Z80.(=N`D CHm^+ZI*3553 3 	3
 -;;<3 3L  !& (*$?B
B&PV$(
T 	rI> ?
$==~0EP EH$=T 2=j BE&=P0 F<P=<, !&CDJ(T&V F,P   =*** )VK$.? !%?B' 
r8   rE   rv  )Yrm   
__future__r   r   r   r   
contextlibr  dataclassesr<  rA  rQ   rS   typingr   apitools.base.pyr   r	   r   r
   googlecloudsdk.api_lib.runr   r  r   r   r   r   r   r   r   r   r   r   r   r5  googlecloudsdk.api_lib.utilr   r   rm  r   googlecloudsdk.callioper   googlecloudsdk.command_lib.iamr   googlecloudsdk.command_lib.runr   r_  r   r   r   r    r!   r"   ,googlecloudsdk.command_lib.run.sourcedeploysr#   r$   googlecloudsdk.corer%   r&   r'   r(   googlecloudsdk.core.consoler)   'googlecloudsdk.core.universe_descriptorr*   googlecloudsdk.core.utilr+   r  DEFAULT_ENDPOINT_VERSIONr[   r  r  r&  r-  Errorr0   contextmanagerrL   r\   	dataclassTemplateConfigChangerr_   RevisionNameChangesrq   rz   r|   r   objectrE   r2   r8   r9   <module>r     s  " N &  % '         % 9 ' A 4 5 0 5 * 3 / , . + E , 5 H . ( 3 O N 8 9 5 C 1 A @ * # ' * ) 8 G * 
   %/ "#6  56  N 
j&&  2 2j d#0FF  $$ 2 F F $
 d#.DD  $ d#
0FF 
 $
Y6 Yr8   