????

Your IP : 18.222.215.12


Current Path : /opt/cloudlinux/venv/lib/python3.11/site-packages/vendors_api/__pycache__/
Upload File :
Current File : //opt/cloudlinux/venv/lib/python3.11/site-packages/vendors_api/__pycache__/parser.cpython-311.pyc

�

K�f[6���dZddlmZddlmZddlmZddlZddlZddlmZddl	Z	ddl
Z
ddlZddl
mZddl
mZmZmZmZdd	lmZdd
lmZddlmZmZmZmZmZmZmZmZmZddl m!Z!m"Z"m#Z#m$Z$m%Z%m&Z&m'Z'm(Z(ej)�*ej)�+e,����Z-ej.eej/eej0eej1eiZ2Gd
�d��Z3e4dkr�e3��Z5e6e5�7����e6e5�8d�����e6e5�9����e6e5�:����e6e5�;����dSdS)zt
Main API module that provides class uses as proxy
to public vendors methods and converts data to
internal objects.
�)�print_function)�absolute_import)�divisionN)�compress)�ValidationError)�Optional�List�Dict�Any)�ALL_CL_FEATURES��integration_scripts)	�BadScriptError�MalformedError�ErrorMessage�
InternalError�PermissionDenied�
BadRequest�NotFound�UnexpectedResult�VendorApiMalformedData)�	PanelInfo�	Databases�Package�User�
DomainData�Reseller�Admin�InstalledPHPc��eZdZdZed���Zd�Zd�Zd�Zd�Z	d�Z
d�Zdd
�Z						dd�Z
dd
�Zdd�Zdd�Zdeefd�Zd	S)�	PublicApiz>
    Proxy to the public universal api for control panels
    c��t��S)zU
        Re-read this each time we call api
        due to lve-stats daemon.
        r
)�selfs ��/builddir/build/BUILDROOT/alt-python27-cllib-3.4.8-1.el8.cloudlinux.x86_64/opt/cloudlinux/venv/lib/python3.11/site-packages/vendors_api/parser.py�_scriptszPublicApi._scriptsCs��#�$�$�$�c�t�tj���}|�dd��d|d<	t	j|tjtjd|���}|���\}}n$#t$r}td|z���d}~wwxYw|�||��S)N�
PYTHONPATH�1�PYTHONNOUSERSITET)�stdout�stderr�text�envz0Something is wrong with integration script: `%s`)�os�environ�copy�pop�
subprocess�Popen�PIPE�DEVNULL�communicate�OSErrorr�	_validate)r#�command�schema_filer.�p�output�_�es        r$�_executezPublicApi._executeMs����j�o�o��������d�#�#�#�"%����
	0�� ��(2��(2�(:�&*�%(�	*�*�*�A�
�
�
���I�F�A�A���	0�	0�	0� �+�-.�/�0�0�
0�����	0����
�~�~�f�k�2�2�2s�AB�
B!�
B�B!c�t�t�|��}|�td||����||���)z�
        Convert documented api error constants into
        python exceptions.
        :param result: error constant
        :param message: custom message that vendor returned
        Nz8Unexpected result key: `%(result)s`; message=`%(error)s`)�result�error)�_ERROR_MESSAGE_TO_ERROR�getr)r#rB�message�	error_clss    r$�_error_key_to_errorzPublicApi._error_key_to_errorcsN��,�/�/��7�7�	���"�J��W�.�.�.�
.��i�� � � r&c�(�	tj|��pi}n$#ttf$rt	|���wxYw	|dpi}|d}n#t
$rt	|����wxYw|dkru	|�|��}tj|d|��n;#tt
tf$r!}tt|�����d}~wwxYw|dS|�||�
d������)	zs
        Checks input for valid json structure
        :param raw_data: json
        :return: dict or list
        �metadatarB)r=�ok�dataNrF)rF)�json�loads�	TypeError�
ValueErrorr�KeyError�_read_data_schema�
jsonschema�validaterr�strrHrE)r#�raw_data�schema_path�deserializedrJrB�schemar?s        r$r9zPublicApi._validatersC��	+��:�h�/�/�5�2�L�L���:�&�	+�	+�	+� ��*�*�*�	+����	2�#�J�/�5�2�H��h�'�F�F���	2�	2�	2� ��1�1�1�1�	2�����T�>�>�
5��/�/��<�<���#�L��$8�&�A�A�A�A��#�X�y�9�
5�
5�
5�-�S��V�V�4�4�4�����
5���� ��'�'��*�*�6�8�<�<�	�;R�;R�*�S�S�Ss+��!:�A�A,�60B'�'C�>C�Cc��ttj�td|����5}tj|���t
j��}ddd��n#1swxYwY|S)a-
        Knowing the fact that we store all data schemas
        in one folder we can easily find their absolute path.

        We do not handle errors here as normally package
        contains all it's files.
        :param filename: schema filename to load
        :return: dict, jsonschema
        �schemasN)	�openr/�path�join�BASE_DIR�yaml�load�read�
SafeLoader)r#�filename�f�data_schemas    r$rRzPublicApi._read_data_schema�s����"�'�,�,�x��H�=�=�
>�
>�	?�!��)�A�F�F�H�H�d�o�>�>�K�	?�	?�	?�	?�	?�	?�	?�	?�	?�	?�	?����	?�	?�	?�	?��s�2A2�2A6�9A6c
��|�|jjd���}t|��}|js|S|jD]B}|t
vr�t
d|�dd�d�t
D���������|S)z�
        Returns the information about the control panel.

        Necessity: Always
        Accessed by: All UNIX users
        Must work inside CageFS also: Yes
        zpanel_info.yaml�r;zFeature zY is not available, please, check your panel_info integration script. Available keys are: z, c��g|]	}|j��
S�)�value)�.0res  r$�
<listcomp>z(PublicApi.panel_info.<locals>.<listcomp>�s��;]�;]�;]��A�G�;]�;]�;]r&)r@r%�
panel_infor�supported_cl_featuresrrr^)r#�
valid_datarB�features    r$rnzPublicApi.panel_info�s����]�]�4�=�#;�IZ�]�[�[�
��:�&�&���+�	��M��3�	a�	a�G��/�)�)��!�/�)0������;]�;]�_�;]�;]�;]�1^�1^�1^�#`�a�a�
a��
r&c�b�|�|jjd���}t|��S)a
        Returns the information about databases that are
        available to the control panel users and are
        managed by the control panel.

        Necessity: Only for LVE-Stats
        Accessed by: admins (UNIX users)
        Must work inside CageFS also: No
        zdb_info.yamlrh)r@r%�db_infor)r#rps  r$rszPublicApi.db_info�s,���]�]�4�=�#8�n�]�U�U�
���$�$�$r&Nc�r�|jj}|�|d|fz
}|�|d���}d�|D��S)a
        Returns list of abstractions called "package" that
        represents a group of users that have the
        same default limits.

        Necessity: For limits functionality
        Accessed by: admins (UNIX users)
        Must work inside CageFS also: No
        N�--ownerz
packages.yamlrhc�,�g|]}t|����Srj)r�rl�xs  r$rmz&PublicApi.packages.<locals>.<listcomp>�s��/�/�/�q���
�
�/�/�/r&)r%�packagesr@)r#�owner�argsrps    r$ryzPublicApi.packages�sL���}�%�����Y��&�&�D��]�]�4�_�]�E�E�
�/�/�J�/�/�/�/r&c�Z��hd�}t|��t|��zrtd���t|tttd��f��std���|�&t
|��|z
}|rtd|z���|g||g�g|gg}	tt|	d�|	D������}
t|
��dkrtd|
z���|j	j
}|�|d	|fz
}|r|r	|d
|d|fz
}�rt�t��r|d�fz
}|r|d
t|��fz
}|r|dd�|��fz
}|�
|d���}d�|D��}
t�ttf��r�fd�|
D��}
|
S)z�
        Returns information about UNIX users, created
        and managed by the control panel.

        Necessity: Always
        Accessed by: admins (UNIX users)
        Must work inside CageFS also: No
        >�id�emailrz�domain�package�username�locale_codez7You can only use package_name and package_owner in pairNz"fields accept only list of stringsz%s are not allowed fieldsc�,�g|]}t|����Srj)�all)rl�is  r$rmz#PublicApi.users.<locals>.<listcomp>�s��4V�4V�4V��S��V�V�4V�4V�4Vr&�z/You cannot use all this args in one request: %sruz--package-namez--package-ownerz
--usernamez	--unix-idz--fields�,z
users.yamlrhc�,�g|]}t|����Srj)rrws  r$rmz#PublicApi.users.<locals>.<listcomp>s��.�.�.�a�$�q�'�'�.�.�.r&c�&��g|]
}|j�v�|��Srj)r��rl�u�filter_namess  �r$rmz#PublicApi.users.<locals>.<listcomp>s%���F�F�F�A�1�:��+E�+E�a�+E�+E�+Er&)�boolrP�
isinstance�list�tuple�type�setr�lenr%�usersrUr^r@)r#rz�package_name�
package_ownerr��unix_id�fields�allowed_fields�not_allowed_fields�exclusive_groups�	used_argsr:rprBs    `         r$r�zPublicApi.users�s>��� G�G�G�������]� 3� 3�3�	:��9�:�:�
:��&�4���T�
�
�";�<�<�	C��A�B�B�B���!$�V���~�!=��!�
S� �!<�?Q�!Q�R�R�R��G�
�=�)�
�N�
�I�	
����"2�4V�4V�EU�4V�4V�4V�W�W�X�X�	��y�>�>�A����"�$-�.�/�/�
/��-�%�����	�5�)�)�G��	:�M�	:��(�,�)�=�:�
:�G��	4�J�|�S�9�9�	4���l�3�3�G��	3���S��\�\�2�2�G��	6��
�C�H�H�V�$4�$4�5�5�G��]�]�7��]�E�E�
�.�.�:�.�.�.���l�T�5�M�2�2�	G�F�F�F�F��F�F�F�F��
r&Fc��|r|rtd���|jj}d}|r|d|fz
}|r|d|fz
}|r|dz
}d}|�||���}i}|���D]\}}	t|	��||<�|S)z�
        Returns key-value object, where a key is a domain (or subdomain)
        and a value is DomainData object

        Necessity: Selectors, some UI features
        Accessed by: All UNIX users
        Must work inside CageFS also: Yes
        z"you cannot use both owner and namezdomains.yamlru�--name)z
--with-phpzdomains_with_php.yamlrh)rPr%�domainsr@�itemsr)
r#rz�name�with_phpr:rYrprB�k�vs
          r$r�zPublicApi.domainss����	C�T�	C��A�B�B�B��-�'�����	*��	�5�)�)�G��	(���$�'�'�G��	-��'�'�G�,�F��]�]�7��]�?�?�
����$�$�&�&�	&�	&�D�A�q�"�1�
�
�F�1�I�I��
r&c�D��|r�rtd���|jj}|�|dt|��fz
}t	�t��r|d�fz
}|�|d���}d�|D��}t	�ttf��r�fd�|D��}|S)	a�
        Gives information about resellers who can be users owners
        in the control panel. Resellers do not obligatory have
        their own same-name UNIX accounts in the system and could
        exist only as an account in the control panel.

        Necessity: Always
        Accessed by: admins (UNIX users)
        Must work inside CageFS also: no
        :param int id_: int, reseller id
        :param filter_names: name or list of reseller names to return
        z&You cannot use id and name at one callNz--idr�zresellers.yamlrhc�,�g|]}t|����Srj)rrws  r$rmz'PublicApi.resellers.<locals>.<listcomp>Ns��2�2�2�!�(�1�+�+�2�2�2r&c�&��g|]
}|j�v�|��Srj�r�r�s  �r$rmz'PublicApi.resellers.<locals>.<listcomp>P�%���B�B�B�A�1�6�\�+A�+A�a�+A�+A�+Ar&)rPr%�	resellersrUr�r@r�r�)r#�id_r�r:rprBs  `   r$r�zPublicApi.resellers6s�����	G�<�	G��E�F�F�F��-�)���?����C���)�)�G��l�C�(�(�	0���,�/�/�G��]�]�7�8H�]�I�I�
�2�2�z�2�2�2���l�T�5�M�2�2�	C�B�B�B�B��B�B�B�F��
r&c�h���r|�td���|jj}t�t��r|d�fz
}|�&|dt	|�����fz
}|�|d���}d�|D��}t�ttf��r�fd�|D��}|S)	u�
        Gives information about panel’s administrators,
        output information about all panel’s administrators who:
        - could be (or actually are) the owners of the users, listed in users()
        - could be (or actually are) the owners of the packages, listed in packages()
        - has UNIX users with the rights to run LVE Manager UI

        Necessity: Always
        Accessed by: admins (UNIX users)
        Must work inside CageFS also: no
        :param filter_names: name or list of names to return
        :param is_main: filter output by type of admins:
                        None means no filtering, return all
                        False means only additional admins
                        True means only main admin
        Nz&unable to use name and is_main at oncer�z	--is-mainzadmins.yamlrhc�,�g|]}t|����Srj)rrws  r$rmz$PublicApi.admins.<locals>.<listcomp>ms��/�/�/�q�%��(�(�/�/�/r&c�&��g|]
}|j�v�|��Srjr�r�s  �r$rmz$PublicApi.admins.<locals>.<listcomp>or�r&)	rPr%�adminsr�rU�lowerr@r�r�)r#r��is_mainr:rprBs `    r$r�zPublicApi.adminsSs����$�	G�G�/��E�F�F�F��-�&���l�C�(�(�	0���,�/�/�G�����S��\�\�%7�%7�%9�%9�:�:�G��]�]�7�
�]�F�F�
�/�/�J�/�/�/���l�T�5�M�2�2�	C�B�B�B�B��B�B�B�F��
r&�returnc�`�|jj}|�|d���}d�|D��S)a%
        Returns list of abstractions called "php" that
        represents an installed php with it's binary,
        ini file, modules directory, etc

        Necessity: For accelerate wp functionality
        Accessed by: admins (UNIX users)
        Must work inside CageFS also: No
        zphp.yamlrhc�,�g|]}t|����Srj)rrws  r$rmz!PublicApi.php.<locals>.<listcomp>~s��4�4�4�A��Q���4�4�4r&)r%�phpr@)r#r{rps   r$r�z
PublicApi.phprs7���}� ���]�]�4�Z�]�@�@�
�4�4��4�4�4�4r&)N)NNNNNN)NNF)NN)�__name__�
__module__�__qualname__�__doc__�propertyr%r@rHr9rRrnrsryr�r�r�r�r	rr�rjr&r$r!r!>s3���������%�%��X�%�3�3�3�,
!�
!�
!�T�T�T�>
�
�
����.%�%�%�0�0�0�0�"�� ����A�A�A�A�F����:����:����>5�d�<�(�5�5�5�5�5�5r&r!�__main__�{)r�)<r��
__future__rrrr/r3�	itertoolsrrMrSr`r�typingrr	r
r�clcommon.featuresr�vendors_api.configr�vendors_api.exceptionsrrrrrrrrr�vendors_api.modelsrrrrrrrrr]�abspath�dirname�__file__r_�INTERNAL_ERROR�PERMISSION_DENIED�BAD_REQUEST�	NOT_FOUNDrDr!r��api�printrnr�r�r�r�rjr&r$�<module>r�s�����
&�%�%�%�%�%�&�&�&�&�&�&�������	�	�	�	�����������������������&�&�&�&�&�&�,�,�,�,�,�,�,�,�,�,�,�,�-�-�-�-�-�-�2�2�2�2�2�2�
�
�
�
�
�
�
�
�
�
�
�
�
�
�
�
�
�
�
�
�
�
����������������������7�?�?�2�7�?�?�8�4�4�5�5������"�$4���j���H�	��@5�@5�@5�@5�@5�@5�@5�@5�F
�z���
�)�+�+�C�	�E�#�.�.�
�
����	�E�#�)�)�C�)�
 �
 �!�!�!�	�E�#�*�*�,�,����	�E�#�-�-�/�/����	�E�#�+�+�-�-�������r&