
    
                         d Z ddlmZ ddlmZ ddlmZ ddlZddlmZ ddlm	Z	  ej                  d      Zd	hZd
 Zd ZddZy)zUtilities for API enablement.    )absolute_import)division)unicode_literalsN)
enable_api)
console_ioz.*Enable it by visiting https://console.(?:cloud|developers).google.com/apis/api/([^/]+)/overview\?project=(\S+) then retry. If you enabled this API recently, wait a few minutes for the action to propagate to our systems and retry.\w*zgoogle.com:cloudsdktoolc                     | t         vS )N)_PROJECTS_NOT_TO_ENABLE)projects    1lib/googlecloudsdk/api_lib/util/api_enablement.pyShouldAttemptProjectEnabler   &   s    	/	//    c                     t         j                  |       }|r5|j                  d      |j                  d      }}|t        |      r|||fS y)zParses error message for API enablement messages.

  Args:
    status_message: str, error message to parse.

  Returns:
    tuple[str]: The project, service token to be used for prompting to enable
        the API.
        N)API_ENABLEMENT_REGEXmatchgroupr   )status_messager   r
   service_tokens       r   GetApiEnablementInfor   *   sR     
$
$^
4%
 %AAmW :7 C%}%%	r   c                     t        j                  |dj                  ||             }|rt        j                  | |       |S )a?  Prompts to enable the API.

  Args:
    project (str): The project that the API is not enabled on.
    service_token (str): The service token of the API to prompt for.
    enable_by_default (bool): The default choice for the enablement prompt.

  Returns:
    bool, whether or not the API was attempted to be enabled
  zhAPI [{}] not enabled on project [{}]. Would you like to enable and retry (this will take a few minutes)?)defaultprompt_string)r   PromptContinueformatr   EnableService)r
   r   enable_by_defaultapi_enable_attempteds       r   PromptToEnableApir   =   sE     $22%&,f]G&D	F
 Wm4	r   )F)__doc__
__future__r   r   r   regooglecloudsdk.api_lib.servicesr   googlecloudsdk.core.consoler   compiler   r	   r   r   r    r   r   <module>r'      sN     $ &  ' 	 6 2 "rzz%&  55 0&r   