Skip to content

Commit

Permalink
trying
Browse files Browse the repository at this point in the history
  • Loading branch information
infiniteregrets committed Sep 27, 2024
1 parent aaf0ff9 commit 82c7918
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 6 deletions.
2 changes: 1 addition & 1 deletion 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 @@ -11,7 +11,7 @@ dirs = "5.0.1"
serde = { version = "1.0.210", features = ["derive"] }
thiserror = "1.0.63"
toml = "0.8.19"
s2 = { git = "ssh://[email protected]/s2-streamstore/s2.rs.git", branch = "basinstate-disp" }
s2 = { git = "ssh://[email protected]/s2-streamstore/s2.rs.git", branch = "main" }
tokio = { version = "*", features = ["full"] }
humantime = "2.1.0"
miette = { version = "7.2.0", features = ["fancy"] }
Expand Down
18 changes: 15 additions & 3 deletions src/account.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
use s2::{
client::Client,
service_error::{CreateBasinError, DeleteBasinError, ServiceError},
service_error::{CreateBasinError, DeleteBasinError, GetBasinConfigError, ServiceError},
types::{
BasinConfig, CreateBasinResponse, ListBasinsResponse, RetentionPolicy, StorageClass,
StreamConfig,
BasinConfig, CreateBasinResponse, GetBasinConfigResponse, ListBasinsResponse,
RetentionPolicy, StorageClass, StreamConfig,
},
};

Expand All @@ -21,6 +21,9 @@ pub enum AccountServiceError {

#[error("Failed to delete basin")]
DeleteBasin(#[from] ServiceError<DeleteBasinError>),

#[error("Failed to get basin config")]
GetBasinConfig(#[from] ServiceError<GetBasinConfigError>),
}

impl AccountService {
Expand Down Expand Up @@ -84,4 +87,13 @@ impl AccountService {
self.client.delete_basin(delete_basin_req).await?;
Ok(())
}

pub async fn get_basin_config(&self, name: String) -> Result<BasinConfig, AccountServiceError> {
let get_basin_config_req = s2::types::GetBasinConfigRequest::builder()
.basin(name)
.build();
let GetBasinConfigResponse { config } =
self.client.get_basin_config(get_basin_config_req).await?;
Ok(config)
}
}
30 changes: 29 additions & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ enum ConfigActions {
},
}

#[deny(missing_docs)]
#[derive(Subcommand, Debug)]
enum AccountActions {
/// List basins
Expand Down Expand Up @@ -101,6 +102,22 @@ enum AccountActions {
/// Basin name to delete.
basin: String,
},

/// Get basin config
GetBasinConfig {
/// Basin name to get config for.
basin: String,
},

/// Reconfigure a basin
ReconfigureBasin {
/// Basin name to reconfigure.
basin: String,

/// Configuration to apply.
#[arg(short, long)]
config: Vec<String>,
},
}

#[derive(Subcommand, Debug)]
Expand All @@ -122,6 +139,9 @@ enum BasinActions {
#[arg(short, long)]
limit: u32,
},

/// Create a stream
CreateStream {},
}

async fn s2_client(auth_token: String) -> Result<Client, S2CliError> {
Expand Down Expand Up @@ -169,7 +189,6 @@ async fn run() -> Result<(), S2CliError> {

Commands::Account { action } => {
let cfg = config::load_config(&config_path)?;
println!("cfg: {:?}", cfg);
let account_service = AccountService::new(s2_client(cfg.auth_token).await?);
match action {
AccountActions::ListBasins {
Expand Down Expand Up @@ -212,6 +231,14 @@ async fn run() -> Result<(), S2CliError> {
account_service.delete_basin(basin).await?;
println!("{}", "✓ Basin deleted successfully".green().bold());
}

AccountActions::GetBasinConfig { basin } => {
let basin_config = account_service.get_basin_config(basin).await?;
println!("{:?}", basin_config);
}
AccountActions::ReconfigureBasin { basin, config } => {
unimplemented!()
}
}
}
Commands::Basins { action } => {
Expand All @@ -232,6 +259,7 @@ async fn run() -> Result<(), S2CliError> {
println!("{}", stream);
}
}
BasinActions::CreateStream {} => todo!(),
}
}
}
Expand Down

0 comments on commit 82c7918

Please sign in to comment.