a
    !f                     @   s$   d Z ddlmZ G dd deZdS )z'Define Stackdriver Logging API Metrics.    )NotFoundc                   @   s   e Zd ZdZdddZedd Zedd	 Zed
d Zedd Z	e
dd Zdd ZdddZdddZdddZd ddZd!ddZdS )"Metrica  Metrics represent named filters for log entries.

    See:
    https://cloud.google.com/logging/docs/api/ref_v2beta1/rest/v2beta1/projects.metrics

    :type name: string
    :param name: the name of the metric

    :type filter_: string
    :param filter_: the advanced logs filter expression defining the entries
                   tracked by the metric.  If not passed, the instance should
                   already exist, to be refreshed via :meth:`reload`.

    :type client: :class:`gcloud.logging.client.Client`
    :param client: A client which holds credentials and project configuration
                   for the metric (which requires a project).

    :type description: string
    :param description: an optional description of the metric.
    N c                 C   s   || _ || _|| _|| _d S )N)name_clientfilter_description)selfr   r   clientr    r   V/var/www/html/python-backend/venv/lib/python3.9/site-packages/gcloud/logging/metric.py__init__)   s    zMetric.__init__c                 C   s   | j S )zClent bound to the logger.r   r	   r   r   r   r
   /   s    zMetric.clientc                 C   s   | j jS )zProject bound to the logger.)r   projectr   r   r   r   r   4   s    zMetric.projectc                 C   s   d| j | jf S )z(Fully-qualified name used in metric APIszprojects/%s/metrics/%s)r   r   r   r   r   r   	full_name9   s    zMetric.full_namec                 C   s   d| j f S )zURL path for the metric's APIsz/%s)r   r   r   r   r   path>   s    zMetric.pathc                 C   s,   |d }|d }| dd}| ||||dS )a  Factory:  construct a metric given its API representation

        :type resource: dict
        :param resource: metric resource representation returned from the API

        :type client: :class:`gcloud.logging.client.Client`
        :param client: Client which holds credentials and project
                       configuration for the metric.

        :rtype: :class:`gcloud.logging.metric.Metric`
        :returns: Metric parsed from ``resource``.
        r   filterr   r   )r
   r   )get)clsresourcer
   Zmetric_namer   r   r   r   r   from_api_reprC   s    zMetric.from_api_reprc                 C   s   |du r| j }|S )a  Check client or verify over-ride.

        :type client: :class:`gcloud.logging.client.Client` or ``NoneType``
        :param client: the client to use.  If not passed, falls back to the
                       ``client`` stored on the current metric.

        :rtype: :class:`gcloud.logging.client.Client`
        :returns: The client passed in or the currently bound client.
        Nr   r	   r
   r   r   r   _require_clientW   s    
zMetric._require_clientc                 C   s(   |  |}|j| j| j| j| j dS )a  API call:  create the metric via a PUT request

        See:
        https://cloud.google.com/logging/docs/api/ref_v2beta1/rest/v2beta1/projects.metrics/create

        :type client: :class:`gcloud.logging.client.Client` or ``NoneType``
        :param client: the client to use.  If not passed, falls back to the
                       ``client`` stored on the current metric.
        N)r   metrics_apiZmetric_creater   r   r   r   r   r   r   r   createe   s    

zMetric.createc                 C   s>   |  |}z|j| j| j W n ty4   Y dS 0 dS dS )a  API call:  test for the existence of the metric via a GET request

        See
        https://cloud.google.com/logging/docs/api/ref_v2beta1/rest/v2beta1/projects.metrics/get

        :type client: :class:`gcloud.logging.client.Client` or ``NoneType``
        :param client: the client to use.  If not passed, falls back to the
                       ``client`` stored on the current metric.

        :rtype: bool
        :returns: Boolean indicating existence of the metric.
        FTN)r   r   
metric_getr   r   r   r   r   r   r   existss   s    
zMetric.existsc                 C   s8   |  |}|j| j| j}|dd| _|d | _dS )a  API call:  sync local metric configuration via a GET request

        See
        https://cloud.google.com/logging/docs/api/ref_v2beta1/rest/v2beta1/projects.metrics/get

        :type client: :class:`gcloud.logging.client.Client` or ``NoneType``
        :param client: the client to use.  If not passed, falls back to the
                       ``client`` stored on the current metric.
        r   r   r   N)r   r   r   r   r   r   r   r   )r	   r
   datar   r   r   reload   s    

zMetric.reloadc                 C   s(   |  |}|j| j| j| j| j dS )a  API call:  update metric configuration via a PUT request

        See
        https://cloud.google.com/logging/docs/api/ref_v2beta1/rest/v2beta1/projects.metrics/update

        :type client: :class:`gcloud.logging.client.Client` or ``NoneType``
        :param client: the client to use.  If not passed, falls back to the
                       ``client`` stored on the current metric.
        N)r   r   Zmetric_updater   r   r   r   r   r   r   r   update   s    

zMetric.updatec                 C   s    |  |}|j| j| j dS )a  API call:  delete a metric via a DELETE request

        See
        https://cloud.google.com/logging/docs/api/ref_v2beta1/rest/v2beta1/projects.metrics/delete

        :type client: :class:`gcloud.logging.client.Client` or ``NoneType``
        :param client: the client to use.  If not passed, falls back to the
                       ``client`` stored on the current metric.
        N)r   r   Zmetric_deleter   r   r   r   r   r   delete   s    

zMetric.delete)NNr   )N)N)N)N)N)__name__
__module____qualname____doc__r   propertyr
   r   r   r   classmethodr   r   r   r   r   r    r!   r   r   r   r   r      s$   









r   N)r%   Zgcloud.exceptionsr   objectr   r   r   r   r   <module>   s   