Refactor notification PUT to expect add/remove sets instead of full certificate set
This commit is contained in:
parent
8eba97fd14
commit
8e8a89bdfb
|
@ -105,6 +105,7 @@ def send_plugin_notification(event_type, data, recipients, notification):
|
||||||
"message": f"Sending expiration notification for to recipients {recipients}",
|
"message": f"Sending expiration notification for to recipients {recipients}",
|
||||||
"notification_type": "expiration",
|
"notification_type": "expiration",
|
||||||
"certificate_targets": recipients,
|
"certificate_targets": recipients,
|
||||||
|
"plugin": notification.plugin.slug,
|
||||||
}
|
}
|
||||||
status = FAILURE_METRIC_STATUS
|
status = FAILURE_METRIC_STATUS
|
||||||
try:
|
try:
|
||||||
|
@ -120,7 +121,7 @@ def send_plugin_notification(event_type, data, recipients, notification):
|
||||||
"notification",
|
"notification",
|
||||||
"counter",
|
"counter",
|
||||||
1,
|
1,
|
||||||
metric_tags={"status": status, "event_type": event_type},
|
metric_tags={"status": status, "event_type": event_type, "plugin": notification.plugin.slug},
|
||||||
)
|
)
|
||||||
|
|
||||||
if status == SUCCESS_METRIC_STATUS:
|
if status == SUCCESS_METRIC_STATUS:
|
||||||
|
|
|
@ -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):
|
||||||
|
|
|
@ -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, certificates, added_certificates, removed_certificates):
|
||||||
"""
|
"""
|
||||||
Updates an existing notification.
|
Updates an existing notification.
|
||||||
|
|
||||||
|
@ -115,6 +115,8 @@ def update(notification_id, label, plugin_name, options, description, active, ce
|
||||||
:param description:
|
:param description:
|
||||||
:param active:
|
:param active:
|
||||||
:param certificates:
|
:param certificates:
|
||||||
|
:param added_certificates:
|
||||||
|
:param removed_certificates:
|
||||||
:rtype : Notification
|
:rtype : Notification
|
||||||
:return:
|
:return:
|
||||||
"""
|
"""
|
||||||
|
@ -125,7 +127,15 @@ 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
|
||||||
|
current_app.logger.info(f"Initial: {notification.certificates}")
|
||||||
|
current_app.logger.info(f"Adding: {added_certificates}")
|
||||||
|
current_app.logger.info(f"Removing: {removed_certificates}")
|
||||||
|
if certificates:
|
||||||
notification.certificates = 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]
|
||||||
|
current_app.logger.info(f"Final: {notification.certificates}")
|
||||||
|
|
||||||
return database.update(notification)
|
return database.update(notification)
|
||||||
|
|
||||||
|
|
|
@ -337,6 +337,7 @@ class Notifications(AuthenticatedResource):
|
||||||
:reqheader Authorization: OAuth token to authenticate
|
:reqheader Authorization: OAuth token to authenticate
|
||||||
:statuscode 200: no error
|
:statuscode 200: no error
|
||||||
"""
|
"""
|
||||||
|
print(f"Updating with data: {data}")
|
||||||
return service.update(
|
return service.update(
|
||||||
notification_id,
|
notification_id,
|
||||||
data["label"],
|
data["label"],
|
||||||
|
@ -345,6 +346,8 @@ class Notifications(AuthenticatedResource):
|
||||||
data["description"],
|
data["description"],
|
||||||
data["active"],
|
data["active"],
|
||||||
data["certificates"],
|
data["certificates"],
|
||||||
|
data["added_certificates"],
|
||||||
|
data["removed_certificates"],
|
||||||
)
|
)
|
||||||
|
|
||||||
def delete(self, notification_id):
|
def delete(self, notification_id):
|
||||||
|
|
|
@ -8,10 +8,27 @@ angular.module('lemur')
|
||||||
if (this.certificates === undefined) {
|
if (this.certificates === undefined) {
|
||||||
this.certificates = [];
|
this.certificates = [];
|
||||||
}
|
}
|
||||||
|
if (this.addedCertificates === undefined) {
|
||||||
|
this.addedCertificates = [];
|
||||||
|
}
|
||||||
this.certificates.push(certificate);
|
this.certificates.push(certificate);
|
||||||
|
this.addedCertificates.push(certificate);
|
||||||
|
if (this.removedCertificates !== undefined) {
|
||||||
|
const index = this.removedCertificates.indexOf(certificate);
|
||||||
|
if (index > -1) {
|
||||||
|
this.removedCertificates.splice(index, 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);
|
||||||
|
this.removedCertificates.push(removedCert);
|
||||||
|
if (this.addedCertificates !== undefined && this.addedCertificates.indexOf(removedCert) > -1) {
|
||||||
|
this.addedCertificates.splice(this.addedCertificates.indexOf(removedCert), 1);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
@ -52,6 +69,7 @@ angular.module('lemur')
|
||||||
};
|
};
|
||||||
|
|
||||||
NotificationService.update = function (notification) {
|
NotificationService.update = function (notification) {
|
||||||
|
this.certificates = [];
|
||||||
return notification.put();
|
return notification.put();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue