HEX
Server: Apache/2.4.52 (Ubuntu)
System: Linux spn-python 5.15.0-89-generic #99-Ubuntu SMP Mon Oct 30 20:42:41 UTC 2023 x86_64
User: arjun (1000)
PHP: 8.1.2-1ubuntu2.20
Disabled: NONE
Upload Files
File: //lib/python3/dist-packages/docker/__pycache__/auth.cpython-310.pyc
o

�2.a�3�@s�ddlZddlZddlZddlmZddlmZddlmZdZde�d�Z	d	Z
e�e�Z
d
d�Zdd
�Zdd�Zdd�Zdd�ZGdd�de�Zd%dd�Zdd�Zdd�Zdd�Zd&dd �Zd'd!d"�Zd#d$�ZdS)(�N�)�credentials)�errors)�configz	docker.iozhttps://index.z/v1/z<token>cCsZd|vr
t�d|�d���t|�\}}|ddks|ddkr't�d�|���t|�|fS)Nz://z)Repository name cannot contain a scheme (�)r�-���z;Invalid index name ({}). Cannot begin or end with a hyphen.)r�InvalidRepository�split_repo_name�format�resolve_index_name)�	repo_name�
index_name�remote_name�r�-/usr/lib/python3/dist-packages/docker/auth.py�resolve_repository_names
��rcCst|�}|dtkrt}|S)Nzindex.)�convert_to_hostname�
INDEX_NAME)rrrrrsrcCsft�d�|jr|jjrt�d�t|jd�|_t|j||jd�}|r,t�d�t|�St�d�dS)NzLooking for auth configz2No auth config in memory - loading from filesystem)�
credstore_envzFound auth configzNo auth config found)�log�debug�
_auth_configs�is_empty�load_configr�resolve_authconfig�
encode_header)�client�registry�authcfgrrr�get_config_header&s
�
�

r cCsL|�dd�}t|�dksd|dvr"d|dvr"|ddkr"t|fSt|�S)N�/r�.r�:�	localhost)�split�lenr�tuple)r
�partsrrrr
<s
$r
cCst|t�s	t|�}|�|�S�N)�
isinstance�
AuthConfig�get_credential_store)�
authconfigrrrrr,Fs

r,c@s�eZdZddd�Zeddd��Zeddd��Zed	d
��Zedd��Z	ed
d��Z
edd��Zddd�Zdd�Z
dd�Zdd�Zdd�Zdd�ZdS)r+NcCs*d|vri|d<|�|�||_i|_dS�N�auths)�update�_credstore_env�_stores)�self�dctrrrr�__init__Ms


zAuthConfig.__init__FcCs�i}|��D]f\}}t|t�s%t�d�|��|r!t�d�|���iSd|vr:t�d�|��d|di||<qd|vrKt�d�|��i||<qt|d�\}}t�d�t	|�t	|���|||�
d	�|d
�||<q|S)a 
        Parses authentication entries

        Args:
          entries:        Dict of authentication entries.
          raise_on_error: If set to true, an invalid format will raise
                          InvalidConfigFile

        Returns:
          Authentication registry.
        z*Config entry for key {} is not auth configz%Invalid configuration for registry {}�
identitytokenz,Found an IdentityToken entry for registry {}�
IdentityToken�authzNAuth data for {} is absent. Client might be using a credentials store instead.z&Found entry (registry={}, username={})�email��username�passwordr9�
serveraddress)�itemsr*�dictrrrr�InvalidConfigFile�decode_auth�repr�get)�cls�entries�raise_on_error�confr�entryr;r<rrr�
parse_authTsT
��	��������zAuthConfig.parse_authc
CsH|sKt�|�}|s|i|�Szt|��
}t�|�}Wd�n1s#wYWn!tttfyJ}zt�	|�|t
|�|�WYd}~Sd}~wwi}|�d�rft�	d�|�d|j
|�d�dd�i�|�d�rzt�	d�|�d|�d�i�|�d�r�t�	d	�|�d|�d�i�|r�|||�St�	d
�|d|�
|�i|�S)a8
        Loads authentication data from a Docker configuration file in the given
        root directory or if config_path is passed use given path.
        Lookup priority:
            explicit config_path parameter > DOCKER_CONFIG environment
            variable > ~/.docker/config.json > ~/.dockercfg
        Nr/zFound 'auths' sectionT)rF�
credsStorezFound 'credsStore' section�credHelperszFound 'credHelpers' sectionzNCouldn't find auth-related section ; attempting to interpret as auth-only file)r�find_config_file�open�json�load�OSError�KeyError�
ValueErrorrr�_load_legacy_configrCr0rI�pop)rD�config_path�config_dictr�config_file�f�e�resrrrr�sD



��
��


��




�zAuthConfig.load_configcC�|�di�Sr.�rC�r3rrrr/��zAuthConfig.authscCs|�dd�S)NrJr\r]rrr�creds_store�r^zAuthConfig.creds_storecCr[)NrKr\r]rrr�cred_helpers�r^zAuthConfig.cred_helperscCs|jo|jo|jSr))r/r_r`r]rrrr�s�zAuthConfig.is_emptycCs�|js|jr)|�|�}|dur)t�d|�d��|�||�}|dur$|St�d�|r/t|�nt}t�dt|����||j	vrOt�dt|����|j	|S|j	�
�D]\}}t|�|krlt�dt|����|SqTt�d�dS)a+
        Returns the authentication data from the given auth configuration for a
        specific registry. As with the Docker client, legacy entries in the
        config with full URLs are stripped down to hostnames before checking
        for a match. Returns None if no match was found.
        NzUsing credentials store "�"z/No entry in credstore - fetching from auth dict�Looking for auth entry for zFound �No entry found)r_r`r,rr�_resolve_authconfig_credstorerrrBr/r>)r3r�
store_name�cfg�keyrGrrrr�s,

�


�
zAuthConfig.resolve_authconfigc
Cs�|r|tkrt}t�dt|����|�|�}z'|�|�}d|i}|dtkr0|d|d<|WS|�|d|dd��|WSt	j
yNt�d�YdSt	jyd}z
t�
dt|�����d}~ww)	Nrb�
ServerAddress�Username�Secretr7)ri�PasswordrczCredentials store error: )r�	INDEX_URLrrrB�_get_store_instancerC�TOKEN_USERNAMEr0r�CredentialsNotFound�
StoreErrorr�DockerException)r3r�credstore_name�store�datarZrYrrrrd�s2

���
���z(AuthConfig._resolve_authconfig_credstorecCs*||jvrtj||jd�|j|<|j|S)N)�environment)r2r�Storer1)r3�namerrrrms

�
zAuthConfig._get_store_instancecCs"|r|tkrt}|j�|�p|jSr))rrlr`rCr_)r3rrrrr,!szAuthConfig.get_credential_storecCs�|j��}|jr(|�|j�}|����D]}|�||j�||<|||t|�<q|j�	�D]\}}|�||�||<|||t|�<q-|Sr))
r/�copyr_rm�list�keysrdrr`r>)r3�	auth_datars�k�regrerrr�get_all_credentials's
��zAuthConfig.get_all_credentialscCs||d|<dSr.r)r3r}rtrrr�add_auth;szAuthConfig.add_authr)�F)�__name__�
__module__�__qualname__r5�classmethodrIr�propertyr/r_r`rrrdrmr,r~rrrrrr+Ls(
D/




#r+cCst|t�s
t||�}|�|�Sr))r*r+r)r-rrrrrr?s


rcCs |�dd��dd��dd�dS)Nzhttp://�zhttps://r!rr)�replacer%)�urlrrrrEs rcCsBt|t�r
|�d�}t�|�}|�dd�\}}|�d�|�d�fS)N�ascii�:r�utf8)r*�str�encode�base64�	b64decoder%�decode)r8�s�login�pwdrrrrAIs



rAcCst�|��d�}t�|�S)Nr�)rN�dumpsr�r��urlsafe_b64encode)r8�	auth_jsonrrrrQs
rFcCst�||�S)a
    Parses authentication entries

    Args:
      entries:        Dict of authentication entries.
      raise_on_error: If set to true, an invalid format will raise
                      InvalidConfigFile

    Returns:
      Authentication registry.
    )r+rI)rErFrrrrIVs
rIcCst�|||�Sr))r+r)rUrVrrrrrfsrc
Cs�t�d�zJg}t|��&}|��D]}|�|���d�d�qt|�dkr+t�	d��Wd�n1s5wYt
|d�\}}dt|||dtd�iiWSt
yf}zt�|�WYd}~nd}~wwt�d	�iS)
Nz+Attempting to parse legacy auth file formatz = r�z$Invalid or empty configuration file!rr/r:z4All parsing attempts failed - returning empty config)rrrM�	readlines�append�stripr%r&rr@rArrl�	Exception)rWrtrX�liner;r<rYrrrrSjs8

���	��
��
rS)NNr�)NNN)r�rN�loggingr�rr�utilsrrrlrn�	getLoggerr�rrrr r
r,r?r+rrrArrIrrSrrrr�<module>s0


t