}CedZddlmZddlmZddlmZddlZddlmZddlm Z ddl m Z d Z Gd d eZ Gd d e ZGdde ZGddZdS)z, Everything that is related to whmapi calls )print_function)absolute_import)divisionN)FormattedException) run_command) urlencode) WhmApiRequest WhmApiErrorceZdZdZdZdS)r zW An error that is raised in case of an error in communication with whmapi. c 6tj|||ddS)N)messagecontext)r__init__)selfr rs /builddir/build/BUILDROOT/alt-python27-cllib-3.3.7-2.el7.cloudlinux.x86_64/opt/cloudlinux/venv/lib/python3.11/site-packages/clcommon/lib/whmapi_lib.pyrzWhmApiError.__init__s3#D+ +      N)__name__ __module__ __qualname____doc__rrrr r s-      rr ceZdZdZdS)WhmLicenseErrorz)A license-related error raised by whmapi.Nrrrrrrrrr%s33DrrceZdZdZdS)WhmNoPhpBinariesErrorz; An error when there are no installed php binaries Nrrrrrr*s DrrcteZdZdZdZdZdZdZedZ e dZ e dZ d Z d Zd S) r a Wrapper over cpanel's whm command-line api tool that allows us to easily build complex requests (filter, sorting, etc) See details in the official cpanel docs (link below) https://documentation.cpanel.net/display/DD/Guide+to+WHM+API+1 z/usr/sbin/whmapi1cB||_i|_i|_ddg|_dS)Nz--outputjson)_command_filters_args _extra_args)rcommands rrzWhmApiRequest.__init__=s*   '1rcNt|d\}}}|dkrtd| tj|}d|vr#d|dvr|dd d|dd<n&#tt f$rtd | wxYw|||S) NT)return_full_outputrz whmapi exited with code %(code)i)codemetadatareasonzTwhmapi returned invalid response that cannot be parsed with json, output: %(output)s)output)rr r loads TypeError ValueError _validate)rr%exitcoder,_responses r _run_whmapizWhmApiRequest._run_whmapiCs) ...&! q==2   z&))H h&&!Xj%999!*-h7?13$X.:&   A   x   s ;A**#B c~||rtd|d||rtd|dd |dd|dd}}n#t$rt d|wxYw|t jkrt d | d S) z) Check response metadata z"whmapi license error: %(response)s statusmsgr3z Php binaries error: %(response)sr)r*resultz7whmapi metadata section is broken, output: %(response)sz4whmapi failed to execute request, reason: %(reason)s)r*N)_is_license_errorr_is_no_php_binaries_errorrKeyErrorr r API_RESULT_OK)clsr3r8r*s rr0zWhmApiRequest._validate_s   * * !4x ?T   ( ( 2 2 '2Xj=QRZ=[  $X.0DX0NFF   I!   ]0 0 0F  1 0s A==BcZd|vo'|ddkod|dvS)a# Distinguish license-related WHM API errors from others. License errors are on the client's side, and should not be logged to sentry. An error is considered license-related if the API returns status 0 and the error message contains the word 'license' r6statusrlicense)lowerr7s rr9zWhmApiRequest._is_license_error|sAx';"a';Xk288::: d|vod|dvod|ddvS)u No binaries error can be detected by checking special message '“PHP” is not installed on the system' whmapi output r)r*u(“PHP” is not installed on the systemrr7s rr:z'WhmApiRequest._is_no_php_binaries_errors> h&]HZ00]:hz>RS[>\\ ^rc :|j||S)z Add some extra arguments to subprocess call Useful for methods like createacct, removeacct :param kwargs: arguments that will be added to cmd :rtype: WhmApiRequest )r#update)rkwargss rwith_argumentszWhmApiRequest.with_argumentss &!!! rc|j|jg}t|jD]O\}}t |t rt|}t||i}| |P| |j | |}d|vr|dSd|vr|dS|S)zp Run subprocess, run output validation and return json-loaded response :return: datar,) WHMAPIr!listr#items isinstanceboolintrappendextendr$r4)rcmdkvargumentr8s rcallzWhmApiRequest.calls K M ))++,, ! !DAq!T""  FF !Q((H JJx 4#$$$!!#&& V  &> !   (# #MrN)rrrrrIr<rr4 classmethodr0 staticmethodr9r:rFrUrrrr r 1s"FM222 8[8 < <\ <^^\^($$$$$rr )r __future__rrrr clcommonrclcommon.utilsr urllib.parser__all__r rrr rrrr]sF&%%%%%&&&&&& ''''''&&&&&&"""""" *      $         k        K   YYYYYYYYYYr