a
    !f                     @   s$   d Z ddlmZ G dd deZdS )z%Define Stackdriver Logging API Sinks.    )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 )!Sinka  Sinks represent filtered exports for log entries.

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

    :type name: string
    :param name: the name of the sink

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

    :type destination: string
    :param destination: destination URI for the entries exported by the sink.
                        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 sink (which requires a project).
    Nc                 C   s   || _ || _|| _|| _d S )N)namefilter_destination_client)selfr   r   r   client r
   T/var/www/html/python-backend/venv/lib/python3.9/site-packages/gcloud/logging/sink.py__init__+   s    zSink.__init__c                 C   s   | j S )zClent bound to the sink.r   r   r
   r
   r   r	   1   s    zSink.clientc                 C   s   | j jS )zProject bound to the sink.)r   projectr   r
   r
   r   r   6   s    zSink.projectc                 C   s   d| j | jf S )z&Fully-qualified name used in sink APIszprojects/%s/sinks/%s)r   r   r   r
   r
   r   	full_name;   s    zSink.full_namec                 C   s
   d| j  S )zURL path for the sink's APIsz/%s)r   r   r
   r
   r   path@   s    z	Sink.pathc                 C   s(   |d }|d }|d }| ||||dS )ax  Factory:  construct a sink given its API representation

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

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

        :rtype: :class:`gcloud.logging.sink.Sink`
        :returns: Sink parsed from ``resource``.
        :raises: :class:`ValueError` if ``client`` is not ``None`` and the
                 project from the resource does not agree with the project
                 from the client.
        r   filterr   )r	   r
   )clsresourcer	   Z	sink_namer   r   r
   r
   r   from_api_reprE   s    zSink.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 sink.

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

        See:
        https://cloud.google.com/logging/docs/api/ref_v2beta1/rest/v2beta1/projects.sinks/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 sink.
        N)r   	sinks_apiZsink_creater   r   r   r   r   r
   r
   r   createi   s    

zSink.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 sink via a GET request

        See
        https://cloud.google.com/logging/docs/api/ref_v2beta1/rest/v2beta1/projects.sinks/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 sink.

        :rtype: bool
        :returns: Boolean indicating existence of the sink.
        FTN)r   r   sink_getr   r   r   r   r
   r
   r   existsw   s    
zSink.existsc                 C   s4   |  |}|j| j| j}|d | _|d | _dS )a  API call:  sync local sink configuration via a GET request

        See
        https://cloud.google.com/logging/docs/api/ref_v2beta1/rest/v2beta1/projects.sinks/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 sink.
        r   r   N)r   r   r   r   r   r   r   )r   r	   datar
   r
   r   reload   s    

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

        See
        https://cloud.google.com/logging/docs/api/ref_v2beta1/rest/v2beta1/projects.sinks/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 sink.
        N)r   r   Zsink_updater   r   r   r   r   r
   r
   r   update   s    

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

        See
        https://cloud.google.com/logging/docs/api/ref_v2beta1/rest/v2beta1/projects.sinks/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 sink.
        N)r   r   Zsink_deleter   r   r   r
   r
   r   delete   s    

zSink.delete)NNN)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   