Minor fixes. (#502)
This commit is contained in:
parent
eaf34b1c8b
commit
3f2691c5d4
|
@ -858,12 +858,13 @@ class Sources(Command):
|
||||||
Defines a set of actions to take against Lemur's sources.
|
Defines a set of actions to take against Lemur's sources.
|
||||||
"""
|
"""
|
||||||
option_list = (
|
option_list = (
|
||||||
Option('-s', '--sources', dest='sources', action='append', help='Sources to operate on.'),
|
Option('-s', '--sources', dest='source_strings', action='append', help='Sources to operate on.'),
|
||||||
Option('-a', '--action', choices=['sync', 'clean'], dest='action', help='Action to take on source.')
|
Option('-a', '--action', choices=['sync', 'clean'], dest='action', help='Action to take on source.')
|
||||||
)
|
)
|
||||||
|
|
||||||
def run(self, sources, action):
|
def run(self, source_strings, action):
|
||||||
if not sources:
|
sources = []
|
||||||
|
if not source_strings:
|
||||||
table = []
|
table = []
|
||||||
for source in source_service.get_all():
|
for source in source_service.get_all():
|
||||||
table.append([source.label, source.active, source.description])
|
table.append([source.label, source.active, source.description])
|
||||||
|
@ -871,12 +872,19 @@ class Sources(Command):
|
||||||
sys.stdout.write(tabulate(table, headers=['Label', 'Active', 'Description']))
|
sys.stdout.write(tabulate(table, headers=['Label', 'Active', 'Description']))
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
for label in sources:
|
elif 'all' in source_strings:
|
||||||
source = source_service.get_by_label(label)
|
sources = source_service.get_all()
|
||||||
|
|
||||||
if not source:
|
else:
|
||||||
sys.stderr.write("Unable to find specified source with label: {0}".format(label))
|
for source_str in source_strings:
|
||||||
|
source = source_service.get_by_label(source_str)
|
||||||
|
|
||||||
|
if not source:
|
||||||
|
sys.stderr.write("Unable to find specified source with label: {0}".format(source_str))
|
||||||
|
|
||||||
|
sources.append(source)
|
||||||
|
|
||||||
|
for source in sources:
|
||||||
if action == 'sync':
|
if action == 'sync':
|
||||||
self.sync(source)
|
self.sync(source)
|
||||||
|
|
||||||
|
@ -888,8 +896,10 @@ class Sources(Command):
|
||||||
start_time = time.time()
|
start_time = time.time()
|
||||||
sys.stdout.write("[+] Staring to sync source: {label}!\n".format(label=source.label))
|
sys.stdout.write("[+] Staring to sync source: {label}!\n".format(label=source.label))
|
||||||
|
|
||||||
|
user = user_service.get_by_username('lemur')
|
||||||
|
|
||||||
try:
|
try:
|
||||||
source_service.sync(source)
|
source_service.sync(source, user)
|
||||||
sys.stdout.write(
|
sys.stdout.write(
|
||||||
"[+] Finished syncing source: {label}. Run Time: {time}\n".format(
|
"[+] Finished syncing source: {label}. Run Time: {time}\n".format(
|
||||||
label=source.label,
|
label=source.label,
|
||||||
|
@ -900,10 +910,10 @@ class Sources(Command):
|
||||||
current_app.logger.exception(e)
|
current_app.logger.exception(e)
|
||||||
|
|
||||||
sys.stdout.write(
|
sys.stdout.write(
|
||||||
"[X] Failed syncing source {label}!\n".format(labe=source.label)
|
"[X] Failed syncing source {label}!\n".format(label=source.label)
|
||||||
)
|
)
|
||||||
|
|
||||||
metrics.send('{0}_sync_failed'.format(source.label), 'counter', 1)
|
metrics.send('sync_failed', 'counter', 1, metric_tags={'source': source.label})
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def clean(source):
|
def clean(source):
|
||||||
|
|
|
@ -151,7 +151,7 @@ def sync_endpoints(source):
|
||||||
_disassociate_endpoints_from_source(endpoints, source)
|
_disassociate_endpoints_from_source(endpoints, source)
|
||||||
|
|
||||||
|
|
||||||
def sync_certificates(source):
|
def sync_certificates(source, user):
|
||||||
new, updated = 0, 0
|
new, updated = 0, 0
|
||||||
|
|
||||||
current_app.logger.debug("Retrieving certificates from {0}".format(source.label))
|
current_app.logger.debug("Retrieving certificates from {0}".format(source.label))
|
||||||
|
@ -161,6 +161,9 @@ def sync_certificates(source):
|
||||||
for certificate in certificates:
|
for certificate in certificates:
|
||||||
exists = cert_service.find_duplicates(certificate)
|
exists = cert_service.find_duplicates(certificate)
|
||||||
|
|
||||||
|
certificate['owner'] = user.email
|
||||||
|
certificate['creator'] = user
|
||||||
|
|
||||||
if not exists:
|
if not exists:
|
||||||
certificate_create(certificate, source)
|
certificate_create(certificate, source)
|
||||||
new += 1
|
new += 1
|
||||||
|
@ -180,8 +183,8 @@ def sync_certificates(source):
|
||||||
_disassociate_certs_from_source(certificates, source)
|
_disassociate_certs_from_source(certificates, source)
|
||||||
|
|
||||||
|
|
||||||
def sync(source):
|
def sync(source, user):
|
||||||
sync_certificates(source)
|
sync_certificates(source, user)
|
||||||
sync_endpoints(source)
|
sync_endpoints(source)
|
||||||
|
|
||||||
source.last_run = datetime.datetime.utcnow()
|
source.last_run = datetime.datetime.utcnow()
|
||||||
|
|
Loading…
Reference in New Issue