snowflakedb / snowflake-cli

Snowflake CLI is an open-source command-line tool explicitly designed for developer-centric workloads in addition to SQL operations.
https://docs.snowflake.com/developer-guide/snowflake-cli-v2/index
Apache License 2.0
166 stars 52 forks source link

SNOW-1496083: Configure `--authenticator` or `--connection` using environment variables #1247

Closed SoheilSalmani closed 1 week ago

SoheilSalmani commented 1 month ago

Description

According to the documentation, we can configure some connection parameters (such as the account, user, etc.) using environment variables, but I can't find an equivalent environment variable for configuring the authenticator. I would like to be able to set it (e.g., export SNOWFLAKE_AUTHENTICATOR=externalbrowser) when using SSO.

Another approach I'd like to take is specifying connection parameters in a named connection and then setting the connection to be used with something like export SNOWFLAKE_CONNECTION=<connection_name>.

Context

I am using direnv to set my environment variables based on the current directory I am in. I would like to simply type snow sql to execute SQL using the correct context without needing to set any options. However, I can't do this when SSO is required.

sfc-gh-vtimofeenko commented 1 month ago

SNOWFLAKE_AUTHENTICATOR works with direnv, but this would need to be documented in snowcli docs:

❯ cat .envrc 
export SNOWFLAKE_ACCOUNT="<REDACTED>"
export SNOWFLAKE_USER="<REDACTED>"
export SNOWFLAKE_AUTHENTICATOR="externalbrowser"
❯ snow  connection test --temporary-connection
+----------------------------------------------------+
| key             | value                            |
|-----------------+----------------------------------|
| Connection name | None                             |
| Status          | OK                               |
...
SoheilSalmani commented 1 month ago

snow connection test also works on my side, thank you.

I get this error if I just use environment variables without having declared any default connection when using snow sql commands. It would be great if we could only rely on environment variables without having to touch the config.toml file.

$ echo "select 1" | snow sql --stdin
Couldn't find connection for default connection `default`. Specify connection name or configure default connection. 
SoheilSalmani commented 1 month ago

I just find out that we could also add a connection using snow connection add and specify the named connection to use on a per-directory basis using the SNOWFLAKE_DEFAULT_CONNECTION_NAME environment variable (which can be automatically set by direnv).

sfc-gh-pczajka commented 1 month ago

@SoheilSalmani Thanks for the report! We will update the documentation