Skip to content

No snow snowflake restful further implementation#638

Draft
sfc-gh-turbaszek wants to merge 2 commits intomainfrom
NO-SNOW-SnowflakeRestful-further-implementation
Draft

No snow snowflake restful further implementation#638
sfc-gh-turbaszek wants to merge 2 commits intomainfrom
NO-SNOW-SnowflakeRestful-further-implementation

Conversation

@sfc-gh-turbaszek
Copy link
Contributor

No description provided.

sfc-gh-turbaszek and others added 2 commits March 19, 2026 15:38
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>
Copilot AI review requested due to automatic review settings March 19, 2026 16:07
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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_token to ConnectionGetInfoResponse and plumb it through Rust ↔ protobuf ↔ Python.
  • Add ConnectionSendHttp and ConnectionRequestToken RPCs and implement them in sf_core.
  • Implement SnowflakeRestful request/fetch/token-request methods in Python and add integration coverage; update pre-commit Python hook to run via uv.

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}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants