Perform handshakes asynchronously
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
"""
|
||||
Usage:
|
||||
certo [-vj] <hostnames>... [-d DAYS|--days-to-expiration=DAYS] [-t SECONDS|--timeout=SECONDS]
|
||||
certo [-vj] [-d DAYS|--days-to-expiration=DAYS] [-t SECONDS|--timeout=SECONDS] <hostnames>...
|
||||
certo -h | --help
|
||||
|
||||
Options:
|
||||
@@ -10,6 +10,7 @@ Options:
|
||||
-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
|
||||
@@ -17,7 +18,8 @@ from docopt import docopt
|
||||
from certo.checks.hostname import check_host_certificate_expiration
|
||||
from certo.report import JSONReporter, DefaultReporter
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
||||
async def main():
|
||||
args = docopt(__doc__)
|
||||
|
||||
output_as_json = args.get("-j")
|
||||
@@ -32,12 +34,19 @@ if __name__ == "__main__":
|
||||
else:
|
||||
reporter = DefaultReporter()
|
||||
|
||||
# @todo async
|
||||
for hs in hostnames:
|
||||
logging.info(f"Getting CERT from {hs}")
|
||||
reporter.add_check(check_host_certificate_expiration(hs, days_to_expiration))
|
||||
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())
|
||||
|
||||
Reference in New Issue
Block a user