amoghrajesh commented on code in PR #49482:
URL: https://github.com/apache/airflow/pull/49482#discussion_r2051999794
##########
providers/snowflake/src/airflow/providers/snowflake/hooks/snowflake_sql_api.py:
##########
@@ -232,29 +232,15 @@ def get_headers(self) -> dict[str, Any]:
}
return headers
- def get_oauth_token(self, conn_config: dict[str, Any]) -> str:
+ def get_oauth_token(self, conn_config: dict[str, Any] | None = None) ->
str:
"""Generate temporary OAuth access token using refresh token in
connection details."""
- url =
f"{self.account_identifier}.snowflakecomputing.com/oauth/token-request"
- data = {
- "grant_type": "refresh_token",
- "refresh_token": conn_config["refresh_token"],
- "redirect_uri": conn_config.get("redirect_uri",
"https://localhost.com"),
- }
- response = requests.post(
- url,
- data=data,
- headers={
- "Content-Type": "application/x-www-form-urlencoded",
- },
- auth=HTTPBasicAuth(conn_config["client_id"],
conn_config["client_secret"]), # type: ignore[arg-type]
+ warnings.warn(
+ "This method is deprecated. Please use get_oauth_token() method
from SnowflakeHook instead. "
Review Comment:
```suggestion
"This method is deprecated. Please use `get_oauth_token` method
from `SnowflakeHook` instead. "
```
##########
providers/snowflake/src/airflow/providers/snowflake/hooks/snowflake.py:
##########
@@ -187,16 +187,22 @@ def _get_field(self, extra_dict, field_name):
return extra_dict[field_name] or None
return extra_dict.get(backcompat_key) or None
- def get_oauth_token(self, conn_config: dict) -> str:
+ def get_oauth_token(self, conn_config: dict | None = None) -> str:
"""Generate temporary OAuth access token using refresh token in
connection details."""
- url =
f"https://{conn_config['account']}.snowflakecomputing.com/oauth/token-request"
+ if conn_config is None:
+ conn_config = self._get_conn_params
+
+ def generate_url():
+ region = f"{conn_config['region']}" if conn_config.get("region")
else ""
+ return
f"https://{conn_config['account']}.{region}.snowflakecomputing.com/oauth/token-request"
Review Comment:
This is not right when region is not defined.
```
conn_config = {"region": "test-region", "account": "my-account"}
generate_url()
Out[4]:
'https://my-account.test-region.snowflakecomputing.com/oauth/token-request'
conn_config.pop("region")
Out[5]: 'test-region'
conn_config
Out[6]: {'account': 'my-account'}
generate_url()
Out[7]: 'https://my-account..snowflakecomputing.com/oauth/token-request'
```
Extra dots get added. We should instead handle this better
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]