Skip to content

Commit

Permalink
Added required parameter for MFA caching and removed internal app par… (
Browse files Browse the repository at this point in the history
  • Loading branch information
sfc-gh-astus authored Jun 11, 2024
1 parent d69c305 commit 9bf2570
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 23 deletions.
1 change: 1 addition & 0 deletions RELEASE-NOTES.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
* Fixed error handling for malformatted `config.toml`
* Fixed ZIP packaging of Snowpark project dependencies containing implicit namespace packages like `snowflake`.
* Deploying function/procedure with `--replace` flag now copies all grants
* Fixed MFA caching

# v2.4.0
## Backward incompatibility
Expand Down
1 change: 0 additions & 1 deletion src/snowflake/cli/app/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,3 @@
from typing import Literal

PARAM_APPLICATION_NAME: Literal["snowcli"] = "snowcli"
PARAM_INTERNAL_APPLICATION_NAME: Literal["snowcli"] = "snowcli"
7 changes: 3 additions & 4 deletions src/snowflake/cli/app/snow_connector.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,15 +30,13 @@
from snowflake.cli.api.secure_path import SecurePath
from snowflake.cli.app.constants import (
PARAM_APPLICATION_NAME,
PARAM_INTERNAL_APPLICATION_NAME,
)
from snowflake.cli.app.telemetry import command_info
from snowflake.connector import SnowflakeConnection
from snowflake.connector.errors import DatabaseError, ForbiddenError

log = logging.getLogger(__name__)

from snowflake.cli.__about__ import VERSION

ENCRYPTED_PKCS8_PK_HEADER = b"-----BEGIN ENCRYPTED PRIVATE KEY-----"
UNENCRYPTED_PKCS8_PK_HEADER = b"-----BEGIN PRIVATE KEY-----"
Expand Down Expand Up @@ -98,6 +96,9 @@ def connect_to_snowflake(
if mfa_passcode:
connection_parameters["passcode"] = mfa_passcode

if connection_parameters.get("authenticator") == "username_password_mfa":
connection_parameters["client_request_mfa_token"] = True

if enable_diag:
connection_parameters["enable_connection_diag"] = enable_diag
if diag_log_path:
Expand Down Expand Up @@ -171,8 +172,6 @@ def _update_connection_application_name(connection_parameters: Dict):
"""Update version and name of app handling connection."""
connection_application_params = {
"application_name": PARAM_APPLICATION_NAME,
"internal_application_name": PARAM_INTERNAL_APPLICATION_NAME,
"internal_application_version": VERSION,
}
connection_parameters.update(connection_application_params)

Expand Down
26 changes: 12 additions & 14 deletions tests/test_connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -405,8 +405,6 @@ def test_temporary_connection(mock_connector, mock_ctx, option, runner):
schema="PUBLIC",
warehouse="xsmall",
application_name="snowcli",
internal_application_name="snowcli",
internal_application_version="0.0.0-test_patched",
)


Expand Down Expand Up @@ -487,8 +485,6 @@ def test_key_pair_authentication(mock_connector, mock_ctx, runner):
schema="PUBLIC",
warehouse="xsmall",
application_name="snowcli",
internal_application_name="snowcli",
internal_application_version="0.0.0-test_patched",
)


Expand Down Expand Up @@ -537,8 +533,6 @@ def test_session_and_master_tokens(mock_connector, mock_ctx, runner):
warehouse="xsmall",
server_session_keep_alive=True,
application_name="snowcli",
internal_application_name="snowcli",
internal_application_version="0.0.0-test_patched",
)


Expand Down Expand Up @@ -586,8 +580,6 @@ def test_key_pair_authentication_from_config(
authenticator="SNOWFLAKE_JWT",
private_key="secret value",
application_name="snowcli",
internal_application_name="snowcli",
internal_application_version="0.0.0-test_patched",
)


Expand Down Expand Up @@ -673,6 +665,18 @@ def test_no_mfa_passcode(mock_connect, runner):
assert kwargs.get("passcode") is None


@mock.patch("snowflake.connector.connect")
def test_mfa_cache(mock_connect, runner):
result = runner.invoke(
["sql", "-q", "select 1", "--authenticator", "username_password_mfa"]
)

assert result.exit_code == 0, result.output
args, kwargs = mock_connect.call_args
assert kwargs["authenticator"] == "username_password_mfa"
assert kwargs["client_request_mfa_token"]


@pytest.mark.parametrize(
"env",
[
Expand Down Expand Up @@ -713,8 +717,6 @@ def test_connection_details_are_resolved_using_environment_variables(
"role": "role",
"password": "dummy",
"application_name": "snowcli",
"internal_application_name": "snowcli",
"internal_application_version": "0.0.0-test_patched",
}


Expand Down Expand Up @@ -774,8 +776,6 @@ def test_flags_take_precedence_before_environment_variables(
"password": "password_from_flag",
"role": "role_from_flag",
"application_name": "snowcli",
"internal_application_name": "snowcli",
"internal_application_version": "0.0.0-test_patched",
}


Expand Down Expand Up @@ -813,8 +813,6 @@ def test_source_precedence(mock_connect, runner):
"database": "database_from_connection_env",
"role": "role_from_global_env",
"application_name": "snowcli",
"internal_application_name": "snowcli",
"internal_application_version": "0.0.0-test_patched",
}


Expand Down
2 changes: 0 additions & 2 deletions tests/test_main.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,6 @@ def test_custom_config_path(mock_conn, runner, mock_cursor):
warehouse="xs",
password="dummy_password",
application_name="snowcli",
internal_application_name="snowcli",
internal_application_version="0.0.0-test_patched",
)


Expand Down
2 changes: 0 additions & 2 deletions tests/test_snow_connector.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,6 @@ def test_command_context_is_passed_to_snowflake_connection(
warehouse="xs",
password="dummy_password",
application_name="snowcli",
internal_application_name="snowcli",
internal_application_version="0.0.0-test_patched",
)


Expand Down

0 comments on commit 9bf2570

Please sign in to comment.