|
20 | 20 | "get_secret_type", |
21 | 21 | "get_username_password", |
22 | 22 | "get_cloud_provider_token", |
| 23 | + "get_wif_token", |
23 | 24 | "UsernamePassword", |
24 | 25 | "CloudProviderToken", |
25 | 26 | ] |
@@ -61,6 +62,10 @@ def get_username_password(self, secret_name: str) -> UsernamePassword: |
61 | 62 | def get_cloud_provider_token(self, secret_name: str) -> CloudProviderToken: |
62 | 63 | pass |
63 | 64 |
|
| 65 | + @abstractmethod |
| 66 | + def get_wif_token(self, secret_name: str, audience: str) -> str: |
| 67 | + pass |
| 68 | + |
64 | 69 |
|
65 | 70 | class _SnowflakeSecretsServer(_SnowflakeSecrets): |
66 | 71 | """Secret instance for Snowflake server environment (using _snowflake module).""" |
@@ -89,6 +94,9 @@ def get_cloud_provider_token(self, secret_name: str) -> CloudProviderToken: |
89 | 94 | secret_object.token, |
90 | 95 | ) |
91 | 96 |
|
| 97 | + def get_wif_token(self, secret_name: str, audience: str) -> str: |
| 98 | + return self._snowflake.get_wif_token(secret_name, audience) |
| 99 | + |
92 | 100 |
|
93 | 101 | class _SnowflakeSecretsSPCS(_SnowflakeSecrets): |
94 | 102 | """Secret instance for SPCS container environment (file-based secrets).""" |
@@ -173,6 +181,11 @@ def get_cloud_provider_token(self, secret_name: str) -> CloudProviderToken: |
173 | 181 | "Cloud provider token secrets are not supported in SPCS container environments." |
174 | 182 | ) |
175 | 183 |
|
| 184 | + def get_wif_token(self, secret_name: str, audience: str) -> str: |
| 185 | + raise NotImplementedError( |
| 186 | + "WIF token secrets are not supported in SPCS container environments." |
| 187 | + ) |
| 188 | + |
176 | 189 |
|
177 | 190 | def _is_spcs_environment() -> bool: |
178 | 191 | return os.getenv(_SCLS_SPCS_SECRET_ENV_NAME, None) is not None |
@@ -259,3 +272,29 @@ def get_cloud_provider_token(secret_name: str) -> CloudProviderToken: |
259 | 272 | NotImplementedError: If running outside Snowflake server environment. |
260 | 273 | """ |
261 | 274 | return _get_secrets_instance().get_cloud_provider_token(secret_name) |
| 275 | + |
| 276 | + |
| 277 | +def get_wif_token(secret_name: str, audience: str) -> str: |
| 278 | + """Get a workload identity federation (WIF) token from Snowflake. |
| 279 | +
|
| 280 | + Note: |
| 281 | + Requires a Snowflake environment with a WIF secret configured and an |
| 282 | + external access integration that allows the UDF or stored procedure to |
| 283 | + use that secret. The ``audience`` must match the token audience expected |
| 284 | + by the external system (for example, an OAuth token endpoint URL). |
| 285 | +
|
| 286 | + Args: |
| 287 | + secret_name: The secret reference name bound to the WIF secret. |
| 288 | + audience: The intended audience (``aud``) for the issued token. |
| 289 | +
|
| 290 | + Returns: |
| 291 | + The issued token as a string (typically a JWT). |
| 292 | +
|
| 293 | + Raises: |
| 294 | + NotImplementedError: If running outside the Snowflake server environment |
| 295 | + (including SPCS file-based secret environments, where WIF tokens cannot |
| 296 | + be minted). |
| 297 | + ValueError: If the secret does not exist or is not authorized (when |
| 298 | + applicable in supported environments). |
| 299 | + """ |
| 300 | + return _get_secrets_instance().get_wif_token(secret_name, audience) |
0 commit comments