
    )2                        S r SSK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Jr  SS	KJr  SSKJr  SS
KJr  SSKJr  SSKJr  SrSrSrSrSrSr\R:                  " S5      rS rS\R@                  S\S\\RB                     4S jr"S\R@                  S\S\RF                  4S jr$ S/S\R@                  S\S\\\RJ                        S\\RL                     4S jjr'S\R@                  S\S\RB                  S\RP                  4S jr) S/S\R@                  S\S\RB                  S\\*   S\RP                  4
S jjr+ S0S\R@                  S\S \RX                  S!\\-   S\RP                  4
S" jjr.S\R@                  S#\*S\\RX                     4S$ jr/S\R@                  S%\RP                  S\RB                  4S& jr0S\R@                  S%\RP                  S\RX                  4S' jr1  S1S\R@                  S%\RP                  4S( jjr2S%\RP                  S\Rf                  4S) jr4S\R@                  S*\*S\Rj                  4S+ jr6S,\*S-\7S\74S. jr8g)2z;Functionality related to Cloud Run Integration API clients.    N)ListOptional)encoding)
exceptions)apis)waiter)log)	resources)retry)runapps_v1alpha1_client)runapps_v1alpha1_messagesrunappsv1alpha1configr
   i@w   zLocation [\w-]+ is not foundc                  @    [         R                  " [        [        5      $ )zReturns the messages module for the Runapps API.

Returns:
  Module containing the definitions of messages for the Runapps API.
)r   GetMessagesModuleAPI_NAMEAPI_VERSION     8lib/googlecloudsdk/api_lib/run/integrations/api_utils.pyGetMessagesr   3   s     
		+	66r   clientapp_refreturnc                     U R                   R                  UR                  5       S9n U R                  R	                  U5      $ ! [
        R                   a     g[
        R                   a   n[        UR                  U5         SnAgSnAff = f)ad  Calls GetApplication API of Runapps for the specified reference.

Args:
  client: The api client to use.
  app_ref: The resource reference of the application.

Raises:
  exceptions.UnsupportedIntegrationsLocationError: if the region does not
    exist for the user.

Returns:
  The application.  If the application does not exist, then
  None is returned.
nameN)
MESSAGES_MODULE.RunappsProjectsLocationsApplicationsGetRequestRelativeNameprojects_locations_applicationsGetapitools_exceptionsHttpNotFoundErrorHttpForbiddenError_HandleLocationErrorlocationsId)r   r   requestes       r   GetApplicationr,   <   s    $ KK##% L ' 
11155g>>		.	. 		/	/ 1,,a001s   A BB-BBc           	      :   U R                   R                  UR                  5       S9nU R                  R	                  U5      nUR
                  (       aG  [        R                  " SR                  SR                  [        UR
                  5      5      5      5        U$ )zBCalls ListApplications API of Runapps for the specified reference.)parentzIThe following regions did not respond: {}. List results may be incompletez, )r    /RunappsProjectsLocationsApplicationsListRequestr"   r#   r   unreachabler	   warningformatjoinsorted)r   r   r*   responses       r   ListApplicationsr6   Y   s    
 LL%%' M  
 3388A(KK	))/IIfX1123*
 
/r   resource_idsc                 6   U(       a,  U Vs/ s H  o3R                   S-   UR                  -   PM      nnO/ nU R                  nUR                  UR	                  5       US9n U R
                  R                  U5      $ s  snf ! [        R                   a     gf = f)ag  Calls GetApplicationStatus API of Runapps for the specified reference.

Args:
  client: the api client to use.
  app_ref: the resource reference of the application.
  resource_ids: ResourceID of the resource to get status for. If not given,
    all resources in the application will be queried.

Returns:
  The ApplicationStatus object. Or None if not found.
/)r   r
   N)	typer   r    4RunappsProjectsLocationsApplicationsGetStatusRequestr"   r#   	GetStatusr%   r&   )r   r   r7   res_idres_filtersmoduler*   s          r   GetApplicationStatusr@   o   s    " 6B6BFcFKK'l  K K!!&GG![ H '11;;GDD 
	.	. s   %A<!B BBapplicationc                     U R                   R                  U R                  R                  UUR                  UR                  5       R                  5       S95      $ )zCalls CreateApplicaton API of Runapps for the specified reference.

Args:
  client: the api client to use.
  app_ref: the resource reference of
    the application.
  application: the application to create

Returns:
  the LRO of this request.
)rA   applicationIdr.   )r#   Creater    1RunappsProjectsLocationsApplicationsCreateRequestr   Parentr"   )r   r   rA   s      r   CreateApplicationrG      sV      
	/	/	6	6NN!#((!..0 O 2
3 3r   update_maskc                     U R                   R                  U R                  R                  UUUR	                  5       S95      $ )a:  Calls ApplicationPatch API of Runapps for the specified reference.

Args:
  client: the api client to use.
  app_ref: the resource reference of
    the application.
  application: the application to patch
  update_mask: comma separated string listing the fields to be updated.

Returns:
  the LRO of this request.
)rA   
updateMaskr   )r#   Patchr    0RunappsProjectsLocationsApplicationsPatchRequestr"   )r   r   rA   rH   s       r   PatchApplicationrM      sI    " 
	/	/	5	5MM! ##% N '
( (r   
deploymentvalidate_onlyc           	          U R                   R                  U R                  R                  UR	                  5       UUR
                  US95      $ )a   Calls CreateDeployment API of Runapps.

Args:
  client: the api client to use.
  app_ref: the resource reference of the application the deployment belongs to
  deployment: the deployment object
  validate_only: whether to only validate the deployment

Returns:
  the LRO of this request.
)r.   rN   deploymentIdvalidateOnly)+projects_locations_applications_deploymentsrD   r    <RunappsProjectsLocationsApplicationsDeploymentsCreateRequestr"   r   )r   r   rN   rO   s       r   CreateDeploymentrU      sP    " 
	;	;	B	BCC%%'!$	 D &
 r   deployment_namec                      U R                   R                  U R                  R                  US95      $ ! [        R
                   a     gf = f)a:  Calls GetDeployment API of Runapps.

Args:
  client: the api client to use.
  deployment_name: the canonical name of the deployment.  For example:
    projects/<project>/locations/<location>/applications/<app>/deployment/<id>

Returns:
  the Deployment object.  None is returned if the deployment cannot be found.
r   N)rS   r$   r    9RunappsProjectsLocationsApplicationsDeploymentsGetRequestr%   r&   )r   rV   s     r   GetDeploymentrY      sW    ==AA	B	B  
C 
"
 

 
	.	. s   14 A
A	operationc                 .    [        XU R                  5      $ )zWaits for an operation to complete.

Args:
  client:  client used to make requests.
  operation: object to wait for.

Returns:
  the application from the operation.
)_WaitForOperationr#   )r   rZ   s     r   WaitForApplicationOperationr]      s     
6!AA
C Cr   c                 0    [        XU R                  X#5      $ )a)  Waits for an operation to complete.

Args:
  client: client used to make requests.
  operation: object to wait for.
  tracker: The ProgressTracker that tracks the operation progress.
  tracker_update_func: function to update the tracker on polling.

Returns:
  the deployment from thex operation.
)r\   rS   )r   rZ   trackertracker_update_funcs       r   WaitForDeploymentOperationra     s      
6!MM"
9 9r   c           
        ^^ [         R                  " UU R                  5      n[        R                  R                  UR                  SR                  [        5      S9nUU4S jn UR                  [         R                  " UU[        [        US95      $ ! [         R                   at    UR                  U5      n[        R                   " SR                  UR"                  R$                  [&        R(                  " UR"                  R*                  5      5      5      e[,        R.                   a-    [         R0                  " SR                  [        S-  5      5      ef = f)a}  Waits for an operation to complete.

Args:
  client:  client used to make requests.
  operation: object to wait for.
  resource_type: type, the expected type of resource response
  tracker: The ProgressTracker that tracks the operation progress.
  tracker_update_func: function to update the tracker on polling.

Returns:
  The resulting resource of input paramater resource_type.
z {}.projects.locations.operations)
collectionc                 P   > Tc  g T(       a
  T" TX5        g TR                  5         g N)Tick)resultstatusr_   r`   s     r   _StatusUpdate(_WaitForOperation.<locals>._StatusUpdate/  s!    '62llnr   )max_wait_mswait_ceiling_msstatus_updatez%OperationError: code={0}, message={1}zkOperation timed out after {0} seconds. The operations may still be underway remotely and may still succeed.r   )r   CloudOperationPollerprojects_locations_operationsr
   REGISTRYParseRelativeNamer   r2   r   	GetResultPollUntilDone_POLLING_TIMEOUT_MS_RETRY_TIMEOUT_MSOperationErrorPollr   IntegrationsOperationErrorerrorcoder   Decodemessager   WaitExceptionTimeoutError)r   rZ   resource_typer_   r`   polleroperation_refri   s      ``   r   r\   r\     s0   " &&}'-'K'KM&$$66nn3::8D 7 F--+-'	)* * 
		 MM*I

/
//66OO  (//)//2I2I"J	LM M 
		 -


	6	#d*	+- --s   '.B CEc                     [         R                  " U R                  [         R                  " UR                  5      5      $ )zGet the metadata message for the deployment operation.

Args:
  messages: Module containing the definitions of messages for the Runapps
    API.
  operation: The LRO

Returns:
  The DeploymentOperationMetadata object.
)apitools_encodingPyValueToMessageDeploymentOperationMetadataMessageToPyValuemetadata)messagesrZ   s     r   GetDeploymentOperationMetadatar   L  s4     
	+	+**((););<
> >r   proj_idc                     U R                   R                  SR                  U5      S9nU R                  R	                  U5      $ )zGet the list of all available regions from control plane.

Args:
  client: instance of a client to use for the list request.
  proj_id: project id of the project to query.

Returns:
  A list of location resources.
zprojects/{0}r   )r    #RunappsProjectsLocationsListRequestr2   projects_locationsr   )r   r   r*   s      r   ListLocationsr   `  sG     ""FF  ) G ' 
	"	"	'	'	00r   regionry   c                     [         R                  " U5      n[        R                  UR                  R
                  5      (       a%  [        R                  " SR                  U 5      5      eUe)zGet the metadata message for the deployment operation.

Args:
  region: target region of the request.
  error: original HttpError.

Raises:
  UnsupportedIntegrationsLocationError if it's location error. Otherwise
  raise the original error.
z3Location {} is not found or access is unauthorized.)	api_lib_exceptionsHttpException_LOCATION_ERROR_REGEXmatchpayloadstatus_messager   $UnsupportedIntegrationsLocationErrorr2   )r   ry   
parsed_errs      r   r(   r(   r  sY     "//6*  !3!3!B!BCC

9
9=DDVL  	+r   re   )F)NN)9__doc__retypingr   r   apitools.base.pyr   r   r   r%   googlecloudsdk.api_lib.utilr   r   r   "googlecloudsdk.command_lib.runappsgooglecloudsdk.corer	   r
   googlecloudsdk.core.utilr   6googlecloudsdk.generated_clients.apis.runapps.v1alpha1r   r   r   r   APP_DICT_CONFIG_KEYAPP_CONFIG_DICT_RESOURCES_KEYrt   ru   compiler   r   RunappsV1alpha1Applicationr,   ListApplicationsResponser6   
ResourceIDApplicationStatusr@   	OperationrG   strrM   
DeploymentboolrU   rY   r]   ra   r\   r   r   ListLocationsResponser   	Exceptionr(   r   r   r   <module>r      s   B 
 ! : > , H . 9 # ) - * Z \    +  %  

#BC 71#3311#$=$I$IJ1:#33>G772 JN#33 4 9 D DEF '99:	B3#3333 +663 
#	,	,	36 "&	(#33(( +66( #	( +D*M*M	(8 %*	#33 *44 D>	
 
#	,	,6#33%&?&J&JK.C#33C(22C 
#	.	.C$9#339(229 &?%I%I90 #*.	1-5EE 1-!:!D!D1-h>(22> 
#	>	>>(1#3311.DD1$ Y 9 r   