Sindbad~EG File Manager
# coding=utf-8
#
# Copyright © Cloud Linux GmbH & Cloud Linux Software, Inc 2010-2021 All Rights Reserved
#
# Licensed under CLOUD LINUX LICENSE AGREEMENT
# http://cloudlinux.com/docs/LICENCE.TXT
#
from __future__ import absolute_import
from __future__ import division
from __future__ import print_function
from typing import NamedTuple, Dict, List, Optional # NOQA
class _Base: # pylint: disable=eq-without-hash
__slots__ = ('_received_fields', '_api')
def __init__(self, opts):
"""
Initializes class by given dictionary and api object.
:type opts: dict
"""
# required for subclasses to know
# which fields we really received from
# API and which are just None
# e.g. case when we asked vendor's script to
# return username & package and tried to access
# 'id' somewhere (see __getattribute__ implementation)
self._received_fields = set(opts.keys())
def __getattribute__(self, item):
"""
When parsing data in __init__, we save list of received
fields. When accesing any of those fields, we must check
that is was received first. This is needed for dynamic
instances of "user" which can be different depending on 'fields'
argument passed to the integration script.
:type item: str
:return: object or raise exception
"""
if item == '__slots__' or item not in self.__slots__ or item in self._received_fields:
return object.__getattribute__(self, item)
raise AttributeError('%s is not set, but used in code' % item)
def __repr__(self):
return '%s (%s)' % (self.__class__.__name__, {k: getattr(self, k) for k in self._received_fields})
def __eq__(self, other):
if self.__slots__ != other.__slots__:
return False
# models with different scopes cannot be equal
if self._received_fields != other._received_fields:
return False
# loop and check all values
for slot in set(self.__slots__) & self._received_fields:
if getattr(self, slot) != getattr(other, slot):
return False
return True
def __ne__(self, other):
return not self == other
class PanelInfo(_Base):
__slots__ = (
'name',
'version',
'user_login_url',
'supported_cl_features'
)
def __init__(self, opts):
# optional field default value
opts.setdefault('supported_cl_features', None)
self.name: str = opts['name']
self.version: str = opts['version']
self.user_login_url: str = opts['user_login_url']
self.supported_cl_features: Optional[Dict[str, bool]] = \
opts['supported_cl_features']
super(PanelInfo, self).__init__(opts)
DbAccess = NamedTuple('DbAccess', [
('login', str),
('password', str),
('host', str),
('port', str),
])
DbInfo = NamedTuple('DBInfo', [
('access', DbAccess),
('mapping', Dict[str, List[str]]) # pylint: disable=invalid-sequence-index
])
class Databases(_Base):
__slots__ = (
'mysql',
)
def __init__(self, opts):
self.mysql = None # type: Optional[DbInfo]
mysql_raw = opts.get('mysql')
if mysql_raw is not None:
access = mysql_raw['access']
self.mysql = DbInfo(
access=DbAccess(**access),
mapping=mysql_raw['mapping']
)
super(Databases, self).__init__(opts)
class Package(_Base):
__slots__ = (
'name',
'owner',
)
def __init__(self, opts):
self.owner = opts['owner'] # type: str
self.name = opts['name'] # type: str
super(Package, self).__init__(opts)
class User(_Base):
__slots__ = (
'id',
'username',
'owner',
'domain',
'package',
'email',
'locale_code',
)
def __init__(self, opts):
self.id = opts.get('id') # type: int
self.username = opts.get('username') # type: str
self.owner = opts.get('owner') # type: str
if opts.get('package'):
self.package = Package(opts.get('package')) # type: Package
else:
self.package = None
self.email = opts.get('email') # type: str
self.domain = opts.get('domain') # type: str
self.locale_code = opts.get('locale_code') # type: str
super(User, self).__init__(opts)
class PHPConf(NamedTuple):
"""
An object representing structure of input PHP configuration for a domain
"""
version: str # PHP version XY
ini_path: str # path to directory with additional ini files
is_native: bool = False # is PHP version set in native.conf
fpm: Optional[str] = None # FPM service name
class DomainData(_Base):
__slots__ = [
'owner',
'document_root',
'is_main',
'php',
]
def __init__(self, opts):
# optional field default value
opts.setdefault('php', None)
self.owner = opts['owner'] # type: str
self.document_root = opts['document_root'] # type: str
self.is_main = opts['is_main'] # type: bool
self.php = None # type: Optional[PHPConf]
php_conf = opts['php']
if php_conf is not None:
self.php = PHPConf(**php_conf)
super(DomainData, self).__init__(opts)
class Reseller(_Base):
__slots__ = [
'id',
'name',
'locale_code',
'email',
]
def __init__(self, opts):
self.id = opts['id'] # type: str
self.name = opts['name'] # type: str
self.locale_code = opts['locale_code'] # type: str
self.email = opts['email'] # type: Optional[str]
super(Reseller, self).__init__(opts)
class Admin(_Base):
__slots__ = [
'name',
'unix_user',
'locale_code',
'email',
'is_main',
]
def __init__(self, opts):
self.name = opts['name'] # type: str
self.unix_user = opts['unix_user'] # type: Optional[str]
self.locale_code = opts['locale_code'] # type: str
self.email = opts['email'] # type: Optional[str]
self.is_main = opts['is_main'] # type: bool
super(Admin, self).__init__(opts)
Sindbad File Manager Version 1.0, Coded By Sindbad EG ~ The Terrorists