Skip to content

Commit

Permalink
Snowflake key pair auth support
Browse files Browse the repository at this point in the history
  • Loading branch information
josemaria-vilaplana committed Jan 8, 2025
1 parent 5f1d19b commit 0693424
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 16 deletions.
48 changes: 34 additions & 14 deletions raster_loader/cli/snowflake.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,14 +141,24 @@ def upload(
get_block_dims,
)

if (
token is None
and (username is None or password is None)
and private_key_path is None
) or all(v is not None for v in [token, username, password, private_key_path]):
if not (
(token is not None and username is None)
or (
token is None
and username is not None
and password is not None
and private_key_path is None
)
or (
token is None
and username is not None
and password is None
and private_key_path is not None
)
):
raise ValueError(
"Either --token or --private-key-path or --username and --password"
" must be provided."
"Either (--token) or (--username and --private-key-path) or"
" (--username and --password) must be provided."
)

if private_key_path is not None:
Expand Down Expand Up @@ -277,14 +287,24 @@ def describe(
limit,
):

if (
token is None
and (username is None or password is None)
and private_key_path is None
) or all(v is not None for v in [token, username, password, private_key_path]):
if not (
(token is not None and username is None)
or (
token is None
and username is not None
and password is not None
and private_key_path is None
)
or (
token is None
and username is not None
and password is None
and private_key_path is not None
)
):
raise ValueError(
"Either --token or --private-key-path or --username and --password"
" must be provided."
"Either (--token) or (--username and --private-key-path) or"
" (--username and --password) must be provided."
)

if private_key_path is not None:
Expand Down
6 changes: 4 additions & 2 deletions raster_loader/tests/snowflake/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,8 @@ def test_snowflake_credentials_validation(*args, **kwargs):
)
assert result.exit_code == 1
assert (
"Either --token or --username and --password must be provided." in result.output
"Either (--token) or (--username and --private-key-path) or"
" (--username and --password) must be provided." in result.output
)

result = runner.invoke(
Expand Down Expand Up @@ -213,7 +214,8 @@ def test_snowflake_credentials_validation(*args, **kwargs):
)
assert result.exit_code == 1
assert (
"Either --token or --username and --password must be provided." in result.output
"Either (--token) or (--username and --private-key-path) or"
" (--username and --password) must be provided." in result.output
)


Expand Down

0 comments on commit 0693424

Please sign in to comment.