1
0
mirror of https://github.com/laurivosandi/certidude synced 2024-12-22 16:25:17 +00:00

cli: Fix 'certidude list [CA]...' command

This commit is contained in:
Priit Laes 2015-09-30 13:48:04 +03:00
parent f73885fe70
commit 91d09629e2
2 changed files with 31 additions and 8 deletions

View File

@ -646,7 +646,15 @@ def certidude_list(ca, show_key_type, show_extensions, show_path):
click.echo(" | |")
config = load_config()
for ca in config.all_authorities():
wanted_list = None
if ca:
missing = list(set(ca) - set(config.ca_list))
if missing:
raise click.NoSuchOption(option_name='', message="Unable to find certificate authority.", possibilities=config.ca_list)
wanted_list = ca
for ca in config.all_authorities(wanted_list):
click.echo("Certificate authority " + click.style(ca.slug, fg="blue"))
# if ca.certificate.email_address:
# click.echo(" \u2709 %s" % ca.certificate.email_address)

View File

@ -107,13 +107,28 @@ class CertificateAuthorityConfig(object):
authority = CertificateAuthority(slug, **dirs)
return authority
def all_authorities(self):
for section in self._config:
if section.startswith("CA_"):
try:
yield self.instantiate_authority(section[3:])
except FileNotFoundError:
pass
def all_authorities(self, wanted=None):
for ca in self.ca_list:
if wanted and ca not in wanted:
continue
try:
yield self.instantiate_authority(ca)
except FileNotFoundError:
pass
@property
def ca_list(self):
"""
Returns sorted list of CA-s defined in the configuration file.
"""
l = [s[3:] for s in self._config if s.startswith("CA_")]
# Sanity check for duplicates (although ConfigParser fails earlier)
if len(l) != len(set(l)):
raise ValueError
return sorted(l)
def pop_certificate_authority(self):
def wrapper(func):