From b496ada16c40a108a2a290b00efe6010c98c08ff Mon Sep 17 00:00:00 2001 From: bain Date: Mon, 4 Nov 2024 22:12:42 +0100 Subject: [PATCH] add certs-only flag --- ncc/main.py | 36 ++++++++++++++++++++++-------------- ncc/sysaction.py | 2 +- 2 files changed, 23 insertions(+), 15 deletions(-) diff --git a/ncc/main.py b/ncc/main.py index aa326a0..2ab4524 100644 --- a/ncc/main.py +++ b/ncc/main.py @@ -91,13 +91,13 @@ def cli(): @cli.command() @click.option( - "--dehydrated-only", + "--certs-only", type=bool, is_flag=True, help="Only fetches and deploys new certificates", ) @click.option("--skip-master-check", type=bool, is_flag=True) -def up(dehydrated_only: bool, skip_master_check: bool): +def up(certs_only: bool, skip_master_check: bool): """Deploy the configuration to the cluster Does the following: @@ -117,7 +117,7 @@ def up(dehydrated_only: bool, skip_master_check: bool): with Step("Preparing configuration..."): dehydrated_dir = Path(CONFIG["dehydrated_dir"]) - if not dehydrated_only: + if not certs_only: certs.generate_ssl( Path(CONFIG["main_config"]), Path(CONFIG["dehydrated_dir"]) / "domains.txt", @@ -133,23 +133,31 @@ def up(dehydrated_only: bool, skip_master_check: bool): f"dehydrated returned {ec} (log: {click.format_filename(log)})" ) - ec, stdout = sysaction.run_shell( - ("nginx", "-t", "-p", ".", "-c", CONFIG["main_config"]), window_height=5 - ) - if ec != 0: - raise NccException("configuration did not pass nginx test", log=stdout) + if not certs_only: + ec, stdout = sysaction.run_shell( + ("nginx", "-t", "-p", ".", "-c", CONFIG["main_config"]), window_height=5 + ) + if ec != 0: + raise NccException("configuration did not pass nginx test", log=stdout) with Step("Deploying to cluster...") as step: for target in CONFIG["targets"]: step.echo('deploying to "' + target + '"', nl=False) try: - sysrsync.run( - source=os.getcwd(), - destination=target, - exclusions=[str(dehydrated_dir / "archive/**")], - options=["-a", "--delete"], - ) + if certs_only: + sysrsync.run( + source=os.getcwd() + "/" + str(dehydrated_dir / "certs"), + destination=target + "/" + str(dehydrated_dir / "certs"), + options=["-a", "--delete"], + ) + else: + sysrsync.run( + source=os.getcwd(), + destination=target, + exclusions=[str(dehydrated_dir / "archive/**")], + options=["-a", "--delete"], + ) except Exception as e: step.echo(click.style(" E", fg="red")) raise NccException("failed to rsync configuration") from e diff --git a/ncc/sysaction.py b/ncc/sysaction.py index d7c928a..0b21354 100644 --- a/ncc/sysaction.py +++ b/ncc/sysaction.py @@ -21,7 +21,7 @@ def run_shell(cmd, window_height=0): buf = deque() for line in out.stdout: term_size = os.get_terminal_size() - prefixed = (" => " + line).rstrip()[: term_size[0] - 1] + "\n" + prefixed = (" => " + line).replace("\t", " ").rstrip()[: term_size[0] - 1] + "\n" stdout.append(line) buf.append(prefixed)