No snow snowflake restful further implementation#638
Draft
sfc-gh-turbaszek wants to merge 2 commits intomainfrom
Draft
No snow snowflake restful further implementation#638sfc-gh-turbaszek wants to merge 2 commits intomainfrom
sfc-gh-turbaszek wants to merge 2 commits intomainfrom
Conversation
Expose master_token via ConnectionGetInfoResponse and implement the three REST methods (request, fetch, _token_request) that Snowflake CLI depends on. Uses the requests library for HTTP calls with session/master token authentication. Adds integration tests covering all properties and request patterns. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Replace direct Python `requests` library usage with two new protobuf RPCs (ConnectionSendHttp, ConnectionRequestToken) that execute HTTP requests through sf_core's Rust networking stack. This ensures all REST calls from SnowflakeRestful go through the same TLS/OCSP/CRL client used by the rest of the driver. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Contributor
There was a problem hiding this comment.
Pull request overview
This PR extends the DatabaseDriver v1 surface to support a backward-compatible “REST” interface used by Snowflake CLI, by exposing master_token in connection info and adding new RPCs for “generic HTTP via core TLS client” and “token-request via master token”, with corresponding Python wrapper methods and integration tests.
Changes:
- Add
master_tokentoConnectionGetInfoResponseand plumb it through Rust ↔ protobuf ↔ Python. - Add
ConnectionSendHttpandConnectionRequestTokenRPCs and implement them insf_core. - Implement
SnowflakeRestfulrequest/fetch/token-request methods in Python and add integration coverage; update pre-commit Python hook to run viauv.
Reviewed changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated 11 comments.
Show a summary per file
| File | Description |
|---|---|
sf_core/src/protobuf/apis/database_driver_v1.rs |
Maps Rust connection info (now including master_token) into protobuf responses; adds RPC handlers that forward into the driver implementation. |
sf_core/src/apis/database_driver_v1/connection.rs |
Adds core implementations for generic HTTP requests and token-request calls using the connection’s configured HTTP client/tokens. |
protobuf/database_driver_v1.proto |
Extends the proto with master_token plus new HTTP/token-request messages and RPCs. |
python/src/snowflake/connector/_internal/snowflake_restful.py |
Implements the Python-side REST compatibility wrapper by calling the new RPCs. |
python/tests/integ/test_snowflake_restful.py |
Adds integration tests that mirror Snowflake CLI call patterns against connection.rest. |
.pre-commit-config.yaml |
Switches Python pre-commit hook to run checks via uv. |
You can also share your feedback on Copilot code review. Take the survey.
| .map_err(|_| ApiError::GenericError { | ||
| location: snafu::Location::default(), | ||
| })?; | ||
|
|
Comment on lines
+796
to
+798
| let response = builder.send().await.map_err(|_| ApiError::GenericError { | ||
| location: snafu::Location::default(), | ||
| })?; |
Comment on lines
+723
to
+725
| _no_retry: bool, | ||
| auth_token: Option<String>, | ||
| ) -> Result<HttpResponse, ApiError> { |
Comment on lines
+854
to
+858
| let token_url = reqwest::Url::parse(server_url) | ||
| .and_then(|base| base.join("/session/token-request")) | ||
| .map_err(|_| ApiError::GenericError { | ||
| location: snafu::Location::default(), | ||
| })?; |
Comment on lines
+778
to
+781
| let mut builder = http_client.request(reqwest_method, &full_url).header( | ||
| reqwest::header::AUTHORIZATION, | ||
| snowflake::authorization_header(&token), | ||
| ); |
| builder = builder.header(key.as_str(), value.as_str()); | ||
| } | ||
|
|
||
| if let Some(timeout) = timeout_secs { |
Comment on lines
+732
to
+748
| let conn = conn_ptr.lock().await; | ||
|
|
||
| let http_client = conn | ||
| .http_client | ||
| .as_ref() | ||
| .context(ConnectionNotInitializedSnafu)?; | ||
|
|
||
| let server_url = conn | ||
| .server_url | ||
| .as_ref() | ||
| .context(ConnectionNotInitializedSnafu)?; | ||
|
|
||
| // Determine the token to use for authentication | ||
| let token = match &auth_token { | ||
| Some(t) => t.clone(), | ||
| None => { | ||
| let tokens_guard = conn.tokens.read().await; |
Comment on lines
+832
to
+836
| let conn = conn_ptr.lock().await; | ||
|
|
||
| let http_client = conn | ||
| .http_client | ||
| .as_ref() |
| &self, | ||
| conn_handle: Handle, | ||
| request_type: String, | ||
| ) -> Result<Vec<u8>, ApiError> { |
Comment on lines
41
to
+50
| def _protocol(self) -> str | None: | ||
| return urlparse(self._connection_info.server_url).scheme | ||
|
|
||
| @property | ||
| def _port(self) -> int | None: | ||
| return urlparse(self._connection_info.server_url).port or 443 | ||
|
|
||
| @property | ||
| def server_url(self) -> str: | ||
| return f"{self._protocol}://{self._host}:{self._port}" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
No description provided.