
                         Z    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  G d de	      Z
y	)
z8API client library for Certificate Manager certificates.    )absolute_import)division)unicode_literals)
list_pager)
api_clientc                   P    e Zd ZdZd	dZ	 	 	 d
dZd Z	 	 	 	 ddZd Z	 	 	 ddZ	y)CertificateClientz0API client for Certificate Manager certificates.Nc                     |xs t        j                         | _        | j                  j                  | _        |xs | j                  j
                  | _        y )N)r   GetClientInstance_clientprojects_locations_certificates_serviceMESSAGES_MODULEmessages)selfclientr   s      >lib/googlecloudsdk/api_lib/certificate_manager/certificates.py__init__zCertificateClient.__init__   s>    ;Z99;DLLL@@DM< < <DM    c           	          | j                   j                  |j                         || j                   j                  |||            }| j                  j                  |      S )a  Creates a certificate.

    Args:
      parent_ref: a Resource reference to a
        certificatemanager.projects.locations resource for the parent of this
        certificate.
      cert_id: str, the ID of the cerificate to create.
      self_managed_cert_data: API message for self-managed certificate data.
      description: str, user-provided description.
      labels: Unified GCP Labels for the resource.

    Returns:
      Operation: the long running operation to create a certificate.
    )labelsdescriptionselfManagedCertData)parentcertificateIdcertificate)r   <CertificatemanagerProjectsLocationsCertificatesCreateRequestRelativeNameCertificater   Create)r   
parent_refcert_idself_managed_cert_datar   r   reqs          r   r    zCertificateClient.Create"   sd    ( --
T
T&&(MM--# 6 . 
 U C ==$$r   c                     | j                   j                  |j                               }| j                  j	                  |      S )zGets certificate.

    Args:
      cert_ref: a Resource reference to a
        certificatemanager.projects.locations.certificates resource to get.

    Returns:
      Certificate API representation.
    name)r   9CertificatemanagerProjectsLocationsCertificatesGetRequestr   r   Get)r   cert_refget_reqs      r   r)   zCertificateClient.GetA   s?     mmUU""$ V &G==W%%r   c           
          | j                   j                  |j                         ||      }t        j                  | j
                  |||dddd      S )a  List certificates in a given project and location.

    Args:
      parent_ref: a Resource reference to a
        certificatemanager.projects.locations resource to list certs for.
      limit: int, the total number of results to return from the API.
      page_size: int, the number of results in each batch from the API.
      list_filter: str, filter to apply in the list request.
      order_by: str, fields used for resource ordering.

    Returns:
      A list of the certificates in the project.
    )r   filterorderBy	pageTokennextPageTokencertificatespageSize)
batch_sizelimitcurrent_token_attributenext_token_attributefieldbatch_size_attribute)r   :CertificatemanagerProjectsLocationsCertificatesListRequestr   r   YieldFromListr   )r   r!   r4   	page_sizelist_filterorder_bylist_reqs          r   ListzCertificateClient.ListO   s^    * }}WW&&(h X PH## +,') )r   c                     | j                   j                  |j                               }| j                  j	                  |      S )zDeletes certificate.

    Args:
      cert_ref: a Resource reference to a
        certificatemanager.projects.locations.certificates resource to delete.

    Returns:
      Operation: the long running operation to delete certificate.
    r&   )r   <CertificatemanagerProjectsLocationsCertificatesDeleteRequestr   r   Delete)r   r*   
delete_reqs      r   rB   zCertificateClient.Deletep   s?     [[""$ \ &J==
++r   c                    | j                   j                         }g }|r||_        |j                  d       |r||_        |j                  d       |r||_        |j                  d       dj                  |      }| j                   j                  ||j                         |      }| j                  j                  |      S )a  Updates a certificate.

    Used for updating labels, description and certificate data.

    Args:
      cert_ref: a Resource reference to a
        certificatemanager.projects.locations.certificates resource.
      self_managed_cert_data: API message for self-managed certificate data.
      labels: unified GCP Labels for the resource.
      description: str, new description

    Returns:
      Operation: the long running operation to patch certificate.
    self_managedr   r   ,)r   r'   
updateMask)r   r   selfManagedappendr   r   join;CertificatemanagerProjectsLocationsCertificatesPatchRequestr   r   Patch)	r   r*   r#   r   r   r   updated_fieldsupdate_mask	patch_reqs	            r   rL   zCertificateClient.Patch~   s    & --++-KN 6kN+!kH% +kM*((>*KYY""$ Z  I ==y))r   )NN)N N)NNNN)NNN)
__name__
__module____qualname____doc__r   r    r)   r?   rB   rL    r   r   r	   r	      sH    8= %)%>&" )B,  $(	$*r   r	   N)rT   
__future__r   r   r   apitools.base.pyr   *googlecloudsdk.api_lib.certificate_managerr   objectr	   rU   r   r   <module>rZ      s'    ? &  ' ' AH* H*r   