o
    
                     @   sv   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
dZd	hZd
d Zdd ZdddZdS )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                 C   s   | t vS )N)_PROJECTS_NOT_TO_ENABLE)project r	   G/tmp/google-cloud-sdk/lib/googlecloudsdk/api_lib/util/api_enablement.pyShouldAttemptProjectEnable&   s   r   c                 C   sH   t | }|r"|d|d}}|dur"t|r"|dur"||fS dS )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_tokenr	   r	   r
   GetApiEnablementInfo*   s   

r   Fc                 C   s*   t j|d|| d}|rt| | |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_attemptedr	   r	   r
   PromptToEnableApi=   s   r   )F)__doc__
__future__r   r   r   regooglecloudsdk.api_lib.servicesr   googlecloudsdk.core.consoler   compiler   r   r   r   r   r	   r	   r	   r
   <module>   s   