§
    8?ÄjR;  ã                   óø  — d Z ddlmZ ddlZddlZddlmZ ddlmZm	Z	 ddl
mZ 	 ddlZn# e$ rZ ed¦  «        e‚dZ[ww xY w eedd¦  «        Z eee¦  «        rgg Ze                     d	¦  «        D ]-Z	 e                      ee¦  «        ¦  «         Œ"# e$ r Y  nw xY wer  ee¦  «        d
k     r ej        de¦  «          ej        e¦  «        Z G d„ dej        ¦  «        Z	 	 dd„Z  G d„ d¦  «        Z!dS )zAuthorization support for gRPC.é    )Úabsolute_importN)Ú
exceptions)Ú_mtls_helperÚmtls)Úservice_accountzWgRPC is not installed from please install the grpcio package to use the gRPC transport.Ú__version__ú.)é   éS   r   a^  grpcio < 1.83.0 does not support Post-Quantum Cryptography (PQC). Support for non-PQC environments is deprecated. In April 2027, google-auth will raise its minimum requirements to enforce grpcio >= 1.83.0. For more details on Google Cloud's post-quantum security migration, visit: https://cloud.google.com/security/resources/post-quantum-cryptographyc                   ó8   ‡ — e Zd ZdZ	 dddœˆ fd„Zd„ Zd„ Zˆ xZS )	ÚAuthMetadataPluginaó  A `gRPC AuthMetadataPlugin`_ that inserts the credentials into each
    request.

    .. _gRPC AuthMetadataPlugin:
        http://www.grpc.io/grpc/python/grpc.html#grpc.AuthMetadataPlugin

    Args:
        credentials (google.auth.credentials.Credentials): The credentials to
            add to requests.
        request (google.auth.transport.Request): A HTTP transport request
            object used to refresh credentials as needed.
        default_host (Optional[str]): A host like "pubsub.googleapis.com".
            This is used when a self-signed JWT is created from service
            account credentials.
        suppress_metrics_header (bool): When enabled, ``x-goog-api-client``
            will be stripped from authorization headers.
    NF)Úsuppress_metrics_headerc                óŽ   •— t          t          | ¦  «                             ¦   «          || _        || _        || _        || _        d S ©N)Úsuperr   Ú__init__Ú_credentialsÚ_requestÚ_default_hostÚ_suppress_metrics_header)ÚselfÚcredentialsÚrequestÚdefault_hostr   Ú	__class__s        €úKC:\Projects\Historical\venv\Lib\site-packages\google/auth/transport/grpc.pyr   zAuthMetadataPlugin.__init__K   sG   ø€ õ 	Õ  $Ñ'Ô'×0Ò0Ñ2Ô2Ð2Ø'ˆÔØˆŒØ)ˆÔØ(?ˆÔ%Ð%Ð%ó    c                 óp  — i }t          | j        t          j        ¦  «        r;| j                             | j        rd                     | j        ¦  «        nd¦  «         | j                             | j        |j	        |j
        |¦  «         | j        rd|v r|d= t          |                     ¦   «         ¦  «        S )z½Gets the authorization headers for a request.

        Returns:
            Sequence[Tuple[str, str]]: A list of request headers (key, value)
                to add to the request.
        zhttps://{}/Nzx-goog-api-client)Ú
isinstancer   r   ÚCredentialsÚ_create_self_signed_jwtr   ÚformatÚbefore_requestr   Úmethod_nameÚservice_urlr   ÚlistÚitems)r   ÚcontextÚheaderss      r   Ú_get_authorization_headersz-AuthMetadataPlugin._get_authorization_headersW   sÅ   € ð ˆõ �dÔ'­Ô)DÑEÔEð 	ØÔ×5Ò5Ø<@Ô<NÐX�×$Ò$ TÔ%7Ñ8Ô8Ð8ÐTXñô ð ð 	Ô×(Ò(ØŒM˜7Ô.°Ô0CÀWñ	
ô 	
ð 	
ð Ô(ð 	-Ð-@ÀGÐ-KÐ-KØÐ+Ð,å�G—M’M‘O”OÑ$Ô$Ð$r   c                 óD   —  ||                       |¦  «        d¦  «         dS )a   Passes authorization metadata into the given callback.

        Args:
            context (grpc.AuthMetadataContext): The RPC context.
            callback (grpc.AuthMetadataPluginCallback): The callback that will
                be invoked to pass in the authorization metadata.
        N)r*   )r   r(   Úcallbacks      r   Ú__call__zAuthMetadataPlugin.__call__r   s*   € ð 	ˆ�×0Ò0°Ñ9Ô9¸4Ñ@Ô@Ð@Ð@Ð@r   r   )Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r*   r-   Ú__classcell__)r   s   @r   r   r   8   s†   ø€ € € € € ðð ð& 26ð
@ØRWð
@ð 
@ð 
@ð 
@ð 
@ð 
@ð 
@ð%ð %ð %ð6Að Að Að Að Að Að Ar   r   c                 óš  — t          | |¦  «        }t          j        |¦  «        }|r|rt          j        d¦  «        ‚|sft          j        ¦   «         }|r&|r$ |¦   «         \  }	}
t          j        |	|
¬¦  «        }n+|rt          ¦   «         }|j	        }nt          j        ¦   «         }t          j
        ||¦  «        }t          j        ||fi |¤ŽS )au  Creates a secure authorized gRPC channel.

    This creates a channel with SSL and :class:`AuthMetadataPlugin`. This
    channel can be used to create a stub that can make authorized requests.
    Users can configure client certificate or rely on device certificates to
    establish a mutual TLS channel, if the `GOOGLE_API_USE_CLIENT_CERTIFICATE`
    variable is explicitly set to `true`.

    Example::

        import google.auth
        import google.auth.transport.grpc
        import google.auth.transport.requests
        from google.cloud.speech.v1 import cloud_speech_pb2

        # Get credentials.
        credentials, _ = google.auth.default()

        # Get an HTTP request function to refresh credentials.
        request = google.auth.transport.requests.Request()

        # Create a channel.
        channel = google.auth.transport.grpc.secure_authorized_channel(
            credentials, regular_endpoint, request,
            ssl_credentials=grpc.ssl_channel_credentials())

        # Use the channel to create a stub.
        cloud_speech.create_Speech_stub(channel)

    Usage:

    There are actually a couple of options to create a channel, depending on if
    you want to create a regular or mutual TLS channel.

    First let's list the endpoints (regular vs mutual TLS) to choose from::

        regular_endpoint = 'speech.googleapis.com:443'
        mtls_endpoint = 'speech.mtls.googleapis.com:443'

    Option 1: create a regular (non-mutual) TLS channel by explicitly setting
    the ssl_credentials::

        regular_ssl_credentials = grpc.ssl_channel_credentials()

        channel = google.auth.transport.grpc.secure_authorized_channel(
            credentials, request, regular_endpoint,
            ssl_credentials=regular_ssl_credentials)

    Option 2: create a mutual TLS channel by calling a callback which returns
    the client side certificate and the key (Note that
    `GOOGLE_API_USE_CLIENT_CERTIFICATE` environment variable must be explicitly
    set to `true`)::

        def my_client_cert_callback():
            code_to_load_client_cert_and_key()
            if loaded:
                return (pem_cert_bytes, pem_key_bytes)
            raise MyClientCertFailureException()

        try:
            channel = google.auth.transport.grpc.secure_authorized_channel(
                credentials, request, mtls_endpoint,
                client_cert_callback=my_client_cert_callback)
        except MyClientCertFailureException:
            # handle the exception

    Option 3: use application default SSL credentials. It searches and uses
    the command in a context aware metadata file, which is available on devices
    with endpoint verification support (Note that
    `GOOGLE_API_USE_CLIENT_CERTIFICATE` environment variable must be explicitly
    set to `true`).
    See https://cloud.google.com/endpoint-verification/docs/overview::

        try:
            default_ssl_credentials = SslCredentials()
        except:
            # Exception can be raised if the context aware metadata is malformed.
            # See :class:`SslCredentials` for the possible exceptions.

        # Choose the endpoint based on the SSL credentials type.
        if default_ssl_credentials.is_mtls:
            endpoint_to_use = mtls_endpoint
        else:
            endpoint_to_use = regular_endpoint
        channel = google.auth.transport.grpc.secure_authorized_channel(
            credentials, request, endpoint_to_use,
            ssl_credentials=default_ssl_credentials)

    Option 4: not setting ssl_credentials and client_cert_callback. For devices
    without endpoint verification support or `GOOGLE_API_USE_CLIENT_CERTIFICATE`
    environment variable is not `true`, a regular TLS channel is created;
    otherwise, a mutual TLS channel is created, however, the call should be
    wrapped in a try/except block in case of malformed context aware metadata.

    The following code uses regular_endpoint, it works the same no matter the
    created channle is regular or mutual TLS. Regular endpoint ignores client
    certificate and key::

        channel = google.auth.transport.grpc.secure_authorized_channel(
            credentials, request, regular_endpoint)

    The following code uses mtls_endpoint, if the created channle is regular,
    and API mtls_endpoint is confgured to require client SSL credentials, API
    calls using this channel will be rejected::

        channel = google.auth.transport.grpc.secure_authorized_channel(
            credentials, request, mtls_endpoint)

    Args:
        credentials (google.auth.credentials.Credentials): The credentials to
            add to requests.
        request (google.auth.transport.Request): A HTTP transport request
            object used to refresh credentials as needed. Even though gRPC
            is a separate transport, there's no way to refresh the credentials
            without using a standard http transport.
        target (str): The host and port of the service.
        ssl_credentials (grpc.ChannelCredentials): Optional SSL channel
            credentials. This can be used to specify different certificates.
            This argument is mutually exclusive with client_cert_callback;
            providing both will raise an exception.
            If ssl_credentials and client_cert_callback are None, application
            default SSL credentials are used if `GOOGLE_API_USE_CLIENT_CERTIFICATE`
            environment variable is explicitly set to `true`, otherwise one way TLS
            SSL credentials are used.
        client_cert_callback (Callable[[], (bytes, bytes)]): Optional
            callback function to obtain client certicate and key for mutual TLS
            connection. This argument is mutually exclusive with
            ssl_credentials; providing both will raise an exception.
            This argument does nothing unless `GOOGLE_API_USE_CLIENT_CERTIFICATE`
            environment variable is explicitly set to `true`.
        kwargs: Additional arguments to pass to :func:`grpc.secure_channel`.

    Returns:
        grpc.Channel: The created gRPC channel.

    Raises:
        google.auth.exceptions.MutualTLSChannelError: If mutual TLS channel
            creation failed for any reason.
    zUReceived both ssl_credentials and client_cert_callback; these are mutually exclusive.©Úcertificate_chainÚprivate_key)r   ÚgrpcÚmetadata_call_credentialsr   ÚMalformedErrorr   Úcheck_use_client_certÚssl_channel_credentialsÚSslCredentialsÚssl_credentialsÚcomposite_channel_credentialsÚsecure_channel)r   r   Útargetr=   Úclient_cert_callbackÚkwargsÚmetadata_pluginÚgoogle_auth_credentialsÚuse_client_certÚcertÚkeyÚadc_ssl_credentilsÚcomposite_credentialss                r   Úsecure_authorized_channelrJ   }   s  € õh )¨°gÑ>Ô>€Oõ #Ô<¸_ÑMÔMÐàð 
Ð/ð 
ÝÔ'ð,ñ
ô 
ð 	
ð ð =Ý&Ô<Ñ>Ô>ˆØð 	=Ð3ð 	=à,Ð,Ñ.Ô.‰IˆD�#Ý"Ô:Ø"&°Cðñ ô ˆOˆOð ð 	=å!/Ñ!1Ô!1ÐØ0Ô@ˆOˆOå"Ô:Ñ<Ô<ˆOõ !Ô>ØÐ0ñô Ðõ Ô˜vÐ'<ÐGÐGÀÐGÐGÐGr   c                   óD   — e Zd ZdZd„ Zed„ ¦   «         Zed„ ¦   «         ZdS )r<   a*  Class for application default SSL credentials.

    Mutual TLS (mTLS) is enabled if either:

    1. The `GOOGLE_API_USE_CLIENT_CERTIFICATE` environment variable is explicitly
       set to `"true"`.
    2. The `GOOGLE_API_USE_CLIENT_CERTIFICATE` environment variable is unset or empty,
       but a valid workload certificate configuration is found (e.g., via the
       `GOOGLE_API_CERTIFICATE_CONFIG` environment variable or the default gcloud config path).

    See https://google.aip.dev/auth/4114 for client certificate discovery details.

    If client certificate usage is enabled, then for devices with endpoint
    verification support, a device certificate will be automatically loaded and
    mutual TLS will be established.
    See https://cloud.google.com/endpoint-verification/docs/overview.
    c                 ór   — t          j        ¦   «         }|s	d| _        d S t          j        ¦   «         | _        d S )NF)r   r:   Ú_is_mtlsr   Úhas_default_client_cert_source)r   rE   s     r   r   zSslCredentials.__init__G  s8   € Ý&Ô<Ñ>Ô>ˆØð 	BØ!ˆDŒMˆMˆMå Ô?ÑAÔAˆDŒMˆMˆMr   c                 óf  — | j         rŒ	 t          j        ¦   «         \  }}}}|rt          j        ||¬¦  «        | _        nt          j        ¦   «         | _        d| _         nM# t          j        t          f$ r}t          j	        |¦  «        }||‚d}~ww xY wt          j        ¦   «         | _        | j        S )a  Get the created SSL channel credentials.

        For devices with endpoint verification support, if the device certificate
        loading has any problems, corresponding exceptions will be raised. For
        a device without endpoint verification support, no exceptions will be
        raised.

        Returns:
            grpc.ChannelCredentials: The created grpc channel credentials.

        Raises:
            google.auth.exceptions.MutualTLSChannelError: If mutual TLS channel
                creation failed for any reason.
        r4   FN)
rM   r   Úget_client_ssl_credentialsr7   r;   Ú_ssl_credentialsr   ÚClientCertErrorÚOSErrorÚMutualTLSChannelError)r   Úhas_certrF   rG   Ú_Ú
caught_excÚnew_excs          r   r=   zSslCredentials.ssl_credentialsN  sË   € ð  Œ=ð 	Cð.Ý)5Ô)PÑ)RÔ)RÑ&�˜$  QØð *Ý,0Ô,HØ*.¸Cð-ñ -ô -�DÔ)Ð)õ -1Ô,HÑ,JÔ,J�DÔ)Ø$)�D”MøøÝÔ.µÐ8ð .ð .ð .Ý$Ô:¸:ÑFÔF�Ø :Ð-øøøøð.øøøõ %)Ô$@Ñ$BÔ$BˆDÔ!àÔ$Ð$s   ‰AA ÁBÁ5BÂBc                 ó   — | j         S )z?Indicates if the created SSL channel credentials is mutual TLS.)rM   )r   s    r   Úis_mtlszSslCredentials.is_mtlsp  s   € ð Œ}Ðr   N)r.   r/   r0   r1   r   Úpropertyr=   rZ   © r   r   r<   r<   4  sg   € € € € € ðð ð$Bð Bð Bð ð%ð %ñ „Xð%ðB ðð ñ „Xðð ð r   r<   )NN)"r1   Ú
__future__r   ÚloggingÚwarningsÚgoogle.authr   Úgoogle.auth.transportr   r   Úgoogle.oauth2r   r7   ÚImportErrorrW   ÚgetattrÚ_grpc_ver_strr   ÚstrÚ_partsÚsplitÚ_partÚappendÚintÚ
ValueErrorÚtupleÚwarnÚFutureWarningÚ	getLoggerr.   Ú_LOGGERr   rJ   r<   r\   r   r   ú<module>rr      s)  ðð &Ð %à &Ð &Ð &Ð &Ð &Ð &à €€€Ø €€€à "Ð "Ð "Ð "Ð "Ð "Ø 4Ð 4Ð 4Ð 4Ð 4Ð 4Ð 4Ð 4Ø )Ð )Ð )Ð )Ð )Ð )ðØ€K€K€K€KøØð ð ð Ø
ˆ+Øañô àðøøøøðøøøð �˜˜m¨TÑ2Ô2€Ø€:ˆm˜SÑ!Ô!ð 
Ø€FØ×$Ò$ SÑ)Ô)ð ð ˆð	Ø�MŠM˜#˜#˜e™*œ*Ñ%Ô%Ð%Ð%øØð 	ð 	ð 	ØˆEˆEð	øøøàð 	
�%�%˜‘-”- *Ò,Ð,ØˆŒðTð ñ	
ô 	
ð 	
ð ˆ'Ô
˜HÑ
%Ô
%€ðBAð BAð BAð BAð BA˜Ô0ñ BAô BAð BAðR ØðtHð tHð tHð tHðn?ð ?ð ?ð ?ð ?ñ ?ô ?ð ?ð ?ð ?s$   ¦+ «A°<¼AÁ7BÂBÂB