SnowflakeHook: extract OAuth token lifecycle management into dedicated helper#68549
Conversation
phanikumv
left a comment
There was a problem hiding this comment.
still see some reference to _get_valid_oauth_token in the test_snowflake.py, could you please correct it
management. Move grant type validation, token requests, token caching and token expiration tracking out of SnowflakeHook while preserving the existing public API. SnowflakeHook continues to expose get_oauth_token(), but now delegates OAuth token management to the dedicated helper.
14b9f5d to
e858cbd
Compare
e858cbd to
4ed50ee
Compare
jason810496
left a comment
There was a problem hiding this comment.
Thanks for the PR. Sorry for pushing back, but I'm not sure the extraction earns its keep.
_SnowflakeOAuthManager has a single consumer. SnowflakeHook creates it once, it's private, and it isn't injected or swappable, so we pay for the indirection without the usual payoffs (reuse, isolation, substitutability).
The boundary is also leaky. Every method still takes conn_config and indexes into it (account, client_id, refresh_token...), and validate_grant_type still runs in _get_conn_params then again inside get_valid_oauth_token. That duplicate validation is relocated, not fixed.
It's behavior-preserving, so nothing breaks, but it's mostly lateral churn on recently landed code (#60027), and the tests now reach into hook._oauth.validate_grant_type, coupling to internals the PR is trying to hide.
If there's a concrete second consumer or isolation benefit in mind, I'd be glad to hear it. Otherwise I'd lean toward holding off.
After considering your argument, I have to agree now that adding a new internal helper class is difficult to justify considering that it is only used by one other class. The motivation for this PR was to group all Oauth related functionality in one part of the hook to improve maintainability and this naturally led me to consider creating |
|
Whilst your argument is valid considering the current state of the provider, you may have to keep in mind that I am currently in process of adding a new hook for Snowflake Cortex Agents (PR #68942). Would it be better to wait until that is reviewed as |
There was a problem hiding this comment.
you may have to keep in mind that I am currently in process of adding a new hook for Snowflake Cortex Agents (PR #68942).
Then it makes sense now, I will merge this one first so your new Snowflake Cortex Agents hook can rebase on top of this and reuse the _SnowflakeOAuthManager util. Thanks.
Description
This change refactors OAuth token handling in
SnowflakeHookby extracting token lifecycle responsibilities into a dedicated_SnowflakeOAuthManagerhelper.OAuth-specific functionality previously implemented directly in
SnowflakeHook, including grant type validation, token retrieval, token caching, and token expiration tracking, has been moved into the new helper class.SnowflakeHookcontinues to expose the existingget_oauth_token()interface, but now delegates OAuth token management to the helper.Rationale
SnowflakeHookpreviously mixed connection management responsibilities with OAuth-specific concerns. Extracting OAuth token lifecycle management into_SnowflakeOAuthManagerestablishes a clearer separation of concerns and provides a dedicated owner for token acquisition, refresh, validation, and cache management.This reduces the amount of authentication-specific state maintained by
SnowflakeHook, simplifies the hook implementation, and makes OAuth functionality easier to reason about and maintain independently.Tests
Notes
_get_static_conn_params()docstring to reflect the new ownership boundaries introduced by_SnowflakeOAuthManager.Backwards Compatibility
This change is a refactor only and does not modify public APIs or runtime behavior.
SnowflakeHookcontinues to expose the existingget_oauth_token()interface, and existing authentication flows remain unchanged.