Skip to content

Commit

Permalink
hide --keyfile-pfx-map option by default
Browse files Browse the repository at this point in the history
  • Loading branch information
padhia committed Nov 27, 2024
1 parent bb4968d commit 56e98b2
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 13 deletions.
4 changes: 2 additions & 2 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@
nixpkgs.url = "github:nixos/nixpkgs/nixos-unstable";
flake-utils.url = "github:numtide/flake-utils";

nix-utils.url = "github:padhia/nix-utils/next";
nix-utils.url = "github:padhia/nix-utils";
nix-utils.inputs.nixpkgs.follows = "nixpkgs";

snowflake.url = "github:padhia/snowflake/next";
snowflake.url = "github:padhia/snowflake";
snowflake.inputs = {
nixpkgs.follows = "nixpkgs";
flake-utils.follows = "flake-utils";
Expand Down
27 changes: 17 additions & 10 deletions sfconn/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ def wrapped(
role: str | None,
schema: str | None,
warehouse: str | None,
loglevel: int,
loglevel: int = logging.WARNING,
*args: P.args,
**kwargs: P.kwargs,
) -> R:
Expand All @@ -74,7 +74,7 @@ def wrapped(
return wrapper


def add_conn_args(parser: ArgumentParser) -> None:
def add_conn_args(parser: ArgumentParser, *, debug_opt: bool = True, hide_keyfile_pfx_map: bool = True) -> None:
"add connection arguments"

def path_pair(v: str) -> tuple[Path, Path]:
Expand All @@ -97,39 +97,46 @@ def path_pair(v: str) -> tuple[Path, Path]:
"--keyfile-pfx-map",
metavar="PATH:PATH",
type=path_pair,
help="temporarily change private_key_file path prefix (format: <from-path>:<to-path>, default: $SFCONN_KEYFILE_PFX_MAP)",
help=SUPPRESS
if hide_keyfile_pfx_map
else "temporarily change private_key_file path prefix (format: <from-path>:<to-path>, default: $SFCONN_KEYFILE_PFX_MAP)",
)

parser.add_argument(
"--debug", dest="loglevel", action="store_const", const=logging.DEBUG, default=logging.WARNING, help=SUPPRESS
)
if debug_opt:
parser.add_argument(
"--debug", dest="loglevel", action="store_const", const=logging.DEBUG, default=logging.WARNING, help=SUPPRESS
)


def with_connection_args(doc: str | None, **kwargs: Any) -> Callable[..., Callable[..., Any]]:
def with_connection_args(
doc: str | None, debug_opt: bool = True, hide_keyfile_pfx_map: bool = True, **kwargs: Any
) -> Callable[..., Callable[..., Any]]:
"""Function decorator that instantiates and adds snowflake database connection arguments"""

def getargs(fn: Callable[[ArgumentParser], None]) -> Callable[..., Any]:
@wraps(fn)
def wrapped(args: list[str] | None = None) -> Any:
parser = ArgumentParser(description=doc, **kwargs)
add_conn_args(parser)
fn(parser)
add_conn_args(parser, debug_opt=debug_opt, hide_keyfile_pfx_map=hide_keyfile_pfx_map)
return parser.parse_args(args)

return wrapped

return getargs


def with_rest_args(doc: str | None, **kwargs: Any) -> Callable[..., Callable[..., Any]]:
def with_rest_args(
doc: str | None, debug_opt: bool = True, hide_keyfile_pfx_map: bool = True, **kwargs: Any
) -> Callable[..., Callable[..., Any]]:
"""Function decorator that instantiates and adds snowflake JWT as first argument"""

def getargs(fn: Callable[[ArgumentParser], None]) -> Callable[..., Any]:
@wraps(fn)
def wrapped(args: list[str] | None = None) -> Any:
parser = ArgumentParser(description=doc, **kwargs)
fn(parser)
add_conn_args(parser)
add_conn_args(parser, debug_opt=debug_opt, hide_keyfile_pfx_map=hide_keyfile_pfx_map)
parser.add_argument(
"-L",
"--lifetime",
Expand Down
2 changes: 1 addition & 1 deletion sfconn/utils_snowpark.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ def wrapped(
role: str | None,
schema: str | None,
warehouse: str | None,
loglevel: int,
loglevel: int = logging.WARNING,
*args: P.args,
**kwargs: P.kwargs,
) -> R:
Expand Down

0 comments on commit 56e98b2

Please sign in to comment.