Black lint all the things
This commit is contained in:
@@ -13,49 +13,73 @@ from lemur.reporting.service import fqdns, expiring_certificates
|
||||
manager = Manager(usage="Reporting related tasks.")
|
||||
|
||||
|
||||
@manager.option('-v', '--validity', dest='validity', choices=['all', 'expired', 'valid'], default='all', help='Filter certificates by validity.')
|
||||
@manager.option('-d', '--deployment', dest='deployment', choices=['all', 'deployed', 'ready'], default='all', help='Filter by deployment status.')
|
||||
@manager.option(
|
||||
"-v",
|
||||
"--validity",
|
||||
dest="validity",
|
||||
choices=["all", "expired", "valid"],
|
||||
default="all",
|
||||
help="Filter certificates by validity.",
|
||||
)
|
||||
@manager.option(
|
||||
"-d",
|
||||
"--deployment",
|
||||
dest="deployment",
|
||||
choices=["all", "deployed", "ready"],
|
||||
default="all",
|
||||
help="Filter by deployment status.",
|
||||
)
|
||||
def fqdn(deployment, validity):
|
||||
"""
|
||||
Generates a report in order to determine the number of FQDNs covered by Lemur issued certificates.
|
||||
"""
|
||||
headers = ['FQDN', 'Root Domain', 'Issuer', 'Owner', 'Validity End', 'Total Length (days), Time Until Expiration (days)']
|
||||
headers = [
|
||||
"FQDN",
|
||||
"Root Domain",
|
||||
"Issuer",
|
||||
"Owner",
|
||||
"Validity End",
|
||||
"Total Length (days), Time Until Expiration (days)",
|
||||
]
|
||||
rows = []
|
||||
|
||||
for cert in fqdns(validity=validity, deployment=deployment).all():
|
||||
for domain in cert.domains:
|
||||
rows.append([
|
||||
domain.name,
|
||||
'.'.join(domain.name.split('.')[1:]),
|
||||
cert.issuer,
|
||||
cert.owner,
|
||||
cert.not_after,
|
||||
cert.validity_range.days,
|
||||
cert.validity_remaining.days
|
||||
])
|
||||
rows.append(
|
||||
[
|
||||
domain.name,
|
||||
".".join(domain.name.split(".")[1:]),
|
||||
cert.issuer,
|
||||
cert.owner,
|
||||
cert.not_after,
|
||||
cert.validity_range.days,
|
||||
cert.validity_remaining.days,
|
||||
]
|
||||
)
|
||||
|
||||
print(tabulate(rows, headers=headers))
|
||||
|
||||
|
||||
@manager.option('-ttl', '--ttl', dest='ttl', default=30, help='Days til expiration.')
|
||||
@manager.option('-d', '--deployment', dest='deployment', choices=['all', 'deployed', 'ready'], default='all', help='Filter by deployment status.')
|
||||
@manager.option("-ttl", "--ttl", dest="ttl", default=30, help="Days til expiration.")
|
||||
@manager.option(
|
||||
"-d",
|
||||
"--deployment",
|
||||
dest="deployment",
|
||||
choices=["all", "deployed", "ready"],
|
||||
default="all",
|
||||
help="Filter by deployment status.",
|
||||
)
|
||||
def expiring(ttl, deployment):
|
||||
"""
|
||||
Returns certificates expiring in the next n days.
|
||||
"""
|
||||
headers = ['Common Name', 'Owner', 'Issuer', 'Validity End', 'Endpoint']
|
||||
headers = ["Common Name", "Owner", "Issuer", "Validity End", "Endpoint"]
|
||||
rows = []
|
||||
|
||||
for cert in expiring_certificates(ttl=ttl, deployment=deployment).all():
|
||||
for endpoint in cert.endpoints:
|
||||
rows.append(
|
||||
[
|
||||
cert.cn,
|
||||
cert.owner,
|
||||
cert.issuer,
|
||||
cert.not_after,
|
||||
endpoint.dnsname
|
||||
]
|
||||
[cert.cn, cert.owner, cert.issuer, cert.not_after, endpoint.dnsname]
|
||||
)
|
||||
|
||||
print(tabulate(rows, headers=headers))
|
||||
|
@@ -9,10 +9,10 @@ from lemur.certificates.models import Certificate
|
||||
|
||||
|
||||
def filter_by_validity(query, validity=None):
|
||||
if validity == 'expired':
|
||||
if validity == "expired":
|
||||
query = query.filter(Certificate.expired == True) # noqa
|
||||
|
||||
elif validity == 'valid':
|
||||
elif validity == "valid":
|
||||
query = query.filter(Certificate.expired == False) # noqa
|
||||
|
||||
return query
|
||||
@@ -33,10 +33,10 @@ def filter_by_issuer(query, issuer=None):
|
||||
|
||||
|
||||
def filter_by_deployment(query, deployment=None):
|
||||
if deployment == 'deployed':
|
||||
if deployment == "deployed":
|
||||
query = query.filter(Certificate.endpoints.any())
|
||||
|
||||
elif deployment == 'ready':
|
||||
elif deployment == "ready":
|
||||
query = query.filter(not_(Certificate.endpoints.any()))
|
||||
|
||||
return query
|
||||
@@ -55,8 +55,8 @@ def fqdns(**kwargs):
|
||||
:return:
|
||||
"""
|
||||
query = database.session_query(Certificate)
|
||||
query = filter_by_deployment(query, deployment=kwargs.get('deployed'))
|
||||
query = filter_by_validity(query, validity=kwargs.get('validity'))
|
||||
query = filter_by_deployment(query, deployment=kwargs.get("deployed"))
|
||||
query = filter_by_validity(query, validity=kwargs.get("validity"))
|
||||
return query
|
||||
|
||||
|
||||
@@ -65,13 +65,13 @@ def expiring_certificates(**kwargs):
|
||||
Returns an Expiring report.
|
||||
:return:
|
||||
"""
|
||||
ttl = kwargs.get('ttl', 30)
|
||||
ttl = kwargs.get("ttl", 30)
|
||||
now = arrow.utcnow()
|
||||
validity_end = now + timedelta(days=ttl)
|
||||
|
||||
query = database.session_query(Certificate)
|
||||
query = filter_by_deployment(query, deployment=kwargs.get('deployed'))
|
||||
query = filter_by_validity(query, validity='valid')
|
||||
query = filter_by_deployment(query, deployment=kwargs.get("deployed"))
|
||||
query = filter_by_validity(query, validity="valid")
|
||||
query = filter_by_validity_end(query, validity_end=validity_end)
|
||||
|
||||
return query
|
||||
|
Reference in New Issue
Block a user