l#gddlZddlZddlZddlZddlZddlZddlmZddl m Z ddl m Z ddl mZe eZGddeZdZd Zd Zd Zd Zd Z ddZddddefdZdZdZdS)N)partial) getLogger)Path)ANTIVIRUS_MODEceZdZfdZxZS)ZendeskAPIErrorct||_||_||_t|dS)N)error descriptiondetailssuper__init__)selfr r r __class__s R/opt/imunify360/venv/lib/python3.11/site-packages/defence360agent/utils/support.pyrzZendeskAPIError.__init__s7 &  %%%%%)__name__ __module__ __qualname__r __classcell__)rs@rrrs8&&&&&&&&&rrz(https://cloudlinux.zendesk.com/api/v2/{}z-https://cloudlinux.zendesk.com/hc/requests/{}iqiiQdlVA,cKt|d{V}t|}||g|d<t||}ttrdnddtddg} |r| t |d|r| t|dt|||| } t| d{VS) z? Send request to support of Imunify360 via Zendesk API N)bodyuploads)nameemail pr_imunify_avpr_im360)idvalueT) requestersubjectcomment custom_fields) _upload_attachmentsdict _PRODUCT_IDr_PRIVACY_POLICY_IDappend _DOCTOR_ID_CLN_ID_post_support_request) sender_emailr!r doctor_keycln attachments upload_tokenr"r r#requests r send_requestr2"s-[99999999L $$$G*^ ,l;;;I (6F__J  "D11 MFJDDEEE <Gc::;;;# G'w// / / / / / //r)paramstimeoutdatac|tj|}|j}|r|dz }|tj|z }tj|j|j|j|j ||j f}d} tj tj ||||5}|j||fcdddS#1swxYwYdS#tj$rt"t$$r6} t'| ds| j| j || nifcYd} ~ Sd} ~ wwxYw)zHTTP POST *data* to *url* with given *headers*. Add query *params* to the *url* if given. Return (http_status, decoded_json_response) tuple. N&ctjtj||jdS)Nzutf-8)encoding)jsonloadio TextIOWrapperheadersget_content_charset)responses rdecode_as_jsonz"_post_data..decode_as_jsondsBy  !)==gFF      r)r5r>)r4code)urllibparseurlparsequery urlencode urlunparseschemenetlocpathr3fragmentr1urlopenRequestrBsocketr4 TimeoutErrorOSErrorhasattrfp) urlr5r>r3r4prFrAr@es r _post_datarWSs L ! !# & &   SLE ''///l%% Xqx5!* E      I ^ # # N " "3T7 " C C$   =M>>(#;#;<  = = = = = = = = = = = = = = = = = = > IIIq&!!  ad.>***BHHHHHHH IsCADC4' D4C88D;C8<DE +E EEcKtd}ddi}tjt |dd}t j}|dt|||d{V\}}|d krs| d }|r t|d Sd | vrdStd dd|t| dd| d| di)zReturn url of the support request or None if request is suspended, because of we not able to obtain the id of the ticket if it suspended. z requests.json Content-Typezapplication/json)r1T) sort_keysasciiNr1rsuspended_ticketzResponse errorz UNKNOWN ERRORz{!r}r r r ) _API_URL_TMPLformatr:dumpsr%encodeasyncioget_event_looprun_in_executorrWget _HC_URL_TMPLkeysr)r1rTr>r5loopstatusresult request_datas rr+r+{sb    / /C12G :d7+++t < < < C CG L LD  ! # #D// j#tWNFF}}zz),,  &&|D'9:: : 6;;== 0 04! /6==3H3H  JJw 0 0 JJ} % % JJy" % %   rc Kd}||Stj}|D]}t|}d|ji}|||d<|dt t td| ddi|d{V\}}|dkr#t d||d ||d d}|S) Nfilenametokenz uploads.jsonrYzapplication/binary)r5r>r3r\z'Failed to upload file %s to Zendesk: %sr upload) rbrcrrrdrrWr^r_ read_bytesloggerwarning)r/r0rh attachmentrKr3rirjs rr$r$s$L  ! # #D!55 Jdi(  #*F7O#33  $$^44__&&')=>            S== NN9w      !(+G4L r)NNN)rbr<r:rO urllib.parserCurllib.request functoolsrloggingrpathlibr defence360agent.contracts.configrrrq Exceptionrr^rfr&r)r*r'r2bytesrWr+r$rrr}sa ;;;;;; 8  &&&&&i&&&; >   #  .0.0.0.0b59$%I%I%I%%I%I%I%IP   :!!!!!r