a
    w=icD                     @   sf   d Z ddlZddlZddlmZ ddlmZ ddlmZ ddlmZ dZ	e	d Z
G d	d
 d
ejZdS )zTools for using the Google `Cloud Identity and Access Management (IAM)
API`_'s auth-related functionality.

.. _Cloud Identity and Access Management (IAM) API:
    https://cloud.google.com/iam/docs/
    N)http_client)_helpers)crypt)
exceptionsz(https://iamcredentials.googleapis.com/v1z0/projects/-/serviceAccounts/{}:signBlob?alt=jsonc                   @   s@   e Zd ZdZdd Zdd Zedd Ze	e
jdd	 Zd
S )Signera  Signs messages using the IAM `signBlob API`_.

    This is useful when you need to sign bytes but do not have access to the
    credential's private key file.

    .. _signBlob API:
        https://cloud.google.com/iam/reference/rest/v1/projects.serviceAccounts
        /signBlob
    c                 C   s   || _ || _|| _dS )a  
        Args:
            request (google.auth.transport.Request): The object used to make
                HTTP requests.
            credentials (google.auth.credentials.Credentials): The credentials
                that will be used to authenticate the request to the IAM API.
                The credentials must have of one the following scopes:

                - https://www.googleapis.com/auth/iam
                - https://www.googleapis.com/auth/cloud-platform
            service_account_email (str): The service account email identifying
                which service account to use to sign bytes. Often, this can
                be the same as the service account email in the given
                credentials.
        N)_request_credentials_service_account_email)selfrequestcredentialsZservice_account_email r   `/home/droni/.local/share/virtualenvs/DPS-5Je3_V2c/lib/python3.9/site-packages/google/auth/iam.py__init__.   s    zSigner.__init__c                 C   s   t |}d}t| j}ddi}tdt|	di
d}| j| j||| | j||||d}|jtjkrtd|jt|j	dS )z(Makes a request to the API signBlob API.POSTzContent-Typezapplication/jsonpayloadzutf-8)urlmethodbodyheadersz&Error calling the IAM signBlob API: {})r   to_bytes_SIGN_BLOB_URIformatr	   jsondumpsbase64	b64encodedecodeencoder   Zbefore_requestr   statusr   OKr   ZTransportErrordataloads)r
   messager   r   r   r   responser   r   r   _make_signing_requestB   s     

zSigner._make_signing_requestc                 C   s   dS )zOptional[str]: The key ID used to identify this private key.

        .. warning::
           This is always ``None``. The key ID used by IAM can not
           be reliably determined ahead of time.
        Nr   )r
   r   r   r   key_idW   s    zSigner.key_idc                 C   s   |  |}t|d S )NZ
signedBlob)r%   r   	b64decode)r
   r#   r$   r   r   r   signa   s    
zSigner.signN)__name__
__module____qualname____doc__r   r%   propertyr&   r   Zcopy_docstringr   r   r(   r   r   r   r   r   #   s   

	
r   )r,   r   r   Z	six.movesr   Zgoogle.authr   r   r   Z_IAM_API_ROOT_URIr   r   r   r   r   r   <module>   s   