o
    €Ïó  ã                   @   sl   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	„ Z
ddd„Zddd„ZdS )z!services enable helper functions.é    )Úabsolute_import)Údivision)Úunicode_literals)Úservices_util)Úserviceusage)Úlogc                 C   s   t  | |¡}t  |¡S )a´  Return true if the service is enabled.

  Args:
    project_id: The ID of the project we want to query.
    service_name: The name of the service.

  Raises:
    exceptions.GetServicePermissionDeniedException: if a 403 or 404
        error is returned by the Get request.
    apitools_exceptions.HttpError: Another miscellaneous error with the listing
        service.

  Returns:
    True if the service is enabled, false otherwise.
  )r   Ú
GetServiceÚIsServiceEnabled)Ú
project_idÚservice_nameÚservice© r   úG/tmp/google-cloud-sdk/lib/googlecloudsdk/api_lib/services/enable_api.pyr	      s   
r	   Fc                 C   sP   t j d || ¡¡ t | |¡}|s$|js&t |j	tj
¡}t |¡ dS dS dS )aC  Enable a service without checking if it is already enabled.

  Args:
    project_id: The ID of the project for which to enable the service.
    service_name: The name of the service to enable on the project.
    is_async: bool, if True, print the operation ID and return immediately,
           without waiting for the op to complete.

  Raises:
    exceptions.EnableServicePermissionDeniedException: when enabling the API
        fails with a 403 or 404 error code.
    api_lib_exceptions.HttpException: Another miscellaneous error with the
        servicemanagement service.
  z*Enabling service [{0}] on project [{1}]...N)r   ÚstatusÚPrintÚformatr   ÚEnableApiCallÚdoner   ÚWaitOperationÚnameÚGetOperationÚPrintOperation)r
   r   Úis_asyncÚopr   r   r   ÚEnableService/   s   
ÿ
þr   c                 C   s0   t | |ƒrt d || ¡¡ dS t| ||ƒ dS )aÀ  Check to see if the service is enabled, and if it is not, do so.

  Args:
    project_id: The ID of the project for which to enable the service.
    service_name: The name of the service to enable on the project.
    is_async: bool, if True, print the operation ID and return immediately,
           without waiting for the op to complete.

  Raises:
    exceptions.ListServicesPermissionDeniedException: if a 403 or 404 error
        is returned by the listing service.
    exceptions.EnableServicePermissionDeniedException: when enabling the API
        fails with a 403 or 404 error code.
    api_lib_exceptions.HttpException: Another miscellaneous error with the
        servicemanagement service.
  z2Service [{0}] is already enabled for project [{1}]N)r	   r   Údebugr   r   )r
   r   r   r   r   r   ÚEnableServiceIfDisabledH   s   
ÿr   N)F)Ú__doc__Ú
__future__r   r   r   Úgooglecloudsdk.api_lib.servicesr   r   Úgooglecloudsdk.corer   r	   r   r   r   r   r   r   Ú<module>   s   
