Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: sdk update #31

Merged
merged 1 commit into from
Nov 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"] }
Expand Down
8 changes: 4 additions & 4 deletions src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(())
}
Expand All @@ -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),
}
14 changes: 7 additions & 7 deletions src/error.rs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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))]
Expand Down
11 changes: 6 additions & 5 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
};
Expand Down Expand Up @@ -292,11 +292,12 @@ fn parse_records_output_source(s: &str) -> Result<RecordsOut, std::io::Error> {
}
}

fn client_config(auth_token: String) -> Result<ClientConfig, ParseError> {
Ok(ClientConfig::new(auth_token.to_string())
fn client_config(auth_token: String) -> Result<ClientConfig, S2CliError> {
let endpoints = S2Endpoints::from_env().map_err(S2CliError::EndpointsFromEnv)?;
let client_config = ClientConfig::new(auth_token.to_string())
.with_user_agent("s2-cli".parse::<HeaderValue>().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]
Expand Down