From 2f8c88dedc76fc1001aeb95bfdc1914c45ca5999 Mon Sep 17 00:00:00 2001 From: Mike Gouline <1960272+gouline@users.noreply.github.com> Date: Fri, 26 Jan 2024 21:29:12 +1100 Subject: [PATCH] Fix CLI list flags and re-introduce --http-header flag (#222) * Fix CLI flag list types * Re-introduce --http-header CLI flag * List and tuple CLI flags in sandbox invocation to catch issues early --- Makefile | 2 ++ dbtmetabase/__main__.py | 15 ++++++++++++--- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/Makefile b/Makefile index 62c41f2..487226a 100644 --- a/Makefile +++ b/Makefile @@ -77,6 +77,8 @@ sandbox-models: --metabase-username $$MB_USER \ --metabase-password $$MB_PASSWORD \ --metabase-database $$POSTGRES_DB \ + --include-schemas "public",other \ + --http-header x-dummy-key dummy-value \ --verbose ) .PHONY: sandbox-models diff --git a/dbtmetabase/__main__.py b/dbtmetabase/__main__.py index be10f89..d144aa9 100644 --- a/dbtmetabase/__main__.py +++ b/dbtmetabase/__main__.py @@ -1,7 +1,7 @@ import functools import logging from pathlib import Path -from typing import Any, Callable, List, Mapping, Optional, Sequence, Union, cast +from typing import Any, Callable, List, Mapping, Optional, Sequence, Tuple, Union, cast import click import yaml @@ -34,9 +34,9 @@ def callback( # Lists in defaults (config or option) should be lists return value - elif isinstance(value, str): + if isinstance(value, str): str_value = value - if isinstance(value, list): + elif isinstance(value, list): # When type=list, string value will be a list of chars str_value = "".join(value) else: @@ -143,6 +143,13 @@ def _add_setup(func: Callable) -> Callable: show_default=True, help="HTTP timeout in seconds.", ) + @click.option( + "--http-header", + "http_headers", + type=(str, str), + multiple=True, + help="Additional HTTP request headers.", + ) @click.option( "-v", "--verbose", @@ -159,6 +166,7 @@ def wrapper( skip_verify: bool, cert: Optional[str], http_timeout: int, + http_headers: Sequence[Tuple[str, str]], verbose: bool, **kwargs, ): @@ -177,6 +185,7 @@ def wrapper( skip_verify=skip_verify, cert=cert, http_timeout=http_timeout, + http_headers={k: v for k, v in http_headers}, ), **kwargs, )