Skip to content

Commit

Permalink
feat(cli.py): add utils group and generate-secrets command
Browse files Browse the repository at this point in the history
  • Loading branch information
Michele-Alberti committed Dec 27, 2024
1 parent bac4234 commit 3a45163
Showing 1 changed file with 39 additions and 0 deletions.
39 changes: 39 additions & 0 deletions dlunch/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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")
Expand Down

0 comments on commit 3a45163

Please sign in to comment.