diff --git a/Cargo.lock b/Cargo.lock index c2529fc..328b86a 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1671,7 +1671,7 @@ checksum = "6980e8d7511241f8acf4aebddbb1ff938df5eebe98691418c4468d0b72a96a67" [[package]] name = "streamstore" version = "0.1.0" -source = "git+https://github.com/s2-streamstore/s2-sdk-rust.git?rev=f39cb52c15869b0d02c92e441b2828a27dfeac72#f39cb52c15869b0d02c92e441b2828a27dfeac72" +source = "git+https://github.com/s2-streamstore/s2-sdk-rust.git?rev=63b4964b66503f705e7c73ae07ba47f81019b79a#63b4964b66503f705e7c73ae07ba47f81019b79a" dependencies = [ "async-stream", "backon", @@ -1739,7 +1739,7 @@ dependencies = [ [[package]] name = "sync_docs" version = "0.1.0" -source = "git+https://github.com/s2-streamstore/s2-sdk-rust.git?rev=f39cb52c15869b0d02c92e441b2828a27dfeac72#f39cb52c15869b0d02c92e441b2828a27dfeac72" +source = "git+https://github.com/s2-streamstore/s2-sdk-rust.git?rev=63b4964b66503f705e7c73ae07ba47f81019b79a#63b4964b66503f705e7c73ae07ba47f81019b79a" dependencies = [ "proc-macro2", "quote", diff --git a/Cargo.toml b/Cargo.toml index 7466772..4a30c85 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -17,7 +17,7 @@ pin-project-lite = "0.2" pin-utils = "0.1.0" serde = { version = "1.0.214", features = ["derive"] } serde_json = "1.0.132" -streamstore = { git = "https://github.com/s2-streamstore/s2-sdk-rust.git", rev = "f39cb52c15869b0d02c92e441b2828a27dfeac72" } +streamstore = { git = "https://github.com/s2-streamstore/s2-sdk-rust.git", rev = "63b4964b66503f705e7c73ae07ba47f81019b79a" } thiserror = "1.0.67" tokio = { version = "*", features = ["full"] } tokio-stream = { version = "0.1.16", features = ["io-util"] } diff --git a/src/config.rs b/src/config.rs index a84ff9f..33bb253 100644 --- a/src/config.rs +++ b/src/config.rs @@ -45,11 +45,11 @@ pub fn create_config(config_path: &PathBuf, auth_token: String) -> Result<(), S2 let cfg = S2Config { auth_token }; if let Some(parent) = config_path.parent() { - std::fs::create_dir_all(parent).map_err(S2ConfigError::WriteError)?; + std::fs::create_dir_all(parent).map_err(S2ConfigError::Write)?; } let toml = toml::to_string(&cfg).unwrap(); - std::fs::write(config_path, toml).map_err(S2ConfigError::WriteError)?; + std::fs::write(config_path, toml).map_err(S2ConfigError::Write)?; Ok(()) } @@ -63,8 +63,8 @@ pub enum S2ConfigError { #[diagnostic(help( "Did you run `s2 config set`? or use `S2_AUTH_TOKEN` environment variable." ))] - LoadError(#[from] config::ConfigError), + Load(#[from] config::ConfigError), #[error("Failed to write config file")] - WriteError(#[source] std::io::Error), + Write(#[source] std::io::Error), } diff --git a/src/error.rs b/src/error.rs index 0f7cf2d..1440870 100644 --- a/src/error.rs +++ b/src/error.rs @@ -1,8 +1,5 @@ use miette::Diagnostic; -use streamstore::{ - client::{ClientError, ParseError}, - types::ConvertError, -}; +use streamstore::{client::ClientError, types::ConvertError}; use thiserror::Error; use crate::config::S2ConfigError; @@ -32,9 +29,12 @@ pub enum S2CliError { #[diagnostic(help("Are you trying to operate on an invalid basin?"))] ConvertError(#[from] ConvertError), - #[error(transparent)] - #[diagnostic(help("Are you overriding `S2_CLOUD`, `S2_CELL`, or `S2_BASIN_ZONE`?"))] - HostEndpoints(#[from] ParseError), + #[error("Unable to load S2 endpoints from environment")] + #[diagnostic(help( + "Are you overriding `S2_CLOUD`, `S2_ACCOUNT_ENDPOINT` or `S2_BASIN_ENDPOINT`? + Make sure the values are in the expected format." + ))] + EndpointsFromEnv(String), #[error(transparent)] #[diagnostic(help("{}", BUG_HELP))] diff --git a/src/main.rs b/src/main.rs index 0172700..b81227a 100644 --- a/src/main.rs +++ b/src/main.rs @@ -9,7 +9,7 @@ use error::{S2CliError, ServiceError, ServiceErrorContext}; use stream::{RecordStream, StreamService}; use streamstore::{ bytesize::ByteSize, - client::{BasinClient, Client, ClientConfig, HostEndpoints, ParseError, StreamClient}, + client::{BasinClient, Client, ClientConfig, S2Endpoints, StreamClient}, types::{BasinMetadata, BasinName, MeteredSize as _, ReadOutput}, HeaderValue, }; @@ -292,11 +292,12 @@ fn parse_records_output_source(s: &str) -> Result { } } -fn client_config(auth_token: String) -> Result { - Ok(ClientConfig::new(auth_token.to_string()) +fn client_config(auth_token: String) -> Result { + let endpoints = S2Endpoints::from_env().map_err(S2CliError::EndpointsFromEnv)?; + let client_config = ClientConfig::new(auth_token.to_string()) .with_user_agent("s2-cli".parse::().expect("valid user agent")) - .with_host_endpoints(HostEndpoints::from_env()?) - .with_connection_timeout(std::time::Duration::from_secs(5))) + .with_endpoints(endpoints); + Ok(client_config) } #[tokio::main]