From a873e5c7ea0d629001df64f440464e4a7f7dc6f6 Mon Sep 17 00:00:00 2001 From: kevgliss Date: Mon, 3 Aug 2015 15:52:39 -0700 Subject: [PATCH] Lots of minor fixes --- lemur/authorities/service.py | 8 +++++ lemur/manage.py | 6 ++-- lemur/notifications/service.py | 33 ++++++++++++++----- lemur/plugins/lemur_aws/plugin.py | 2 +- .../destinations/destination/destination.js | 9 +++++ .../notification/notification.js | 9 +++++ .../app/angular/sources/source/source.js | 9 +++++ 7 files changed, 63 insertions(+), 13 deletions(-) diff --git a/lemur/authorities/service.py b/lemur/authorities/service.py index 0c831be8..23961ede 100644 --- a/lemur/authorities/service.py +++ b/lemur/authorities/service.py @@ -9,10 +9,12 @@ """ from flask import g +from flask import current_app from lemur import database from lemur.authorities.models import Authority from lemur.roles import service as role_service +from lemur.notifications import service as notification_service from lemur.roles.models import Role from lemur.certificates.models import Certificate @@ -56,9 +58,15 @@ def create(kwargs): cert.description = "This is the ROOT certificate for the {0} certificate authority".format(kwargs.get('caName')) cert.user = g.current_user + cert.notifications = notification_service.create_default_expiration_notifications( + 'DEFAULT_SECURITY', + current_app.config.get('LEMUR_SECURITY_TEAM_EMAIL') + ) + # we create and attach any roles that the issuer gives us role_objs = [] for r in issuer_roles: + role = role_service.create( r['name'], password=r['password'], diff --git a/lemur/manage.py b/lemur/manage.py index 3621159e..8cee39e0 100755 --- a/lemur/manage.py +++ b/lemur/manage.py @@ -180,7 +180,7 @@ def sync_sources(labels, view): information it discovers. """ if view: - sys.stdout.write("Active", "Label", "Description") + sys.stdout.write("Active\tLabel\tDescription\n") for source in source_service.get_all(): sys.stdout.write( "[{active}]\t{label}\t{description}!\n".format( @@ -199,10 +199,10 @@ def sync_sources(labels, view): sync_lock.acquire(timeout=10) # wait up to 10 seconds if labels: - sys.stdout.write("[+] Staring to sync sources: {labels}!\n".format(labels)) + sys.stdout.write("[+] Staring to sync sources: {labels}!\n".format(labels=labels)) labels = labels.split(",") else: - sys.stdout.write("[+] Starting to sync ALL sources!\n".format(labels)) + sys.stdout.write("[+] Starting to sync ALL sources!\n") sync(labels=labels) sys.stdout.write( diff --git a/lemur/notifications/service.py b/lemur/notifications/service.py index db40b53c..e1198df6 100644 --- a/lemur/notifications/service.py +++ b/lemur/notifications/service.py @@ -180,13 +180,22 @@ def create_default_expiration_notifications(name, recipients): """ options = [ { - 'name': 'recipients', - 'value': ','.join(recipients) + 'name': 'unit', + 'type': 'select', + 'required': True, + 'validation': '', + 'available': ['days', 'weeks', 'months'], + 'helpMessage': 'Interval unit', + 'value': 'days', }, { - 'name': 'unit', - 'value': 'days' - } + 'name': 'recipients', + 'type': 'str', + 'required': True, + 'validation': '^([\w+-.%]+@[\w-.]+\.[A-Za-z]{2,4},?)+$', + 'helpMessage': 'Comma delimited list of email addresses', + 'value': ','.join(recipients) + }, ] intervals = current_app.config.get("LEMUR_DEFAULT_EXPIRATION_NOTIFICATION_INTERVALS") @@ -195,10 +204,16 @@ def create_default_expiration_notifications(name, recipients): for i in intervals: n = get_by_label("{name}_{interval}_DAY".format(name=name, interval=i)) if not n: - inter = [{ - 'name': 'interval', - 'value': i, - }] + inter = [ + { + 'name': 'interval', + 'type': 'int', + 'required': True, + 'validation': '^\d+$', + 'helpMessage': 'Number of days to be alert before expiration.', + 'value': i, + } + ] inter.extend(options) n = create( label="{name}_{interval}_DAY".format(name=name, interval=i), diff --git a/lemur/plugins/lemur_aws/plugin.py b/lemur/plugins/lemur_aws/plugin.py index 06c36d7f..0c6fc09a 100644 --- a/lemur/plugins/lemur_aws/plugin.py +++ b/lemur/plugins/lemur_aws/plugin.py @@ -29,7 +29,7 @@ class AWSDestinationPlugin(DestinationPlugin): options = [ { 'name': 'accountNumber', - 'type': 'int', + 'type': 'str', 'required': True, 'validation': '/^[0-9]{12,12}$/', 'helpMessage': 'Must be a valid AWS account number!', diff --git a/lemur/static/app/angular/destinations/destination/destination.js b/lemur/static/app/angular/destinations/destination/destination.js index 7bb6b66b..321eecfb 100644 --- a/lemur/static/app/angular/destinations/destination/destination.js +++ b/lemur/static/app/angular/destinations/destination/destination.js @@ -23,6 +23,15 @@ angular.module('lemur') .controller('DestinationsEditController', function ($scope, $modalInstance, DestinationService, DestinationApi, PluginService, editId) { DestinationApi.get(editId).then(function (destination) { $scope.destination = destination; + PluginService.getByType('destination').then(function (plugins) { + $scope.plugins = plugins; + _.each($scope.plugins, function (plugin) { + if (plugin.slug === $scope.destination.pluginName) { + plugin.pluginOptions = $scope.destination.destinationOptions; + $scope.destination.plugin = plugin; + } + }); + }); }); PluginService.getByType('destination').then(function (plugins) { diff --git a/lemur/static/app/angular/notifications/notification/notification.js b/lemur/static/app/angular/notifications/notification/notification.js index 9495b6ec..7cb1da50 100644 --- a/lemur/static/app/angular/notifications/notification/notification.js +++ b/lemur/static/app/angular/notifications/notification/notification.js @@ -29,6 +29,15 @@ angular.module('lemur') .controller('NotificationsEditController', function ($scope, $modalInstance, NotificationService, NotificationApi, PluginService, CertificateService, editId) { NotificationApi.get(editId).then(function (notification) { $scope.notification = notification; + PluginService.getByType('notification').then(function (plugins) { + $scope.plugins = plugins; + _.each($scope.plugins, function (plugin) { + if (plugin.slug === $scope.notification.pluginName) { + plugin.pluginOptions = $scope.notification.notificationOptions; + $scope.notification.plugin = plugin; + } + }); + }); NotificationService.getCertificates(notification); }); diff --git a/lemur/static/app/angular/sources/source/source.js b/lemur/static/app/angular/sources/source/source.js index 7c75e3ad..b7378c77 100644 --- a/lemur/static/app/angular/sources/source/source.js +++ b/lemur/static/app/angular/sources/source/source.js @@ -23,6 +23,15 @@ angular.module('lemur') .controller('SourcesEditController', function ($scope, $modalInstance, SourceService, SourceApi, PluginService, editId) { SourceApi.get(editId).then(function (source) { $scope.source = source; + PluginService.getByType('source').then(function (plugins) { + $scope.plugins = plugins; + _.each($scope.plugins, function (plugin) { + if (plugin.slug === $scope.source.pluginName) { + plugin.pluginOptions = $scope.source.sourceOptions; + $scope.source.plugin = plugin; + } + }); + }); }); PluginService.getByType('source').then(function (plugins) {