o
    Mf                      @   s$   d Z ddlmZ G dd deZdS )zDefine Cloud Logging API Sinks.    )NotFoundc                   @   s   e Zd ZdZdddd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eddddZdd ZdddddZddddZddddZdddd d!Zddd"d#ZdS )$SinkzSinks represent filtered exports for log entries.

    See https://cloud.google.com/logging/docs/reference/v2/rest/v2/projects.sinks
    N)filter_parentdestinationclientc                C   s(   || _ || _|| _|| _|| _d| _dS )a  
        Args:
            name (str): The name of the sink.
            parent(Optional[str]): The resource in which to create the sink:

                ::

                    "projects/[PROJECT_ID]"
                    "organizations/[ORGANIZATION_ID]"
                    "billingAccounts/[BILLING_ACCOUNT_ID]"
                    "folders/[FOLDER_ID]".

                Defaults to the project stored on the client.
            filter_ (Optional[str]): The advanced logs filter expression defining
                the entries exported by the sink.
            destination (Optional[str]): Destination URI for the entries exported by the sink.
                If not passed, the instance should already exist, to
                be refreshed via :meth:`reload`.
            client (Optional[~logging_v2.client.Client]): A client which holds
                credentials and project configuration for the sink (which requires a project).
        N)namer   r   _client_parent_writer_identity)selfr   r   r   r   r    r   ^/var/www/html/analyze/labelStudio/lib/python3.10/site-packages/google/cloud/logging_v2/sink.py__init__   s   
zSink.__init__c                 C      | j S )zClient bound to the sink.r	   r   r   r   r   r   9      zSink.clientc                 C   s    | j du rd| jj | _ | j S )zOParent resource of the sink (project, organization, billingAccount, or folder).Nz	projects/)r
   r   projectr   r   r   r   r   >   s   
zSink.parentc                 C   s   | j  d| j S )z&Fully-qualified name used in sink APIsz/sinks/)r   r   r   r   r   r   	full_nameE   s   zSink.full_namec                 C   s   d| j  S )zURL path for the sink's APIs/)r   r   r   r   r   pathJ   s   z	Sink.pathc                 C   r   )z&Identity used for exports via the sink)r   r   r   r   r   writer_identityO   r   zSink.writer_identityc                 C   s&   |d | _ |d| _|d| _dS )z0Helper for API methods returning sink resources.r   filterwriterIdentityN)r   getr   r   )r   resourcer   r   r   _update_from_api_reprT   s   
zSink._update_from_api_repr)r   c                C   s$   |d }| |||d}| | |S )a  Construct a sink given its API representation

        Args:
            resource (dict): sink resource representation returned from the API
            client (~logging_v2.client.Client): Client which holds
                credentials and project configuration for the sink.
            parent(Optional[str]): The resource in which to create the sink:

                ::

                    "projects/[PROJECT_ID]"
                    "organizations/[ORGANIZATION_ID]"
                    "billingAccounts/[BILLING_ACCOUNT_ID]"
                    "folders/[FOLDER_ID]".

                Defaults to the project stored on the client.

        Returns:
            ~logging_v2.sink.Sink: Sink parsed from ``resource``.

        Raises:
            ValueError: if ``client`` is not ``None`` and the
                project from the resource does not agree with the project
                from the client.
        r   )r   r   )r   )clsr   r   r   	sink_nameinstancer   r   r   from_api_reprZ   s   
zSink.from_api_reprc                 C   s   |du r| j }|S )a  Check client or verify over-ride. Also sets ``parent``.

        Args:
            client (Union[None, ~logging_v2.client.Client]):
                The client to use.  If not passed, falls back to the
                ``client`` stored on the current sink.

        Returns:
            ~logging_v2.client.Client: The client passed in
                or the currently bound client.
        Nr   r   r   r   r   r   _require_clientz   s   zSink._require_clientF)r   unique_writer_identityc                C   s6   |  |}|jj| j| j| j| j|d}| | dS )a  Create the sink via a PUT request

        See
        https://cloud.google.com/logging/docs/reference/v2/rest/v2/projects.sinks/create

        Args:
            client (Optional[~logging_v2.client.Client]):
                The client to use.  If not passed, falls back to the
                ``client`` stored on the current sink.
            unique_writer_identity (Optional[bool]): Determines the kind of
                IAM identity returned as writer_identity in the new sink.
        r$   N)r#   	sinks_apisink_creater   r   r   r   r   r   r   r$   r   r   r   r   create   s   
zSink.create)r   c                C   s4   |  |}z
|j| j W dS  ty   Y dS w )a  Test for the existence of the sink via a GET request

        See
        https://cloud.google.com/logging/docs/reference/v2/rest/v2/projects.sinks/get

        Args:
            client (Optional[~logging_v2.client.Client]):
                The client to use.  If not passed, falls back to the
                ``client`` stored on the current sink.

        Returns:
            bool: Boolean indicating existence of the sink.
        FT)r#   r&   sink_getr   r   r"   r   r   r   exists   s   
zSink.existsc                C   s&   |  |}|j| j}| | dS )a`  Sync local sink configuration via a GET request

        See
        https://cloud.google.com/logging/docs/reference/v2/rest/v2/projects.sinks/get

        Args:
            client (Optional[~logging_v2.client.Client]):
                The client to use.  If not passed, falls back to the
                ``client`` stored on the current sink.
        N)r#   r&   r*   r   r   )r   r   r   r   r   r   reload   s   
zSink.reloadc                C   s2   |  |}|jj| j| j| j|d}| | dS )a  Update sink configuration via a PUT request

        See
        https://cloud.google.com/logging/docs/reference/v2/rest/v2/projects.sinks/update

        Args:
            client (Optional[~logging_v2.client.Client]):
                The client to use.  If not passed, falls back to the
                ``client`` stored on the current sink.
            unique_writer_identity (Optional[bool]): Determines the kind of
                IAM identity returned as writer_identity in the new sink.
        r%   N)r#   r&   sink_updater   r   r   r   r(   r   r   r   update   s   
zSink.updatec                C   s   |  |}|j| j dS )aV  Delete a sink via a DELETE request

        See
        https://cloud.google.com/logging/docs/reference/v2/rest/v2/projects.sinks/delete

        Args:
            client (Optional[~logging_v2.client.Client]):
                The client to use.  If not passed, falls back to the
                ``client`` stored on the current sink.
        N)r#   r&   sink_deleter   r"   r   r   r   delete   s   
zSink.delete)__name__
__module____qualname____doc__r   propertyr   r   r   r   r   r   classmethodr!   r#   r)   r+   r,   r.   r0   r   r   r   r   r      s.    




r   N)r4   google.cloud.exceptionsr   objectr   r   r   r   r   <module>   s   