|
| 1 | +from __future__ import annotations |
| 2 | + |
| 3 | +EnvVars = dict[str, str] |
| 4 | + |
| 5 | +DicoveredVars = list[dict[str, str]] |
| 6 | +UnusedVars = list[dict[str, str]] |
| 7 | +Summary = str |
| 8 | + |
| 9 | +CheckResult = tuple[DicoveredVars, UnusedVars, Summary] |
| 10 | + |
| 11 | +KNOWN_SNOWSQL_ENV_VARS = { |
| 12 | + "SNOWSQL_ACCOUNT": { |
| 13 | + "Found": "SNOWSQL_ACCOUNT", |
| 14 | + "Suggested": "SNOWFLAKE_ACCOUNT", |
| 15 | + "Additional info": "https://docs.snowflake.com/en/developer-guide/snowflake-cli/connecting/configure-connections#use-environment-variables-for-snowflake-credentials", |
| 16 | + }, |
| 17 | + "SNOWSQL_PWD": { |
| 18 | + "Found": "SNOWSQL_PASSWORD", |
| 19 | + "Suggested": "SNOWFLAKE_PASSWORD", |
| 20 | + "Additional info": "https://docs.snowflake.com/en/developer-guide/snowflake-cli/connecting/configure-connections#use-environment-variables-for-snowflake-credentials", |
| 21 | + }, |
| 22 | + "SNOWSQL_USER": { |
| 23 | + "Found": "SNOWSQL_USER", |
| 24 | + "Suggested": "SNOWFLAKE_USER", |
| 25 | + "Additional info": "https://docs.snowflake.com/en/developer-guide/snowflake-cli/connecting/configure-connections#use-environment-variables-for-snowflake-credentials", |
| 26 | + }, |
| 27 | + "SNOWSQL_REGION": { |
| 28 | + "Found": "SNOWSQL_REGION", |
| 29 | + "Suggested": "SNOWFLAKE_REGION", |
| 30 | + "Additional info": "https://docs.snowflake.com/en/developer-guide/snowflake-cli/connecting/configure-connections#use-environment-variables-for-snowflake-credentials", |
| 31 | + }, |
| 32 | + "SNOWSQL_ROLE": { |
| 33 | + "Found": "SNOWSQL_ROLE", |
| 34 | + "Suggested": "SNOWFLAKE_ROLE", |
| 35 | + "Additional info": "https://docs.snowflake.com/en/developer-guide/snowflake-cli/connecting/configure-connections#use-environment-variables-for-snowflake-credentials", |
| 36 | + }, |
| 37 | + "SNOWSQL_WAREHOUSE": { |
| 38 | + "Found": "SNOWSQL_WAREHOUSE", |
| 39 | + "Suggested": "SNOWFLAKE_WAREHOUSE", |
| 40 | + "Additional info": "https://docs.snowflake.com/en/developer-guide/snowflake-cli/connecting/configure-connections#use-environment-variables-for-snowflake-credentials", |
| 41 | + }, |
| 42 | + "SNOWSQL_DATABASE": { |
| 43 | + "Found": "SNOWSQL_DATABASE", |
| 44 | + "Suggested": "SNOWFLAKE_DATABASE", |
| 45 | + "Additional info": "https://docs.snowflake.com/en/developer-guide/snowflake-cli/connecting/configure-connections#use-environment-variables-for-snowflake-credentials", |
| 46 | + }, |
| 47 | + "SNOWSQL_SCHEMA": { |
| 48 | + "found": "SNOWSQL_SCHEMA", |
| 49 | + "Suggested": "SNOWFLAKE_SCHEMA", |
| 50 | + "Additional info": "https://docs.snowflake.com/en/developer-guide/snowflake-cli/connecting/configure-connections#use-environment-variables-for-snowflake-credentials", |
| 51 | + }, |
| 52 | + "SNOWSQL_HOST": { |
| 53 | + "Found": "SNOWSQL_HOST", |
| 54 | + "Suggested": "SNOWFLAKE_HOST", |
| 55 | + "Additional info": "https://docs.snowflake.com/en/developer-guide/snowflake-cli/connecting/configure-connections#use-environment-variables-for-snowflake-credentials", |
| 56 | + }, |
| 57 | + "SNOWSQL_PORT": { |
| 58 | + "Found": "SNOWSQL_PORT", |
| 59 | + "Suggested": "SNOWFLAKE_PORT", |
| 60 | + "Additional info": "https://docs.snowflake.com/en/developer-guide/snowflake-cli/connecting/configure-connections#use-environment-variables-for-snowflake-credentials", |
| 61 | + }, |
| 62 | + "SNOWSQL_PROTOCOL": { |
| 63 | + "Found": "SNOWSQL_PROTOCOL", |
| 64 | + "Suggested": "SNOWFLAKE_PROTOCOL", |
| 65 | + "Additional info": "https://docs.snowflake.com/en/developer-guide/snowflake-cli/connecting/configure-connections#use-environment-variables-for-snowflake-credentials", |
| 66 | + }, |
| 67 | + "SNOWSQL_PROXY_HOST": { |
| 68 | + "Found": "SNOWSQL_PROXY_HOST", |
| 69 | + "Suggested": "PROXY_HOST", |
| 70 | + "Additional info": "https://docs.snowflake.com/en/developer-guide/snowflake-cli/connecting/configure-cli#use-a-proxy-server", |
| 71 | + }, |
| 72 | + "SNOWSQL_PROXY_PORT": { |
| 73 | + "Found": "SNOWSQL_PROXY_HOST", |
| 74 | + "Suggested": "PROXY_HOST", |
| 75 | + "Additional info": "https://docs.snowflake.com/en/developer-guide/snowflake-cli/connecting/configure-cli#use-a-proxy-server", |
| 76 | + }, |
| 77 | + "SNOWSQL_PROXY_USER": { |
| 78 | + "Found": "SNOWSQL_PROXY_PORT", |
| 79 | + "Suggested": "PROXY_PORT", |
| 80 | + "Additional info": "https://docs.snowflake.com/en/developer-guide/snowflake-cli/connecting/configure-cli#use-a-proxy-server", |
| 81 | + }, |
| 82 | + "SNOWSQL_PROXY_PWD": { |
| 83 | + "Found": "SNOWSQL_PROXY_PWD", |
| 84 | + "Suggested": "PROXY_PWD", |
| 85 | + "Additional info": "https://docs.snowflake.com/en/developer-guide/snowflake-cli/connecting/configure-cli#use-a-proxy-server", |
| 86 | + }, |
| 87 | + "SNOWSQL_PRIVATE_KEY_PASSPHRASE": { |
| 88 | + "Found": "SNOWSQL_PRIVATE_KEY_PASSPHRASE", |
| 89 | + "Suggested": "PRIVATE_KEY_PASSPHRASE", |
| 90 | + "Additional info": "https://docs.snowflake.com/en/developer-guide/snowflake-cli/connecting/configure-connections", |
| 91 | + }, |
| 92 | +} |
| 93 | + |
| 94 | + |
| 95 | +def check_env_vars(variables: EnvVars) -> CheckResult: |
| 96 | + """Checks passed dict objects for possible SnowSQL variables. |
| 97 | +
|
| 98 | + Returns tuple of |
| 99 | + - sequence of variables that can be adjusted |
| 100 | + - sequence of variables that have no corresponding variables |
| 101 | + - a summary messages |
| 102 | + """ |
| 103 | + discovered: DicoveredVars = [] |
| 104 | + unused: UnusedVars = [] |
| 105 | + |
| 106 | + prefix_matched = (e for e in variables if e.lower().startswith("snowsql")) |
| 107 | + |
| 108 | + for var in prefix_matched: |
| 109 | + if suggestion := KNOWN_SNOWSQL_ENV_VARS.get(var, None): |
| 110 | + discovered.append(suggestion) |
| 111 | + else: |
| 112 | + unused.append( |
| 113 | + { |
| 114 | + "Found": var, |
| 115 | + "Suggested": "n/a", |
| 116 | + "Additional info": "Unused variable", |
| 117 | + } |
| 118 | + ) |
| 119 | + |
| 120 | + discovered_cnt = len(discovered) |
| 121 | + unused_cnt = len(unused) |
| 122 | + |
| 123 | + summary: Summary = ( |
| 124 | + f"Found {discovered_cnt + unused_cnt} SnowSQL environment variables," |
| 125 | + f" {discovered_cnt} with replacements, {unused_cnt} unused." |
| 126 | + ) |
| 127 | + |
| 128 | + return discovered, unused, summary |
0 commit comments