55 lines
1.6 KiB
Python
55 lines
1.6 KiB
Python
"""
|
|
Usage:
|
|
certo [-vjf] [-d DAYS|--days-to-expiration=DAYS] [-t SECONDS|--timeout=SECONDS] <hostnames>...
|
|
certo -h | --help
|
|
|
|
Options:
|
|
-h --help Show this help.
|
|
-j Output in JSON format [default: False].
|
|
-v Increase verbosity [default: False].
|
|
-f --failonly Output failures only [default: False]
|
|
-d DAYS --days-to-expiration=DAYS Warn about near expiration if within DAYS of the cert's notAfter [default: 5].
|
|
-t SECONDS --timeout=SECONDS Timeout for SSL Handshake [default: 5].
|
|
"""
|
|
import asyncio
|
|
import logging
|
|
|
|
from docopt import docopt
|
|
|
|
from certo.checks.hostname import check_host_certificate_expiration
|
|
from certo.report import JSONReporter, DefaultReporter
|
|
|
|
|
|
async def main():
|
|
args = docopt(__doc__)
|
|
|
|
output_as_json = args.get("-j")
|
|
output_passes = not args.get("--failonly")
|
|
if args.get("-v"):
|
|
logging.getLogger().setLevel(logging.INFO)
|
|
hostnames = args.get("<hostnames>")
|
|
days_to_expiration = int(args.get("--days-to-expiration"))
|
|
|
|
# @todo factory
|
|
if output_as_json:
|
|
reporter = JSONReporter(output_passes)
|
|
else:
|
|
reporter = DefaultReporter(output_passes)
|
|
|
|
jobs = {
|
|
check_host_certificate_expiration(hs, days_to_expiration) for hs in hostnames
|
|
}
|
|
checks = await asyncio.gather(*jobs)
|
|
|
|
for check in checks:
|
|
reporter.append(check)
|
|
|
|
if log := reporter.report():
|
|
print(log)
|
|
|
|
exit(reporter.num_failed())
|
|
|
|
|
|
if __name__ == "__main__":
|
|
asyncio.run(main())
|