
    2                        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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!\RD                  " S5      r#S r$S\RJ                  S\S\	\RL                     4S jr'S\RJ                  S\S\RP                  4S jr) S3S\RJ                  S\S\	\\RT                        S\	\RV                     4S jjr,S\RJ                  S\S \RL                  S\RZ                  4S! jr. S3S\RJ                  S\S \RL                  S"\	\/   S\RZ                  4
S# jjr0 S4S\RJ                  S\S$\Rb                  S%\	\2   S\RZ                  4
S& jjr3S\RJ                  S'\/S\	\Rb                     4S( jr4S\RJ                  S)\RZ                  S\RL                  4S* jr5S\RJ                  S)\RZ                  S\Rb                  4S+ jr6  S5S\RJ                  S)\RZ                  4S, jjr7S)\RZ                  S\Rp                  4S- jr9S\RJ                  S.\/S\Rt                  4S/ jr;S0\/S1\<S\<4S2 jr=g)6z;Functionality related to Cloud Run Integration API clients.    )absolute_import)division)print_function)unicode_literalsN)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   7   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   GetApplicationr0   @   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   ListApplicationsr:   ]   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   r;   res_idres_filtersmoduler.   s          r   GetApplicationStatusrD   s   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.
)rE   applicationIdr2   )r'   Creater$   1RunappsProjectsLocationsApplicationsCreateRequestr#   Parentr&   )r   r   rE   s      r   CreateApplicationrK      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.
)rE   
updateMaskr#   )r'   Patchr$   0RunappsProjectsLocationsApplicationsPatchRequestr&   )r   r   rE   rL   s       r   PatchApplicationrQ      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.
)r2   rR   deploymentIdvalidateOnly)+projects_locations_applications_deploymentsrH   r$   <RunappsProjectsLocationsApplicationsDeploymentsCreateRequestr&   r#   )r   r   rR   rS   s       r   CreateDeploymentrY      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)rW   r(   r$   9RunappsProjectsLocationsApplicationsDeploymentsGetRequestr)   r*   )r   rZ   s     r   GetDeploymentr]      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   r^   s     r   WaitForApplicationOperationra      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`   rW   )r   r^   trackertracker_update_funcs       r   WaitForDeploymentOperationre     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statusrc   rd   s     r   _StatusUpdate(_WaitForOperation.<locals>._StatusUpdate3  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#   r6   r   	GetResultPollUntilDone_POLLING_TIMEOUT_MS_RETRY_TIMEOUT_MSOperationErrorPollr
   IntegrationsOperationErrorerrorcoder	   Decodemessager   WaitExceptionTimeoutError)r   r^   resource_typerc   rd   polleroperation_refrm   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)messagesr^   s     r   GetDeploymentOperationMetadatar   P  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$   #RunappsProjectsLocationsListRequestr6   projects_locationsr   )r   r   r.   s      r   ListLocationsr   d  sG     ""FF  ) G ' 
	"	"	'	'	00r   regionr}   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
   $UnsupportedIntegrationsLocationErrorr6   )r   r}   
parsed_errs      r   r,   r,   v  sY     "//6*  !3!3!B!BCC

9
9=DDVL  	+r   ri   )F)NN)>__doc__
__future__r   r   r   r   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_KEYrx   ry   compiler   r   RunappsV1alpha1Applicationr0   ListApplicationsResponser:   
ResourceIDApplicationStatusrD   	OperationrK   strrQ   
DeploymentboolrY   r]   ra   re   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   