From 85b053ed9877d68907e693b823d5fd70b65833d1 Mon Sep 17 00:00:00 2001 From: Jasmine Schladen Date: Thu, 18 Feb 2021 14:35:51 -0800 Subject: [PATCH] Ignore submitted certificates --- lemur/notifications/schemas.py | 1 - lemur/notifications/service.py | 10 +++---- lemur/notifications/views.py | 48 +++++++++++++++++++++++++--------- 3 files changed, 39 insertions(+), 20 deletions(-) diff --git a/lemur/notifications/schemas.py b/lemur/notifications/schemas.py index 6ef5c506..d69da14d 100644 --- a/lemur/notifications/schemas.py +++ b/lemur/notifications/schemas.py @@ -20,7 +20,6 @@ class NotificationInputSchema(LemurInputSchema): description = fields.String() active = fields.Boolean() plugin = fields.Nested(PluginInputSchema, required=True) - certificates = fields.Nested(AssociatedCertificateSchema, many=True, missing=[]) added_certificates = fields.Nested(AssociatedCertificateSchema, many=True, missing=[]) removed_certificates = fields.Nested(AssociatedCertificateSchema, many=True, missing=[]) diff --git a/lemur/notifications/service.py b/lemur/notifications/service.py index 2e4566eb..372c1843 100644 --- a/lemur/notifications/service.py +++ b/lemur/notifications/service.py @@ -104,7 +104,7 @@ def create(label, plugin_name, options, description, certificates): return database.create(notification) -def update(notification_id, label, plugin_name, options, description, active, certificates, added_certificates, removed_certificates): +def update(notification_id, label, plugin_name, options, description, active, added_certificates, removed_certificates): """ Updates an existing notification. @@ -114,7 +114,6 @@ def update(notification_id, label, plugin_name, options, description, active, ce :param options: :param description: :param active: - :param certificates: :param added_certificates: :param removed_certificates: :rtype: Notification @@ -127,11 +126,8 @@ def update(notification_id, label, plugin_name, options, description, active, ce notification.options = options notification.description = description notification.active = active - if certificates: - notification.certificates = certificates - else: - notification.certificates = notification.certificates + added_certificates - notification.certificates = [c for c in notification.certificates if c not in removed_certificates] + notification.certificates = notification.certificates + added_certificates + notification.certificates = [c for c in notification.certificates if c not in removed_certificates] return database.update(notification) diff --git a/lemur/notifications/views.py b/lemur/notifications/views.py index fc7be4e7..b1200091 100644 --- a/lemur/notifications/views.py +++ b/lemur/notifications/views.py @@ -117,7 +117,7 @@ class NotificationsList(AuthenticatedResource): """ .. http:post:: /notifications - Creates a new account + Creates a new notification **Example request**: @@ -214,9 +214,12 @@ class NotificationsList(AuthenticatedResource): "id": 2 } - :arg accountNumber: aws account number - :arg label: human readable account label - :arg comments: some description about the account + :label label: notification name + :label slug: notification plugin slug + :label plugin_options: notification plugin options + :label description: notification description + :label active: whether or not the notification is active/enabled + :label certificates: certificates to attach to notification :reqheader Authorization: OAuth token to authenticate :statuscode 200: no error """ @@ -306,17 +309,29 @@ class Notifications(AuthenticatedResource): """ .. http:put:: /notifications/1 - Updates an account + Updates a notification **Example request**: .. sourcecode:: http - POST /notifications/1 HTTP/1.1 + PUT /notifications/1 HTTP/1.1 Host: example.com Accept: application/json, text/javascript Content-Type: application/json;charset=UTF-8 + { + "label": "labelChanged", + "plugin": { + "slug": "email-notification", + "plugin_options": "???" + }, + "description": "Sample notification", + "active": "true", + "added_certificates": "???", + "removed_certificates": "???" + } + **Example response**: @@ -328,14 +343,24 @@ class Notifications(AuthenticatedResource): { "id": 1, - "accountNumber": 11111111111, "label": "labelChanged", - "comments": "this is a thing" + "plugin": { + "slug": "email-notification", + "plugin_options": "???" + }, + "description": "Sample notification", + "active": "true", + "added_certificates": "???", + "removed_certificates": "???" } - :arg accountNumber: aws account number - :arg label: human readable account label - :arg comments: some description about the account + :label label: notification name + :label slug: notification plugin slug + :label plugin_options: notification plugin options + :label description: notification description + :label active: whether or not the notification is active/enabled + :label added_certificates: certificates to add + :label removed_certificates: certificates to remove :reqheader Authorization: OAuth token to authenticate :statuscode 200: no error """ @@ -346,7 +371,6 @@ class Notifications(AuthenticatedResource): data["plugin"]["plugin_options"], data["description"], data["active"], - data["certificates"], data["added_certificates"], data["removed_certificates"], )