HEX
Server: Apache
System: Linux pdx1-shared-a1-38 6.6.104-grsec-jammy+ #3 SMP Tue Sep 16 00:28:11 UTC 2025 x86_64
User: mmickelson (3396398)
PHP: 8.1.31
Disabled: NONE
Upload Files
File: //usr/lib/python3/dist-packages/duplicity/backends/pyrax_identity/__pycache__/hubic.cpython-310.pyc
o

�ka�'�
@s�ddlmZddlmZe��ddlmZddlZddlZddl	Z	ddl
Z
ddlZddl
mZmZddlZzddlZddlmZmZddlmZWney^Zzedee���dZ[wwdZd	Zej�d
�ZGdd�dej j!�Z"Gd
d�de�Z#dS)�)�print_function)�standard_library)�strN)�quote�
quote_plus)�BaseIdentity�ServicezPHubic backend requires the pyrax library available from Rackspace.
Exception: %szhttps://api.hubic.com/oauth/zhttps://api.hubic.com/1.0/z~/.hubic_tokensc@seZdZdd�Zdd�ZdS)�BearerTokenAuthcCs
||_dS�N)�token)�selfr�r
�I/usr/lib/python3/dist-packages/duplicity/backends/pyrax_identity/hubic.py�__init__#s
zBearerTokenAuth.__init__cCsd|j|jd<|S)NzBearer �
Authorization)r�headers)r�reqr
r
r�__call__&szBearerTokenAuth.__call__N)�__name__�
__module__�__qualname__rrr
r
r
rr	"sr	csXeZdZ�fdd�Zdd�Z	ddd�Zdd	�Zd
d�Zdd
�Zdd�Z	dd�Z
�ZS)�
HubicIdentitycstt|��|�dSr
)�superrr�r��	__class__r
rr,szHubicIdentity.__init__cCsdS)N�r
rr
r
r�_get_auth_endpoint/sz HubicIdentity._get_auth_endpointFcCs8||_||_||_||_||_||_|r|��dSdS)z(Sets the username and password directly.N)�_email�	_password�
_client_id�	tenant_id�_client_secret�
_redirect_uri�authenticate)r�email�password�	client_id�
client_secret�redirect_urir$r
r
r�set_credentials2s�zHubicIdentity.set_credentialscCsR|�dd�|_|�dd�|_|�dd�|_|j|_|�dd�|_|�dd�|_dS)zL
        Parses the credential file with Rackspace-specific labels.
        �hubicr%r&r'r(r)N)�getrrr r!r"r#)r�cfgr
r
r�_read_credential_file?sz#HubicIdentity._read_credential_filecCsDd|jvrdStj�|jd�j}ttj�|��}|d|dd�S)N�location�error�error_description)r0r1)r�urllib�parse�urlsplit�query�dict�	parse_qsl)r�respr5�qsr
r
r�_parse_errorJs

zHubicIdentity._parse_errorcCstjtd||jdd�|j|jfd�}|jdkr3z|��}|j|d<Wni}Yt�	dt
|���|��}t��}|�
t�|�d�sJ|�d�|d	durt|�dd	|d	�ttd
��
}|�|�Wd�n1snwYn	t�	dt
|���|ddur�|�dd|d�ttd
��
}|�|�Wd�n1s�wYnt�	d��|�dd
�r�|�dd
�ttd
��
}|�|�Wd�n1s�wYtd�|�dd��r|�dd�ttd
��
}|�|�Wd�n1s�wYtd�|S)N�token/�authorization_code)�coder)�
grant_type��data�auth��r=�IUnable to get oauth access token, wrong client_id or client_secret ? (%s)r+�access_token�wb�
refresh_tokenz Unable to get the refresh token.r%zEusername has been removed from the .hubic_tokens file sent to the CE.r&zEpassword has been removed from the .hubic_tokens file sent to the CE.)�requests�post�OAUTH_ENDPOINTr#r r"�status_code�json�exc�AuthenticationFailedr�configparser�ConfigParser�read�TOKENS_FILE�has_section�add_section�set�open�write�
has_option�
remove_option�print)rr=�r�err�oauth_token�config�
configfiler
r
r�_get_access_tokenQsj�
�
	�


������
��zHubicIdentity._get_access_tokencCs0t��}|�t�|�dd�}|durt�d��d}d}d}d}d}||kr�|s�tjt	d	|dd
�|j
|jfd�}|jdkrx|jd
kr]t
d|d�|d7}t�|�|d}||kr\|}nz|��}	|j|	d<Wni}	Yt�dt|	���d}||kr�|r(|s�t�d��|��}
|
ddur�|
St�d��)Nr+rFz-refresh_token is null. Not acquiered before ?F�r�ir;)rFr>r?rBi�zstatus_code 509: attempt #z failed��r=rCTz]All the attempts failed to get the refresh token: status_code = 509: Bandwidth Limit ExceededrDz*Unable to get oauth access token from json)rNrOrPrQr,rLrMrGrHrIr r"rJrY�time�sleeprKr)rr]rF�success�max_retries�retries�
sleep_time�max_sleep_timerZr[r\r
r
r�_refresh_access_token�s^

�
�


�����
z#HubicIdentity._refresh_access_tokenc		Cst��}|�t�|�dd�r|��}n�tjtd�	t
|j�t|j
�tj���dd�}|jdkr<t�dt|�|����zdd	lm}WntyOd}Ynw|re|�|j��d
�}|rb|djnd}nt�d|j�}|rs|�d�nd}|s|t�d
��|j dus�|j!dur�t�d��tj"tdd||j |j!ddd�dd�}zt#j$�%|j&d�j'}t(t#j$�)|��d}Wnt�d��|�*|�}|d�+�dkr�t�d��tjt,dt-|d�d�}|�.�}d|_/|d|_0|d|_1t2|d d!d"|d#igd$��|j3d%<d|_4|_5dS)&Nr+rFz_auth/?client_id={0}&redirect_uri={1}&scope=credentials.r,account.r&response_type=code&state={2}F)�allow_redirectsrBz%Incorrect/unauthorized client_id (%s)r)�htmlz//input[@name="oauth"]zD<input\s+[^>]*name=[\'"]?oauth[\'"]?\s+[^>]*value=[\'"]?(\d+)[\'"]?>rbz.Unable to get oauth_id from authorization pagezLCannot retrieve email and/or password. Please run expresslane-hubic-setup.shzauth/�acceptedrZ)�action�oauth�login�user_pwd�account�credentials)r@rlr/r=z7Unable to authorize client_id, invalid login/password ?�
token_type�bearerzUnsupported access token typezaccount/credentialsrD)rATr�expires�HubiC�
cloudfiles�
public_url�endpoint)�name�type�	endpoints�object_store)6rNrOrPrQrWrkrGr,rI�formatrr rr#�pyrax�utils�random_asciirJrLrMrr:�lxmlrm�ImportError�document_fromstring�content�xpath�value�re�search�grouprrrHr2r3r4rr5r6r7r_�lower�API_ENDPOINTr	rK�
authenticatedrrwr�services�usernamer&)	rr]r\rZ�	lxml_htmlrpr5r=�swift_tokenr
r
rr$�s�

���
	���

�	�



�


��zHubicIdentity.authenticate)F)rrrrrr*r.r:r_rkr$�
__classcell__r
r
rrr+s
�
;9r)$�
__future__r�futurer�install_aliases�builtinsrrN�osr�rd�urllib.parser2�requests.compatrrrGr��pyrax.base_identityrr�pyrax.exceptions�
exceptionsrLr��e�BackendExceptionrIr��path�
expanduserrQrA�AuthBaser	rr
r
r
r�<module>s4���