From 02b717dd7ccc93b231791fb950a496be9feb7258 Mon Sep 17 00:00:00 2001
From: kevgliss
Date: Sun, 2 Aug 2015 05:57:26 -0700
Subject: [PATCH] Fixing upload, and removing old unneeded code
---
lemur/certificates/service.py | 45 ++++++++++++++++---
.../certificates/certificate/certificate.js | 3 +-
.../certificates/certificate/upload.js | 10 ++---
.../certificates/certificate/upload.tpl.html | 12 ++++-
.../app/angular/certificates/services.js | 24 +---------
.../angular/certificates/view/view.tpl.html | 18 +++++---
6 files changed, 69 insertions(+), 43 deletions(-)
diff --git a/lemur/certificates/service.py b/lemur/certificates/service.py
index 81b5dca2..8eb2c1e9 100644
--- a/lemur/certificates/service.py
+++ b/lemur/certificates/service.py
@@ -18,6 +18,7 @@ from lemur.destinations.models import Destination
from lemur.notifications.models import Notification
from lemur.authorities.models import Authority
+
from lemur.roles.models import Role
from cryptography import x509
@@ -134,7 +135,10 @@ def import_certificate(**kwargs):
:param kwargs:
"""
from lemur.users import service as user_service
+ from lemur.notifications import service as notification_service
cert = Certificate(kwargs['public_certificate'])
+
+ # TODO future source plugins might have a better understanding of who the 'owner' is we should support this
cert.owner = kwargs.get('owner', current_app.config.get('LEMUR_SECURITY_TEAM_EMAIL'))
cert.creator = kwargs.get('creator', user_service.get_by_email('lemur@nobody'))
@@ -146,7 +150,9 @@ def import_certificate(**kwargs):
if kwargs.get('user'):
cert.user = kwargs.get('user')
- database.update_list(cert, 'notifications', Notification, kwargs.get('notifications'))
+ notification_name = 'DEFAULT_SECURITY'
+ notifications = notification_service.create_default_expiration_notifications(notification_name, current_app.config.get('LEMUR_SECURITY_TEAM_EMAIL'))
+ cert.notifications = notifications
cert = database.create(cert)
return cert
@@ -156,18 +162,35 @@ def upload(**kwargs):
"""
Allows for pre-made certificates to be imported into Lemur.
"""
+ from lemur.notifications import service as notification_service
cert = Certificate(
kwargs.get('public_cert'),
kwargs.get('private_key'),
kwargs.get('intermediate_cert'),
)
- database.update_list(cert, 'destinations', Destination, kwargs.get('destinations'))
- database.update_list(cert, 'notifications', Notification, kwargs.get('notifications'))
+ cert.description = kwargs.get('description')
cert.owner = kwargs['owner']
cert = database.create(cert)
+
g.user.certificates.append(cert)
+
+ database.update_list(cert, 'destinations', Destination, kwargs.get('destinations'))
+
+ database.update_list(cert, 'notifications', Notification, kwargs.get('notifications'))
+
+ # create default notifications for this certificate if none are provided
+ notifications = []
+ if not kwargs.get('notifications'):
+ notification_name = "DEFAULT_{0}".format(cert.owner.split('@')[0].upper())
+ notifications += notification_service.create_default_expiration_notifications(notification_name, [cert.owner])
+
+ notification_name = 'DEFAULT_SECURITY'
+ notifications += notification_service.create_default_expiration_notifications(notification_name, current_app.config.get('LEMUR_SECURITY_TEAM_EMAIL'))
+ cert.notifications = notifications
+
+ database.update(cert)
return cert
@@ -175,12 +198,11 @@ def create(**kwargs):
"""
Creates a new certificate.
"""
+ from lemur.notifications import service as notification_service
cert, private_key, cert_chain = mint(kwargs)
cert.owner = kwargs['owner']
- database.update_list(cert, 'destinations', Destination, kwargs.get('destinations'))
-
database.create(cert)
cert.description = kwargs['description']
g.user.certificates.append(cert)
@@ -188,7 +210,20 @@ def create(**kwargs):
# do this after the certificate has already been created because if it fails to upload to the third party
# we do not want to lose the certificate information.
+ database.update_list(cert, 'destinations', Destination, kwargs.get('destinations'))
+
database.update_list(cert, 'notifications', Notification, kwargs.get('notifications'))
+
+ # create default notifications for this certificate if none are provided
+ notifications = []
+ if not kwargs.get('notifications'):
+ notification_name = "DEFAULT_{0}".format(cert.owner.split('@')[0].upper())
+ notifications += notification_service.create_default_expiration_notifications(notification_name, [cert.owner])
+
+ notification_name = 'DEFAULT_SECURITY'
+ notifications += notification_service.create_default_expiration_notifications(notification_name, current_app.config.get('LEMUR_SECURITY_TEAM_EMAIL'))
+ cert.notifications = notifications
+
database.update(cert)
return cert
diff --git a/lemur/static/app/angular/certificates/certificate/certificate.js b/lemur/static/app/angular/certificates/certificate/certificate.js
index 834c8206..b5253ea5 100644
--- a/lemur/static/app/angular/certificates/certificate/certificate.js
+++ b/lemur/static/app/angular/certificates/certificate/certificate.js
@@ -22,7 +22,7 @@ angular.module('lemur')
$scope.notificationService = NotificationService;
})
- .controller('CertificateCreateController', function ($scope, $modalInstance, CertificateApi, CertificateService, DestinationService, ELBService, AuthorityService, PluginService, MomentService, WizardHandler, LemurRestangular, NotificationService) {
+ .controller('CertificateCreateController', function ($scope, $modalInstance, CertificateApi, CertificateService, DestinationService, AuthorityService, PluginService, MomentService, WizardHandler, LemurRestangular, NotificationService) {
$scope.certificate = LemurRestangular.restangularizeElement(null, {}, 'certificates');
$scope.create = function (certificate) {
@@ -92,7 +92,6 @@ angular.module('lemur')
$scope.plugins = plugins;
});
- $scope.elbService = ELBService;
$scope.authorityService = AuthorityService;
$scope.destinationService = DestinationService;
$scope.notificationService = NotificationService;
diff --git a/lemur/static/app/angular/certificates/certificate/upload.js b/lemur/static/app/angular/certificates/certificate/upload.js
index 685da6f0..6d51a1b4 100644
--- a/lemur/static/app/angular/certificates/certificate/upload.js
+++ b/lemur/static/app/angular/certificates/certificate/upload.js
@@ -2,22 +2,20 @@
angular.module('lemur')
- .controller('CertificateUploadController', function ($scope, $modalInstance, CertificateService, LemurRestangular, DestinationService, NotificationService, ELBService, PluginService) {
+ .controller('CertificateUploadController', function ($scope, $modalInstance, CertificateService, LemurRestangular, DestinationService, NotificationService, PluginService) {
$scope.certificate = LemurRestangular.restangularizeElement(null, {}, 'certificates');
$scope.upload = CertificateService.upload;
$scope.destinationService = DestinationService;
$scope.notificationService = NotificationService;
- $scope.elbService = ELBService;
PluginService.getByType('destination').then(function (plugins) {
$scope.plugins = plugins;
});
- $scope.attachELB = function (elb) {
- $scope.certificate.attachELB(elb);
- ELBService.getListeners(elb).then(function (listeners) {
- $scope.certificate.elb.listeners = listeners;
+ $scope.save = function (certificate) {
+ CertificateService.upload(certificate).then(function () {
+ $modalInstance.close();
});
};
diff --git a/lemur/static/app/angular/certificates/certificate/upload.tpl.html b/lemur/static/app/angular/certificates/certificate/upload.tpl.html
index 42723bb6..6ba63232 100644
--- a/lemur/static/app/angular/certificates/certificate/upload.tpl.html
+++ b/lemur/static/app/angular/certificates/certificate/upload.tpl.html
@@ -18,6 +18,16 @@
email.
+
diff --git a/lemur/static/app/angular/certificates/services.js b/lemur/static/app/angular/certificates/services.js
index db9c1223..9344a3e9 100644
--- a/lemur/static/app/angular/certificates/services.js
+++ b/lemur/static/app/angular/certificates/services.js
@@ -77,18 +77,8 @@ angular.module('lemur')
removeNotification: function (index) {
this.notifications.splice(index, 1);
},
- attachELB: function (elb) {
- this.selectedELB = null;
- if (this.elbs === undefined) {
- this.elbs = [];
- }
- this.elbs.push(elb);
- },
- removeELB: function (index) {
- this.elbs.splice(index, 1);
- },
findDuplicates: function () {
- DomainService.findDomainByName(this.extensions.subAltNames[0]).then(function (domains) { //We should do a better job of searchin multiple domains
+ DomainService.findDomainByName(this.extensions.subAltNames[0]).then(function (domains) { //We should do a better job of searching for multiple domains
this.duplicates = domains.total;
});
},
@@ -205,18 +195,6 @@ angular.module('lemur')
});
};
- CertificateService.getListeners = function (certificate) {
- return certificate.getList('listeners').then(function (listeners) {
- certificate.listeners = listeners;
- });
- };
-
- CertificateService.getELBs = function (certificate) {
- return certificate.getList('listeners').then(function (elbs) {
- certificate.elbs = elbs;
- });
- };
-
CertificateService.getDomains = function (certificate) {
return certificate.getList('domains').then(function (domains) {
certificate.domains = domains;
diff --git a/lemur/static/app/angular/certificates/view/view.tpl.html b/lemur/static/app/angular/certificates/view/view.tpl.html
index 563b4263..b19f14cd 100644
--- a/lemur/static/app/angular/certificates/view/view.tpl.html
+++ b/lemur/static/app/angular/certificates/view/view.tpl.html
@@ -101,14 +101,20 @@
-
+
+ -
+ {{ notification.label }}
+ {{ notification.description}}
+
+
-
+
+ -
+ {{ destination.label }}
+ {{ destination.description }}
+
+