mirror of
https://github.com/dkmstr/openuds.git
synced 2025-01-08 21:18:00 +03:00
* Added help field to configuration REST api
* Better Log Level name for UDS Actor * Refactorized BlockAccess to be a subclass of UDSException
This commit is contained in:
parent
ca0df327d9
commit
c3523bcf8c
@ -39,6 +39,7 @@ from uds.models import ActorToken
|
||||
from uds.REST.exceptions import RequestError, NotFound
|
||||
from uds.REST.model import ModelHandler, OK
|
||||
from uds.core.util import permissions
|
||||
from uds.core.util.log import LogLevel
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
@ -75,7 +76,7 @@ class ActorTokens(ModelHandler):
|
||||
'pre_command': item.pre_command,
|
||||
'post_command': item.post_command,
|
||||
'runonce_command': item.runonce_command,
|
||||
'log_level': ['DEBUG', 'INFO', 'ERROR', 'FATAL'][item.log_level % 4],
|
||||
'log_level': LogLevel.fromActorLevel(item.log_level).name # ['DEBUG', 'INFO', 'ERROR', 'FATAL'][item.log_level % 4],
|
||||
}
|
||||
|
||||
def delete(self) -> str:
|
||||
|
@ -53,6 +53,7 @@ from uds.core.util import log, security
|
||||
from uds.core.util.state import State
|
||||
from uds.core.util.cache import Cache
|
||||
from uds.core.util.config import GlobalConfig
|
||||
from uds.core import exceptions
|
||||
from uds.models.service import ServiceTokenAlias
|
||||
|
||||
from ..handlers import Handler
|
||||
@ -73,7 +74,7 @@ UNMANAGED = 'unmanaged' # matches the definition of UDS Actors OFC
|
||||
cache = Cache('actorv3')
|
||||
|
||||
|
||||
class BlockAccess(Exception):
|
||||
class BlockAccess(exceptions.UDSException):
|
||||
pass
|
||||
|
||||
|
||||
@ -218,7 +219,7 @@ class ActorV3Action(Handler):
|
||||
service.notifyData(validId, self._params['data'])
|
||||
else:
|
||||
raise Exception('Invalid action')
|
||||
|
||||
|
||||
# All right, service notified..
|
||||
except Exception as e:
|
||||
# Log error and continue
|
||||
|
@ -44,12 +44,10 @@ class Config(Handler):
|
||||
needs_admin = True # By default, staff is lower level needed
|
||||
|
||||
def get(self) -> typing.Any:
|
||||
cfg: CfgConfig.Value
|
||||
|
||||
return CfgConfig.getConfigValues(self.is_admin())
|
||||
|
||||
|
||||
def put(self):
|
||||
def put(self) -> typing.Any:
|
||||
for section, secDict in self._params.items():
|
||||
for key, vals in secDict.items():
|
||||
logger.info('Updating config value %s.%s to %s by %s', section, key, vals['value'], self._user.name)
|
||||
|
@ -353,6 +353,7 @@ class Config:
|
||||
'longText': cfg.isLongText(),
|
||||
'type': cfg.getType(),
|
||||
'params': cfg.getParams(),
|
||||
help: cfg.getHelp(),
|
||||
}
|
||||
logger.debug('Configuration: %s', res)
|
||||
return res
|
||||
|
@ -82,6 +82,13 @@ class LogLevel(enum.IntEnum):
|
||||
except ValueError:
|
||||
return cls.OTHER
|
||||
|
||||
@classmethod
|
||||
def fromActorLevel(cls: typing.Type['LogLevel'], level: int) -> 'LogLevel':
|
||||
"""
|
||||
Returns the log level for actor log level
|
||||
"""
|
||||
return [cls.DEBUG, cls.INFO, cls.ERROR, cls.CRITICAL][level % 4]
|
||||
|
||||
# Return all Log levels as tuples of (level value, level name)
|
||||
@staticmethod
|
||||
def all() -> typing.List[typing.Tuple[int, str]]:
|
||||
@ -92,6 +99,7 @@ class LogLevel(enum.IntEnum):
|
||||
def interesting() -> typing.List[typing.Tuple[int, str]]:
|
||||
return [(level.value, level.name) for level in LogLevel if level.value > LogLevel.INFO.value]
|
||||
|
||||
|
||||
class LogSource(enum.StrEnum):
|
||||
INTERNAL = 'internal'
|
||||
ACTOR = 'actor'
|
||||
@ -204,7 +212,6 @@ class UDSLogHandler(logging.handlers.RotatingFileHandler):
|
||||
return msg
|
||||
|
||||
def notify(msg: str, identificator: str, logLevel: LogLevel) -> None:
|
||||
|
||||
NotificationsManager().notify('log', identificator, logLevel, msg)
|
||||
|
||||
if apps.ready and record.levelno >= logging.INFO and not UDSLogHandler.emiting:
|
||||
|
@ -53,7 +53,7 @@ class ActorToken(models.Model):
|
||||
token = models.CharField(max_length=48, db_index=True, unique=True)
|
||||
stamp = models.DateTimeField() # Date creation or validation of this entry
|
||||
|
||||
# New fields for 4.0, optional "custom" data, to be interpreted by specific code (i.e. AppLinux services)
|
||||
# New fields for 4.0, optional "custom" data, to be interpreted by specific code
|
||||
custom = models.TextField(blank=True, default='')
|
||||
|
||||
class Meta: # pylint: disable=too-few-public-methods
|
||||
|
Loading…
Reference in New Issue
Block a user