
                             d Z ddlmZ ddlmZ ddlmZ ddlmZ ddlm	Z	 ddlm
Z
 ddlmZ dd	lmZ dd
lmZ ddlmZ ddlmZ  eddg      Zd Zd Zd Zy)z3Utilities for checking and enabling necessary APIs.    )absolute_import)division)unicode_literalsN)
enable_api)services_util)serviceusage)#GetServicePermissionDeniedException)log)
properties)
console_iorun.googleapis.comz"staging-run.sandbox.googleapis.comc                      t         j                  j                  j                  j	                         } | r)t        j
                  |       j                  }|t        v r|S y)Nr   )r   VALUESapi_endpoint_overridesrunGeturlparsehostname_RUN_API_NAMES)endpointapis     -lib/googlecloudsdk/api_lib/run/api_enabler.pyget_run_apir   $   sK    5599==?(


H
%
.
.C
nj	    c                 @   t         j                  j                  j                  j	                         sy	 t        | |      }|rdj                  |      }t        j                  dddj                  | |      d       t        j                  j                  dj                  |              t        j                  | |      }|j                   sCt#        j$                  |j&                  t        j(                        }t#        j*                  |       y# t        $ r Y yw xY w)z<Ensure the given APIs are enabled for the specified project.Fz
	Tz9The following APIs are not enabled on project [{0}]:
	{1}zIDo you want enable these APIs to continue (this will take a few minutes)?)defaultcancel_on_nomessageprompt_stringz!Enabling APIs on project [{0}]...)r   r   coreshould_prompt_to_enable_apiGetBoolget_disabled_apisr	   joinr   PromptContinueformatr
   statusPrintr   BatchEnableApiCalldoner   WaitOperationnameGetOperationPrintOperation)
project_idrequired_apisapis_not_enabledapis_to_enableops        r   check_and_enable_apisr4   -   s    						;	;	C	C	E(]C [[!12NIVJ/5	 JJ8??
KL		(	(5E	FB77&&rww0I0IJb""2&	) 
- s   D 	DDc                 l    t        |      D cg c]  }t        j                  | |      s| }}|S c c}w )N)sortedr   IsServiceEnabled)r/   r0   r   r1   s       r   r#   r#   K   sH    
 &	 '#((S9 
&	   
s   1)__doc__
__future__r   r   r   urllib.parseparser   googlecloudsdk.api_lib.servicesr   r   r   *googlecloudsdk.api_lib.services.exceptionsr	   googlecloudsdk.corer
   r   googlecloudsdk.core.consoler   	frozensetr   r   r4   r#    r   r   <module>rB      sM    : &  '  6 9 8 Z # * 2?@
<r   