Merge pull request #3428 from jtschladen/add-remove-certs-for-notification

Add/remove certs for notification UI
This commit is contained in:
Jasmine Schladen 2021-02-22 17:18:51 -08:00 committed by GitHub
commit de06f13bb1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 73 additions and 17 deletions

View File

@ -200,6 +200,7 @@ def send_plugin_notification(event_type, data, recipients, notification):
"notification_type": event_type, "notification_type": event_type,
"notification_plugin": notification.plugin.slug, "notification_plugin": notification.plugin.slug,
"certificate_targets": recipients, "certificate_targets": recipients,
"plugin": notification.plugin.slug,
} }
status = FAILURE_METRIC_STATUS status = FAILURE_METRIC_STATUS
try: try:

View File

@ -21,6 +21,8 @@ class NotificationInputSchema(LemurInputSchema):
active = fields.Boolean() active = fields.Boolean()
plugin = fields.Nested(PluginInputSchema, required=True) plugin = fields.Nested(PluginInputSchema, required=True)
certificates = fields.Nested(AssociatedCertificateSchema, many=True, missing=[]) certificates = fields.Nested(AssociatedCertificateSchema, many=True, missing=[])
added_certificates = fields.Nested(AssociatedCertificateSchema, many=True, missing=[])
removed_certificates = fields.Nested(AssociatedCertificateSchema, many=True, missing=[])
class NotificationOutputSchema(LemurOutputSchema): class NotificationOutputSchema(LemurOutputSchema):

View File

@ -104,7 +104,7 @@ def create(label, plugin_name, options, description, certificates):
return database.create(notification) return database.create(notification)
def update(notification_id, label, plugin_name, options, description, active, certificates): def update(notification_id, label, plugin_name, options, description, active, added_certificates, removed_certificates):
""" """
Updates an existing notification. Updates an existing notification.
@ -114,7 +114,8 @@ def update(notification_id, label, plugin_name, options, description, active, ce
:param options: :param options:
:param description: :param description:
:param active: :param active:
:param certificates: :param added_certificates:
:param removed_certificates:
:rtype: Notification :rtype: Notification
:return: :return:
""" """
@ -125,7 +126,8 @@ def update(notification_id, label, plugin_name, options, description, active, ce
notification.options = options notification.options = options
notification.description = description notification.description = description
notification.active = active notification.active = active
notification.certificates = 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) return database.update(notification)

View File

@ -117,7 +117,7 @@ class NotificationsList(AuthenticatedResource):
""" """
.. http:post:: /notifications .. http:post:: /notifications
Creates a new account Creates a new notification
**Example request**: **Example request**:
@ -214,9 +214,12 @@ class NotificationsList(AuthenticatedResource):
"id": 2 "id": 2
} }
:arg accountNumber: aws account number :label label: notification name
:arg label: human readable account label :label slug: notification plugin slug
:arg comments: some description about the account :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 :reqheader Authorization: OAuth token to authenticate
:statuscode 200: no error :statuscode 200: no error
""" """
@ -239,7 +242,7 @@ class Notifications(AuthenticatedResource):
""" """
.. http:get:: /notifications/1 .. http:get:: /notifications/1
Get a specific account Get a specific notification
**Example request**: **Example request**:
@ -306,17 +309,29 @@ class Notifications(AuthenticatedResource):
""" """
.. http:put:: /notifications/1 .. http:put:: /notifications/1
Updates an account Updates a notification
**Example request**: **Example request**:
.. sourcecode:: http .. sourcecode:: http
POST /notifications/1 HTTP/1.1 PUT /notifications/1 HTTP/1.1
Host: example.com Host: example.com
Accept: application/json, text/javascript Accept: application/json, text/javascript
Content-Type: application/json;charset=UTF-8 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**: **Example response**:
@ -328,14 +343,24 @@ class Notifications(AuthenticatedResource):
{ {
"id": 1, "id": 1,
"accountNumber": 11111111111,
"label": "labelChanged", "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 :label label: notification name
:arg label: human readable account label :label slug: notification plugin slug
:arg comments: some description about the account :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 :reqheader Authorization: OAuth token to authenticate
:statuscode 200: no error :statuscode 200: no error
""" """
@ -346,7 +371,8 @@ class Notifications(AuthenticatedResource):
data["plugin"]["plugin_options"], data["plugin"]["plugin_options"],
data["description"], data["description"],
data["active"], data["active"],
data["certificates"], data["added_certificates"],
data["removed_certificates"],
) )
def delete(self, notification_id): def delete(self, notification_id):

View File

@ -8,10 +8,35 @@ angular.module('lemur')
if (this.certificates === undefined) { if (this.certificates === undefined) {
this.certificates = []; this.certificates = [];
} }
if (this.addedCertificates === undefined) {
this.addedCertificates = [];
}
if (_.some(this.addedCertificates, function (cert) {
return cert.id === certificate.id;
})) {
return;
}
this.certificates.push(certificate); this.certificates.push(certificate);
this.addedCertificates.push(certificate);
if (this.removedCertificates !== undefined) {
const indexInRemovedList = _.findIndex(this.removedCertificates, function (cert) {
return cert.id === certificate.id;
});
this.removedCertificates.splice(indexInRemovedList, 1);
}
}, },
removeCertificate: function (index) { removeCertificate: function (index) {
this.certificates.splice(index, 1); if (this.removedCertificates === undefined) {
this.removedCertificates = [];
}
const removedCert = this.certificates.splice(index, 1)[0];
this.removedCertificates.push(removedCert);
if (this.addedCertificates !== undefined) {
const indexInAddedList = _.findIndex(this.addedCertificates, function (cert) {
return cert.id === removedCert.id;
});
this.addedCertificates.splice(indexInAddedList, 1);
}
} }
}); });
}); });