
                             S r SSKJr  SSKJ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.    )absolute_import)division)unicode_literals)	GeneratorOptional)
exceptions)
list_pager)util)types)
propertiesNc            	       X   \ rS rSrSrS rS\\R                  SS4   4S jr	SS\
S\\
   4S	 jjr\R                   SS
\
S\S\\R                      4S jj5       r\R                  S
\
S\R$                  4S j5       r\R                  S
\
S\R$                  4S j5       r\R                  S
\
S\R$                  4S j5       r\R                  S
\
S\R$                  4S j5       r\R                  S
\
S\
S\R$                  4S j5       r\R                  S
\
S\R$                  4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    returnNc                     [         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   regionquery_filterc                     [         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(   r/   )parentfilter)r   r&   r'   r(   r)   r   2CloudfunctionsProjectsLocationsRuntimesListRequestformatr   projects_locations_runtimesList)r   r/   r0   r(   r#   s        r   ListRuntimesFunctionsClient.ListRuntimes9   sx     $$,,668G mmNN6== > 
 	 O G ;;2277@@r   r   raise_if_not_foundc                 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   r:   errors       r   GetFunctionFunctionsClient.GetFunctionO   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   r<   AbortFunctionUpgrader   CCloudfunctionsProjectsLocationsFunctionsAbortFunctionUpgradeRequestr   r   s     r   rJ   $FunctionsClient.AbortFunctionUpgradek   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   r<   CommitFunctionUpgrader   DCloudfunctionsProjectsLocationsFunctionsCommitFunctionUpgradeRequestrL   s     r   rO   %FunctionsClient.CommitFunctionUpgrade{   s<     ;;33IIZZ 	[ 	
 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   r<   RedirectFunctionUpgradeTrafficr   MCloudfunctionsProjectsLocationsFunctionsRedirectFunctionUpgradeTrafficRequestrL   s     r   rS   .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   r<   RollbackFunctionUpgradeTrafficr   MCloudfunctionsProjectsLocationsFunctionsRollbackFunctionUpgradeTrafficRequestrL   s     r   rX   .FunctionsClient.RollbackFunctionUpgradeTraffic   rV   r   trigger_service_accountc           	          U R                   R                  R                  U R                  R	                  UU R                  R                  US9S95      $ )zSets 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.

Returns:
  A long-running operation.
)triggerServiceAccount)r   !setupFunctionUpgradeConfigRequest)r   r<   SetupFunctionUpgradeConfigr   ICloudfunctionsProjectsLocationsFunctionsSetupFunctionUpgradeConfigRequest!SetupFunctionUpgradeConfigRequest)r   r   r[   s      r   r_   *FunctionsClient.SetupFunctionUpgradeConfig   sW     ;;33NN__.2mm.].]&= /^ / 	` 	
 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   r<   DetachFunctionr   =CloudfunctionsProjectsLocationsFunctionsDetachFunctionRequestrL   s     r   rd   FunctionsClient.DetachFunction   s<     ;;33BBSS 	T 	
 r   )r   r   r   )F)__name__
__module____qualname____firstlineno____doc__r   r   r   Locationr-   strr   r8   util_v1 CatchHTTPErrorRaiseHTTPExceptionboolFunctionrG   	OperationrJ   rO   rS   rX   r_   rd   __static_attributes__ r   r   r   r       s   1:9U^^T4%?@ $A AHSM A, ++27+/ ,6 ++s u  , ++   , ++   , ++   , ++03 ,* ++   ,r   r   )rk   
__future__r   r   r   typingr   r   apitools.base.pyr   r?   r	   #googlecloudsdk.api_lib.functions.v1r
   rn   #googlecloudsdk.api_lib.functions.v2r   googlecloudsdk.corer   rB   objectr   rt   r   r   <module>r|      s9    , &  ' & > ' ? 5 4 * 
pf pr   