Skip to content

Commit

Permalink
Add global --debug logging flag
Browse files Browse the repository at this point in the history
  • Loading branch information
elonen committed Oct 8, 2024
1 parent 9cb6bea commit 5807650
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion hsm_secrets/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
#@click.option('-d', '--debug', is_flag=True, help="Enable debug mode")
@click.option('-c', '--config', required=False, type=click.Path(), default=None, help="Path to configuration file")
@click.option('-q', '--quiet', is_flag=True, help="Suppress all non-essential output", default=False)
@click.option("--debug", required=False, is_flag=True, help="Enable debug logging")
@click.option("-y", "--yklabel", required=False, help="Yubikey HSM auth key label (default: first slot)")
@click.option("-s", "--hsmserial", required=False, help="YubiHSM serial number to connect to (default: get master from config)")
@click.option("--auth-yubikey", required=False, is_flag=True, help="Use Yubikey HSM auth key for HSM login")
Expand All @@ -30,7 +31,7 @@
@click.option("--mock", required=False, type=click.Path(dir_okay=False, file_okay=True, exists=False), help="Use mock HSM for testing, data in give file")
@click.version_option()
@click.pass_context
def cli(ctx: click.Context, config: str|None, quiet: bool, yklabel: str|None, hsmserial: str|None,
def cli(ctx: click.Context, config: str|None, quiet: bool, debug: bool, yklabel: str|None, hsmserial: str|None,
auth_default_admin: str|None, auth_yubikey: str|None, auth_password_id: str|None, mock: str|None):
"""Config file driven secret management tool for YubiHSM2 devices.
Expand All @@ -51,6 +52,10 @@ def cli(ctx: click.Context, config: str|None, quiet: bool, yklabel: str|None, hs
"""
ctx.obj = {'quiet': quiet} # early setup for cli_info and other utils to work

if debug:
logging.basicConfig(level=logging.DEBUG)
cli_info("Debug logging enabled", err=True)

# Use config file from env var or default locations if not specified
if not config:
env_var = "HSM_SECRETS_CONFIG"
Expand Down

0 comments on commit 5807650

Please sign in to comment.