MOON
Server: Apache
System: Linux vps.erhabenn.com.br 3.10.0-1160.119.1.el7.tuxcare.els2.x86_64 #1 SMP Mon Jul 15 12:09:18 UTC 2024 x86_64
User: machen (1008)
PHP: 8.2.31
Disabled: NONE
Upload Files
File: //lib/python2.7/site-packages/azurelinuxagent/common/utils/restutil.pyo
�
d�bc
@s�ddlZddlZddlZddlZddlZddlZddljjZddl	jj
Z
ddljjj
Z
ddlmZmZmZddlmZmZmZddlmZmZmZeadZdZdZdZdZ ej!d	�Z"ej#ej$ej%ej&ej'ej(ej)ej*ej+d
g
Z,e,Z-e-j.ej/�ej0gZ1ej2ej3ej4gZ5ej6gZ7dgZ8ej%ej)d
gZ9ej:ej;ej<ej=gZ>dZ?d
Z@dZAdjBee�ZCdjBeC�ZDdZEdZFdZGdZHdeIfd��YZJded�ZKdd�ZMd�ZNd�ZOd�ZPd�ZQd�ZRd�ZSd�ZTd �ZUd!�ZVd"�ZWed#�ZXd$�ZYddeddded%�ZZdeddeeed&�Z[deddeed'�Z\dedded(�Z]dedded)�Z^deddeed*�Z_dedded+�Z`dd,�Zadd-�Zbd.�Zcdd/�Zdd0�ZedS(1i����N(t	HttpErrortResourceGoneErrortInvalidContainerError(t
httpclientturlparsetustr(tPY_VERSION_MAJORt
AGENT_NAMEtGOAL_STATE_AGENT_VERSIONiiis<SAS_SIGNATURE>s3^(https?://[a-zA-Z0-9.].*sig=)([a-zA-Z0-9%-]*)(.*)$i�i�t
http_proxythttps_proxytno_proxys{0}/{1}s
{0}+healthtInvalidContainerConfigurationtRequestRoleConfigFileNotFounds
168.63.129.16itIOErrorCountercBszeZej�ZeZidd6dd6dd6Zeddd��Z
ed��Zed��Zeed��Z
RS(	it
hostplugintprotocoltothercCsntj�_|tjkrQ|tkr;tjdcd7<qdtjdcd7<ntjdcd7<WdQXdS(NRiRR(Rt_lockt_protocol_endpointtHOST_PLUGIN_PORTt_counts(thosttport((sI/usr/lib/python2.7/site-packages/azurelinuxagent/common/utils/restutil.pyt	incrementvs
cCs1tj�"tjj�}tj�|SWdQXdS(N(RRRtcopytreset(tcounts((sI/usr/lib/python2.7/site-packages/azurelinuxagent/common/utils/restutil.pyt
get_and_reset�s

cCs2tj�#idd6dd6dd6t_WdQXdS(NiRRR(RRR(((sI/usr/lib/python2.7/site-packages/azurelinuxagent/common/utils/restutil.pyR�s
cCs
|t_dS(N(RR(tendpoint((sI/usr/lib/python2.7/site-packages/azurelinuxagent/common/utils/restutil.pytset_protocol_endpoint�sN(t__name__t
__module__t	threadingtRLockRtKNOWN_WIRESERVER_IPRRtstaticmethodtNoneRRRR(((sI/usr/lib/python2.7/site-packages/azurelinuxagent/common/utils/restutil.pyRqs
cCsEd}x0t|�D]"}|d|d|df}qW||dS(Nii(ii(trange(t
retry_attempttdelaytfibt_((sI/usr/lib/python2.7/site-packages/azurelinuxagent/common/utils/restutil.pyt_compute_delay�s cCs|dkrt}n||kS(N(R%tRETRY_CODES(tstatustretry_codes((sI/usr/lib/python2.7/site-packages/azurelinuxagent/common/utils/restutil.pyt_is_retry_status�s	cCs2tgtD]}t||�r
|^q
�dkS(Ni(tlentRETRY_EXCEPTIONSt
isinstance(tetx((sI/usr/lib/python2.7/site-packages/azurelinuxagent/common/utils/restutil.pyt_is_retry_exception�scCs
|tkS(N(tTHROTTLE_CODES(R-((sI/usr/lib/python2.7/site-packages/azurelinuxagent/common/utils/restutil.pyt_is_throttle_status�scCs�t|�}|j}|jr6dj||j�}n|jrWdj||j�}nt}|jj�dkr{t}n|j	|j
||fS(st
    Parse URL to get the components of the URL broken down to host, port
    :rtype: string, int, bool, string
    s{0}#{1}s{0}?{1}thttps(RtpathtfragmenttformattquerytFalsetschemetlowertTruethostnameR(turltotrel_uritsecure((sI/usr/lib/python2.7/site-packages/azurelinuxagent/common/utils/restutil.pyt
_parse_url�s				cCsct|�}|jr_|jr@dj|j|j|j|j�Sdj|j|j|j�Sn|S(s:
    Parse URL and return scheme://hostname:port/path
    s{0}://{1}:{2}{3}s{0}://{1}{2}(RRARR;R>R9(RBRC((sI/usr/lib/python2.7/site-packages/azurelinuxagent/common/utils/restutil.pyt_trim_url_parameters�s		"cCs�|jd�dkr�yt|jd�d�}Wntk
rFtSX|dks_|dkrctSytj|jd�d�Wq�tjk
r�tSXntStS(sU
    Very simple check of the cidr format in no_proxy variable.
    :rtype: bool
    t/ii i(	tcounttinttsplitt
ValueErrorR=tsockett	inet_atonterrorR@(tstring_networktmask((sI/usr/lib/python2.7/site-packages/azurelinuxagent/common/utils/restutil.pyt
is_valid_cidr�s
cCs/ddd|>dA}tjtjd|��S(sConverts mask from /xx format to xxx.xxx.xxx.xxx
    Example: if mask is 24 function returns 255.255.255.0
    :rtype: str
    I����ii s>I(RMt	inet_ntoatstructtpack(RQtbits((sI/usr/lib/python2.7/site-packages/azurelinuxagent/common/utils/restutil.pytdotted_netmask�scCs�tjdtj|��d}|jd�\}}tjdtjtt|����d}tjdtj|��d|@}||@||@kS(s�This function allows you to check if an IP belongs to a network subnet
    Example: returns True if ip = 192.168.1.1 and net = 192.168.1.0/24
             returns False if ip = 192.168.1.1 and net = 192.168.100.0/24
    :rtype: bool
    s=LiRH(RTtunpackRMRNRKRWRJ(tiptnettipaddrtnetaddrRVtnetmasktnetwork((sI/usr/lib/python2.7/site-packages/azurelinuxagent/common/utils/restutil.pytaddress_in_network�s
+#cCs-ytj|�Wntjk
r(tSXtS(s
    :rtype: bool
    (RMRNROR=R@(t	string_ip((sI/usr/lib/python2.7/site-packages/azurelinuxagent/common/utils/restutil.pytis_ipv4_address�s
cCsktjjt�p'tjjtj��}|rgg|jdd�jd�D]}|rL|^qL}n|S(Nt tt,(tostenvirontgettNO_PROXY_ENVtuppertreplaceRK(RR((sI/usr/lib/python2.7/site-packages/azurelinuxagent/common/utils/restutil.pytget_no_proxy�s*7cCs�t�}|r�t|�raxs|D]8}t|�rJt||�rZtSq"||kr"tSq"Wq�x0|D]%}|j�j|j��rhtSqhWntS(N(RkRaRRR_R@R?tendswithR=(RRtproxy_iptproxy_domain((sI/usr/lib/python2.7/site-packages/azurelinuxagent/common/utils/restutil.pytbypass_proxys	

cCs�tj�}d}|dk	r-tj�}n||r9tnt}d}x:||j�gD]&}|tjkrXtj|}PqXqXW|dk	r�t	|�\}}}}n||fS(N(
tconftget_httpproxy_hostR%tget_httpproxy_porttHTTPS_PROXY_ENVtHTTP_PROXY_ENVRiReRfRF(RERRthttp_proxy_envthttp_proxy_urltvR*((sI/usr/lib/python2.7/site-packages/azurelinuxagent/common/utils/restutil.pyt_get_http_proxys
cCstjdtd|�S(Ns\1s\3(tSAS_TOKEN_RETRIEVAL_REGEXtsubt
REDACTED_TEXT(RB((sI/usr/lib/python2.7/site-packages/azurelinuxagent/common/utils/restutil.pytredact_sas_tokens_in_urls4sc

Cs�|dkrin|}d|d<|dk	o7|dk	}
|dkr[|rRdnd}nd|krtt|d<n|
r�||}}|r�dnd}
dj|
|||�}n||}}|}|rtj||d	d
�}|
r|j||�qntj||d	d
�}|}|	r.d}ntjd|t	|�t
j|�|�|jd
|d|d|d|�|j
�S(Ntcloset
Connectioni�iPs
User-AgentR8thttps{0}://{1}:{2}{3}ttimeouti
s
[REDACTED]s'HTTP connection [{0}] [{1}] [{2}] [{3}]tmethodRBtbodytheaders(R%tHTTP_USER_AGENTR;RtHTTPSConnectiont
set_tunneltHTTPConnectiontloggertverboseR|ttextutiltstr_to_encoded_ustrtrequesttgetresponse(R�RRDRtdataRER�t
proxy_hostt
proxy_porttredact_datat	use_proxyt	conn_hostt	conn_portR>RBtconntpayload((sI/usr/lib/python2.7/site-packages/azurelinuxagent/common/utils/restutil.pyt
_http_request8s@



							"c
Cs�|dkrt}n|dkr*t}nt|�\}
}}}
d\}}|r�t|
�r�td|�\}}|s�|r�tjd||�q�n|r�tt	d�r�t
j�s�td��nt
}ts�tjd�taq�n|rb|dk	rb|dk	rbtt	jd�rbt
j�s=td��nt
}tsbtjd�taqbnd	}d
}d
}t
}xU||kr�|d
kr�|r�tntd|d|�}tjd
|d|||�tj|�n|d7}y0t||
|
d|d|d|d|d|d|d|�}tjd|j�|	rI|St|�r�t|jd|�r�dj|||j�}t|j�r�t}t|t�}nw}q�n|jtkr�t|�}t |��n|jt	j!krt|�}t"|krt#|��qn|SWq}t	j$k
ru}|	r>�nt%|�}dj|||�}t&|�rqq}nPq}t'k
r�}|	r��nt(j)d|
d|�t%|�}dj|||�}q}q}Xq}Wtdj||���dS(s�
    NOTE: This method provides some logic to handle errors in the HTTP request, including checking the HTTP status of the response
          and handling some exceptions. If return_raw_response is set to True all the error handling will be skipped and the
          method will return the actual HTTP response and bubble up any exceptions while issuing the request. Also note that if
        return_raw_response is True no retries will be done.
    REsHTTP proxy: [{0}:{1}]R�s!HTTPS is unavailable and requireds#Python does not include SSL supportR�s,HTTPS tunnelling is unavailable and requireds(Python does not support HTTPS tunnellingRciR'R(s;[HTTP Retry] Attempt {0} of {1} will delay {2} seconds: {3}iRR�R�R�R�R�s[HTTP Response] Status Code {0}R.s'[HTTP Retry] {0} {1} -- Status Code {2}s*[HTTP Failed] {0} {1} -- HttpException {2}Rs$[HTTP Failed] {0} {1} -- IOError {2}s{0} -- {1} attempts madeN(NN(*R%tDEFAULT_RETRIESR,RFRoRxR�R�thasattrRRptget_allow_httpRR=tSECURE_WARNING_EMITTEDtwarnR@R�tTHROTTLE_DELAY_IN_SECONDSR+ttimetsleepR�R-trequest_failedR/R;R7tmaxtTHROTTLE_RETRIEStRESOURCE_GONE_CODEStread_response_errorRtBAD_REQUESTtINVALID_CONTAINER_CONFIGURATIONRt
HTTPExceptionRGR5tIOErrorRR(R�RBR�R�R�t	max_retryR.tretry_delayR�treturn_raw_responseRRRERDR�R�tmsgtattemptR(t
was_throttledtresptresponse_errorR3t	clean_url((sI/usr/lib/python2.7/site-packages/azurelinuxagent/common/utils/restutil.pythttp_requesths�		

		
		cCs^|dkrt}n|dkr*t}ntd|dd|d|d|d|d|d|�S(	s�
    NOTE: This method provides some logic to handle errors in the HTTP request, including checking the HTTP status of the response
          and handling some exceptions. If return_raw_response is set to True all the error handling will be skipped and the
          method will return the actual HTTP response and bubble up any exceptions while issuing the request. Also note that if
          return_raw_response is True no retries will be done.
    tGETR�R�R�R.R�R�N(R%R�R,R�(RBR�R�R�R.R�R�((sI/usr/lib/python2.7/site-packages/azurelinuxagent/common/utils/restutil.pythttp_get�s		cCsX|dkrt}n|dkr*t}ntd|dd|d|d|d|d|�S(NtHEADR�R�R�R.R�(R%R�R,R�(RBR�R�R�R.R�((sI/usr/lib/python2.7/site-packages/azurelinuxagent/common/utils/restutil.pyt	http_heads		cCsX|dkrt}n|dkr*t}ntd||d|d|d|d|d|�S(NtPOSTR�R�R�R.R�(R%R�R,R�(RBR�R�R�R�R.R�((sI/usr/lib/python2.7/site-packages/azurelinuxagent/common/utils/restutil.pyt	http_post)s		cCs^|dkrt}n|dkr*t}ntd||d|d|d|d|d|d|�S(NtPUTR�R�R�R.R�R�(R%R�R,R�(RBR�R�R�R�R.R�R�((sI/usr/lib/python2.7/site-packages/azurelinuxagent/common/utils/restutil.pythttp_put=s			cCsX|dkrt}n|dkr*t}ntd|dd|d|d|d|d|�S(NtDELETER�R�R�R.R�(R%R�R,R�(RBR�R�R�R.R�((sI/usr/lib/python2.7/site-packages/azurelinuxagent/common/utils/restutil.pythttp_deleteSs		cCs&|dkrt}nt|d|�S(Ntok_codes(R%tOK_CODEStrequest_succeeded(R�R�((sI/usr/lib/python2.7/site-packages/azurelinuxagent/common/utils/restutil.pyR�fs	cCs.|dkrt}n|dk	o-|j|kS(N(R%R�R-(R�R�((sI/usr/lib/python2.7/site-packages/azurelinuxagent/common/utils/restutil.pyR�ls	cCs|dk	o|jtkS(N(R%R-tNOT_MODIFIED_CODES(R�((sI/usr/lib/python2.7/site-packages/azurelinuxagent/common/utils/restutil.pytrequest_not_modifiedrscCs=|dkrt}n|dk	o<|jdko<|j|kS(s`
    Host plugin will return 502 for any upstream issue, so a failure is any 5xx except 502
    i�N(R%t!HOSTPLUGIN_UPSTREAM_FAILURE_CODESR-(R�tupstream_failure_codes((sI/usr/lib/python2.7/site-packages/azurelinuxagent/common/utils/restutil.pytrequest_failed_at_hostpluginvs	cCs�d}|dk	r�y�dj|j|j|j��}tdkr]t|dddd�}n*|jdddd�jdddd�}t	j
|�}Wq�tk
r�}tj
t	j|��q�Xn|S(NRcs[HTTP Failed] [{0}: {1}] {2}itencodingtasciiterrorstignore(R%R;R-treasontreadRRtencodetdecodeR�treplace_non_asciit	ExceptionR�R�tformat_exception(R�tresultR3((sI/usr/lib/python2.7/site-packages/azurelinuxagent/common/utils/restutil.pyR�s 	(fRetreR!R�RMRTtazurelinuxagent.common.conftcommonRptazurelinuxagent.common.loggerR�t%azurelinuxagent.common.utils.textutiltutilsR�t azurelinuxagent.common.exceptionRRRtazurelinuxagent.common.futureRRRtazurelinuxagent.common.versionRRRR=R�R�tDELAY_IN_SECONDSR�R�R{tcompileRyt
RESET_CONTENTtPARTIAL_CONTENTt	FORBIDDENtINTERNAL_SERVER_ERRORtNOT_IMPLEMENTEDtBAD_GATEWAYtSERVICE_UNAVAILABLEtGATEWAY_TIMEOUTtINSUFFICIENT_STORAGER,t'HGAP_GET_EXTENSION_ARTIFACT_RETRY_CODEStappendR�tGONER�tOKtCREATEDtACCEPTEDR�tNOT_MODIFIEDR�R�R6tNotConnectedtIncompleteReadtImproperConnectionStatet
BadStatusLineR1RtRsRhR;R�tHTTP_USER_AGENT_HEALTHR�t"REQUEST_ROLE_CONFIG_FILE_NOT_FOUNDR#RtobjectRR+R%R/R5R7RFRGRRRWR_RaRkRoRxR|R�R�R�R�R�R�R�R�R�R�R�R�(((sI/usr/lib/python2.7/site-packages/azurelinuxagent/common/utils/restutil.pyt<module>s�				!								
		
			0�