%PDF- %PDF-
| Direktori : /opt/alt/python37/lib/python3.7/site-packages/clcommon/lib/__pycache__/ |
| Current File : //opt/alt/python37/lib/python3.7/site-packages/clcommon/lib/__pycache__/cledition.cpython-37.pyc |
B
`�1b�* � @ sx d dl Z d dlZd dlZd dlZd dlmZ d dlmZ d dlm Z d dl
mZmZm
Z
d dlmZmZ d dlmZmZmZ d dlmZ d d lmZ d
ZdZdZd
ZG dd� de�ZG dd� de�Zeejj eej!j eej"j iZ#G dd� d�Z$d-dd�Z%d.dd�Z&d/dd�Z'ed�dd�Z(dd � Z)d!d"� Z*d#d$� Z+d%d&� Z,ee
e- e
e- f d�d'd(�Z.e/d�d)d*�Z0e/d�d+d,�Z1dS )0� N)�Enum)�wraps)�
exceptions)�AnyStr�Tuple�Optional)�CLN_JWT_TOKEN_PATH�CL_EDITION_FILE_FOR_USERS)�read_jwt�
decode_jwt�jwt_token_check)�FormattedException)� in_cagefsz/etc/cloudlinux-edition-solozCloudLinux OS Shared ProzCloudLinux OS SharedzCloudLinux OS Soloc @ s e Zd ZdZdZdZdZdS )�SupportedEditionsz-
Keeps supported CloudLinux editions
ZsoloZsharedZ
shared_proN)�__name__�
__module__�__qualname__�__doc__�SOLO�SHARED�
SHARED_PRO� r r �G/opt/alt/python37/lib/python3.7/site-packages/clcommon/lib/cledition.pyr s r c @ s e Zd Zdd� ZdS )�CLEditionDetectionErrorc K s t �| ||d�� d S )N)�message�context)r
�__init__)�selfr r r r r r + s z CLEditionDetectionError.__init__N)r r r r r r r r r * s r c @ s4 e Zd Zed
dd��Zedd� �Zeddd ��ZdS )�
CLEditionsNTc
C s� | dkrt t�} yt| |d�}W n8 tjk
rX } ztdt� d|� ���W dd}~X Y nX y|d S tk
r� |�d�}|dkr�tdt� d���|r�tj j
S tjj
S X dS )z�
Note: be careful when modifying this method.
Passing token in is used in X-Ray,
ask @dkavchuk or someone else from C-Projects team for details
:param token:
:param verify_exp:
:return:
N)�
verify_expz)Unable to detect edition from jwt token: z-. Please, make sure it is not broken, error: �edition�cl_pluszL. Please, make sure it is not broken, error: not enough fields for detection)r
r r r Z
PyJWTErrorr �KeyError�getr r �valuer )�tokenr �jwt�er! r r r �get_from_jwt; s
&
zCLEditions.get_from_jwtc C sf t jdd| gt jt jdd�}|�� \}}|jdkr>d|kr>dS |jdkrbtd| � d |� d
|� ���dS )NZrpmz-qT)�stdout�stderr�textr zis not installedFzUnable to check is package z is installed, reason: z, )�
subprocess�Popen�PIPEZcommunicate�
returncoder )Zpackage_nameZprocess�out�errr r r �is_package_installedW s
zCLEditions.is_package_installedFc C s� |r|rt d��|sVtj�t�rVy| j||d�}W n tk
rL t� }Y nX |rV|S t� rbt� S |s�tj�t �rzt
jjS t
j
jS dS )a
1. Try to detect edition from jwt token
if edition field is in token -> return edition
if edition field is not present -> recheck via cl_plus flag
if token is broken -> raise error about it
2. Try to detect from file
if edition is in file -> return edition
if file is broken -> raise about it
if file is missed -> check if meta package is present
Detection from file may be switched off using skip_marker_check
In case there is no token with correct edition,
no file we consider edition as regular CL.
Note: be careful when modifying this method.
It is used in X-Ray, ask @dkavchuk or someone else from C-Projects team
for details
zOUnable to detect edition: neither jwt token check, no file marker check enabled)r% r N)r �os�path�isfiler r( �PermissionError�user_cl_editionr �CL_EDITION_FILE_MARKERr r r$ r )�cls�skip_jwt_check�skip_marker_checkZraw_jwtr r r r r �get_cl_editione s zCLEditions.get_cl_edition)NT)FFNT)r r r �staticmethodr( r2 �classmethodr<