
                            S r SSKJr  SSKJrJr  SSKJr  SSKJ	r	  SSK
Jr  SSKJr  SSKJr  SSKJr  SS	Kr " S
 S\5      rg	)z%Cloud Functions (2nd gen) API Client.    )annotations)	GeneratorOptional)
exceptions)
list_pager)util)types)
propertiesNc                     \ rS rSrSrS rSS jrSSS jjr\R                   S     SS jj5       r
\R                  SS j5       r\R                  SS	 j5       r\R                  SS
 j5       r\R                  SS j5       r\R                  SS j5       r\R                     S         SS jj5       r\R                  SS j5       rSrg)FunctionsClient   z)Client for Cloud Functions (2nd gen) API.c                p    [         R                  " U5      U l        [         R                  " U5      U l        g N)r   GetClientInstanceclientGetMessagesModulemessages)selfrelease_tracks     1lib/googlecloudsdk/api_lib/functions/v2/client.py__init__FunctionsClient.__init__!   s&    ((7DK**=9DM    c                    [         R                  R                  R                  R	                  5       nU R
                  R                  SU-   S9n[        R                  " U R                  R                  USSS9$ )z|Lists GCF gen2 regions.

Returns:
  Iterable[cloudfunctions_v2alpha.Location], Generator of available GCF gen2
    regions.
z	projects/name	locationspageSize)servicerequestfieldbatch_size_attribute)r
   VALUEScoreproject	GetOrFailr   *CloudfunctionsProjectsLocationsListRequestr   YieldFromListr   projects_locations)r   r%   r    s      r   ListRegionsFunctionsClient.ListRegions%   sq     $$,,668GmmFF7" G G ##..'	 r   Nc                    [         R                  R                  R                  R	                  5       nU R
                  R                  SR                  X1S9US9nU R                  R                  R                  U5      $ )zLists available GCF Gen 2 Runtimes in a region.

Args:
  region: str, The region targeted to list runtimes in.
  query_filter: str, Filters to apply to the list runtimes request.

Returns:
  v2alpha|v2beta.ListRuntimesResponse, The list runtimes request
z%projects/{project}/locations/{region})r%   region)parentfilter)r
   r#   r$   r%   r&   r   2CloudfunctionsProjectsLocationsRuntimesListRequestformatr   projects_locations_runtimesList)r   r-   query_filterr%   r    s        r   ListRuntimesFunctionsClient.ListRuntimes7   sx     $$,,668G mmNN6== > 
 	 O G ;;2277@@r   c                2    U R                   R                  R                  U R                  R	                  US95      $ ! [
        R                   aD  nU(       d2  UR                  [        R                  R                  R                  :w  a  e  SnAgSnAff = f)a!  Gets the function with the given name or None if not found.

Args:
  name: GCFv2 function resource relative name.
  raise_if_not_found: If set, raises NOT_FOUND http errors instead of
    returning None.

Returns:
  cloudfunctions_v2_messages.Function, the fetched GCFv2 function or None.
r   N)r   projects_locations_functionsGetr   2CloudfunctionsProjectsLocationsFunctionsGetRequestapitools_exceptions	HttpErrorstatus_codesixmoveshttp_client	NOT_FOUND)r   r   raise_if_not_founderrors       r   GetFunctionFunctionsClient.GetFunctionM   s~    [[5599
--
J
J K  
 (( 	


syy44>>
>s   ;> B:BBc                z    U R                   R                  R                  U R                  R	                  US95      $ )zAborts the function upgrade for the given function.

Args:
  name: str, GCFv2 function resource relative name.

Returns:
  A long-running operation.
r   )r   r8   AbortFunctionUpgrader   CCloudfunctionsProjectsLocationsFunctionsAbortFunctionUpgradeRequestr   r   s     r   rG   $FunctionsClient.AbortFunctionUpgradei   s<     ;;33HHYY 	Z 	
 r   c                z    U R                   R                  R                  U R                  R	                  US95      $ )zCommits the function upgrade for the given function.

Args:
  name: str, GCFv2 function resource relative name.

Returns:
  A long-running operation.
r   )r   r8   CommitFunctionUpgrader   DCloudfunctionsProjectsLocationsFunctionsCommitFunctionUpgradeRequestrI   s     r   rL   %FunctionsClient.CommitFunctionUpgradey   s<     ;;33IIZZ 	[ 	
 r   c                z    U R                   R                  R                  U R                  R	                  US95      $ )zCommits the function upgrade for the given function as 2nd Gen.

Args:
  name: str, GCFv2 function resource relative name.

Returns:
  A long-running operation.
r   )r   r8   CommitFunctionUpgradeAsGen2r   JCloudfunctionsProjectsLocationsFunctionsCommitFunctionUpgradeAsGen2RequestrI   s     r   rP   +FunctionsClient.CommitFunctionUpgradeAsGen2   s<     ;;33OO`` 	a 	
 r   c                z    U R                   R                  R                  U R                  R	                  US95      $ )zRedirects function upgrade traffic for the given function.

Args:
  name: str, GCFv2 function resource relative name.

Returns:
  A long-running operation.
r   )r   r8   RedirectFunctionUpgradeTrafficr   MCloudfunctionsProjectsLocationsFunctionsRedirectFunctionUpgradeTrafficRequestrI   s     r   rT   .FunctionsClient.RedirectFunctionUpgradeTraffic   <     ;;33RRcc 	d 	
 r   c                z    U R                   R                  R                  U R                  R	                  US95      $ )zRolls back function upgrade traffic for the given function.

Args:
  name: str, GCFv2 function resource relative name.

Returns:
  A long-running operation.
r   )r   r8   RollbackFunctionUpgradeTrafficr   MCloudfunctionsProjectsLocationsFunctionsRollbackFunctionUpgradeTrafficRequestrI   s     r   rY   .FunctionsClient.RollbackFunctionUpgradeTraffic   rW   r   c                ^   U R                   R                  5       nU(       a  X%l        U(       a  U R                   R                  US9Ul        U(       a  U R                   R                  US9Ul        U R                  R                  R                  U R                   R                  UUS95      $ )ag  Sets up the function upgrade config for the given function.

Args:
  name: str, GCFv2 function resource relative name.
  trigger_service_account: str, The service account to use for the trigger.
  runtime: str, The runtime to use for the new function.
  max_instances: int, The max instances to use for the new function.

Returns:
  A long-running operation.
)runtime)maxInstanceCount)r   !setupFunctionUpgradeConfigRequest)r   !SetupFunctionUpgradeConfigRequesttriggerServiceAccountBuildConfigOverridesbuildConfigOverridesServiceConfigOverridesserviceConfigOverridesr   r8   SetupFunctionUpgradeConfigICloudfunctionsProjectsLocationsFunctionsSetupFunctionUpgradeConfigRequest)r   r   trigger_service_accountr]   max_instancessetup_requests         r   rf   *FunctionsClient.SetupFunctionUpgradeConfig   s    & MMCCEM,C)+/==+M+M ,N ,m( 
--
.
.
.
N * ;;33NN__.; 	` 	
 r   c                z    U R                   R                  R                  U R                  R	                  US95      $ )a  Detach a GCF 2nd gen function from GCF and make it a native Cloud Run function.

Args:
  name: str, GCFv2 function resource relative name which follows the format
    of `projects/{project}/locations/{region}/functions/{function}`.

Returns:
  A long-running operation.
r   )r   r8   DetachFunctionr   =CloudfunctionsProjectsLocationsFunctionsDetachFunctionRequestrI   s     r   rm   FunctionsClient.DetachFunction   s<     ;;33BBSS 	T 	
 r   )r   r   )returnz%Generator[types.Location, None, None]r   )r-   strr4   Optional[str])F)r   rq   rB   boolrp   zOptional[types.Function])r   rq   rp   types.Operation)NNN)
r   rq   rh   rr   r]   rr   ri   zOptional[int]rp   rt   )__name__
__module____qualname____firstlineno____doc__r   r*   r5   util_v1 CatchHTTPErrorRaiseHTTPExceptionrD   rG   rL   rP   rT   rY   rf   rm   __static_attributes__ r   r   r   r      s<   1:$A, ++27+/ ,6 ++ , ++ , ++ , ++ , ++ , ++ 04#%)##  -# 	#
 ## # ,#J ++ ,r   r   )ry   
__future__r   typingr   r   apitools.base.pyr   r;   r   #googlecloudsdk.api_lib.functions.v1r   rz   #googlecloudsdk.api_lib.functions.v2r	   googlecloudsdk.corer
   r>   objectr   r}   r   r   <module>r      s3    , " & > ' ? 5 4 * 
Pf Pr   