...
 
Commits (3)
# Notification system NG
Details has to be written yet.
......@@ -46,7 +46,7 @@ def create_argparser():
parser_action.add_argument("--template", help="Notification type / template", default='simple')
parser_action.add_argument("--persistent", help="Persistent notification", action="store_true")
parser_action.add_argument("--timeout", help="Timeout in minutes after which message disappear", type=int)
parser_action.add_argument("--severity", help="Severity of message")
parser_action.add_argument("--severity", help="Severity of message", choices=['INFO', 'WARNING', 'ERROR', 'ANNOUNCEMENT', 'ACTION_NEEDED'])
parser_action.add_argument("--nodismiss", help="Disable explicit dismiss of message", action="store_false")
parser_action.add_argument("--default-action", help="Set action which will be used as 'default'")
......
......@@ -9,10 +9,12 @@ from .exceptions import (
NoSuchNotificationSkeletonException,
NotificationNotDismissibleException,
NotificationStorageException,
InvalidOptionsException,
)
from .pluginstorage import PluginStorage
from .notificationstorage import NotificationStorage
from .notification import Notification
from .sorting import Sorting
logger = logging.getLogger(__name__)
......@@ -91,6 +93,8 @@ class Api:
if not skel:
raise NoSuchNotificationSkeletonException
self.validate_user_opts(user_opts)
notification_defaults = skel.get_skeleton_defaults()
notification_defaults.update(user_opts)
......@@ -129,3 +133,9 @@ class Api:
self.notifications.remove(msgid)
else:
raise NoSuchNotificationException("Notification with ID '{}' does not exist".format(msgid))
def validate_user_opts(self, opts):
# TODO: validate all user entered options properly
if 'severity' in opts and opts['severity'].upper() not in Sorting.SEVERITY:
logger.warning("Invalid severity level '%s'", opts['severity'])
raise InvalidOptionsException("Invalid severity level '{}'".format(opts['severity']))
......@@ -29,3 +29,6 @@ class NotificationStorageException(NotifylibError):
class VersionMismatchException(NotifylibError):
pass
class InvalidOptionsException(NotifylibError):
pass
......@@ -11,7 +11,8 @@ setup(
url='https://gitlab.labs.nic.cz/turris/notification-system',
license='COPYING',
description='Notification system NG',
long_description=open('README.rst').read(),
long_description=open('README.md').read(),
long_description_content_type="text/markdown",
install_requires=[
'Jinja2',
'PyYAML',
......