a
    !f>                     @   sV   d Z ddlmZ G dd dejZG dd deZG dd deZG d	d
 d
eZ	dS )z7Create / interact with Stackdriver Logging connections.    )
connectionc                   @   s    e Zd ZdZdZdZdZdZdS )
Connectiona)  A connection to Google Stackdriver Logging via the JSON REST API.

    :type credentials: :class:`oauth2client.client.OAuth2Credentials`
    :param credentials: (Optional) The OAuth2 Credentials to use for this
                        connection.

    :type http: :class:`httplib2.Http` or class that defines ``request()``.
    :param http: (Optional) HTTP object to make requests.

    :type api_base_url: string
    :param api_base_url: The base of the API call URL. Defaults to the value
                         :attr:`Connection.API_BASE_URL`.
    zhttps://logging.googleapis.comZv2beta1z"{api_base_url}/{api_version}{path})z,https://www.googleapis.com/auth/logging.readz-https://www.googleapis.com/auth/logging.writez-https://www.googleapis.com/auth/logging.adminz.https://www.googleapis.com/auth/cloud-platformN)__name__
__module____qualname____doc__ZAPI_BASE_URLZAPI_VERSIONZAPI_URL_TEMPLATEZSCOPE r   r   Z/var/www/html/python-backend/venv/lib/python3.9/site-packages/gcloud/logging/connection.pyr      s   r   c                   @   s4   e Zd ZdZdd ZdddZdddZd	d
 ZdS )_LoggingAPIa]  Helper mapping logging-related APIs.

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

    :type connection: :class:`gcloud.logging.connection.Connection`
    :param connection: the connection used to make API requests.
    c                 C   s
   || _ d S N_connectionselfr   r   r   r	   __init__=   s    z_LoggingAPI.__init__Nc                 C   sp   d|i}|dur||d< |dur(||d< |dur8||d< |durH||d< | j jdd|d	}|d
d|dfS )a	  Return a page of log entry resources.

        See:
        https://cloud.google.com/logging/docs/api/ref_v2beta1/rest/v2beta1/entries/list

        :type projects: list of strings
        :param projects: project IDs to include. If not passed,
                            defaults to the project bound to the client.

        :type filter_: str
        :param filter_: a filter expression. See:
                        https://cloud.google.com/logging/docs/view/advanced_filters

        :type order_by: str
        :param order_by: One of :data:`gcloud.logging.ASCENDING` or
                         :data:`gcloud.logging.DESCENDING`.

        :type page_size: int
        :param page_size: maximum number of entries to return, If not passed,
                          defaults to a value set by the API.

        :type page_token: str
        :param page_token: opaque marker for the next "page" of entries. If not
                           passed, the API will return the first page of
                           entries.

        :rtype: tuple, (list, str)
        :returns: list of mappings, plus a "next page token" string:
                  if not None, indicates that more entries can be retrieved
                  with another call (pass that value as ``page_token``).
        Z
projectIdsNfilterZorderBypageSize	pageTokenPOSTz/entries:listmethodpathdataentriesr   nextPageTokenr   api_requestget)r   Zprojectsfilter_Zorder_by	page_size
page_tokenparamsrespr   r   r	   list_entries@   s    !z_LoggingAPI.list_entriesc                 C   sR   dt |i}|dur||d< |dur,||d< |dur<||d< | jjdd|d dS )	a  API call:  log an entry resource via a POST request

        See:
        https://cloud.google.com/logging/docs/api/ref_v2beta1/rest/v2beta1/entries/write

        :type entries: sequence of mapping
        :param entries: the log entry resources to log.

        :type logger_name: string
        :param logger_name: name of default logger to which to log the entries;
                            individual entries may override.

        :type resource: mapping
        :param resource: default resource to associate with entries;
                         individual entries may override.

        :type labels: mapping
        :param labels: default labels to associate with entries;
                       individual entries may override.
        r   NZlogNameresourcelabelsr   z/entries:writer   )listr   r   )r   r   logger_namer$   r%   r   r   r   r	   write_entriest   s    
z_LoggingAPI.write_entriesc                 C   s    d||f }| j jd|d dS )a  API call:  delete all entries in a logger via a DELETE request

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

        :type project: string
        :param project: ID of project containing the log entries to delete

        :type logger_name: string
        :param logger_name: name of logger containing the log entries to delete
        z/projects/%s/logs/%sDELETEr   r   Nr   r   )r   projectr'   r   r   r   r	   logger_delete   s    z_LoggingAPI.logger_delete)NNNN)NNN)r   r   r   r   r   r#   r(   r-   r   r   r   r	   r
   3   s   	  
4  
$r
   c                   @   sB   e Zd ZdZdd ZdddZdd Zd	d
 Zdd Zdd Z	dS )	_SinksAPIa  Helper mapping sink-related APIs.

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

    :type connection: :class:`gcloud.logging.connection.Connection`
    :param connection: the connection used to make API requests.
    c                 C   s
   || _ d S r   r   r   r   r   r	   r      s    z_SinksAPI.__init__Nc                 C   sZ   i }|dur||d< |dur$||d< d|f }| j jd||d}|dd}||d	fS )
a  List sinks for the project associated with this client.

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

        :type project: string
        :param project: ID of the project whose sinks are to be listed.

        :type page_size: int
        :param page_size: maximum number of sinks to return, If not passed,
                          defaults to a value set by the API.

        :type page_token: str
        :param page_token: opaque marker for the next "page" of sinks. If not
                           passed, the API will return the first page of
                           sinks.

        :rtype: tuple, (list, str)
        :returns: list of mappings, plus a "next page token" string:
                  if not None, indicates that more sinks can be retrieved
                  with another call (pass that value as ``page_token``).
        Nr   r   /projects/%s/sinksGETr   r   Zquery_paramssinksr   r   r   )r   r,   r   r    r!   r   r"   r2   r   r   r	   
list_sinks   s    
z_SinksAPI.list_sinksc                 C   s,   d|f }|||d}| j jd||d dS )a  API call:  create a sink resource.

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

        :type project: string
        :param project: ID of the project in which to create the sink.

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

        :type filter_: string
        :param filter_: the advanced logs filter expression defining the
                        entries exported by the sink.

        :type destination: string
        :param destination: destination URI for the entries exported by
                            the sink.
        r/   namer   destinationr   r   Nr+   r   r,   	sink_namer   r6   targetr   r   r   r	   sink_create   s    
z_SinksAPI.sink_createc                 C   s   d||f }| j jd|dS )a  API call:  retrieve a sink resource.

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

        :type project: string
        :param project: ID of the project containing the sink.

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

        :rtype: dict
        :returns: The JSON sink object returned from the API.
        /projects/%s/sinks/%sr0   r*   r+   r   r,   r8   r9   r   r   r	   sink_get   s    z_SinksAPI.sink_getc                 C   s.   d||f }|||d}| j jd||d dS )aw  API call:  update a sink resource.

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

        :type project: string
        :param project: ID of the project containing the sink.

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

        :type filter_: string
        :param filter_: the advanced logs filter expression defining the
                        entries exported by the sink.

        :type destination: string
        :param destination: destination URI for the entries exported by
                            the sink.
        r;   r4   PUTr   Nr+   r7   r   r   r	   sink_update  s    z_SinksAPI.sink_updatec                 C   s    d||f }| j jd|d dS )aH  API call:  delete a sink resource.

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

        :type project: string
        :param project: ID of the project containing the sink.

        :type sink_name: string
        :param sink_name: the name of the sink
        r;   r)   r*   Nr+   r<   r   r   r	   sink_delete#  s    z_SinksAPI.sink_delete)NN)
r   r   r   r   r   r3   r:   r=   r?   r@   r   r   r   r	   r.      s   
%r.   c                   @   sD   e Zd ZdZdd ZdddZdddZd	d
 Zdd Zdd Z	dS )_MetricsAPIa  Helper mapping sink-related APIs.

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

    :type connection: :class:`gcloud.logging.connection.Connection`
    :param connection: the connection used to make API requests.
    c                 C   s
   || _ d S r   r   r   r   r   r	   r   <  s    z_MetricsAPI.__init__Nc                 C   sZ   i }|dur||d< |dur$||d< d|f }| j jd||d}|dd}||d	fS )
a  List metrics for the project associated with this client.

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

        :type project: string
        :param project: ID of the project whose metrics are to be listed.

        :type page_size: int
        :param page_size: maximum number of metrics to return, If not passed,
                          defaults to a value set by the API.

        :type page_token: str
        :param page_token: opaque marker for the next "page" of metrics. If not
                           passed, the API will return the first page of
                           metrics.

        :rtype: tuple, (list, str)
        :returns: list of mappings, plus a "next page token" string:
                  if not None, indicates that more metrics can be retrieved
                  with another call (pass that value as ``page_token``).
        Nr   r   /projects/%s/metricsr0   r1   metricsr   r   r   )r   r,   r   r    r!   r   r"   rC   r   r   r	   list_metrics?  s    
z_MetricsAPI.list_metricsc                 C   s,   d|f }|||d}| j jd||d dS )aV  API call:  create a metric resource.

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

        :type project: string
        :param project: ID of the project in which to create the metric.

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

        :type filter_: string
        :param filter_: the advanced logs filter expression defining the
                        entries exported by the metric.

        :type description: string
        :param description: description of the metric.
        rB   r5   r   descriptionr   r   Nr+   r   r,   metric_namer   rF   r9   r   r   r   r	   metric_created  s    
z_MetricsAPI.metric_createc                 C   s   d||f }| j jd|dS )a  API call:  retrieve a metric resource.

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

        :type project: string
        :param project: ID of the project containing the metric.

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

        :rtype: dict
        :returns: The JSON metric object returned from the API.
        /projects/%s/metrics/%sr0   r*   r+   r   r,   rH   r9   r   r   r	   
metric_get  s    z_MetricsAPI.metric_getc                 C   s.   d||f }|||d}| j jd||d dS )aN  API call:  update a metric resource.

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

        :type project: string
        :param project: ID of the project containing the metric.

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

        :type filter_: string
        :param filter_: the advanced logs filter expression defining the
                        entries exported by the metric.

        :type description: string
        :param description: description of the metric.
        rJ   rE   r>   r   Nr+   rG   r   r   r	   metric_update  s    z_MetricsAPI.metric_updatec                 C   s    d||f }| j jd|d dS )aT  API call:  delete a metric resource.

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

        :type project: string
        :param project: ID of the project containing the metric.

        :type metric_name: string
        :param metric_name: the name of the metric
        rJ   r)   r*   Nr+   rK   r   r   r	   metric_delete  s    z_MetricsAPI.metric_delete)NN)N)
r   r   r   r   r   rD   rI   rL   rM   rN   r   r   r   r	   rA   3  s   
%
rA   N)
r   Zgcloudr   Zbase_connectionZJSONConnectionr   objectr
   r.   rA   r   r   r   r	   <module>   s   u 