Skip to content
Snippets Groups Projects
Commit 865cda6f authored by Moul's avatar Moul
Browse files

auth: import top-level click

parent a4c6d7da
No related branches found
No related tags found
1 merge request!240Drop auth-file default path #420, Use click.prompt(), click_context testing
......@@ -18,7 +18,7 @@ import sys
from getpass import getpass
from pathlib import Path
from click import Context, command, confirm, option, pass_context
import click
from duniterpy.key import SigningKey
from duniterpy.key.scrypt_params import ScryptParams
......@@ -30,8 +30,8 @@ PUBSEC_PUBKEY_PATTERN = f"pub: ({PUBKEY_PATTERN})"
PUBSEC_SIGNKEY_PATTERN = "sec: ([1-9A-HJ-NP-Za-km-z]{87,90})"
@pass_context
def auth_method(ctx: Context) -> SigningKey:
@click.pass_context
def auth_method(ctx: click.Context) -> SigningKey:
if "AUTH_SEED" in ctx.obj and ctx.obj["AUTH_SEED"]:
return auth_by_seed()
if "AUTH_FILE" in ctx.obj and ctx.obj["AUTH_FILE"]:
......@@ -41,8 +41,8 @@ def auth_method(ctx: Context) -> SigningKey:
return auth_by_scrypt()
@pass_context
def has_auth_method(ctx: Context) -> bool:
@click.pass_context
def has_auth_method(ctx: click.Context) -> bool:
return (
("AUTH_SCRYPT" in ctx.obj and ctx.obj["AUTH_SCRYPT"])
or ("AUTH_FILE" in ctx.obj and ctx.obj["AUTH_FILE"])
......@@ -51,8 +51,8 @@ def has_auth_method(ctx: Context) -> bool:
)
@command("authentication", help="Generate authentication file")
@option("--file", default="authfile", show_default=True, help="Path file")
@click.command("authentication", help="Generate authentication file")
@click.option("--file", default="authfile", show_default=True, help="Path file")
def generate_auth_file(file: str) -> None:
key = auth_method()
authfile = Path(file)
......@@ -60,7 +60,7 @@ def generate_auth_file(file: str) -> None:
if authfile.is_file():
message = f"Would you like to erase {file} by an authfile corresponding \n\
to following pubkey `{pubkey_cksum}`?"
confirm(message, abort=True)
click.confirm(message, abort=True)
key.save_seedhex_file(file)
print(
f"Authentication file 'authfile' generated and stored in current\
......@@ -68,8 +68,8 @@ to following pubkey `{pubkey_cksum}`?"
)
@pass_context
def auth_by_auth_file(ctx: Context) -> SigningKey:
@click.pass_context
def auth_by_auth_file(ctx: click.Context) -> SigningKey:
"""
Uses an authentication file to generate the key
Authfile can either be:
......@@ -106,8 +106,8 @@ def auth_by_seed() -> SigningKey:
sys.exit(FAILURE_EXIT_STATUS)
@pass_context
def auth_by_scrypt(ctx: Context) -> SigningKey:
@click.pass_context
def auth_by_scrypt(ctx: click.Context) -> SigningKey:
salt = getpass("Please enter your Scrypt Salt (Secret identifier): ")
password = getpass("Please enter your Scrypt password (masked): ")
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment