Fixing upload, and removing old unneeded code

This commit is contained in:
kevgliss 2015-08-02 05:57:26 -07:00
parent e61de4578e
commit 02b717dd7c
6 changed files with 69 additions and 43 deletions

View File

@ -18,6 +18,7 @@ from lemur.destinations.models import Destination
from lemur.notifications.models import Notification from lemur.notifications.models import Notification
from lemur.authorities.models import Authority from lemur.authorities.models import Authority
from lemur.roles.models import Role from lemur.roles.models import Role
from cryptography import x509 from cryptography import x509
@ -134,7 +135,10 @@ def import_certificate(**kwargs):
:param kwargs: :param kwargs:
""" """
from lemur.users import service as user_service from lemur.users import service as user_service
from lemur.notifications import service as notification_service
cert = Certificate(kwargs['public_certificate']) 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.owner = kwargs.get('owner', current_app.config.get('LEMUR_SECURITY_TEAM_EMAIL'))
cert.creator = kwargs.get('creator', user_service.get_by_email('lemur@nobody')) cert.creator = kwargs.get('creator', user_service.get_by_email('lemur@nobody'))
@ -146,7 +150,9 @@ def import_certificate(**kwargs):
if kwargs.get('user'): if kwargs.get('user'):
cert.user = 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) cert = database.create(cert)
return cert return cert
@ -156,18 +162,35 @@ def upload(**kwargs):
""" """
Allows for pre-made certificates to be imported into Lemur. Allows for pre-made certificates to be imported into Lemur.
""" """
from lemur.notifications import service as notification_service
cert = Certificate( cert = Certificate(
kwargs.get('public_cert'), kwargs.get('public_cert'),
kwargs.get('private_key'), kwargs.get('private_key'),
kwargs.get('intermediate_cert'), kwargs.get('intermediate_cert'),
) )
database.update_list(cert, 'destinations', Destination, kwargs.get('destinations')) cert.description = kwargs.get('description')
database.update_list(cert, 'notifications', Notification, kwargs.get('notifications'))
cert.owner = kwargs['owner'] cert.owner = kwargs['owner']
cert = database.create(cert) cert = database.create(cert)
g.user.certificates.append(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 return cert
@ -175,12 +198,11 @@ def create(**kwargs):
""" """
Creates a new certificate. Creates a new certificate.
""" """
from lemur.notifications import service as notification_service
cert, private_key, cert_chain = mint(kwargs) cert, private_key, cert_chain = mint(kwargs)
cert.owner = kwargs['owner'] cert.owner = kwargs['owner']
database.update_list(cert, 'destinations', Destination, kwargs.get('destinations'))
database.create(cert) database.create(cert)
cert.description = kwargs['description'] cert.description = kwargs['description']
g.user.certificates.append(cert) 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 # 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. # 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')) 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) database.update(cert)
return cert return cert

View File

@ -22,7 +22,7 @@ angular.module('lemur')
$scope.notificationService = NotificationService; $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.certificate = LemurRestangular.restangularizeElement(null, {}, 'certificates');
$scope.create = function (certificate) { $scope.create = function (certificate) {
@ -92,7 +92,6 @@ angular.module('lemur')
$scope.plugins = plugins; $scope.plugins = plugins;
}); });
$scope.elbService = ELBService;
$scope.authorityService = AuthorityService; $scope.authorityService = AuthorityService;
$scope.destinationService = DestinationService; $scope.destinationService = DestinationService;
$scope.notificationService = NotificationService; $scope.notificationService = NotificationService;

View File

@ -2,22 +2,20 @@
angular.module('lemur') 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.certificate = LemurRestangular.restangularizeElement(null, {}, 'certificates');
$scope.upload = CertificateService.upload; $scope.upload = CertificateService.upload;
$scope.destinationService = DestinationService; $scope.destinationService = DestinationService;
$scope.notificationService = NotificationService; $scope.notificationService = NotificationService;
$scope.elbService = ELBService;
PluginService.getByType('destination').then(function (plugins) { PluginService.getByType('destination').then(function (plugins) {
$scope.plugins = plugins; $scope.plugins = plugins;
}); });
$scope.attachELB = function (elb) { $scope.save = function (certificate) {
$scope.certificate.attachELB(elb); CertificateService.upload(certificate).then(function () {
ELBService.getListeners(elb).then(function (listeners) { $modalInstance.close();
$scope.certificate.elb.listeners = listeners;
}); });
}; };

View File

@ -18,6 +18,16 @@
email.</p> email.</p>
</div> </div>
</div> </div>
<div class="form-group"
ng-class="{'has-error': uploadForm.description.$invalid, 'has-success': !uploadForm.$invalid&&uploadForm.description.$dirty}">
<label class="control-label col-sm-2">
Description
</label>
<div class="col-sm-10">
<textarea name="description" ng-model="certificate.description" placeholder="Something elegant" class="form-control" ng-pattern="/^[\w\-\s]+$/" required></textarea>
<p ng-show="uploadForm.description.$invalid && !uploadForm.description.$pristine" class="help-block">You must give a short description about this authority will be used for, this description should only include alphanumeric characters</p>
</div>
</div>
<div class="form-group" <div class="form-group"
ng-class="{'has-error': uploadForm.publicCert.$invalid, 'has-success': !uploadForm.publicCert.$invalid&&uploadForm.publicCert.$dirty}"> ng-class="{'has-error': uploadForm.publicCert.$invalid, 'has-success': !uploadForm.publicCert.$invalid&&uploadForm.publicCert.$dirty}">
<label class="control-label col-sm-2"> <label class="control-label col-sm-2">
@ -66,7 +76,7 @@
</form> </form>
</div> </div>
<div class="modal-footer"> <div class="modal-footer">
<button type="submit" ng-click="upload(certificate)" ng-disabled="uploadForm.$invalid" class="btn btn-success">Import</button> <button type="submit" ng-click="save(certificate)" ng-disabled="uploadForm.$invalid" class="btn btn-success">Import</button>
<button ng-click="cancel()" class="btn btn-danger">Cancel</button> <button ng-click="cancel()" class="btn btn-danger">Cancel</button>
</div> </div>
</div> </div>

View File

@ -77,18 +77,8 @@ angular.module('lemur')
removeNotification: function (index) { removeNotification: function (index) {
this.notifications.splice(index, 1); 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 () { 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; 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) { CertificateService.getDomains = function (certificate) {
return certificate.getList('domains').then(function (domains) { return certificate.getList('domains').then(function (domains) {
certificate.domains = domains; certificate.domains = domains;

View File

@ -101,14 +101,20 @@
</ul> </ul>
</tab> </tab>
<tab heading="Notifications"> <tab heading="Notifications">
<div class="list-group"> <ul class="list-group">
<a href="#/domains/{{ domain.id }}" class="list-group-item" ng-repeat="notification in certificate.notifications">{{ notification.label }}</a> <li class="list-group-item" ng-repeat="notification in certificate.notifications">
</div> <strong>{{ notification.label }}</strong>
<span class="pull-right">{{ notification.description}}</span>
</li>
</ul>
</tab> </tab>
<tab heading="Destinations"> <tab heading="Destinations">
<div class="list-group"> <ul class="list-group">
<a href="#/domains/{{ domain.id }}" class="list-group-item" ng-repeat="destination in certificate.destinations">{{ destination.label }}</a> <li class="list-group-item" ng-repeat="destination in certificate.destinations">
</div> <strong>{{ destination.label }}</strong>
<span class="pull-right">{{ destination.description }}</span>
</li>
</ul>
</tab> </tab>
<tab heading="Domains"> <tab heading="Domains">
<div class="list-group"> <div class="list-group">