2020-02-14 14:11:52 +01:00
|
|
|
import os
|
2020-03-17 10:30:25 +01:00
|
|
|
import sys
|
2020-02-14 14:11:52 +01:00
|
|
|
import click
|
|
|
|
import pathlib
|
2020-04-26 13:13:55 +02:00
|
|
|
import logging
|
|
|
|
from subprocess import Popen, PIPE, STDOUT, CalledProcessError
|
2020-02-14 14:11:52 +01:00
|
|
|
|
|
|
|
from utils.cert import openssl_installed
|
|
|
|
from utils.misc import get_realpath
|
|
|
|
|
|
|
|
gen_tls_script = pathlib.Path(__file__).parent.parent.joinpath('scripts/gencert.sh').absolute()
|
|
|
|
|
|
|
|
@click.command()
|
2020-04-01 10:51:13 +02:00
|
|
|
@click.option('-p', '--path', required=True, type=str,help='the path to store generated cert files')
|
2020-04-01 11:55:33 +02:00
|
|
|
@click.option('-d', '--days', default='365', type=str, help='the expired time for cert')
|
2020-03-17 10:30:25 +01:00
|
|
|
def gencert(path, days):
|
2020-04-01 10:51:13 +02:00
|
|
|
"""
|
|
|
|
gencert command will generate cert files for internal TLS
|
|
|
|
"""
|
2020-02-14 14:11:52 +01:00
|
|
|
path = get_realpath(path)
|
|
|
|
click.echo('Check openssl ...')
|
|
|
|
if not openssl_installed():
|
|
|
|
raise(Exception('openssl not installed'))
|
|
|
|
|
|
|
|
click.echo("start generate internal tls certs")
|
|
|
|
if not os.path.exists(path):
|
|
|
|
click.echo('path {} not exist, create it...'.format(path))
|
|
|
|
os.makedirs(path, exist_ok=True)
|
2020-04-26 13:13:55 +02:00
|
|
|
with Popen([gen_tls_script, days], stdout=PIPE, stderr=STDOUT, cwd=path) as p:
|
|
|
|
for line in p.stdout:
|
|
|
|
click.echo(line, nl=False)
|
|
|
|
if p.returncode != 0:
|
|
|
|
raise CalledProcessError(p.returncode, p.args)
|