From 3a451637c502f33f41a3b98168eeba173e40de2d Mon Sep 17 00:00:00 2001 From: Michele-Alberti <62114934+Michele-Alberti@users.noreply.github.com> Date: Fri, 27 Dec 2024 18:47:53 +0100 Subject: [PATCH] feat(cli.py): add utils group and generate-secrets command --- dlunch/cli.py | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/dlunch/cli.py b/dlunch/cli.py index 6a55cd0..7c9f6d0 100755 --- a/dlunch/cli.py +++ b/dlunch/cli.py @@ -10,6 +10,7 @@ import pkg_resources from hydra import compose, initialize import pandas as pd +import subprocess # Import database object from .models import create_database, create_engine, SCHEMA, Data, metadata_obj @@ -356,6 +357,44 @@ def load_table( click.secho(f"\n ===== EXCEPTION =====\n\n{e}", fg="red") +@cli.group() +@click.pass_obj +def utils(obj): + """Utility commands.""" + + +@utils.command("generate-secrets") +@click.pass_obj +def generate_secrets(obj): + """Generate secrets for DATA_LUNCH_COOKIE_SECRET and DATA_LUNCH_OAUTH_ENC_KEY env variables.""" + + try: + click.secho("Print secrets\n", fg="yellow") + result_secret = subprocess.run( + ["panel", "secret"], + stdout=subprocess.PIPE, + stderr=subprocess.STDOUT, + ) + click.secho( + f"COOKIE SECRET:\n{result_secret.stdout.decode('utf-8')}", + fg="cyan", + ) + result_encription = subprocess.run( + ["panel", "oauth-secret"], + stdout=subprocess.PIPE, + stderr=subprocess.STDOUT, + ) + click.secho( + f"ENCRIPTION KEY:\n{result_encription.stdout.decode('utf-8')}", + fg="cyan", + ) + click.secho("Done", fg="green") + except Exception as e: + # Generic error + click.secho("Cannot generate secrets", fg="red") + click.secho(f"\n ===== EXCEPTION =====\n\n{e}", fg="red") + + def main() -> None: """Main command line entrypoint.""" cli(auto_envvar_prefix="DATA_LUNCH")