diff --git a/examples/basic.rs b/examples/basic.rs index 3aeb38e..3f5c0bb 100644 --- a/examples/basic.rs +++ b/examples/basic.rs @@ -3,7 +3,7 @@ use s2::{ service_error::{CreateBasinError, CreateStreamError, ServiceError}, types::{ CreateBasinRequest, CreateStreamRequest, DeleteBasinRequest, DeleteStreamRequest, - GetStreamConfigRequest, ListBasinsRequest, ListStreamsRequest, + GetBasinConfigRequest, GetStreamConfigRequest, ListBasinsRequest, ListStreamsRequest, }, }; @@ -50,9 +50,8 @@ async fn main() { Err(err) => exit_with_err(err), }; - let basin_client = client.basin_client(basin).await.unwrap(); - - match basin_client.get_basin_config().await { + let get_basin_config_req = GetBasinConfigRequest::builder().basin(basin).build(); + match client.get_basin_config(get_basin_config_req).await { Ok(config) => { println!("Basin config: {config:#?}"); } @@ -62,6 +61,7 @@ async fn main() { let stream = "s2-sdk-example-stream"; let create_stream_req = CreateStreamRequest::builder().stream(stream).build(); + let basin_client = client.basin_client(basin).await.unwrap(); match basin_client.create_stream(create_stream_req).await { Ok(()) => { diff --git a/proto b/proto index d9fca06..d596626 160000 --- a/proto +++ b/proto @@ -1 +1 @@ -Subproject commit d9fca06f96cde9b65102b13d2bfac40dc017b160 +Subproject commit d59662684d1ec81fa00206c7373f14214f519471 diff --git a/src/client.rs b/src/client.rs index 5bb7ab2..5cae598 100644 --- a/src/client.rs +++ b/src/client.rs @@ -13,14 +13,15 @@ use crate::{ service::{ account::{ CreateBasinError, CreateBasinServiceRequest, DeleteBasinError, - DeleteBasinServiceRequest, ListBasinsError, ListBasinsServiceRequest, + DeleteBasinServiceRequest, GetBasinConfigError, GetBasinConfigServiceRequest, + ListBasinsError, ListBasinsServiceRequest, ReconfigureBasinError, + ReconfigureBasinServiceRequest, }, basin::{ CreateStreamError, CreateStreamServiceRequest, DeleteStreamError, - DeleteStreamServiceRequest, GetBasinConfigError, GetBasinConfigServiceRequest, - GetStreamConfigError, GetStreamConfigServiceRequest, ListStreamsError, - ListStreamsServiceRequest, ReconfigureBasinError, ReconfigureBasinServiceRequest, - ReconfigureStreamError, ReconfigureStreamServiceRequest, + DeleteStreamServiceRequest, GetStreamConfigError, GetStreamConfigServiceRequest, + ListStreamsError, ListStreamsServiceRequest, ReconfigureStreamError, + ReconfigureStreamServiceRequest, }, send_request, stream::{GetNextSeqNumError, GetNextSeqNumServiceRequest}, @@ -146,28 +147,15 @@ impl Client { res => res, } } -} - -#[derive(Debug, Clone)] -pub struct BasinClient { - inner: ClientInner, -} - -impl BasinClient { - pub fn stream_client(&self, stream: impl Into) -> StreamClient { - StreamClient { - inner: self.inner.clone(), - stream: stream.into(), - } - } pub async fn get_basin_config( &self, + req: types::GetBasinConfigRequest, ) -> Result> { self.inner .send( - GetBasinConfigServiceRequest::new(self.inner.basin_service_client()), - /* request = */ (), + GetBasinConfigServiceRequest::new(self.inner.account_service_client()), + req, ) .await } @@ -178,11 +166,25 @@ impl BasinClient { ) -> Result<(), ServiceError> { self.inner .send( - ReconfigureBasinServiceRequest::new(self.inner.basin_service_client()), + ReconfigureBasinServiceRequest::new(self.inner.account_service_client()), req, ) .await } +} + +#[derive(Debug, Clone)] +pub struct BasinClient { + inner: ClientInner, +} + +impl BasinClient { + pub fn stream_client(&self, stream: impl Into) -> StreamClient { + StreamClient { + inner: self.inner.clone(), + stream: stream.into(), + } + } pub async fn create_stream( &self, diff --git a/src/lib.rs b/src/lib.rs index 2c04ccd..c0f158f 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -9,8 +9,8 @@ pub use secrecy::SecretString; pub mod service_error { pub use crate::service::{ - account::{CreateBasinError, DeleteBasinError}, - basin::{CreateStreamError, GetBasinConfigError, GetStreamConfigError, ListStreamsError}, + account::{CreateBasinError, DeleteBasinError, GetBasinConfigError}, + basin::{CreateStreamError, GetStreamConfigError, ListStreamsError}, ServiceError, }; } diff --git a/src/service/account.rs b/src/service/account.rs index cb80d3c..8682e40 100644 --- a/src/service/account.rs +++ b/src/service/account.rs @@ -200,3 +200,132 @@ pub enum DeleteBasinError { #[error("Not found: {0}")] NotFound(String), } + +#[derive(Debug, Clone)] +pub struct GetBasinConfigServiceRequest { + client: AccountServiceClient, +} + +impl GetBasinConfigServiceRequest { + pub fn new(client: AccountServiceClient) -> Self { + Self { client } + } +} + +impl ServiceRequest for GetBasinConfigServiceRequest { + type Request = types::GetBasinConfigRequest; + type ApiRequest = api::GetBasinConfigRequest; + type Response = types::GetBasinConfigResponse; + type ApiResponse = api::GetBasinConfigResponse; + type Error = GetBasinConfigError; + + const IDEMPOTENCY_LEVEL: IdempotencyLevel = IdempotencyLevel::NoSideEffects; + + fn prepare_request( + &self, + req: Self::Request, + ) -> Result, types::ConvertError> { + let req: api::GetBasinConfigRequest = req.into(); + Ok(req.into_request()) + } + + fn parse_response( + &self, + resp: tonic::Response, + ) -> Result { + resp.into_inner().try_into() + } + + fn parse_status(&self, status: &tonic::Status) -> Option { + match status.code() { + tonic::Code::NotFound => { + Some(GetBasinConfigError::NotFound(status.message().to_string())) + } + _ => None, + } + } + + async fn send( + &mut self, + req: tonic::Request, + ) -> Result, tonic::Status> { + self.client.get_basin_config(req).await + } + + fn should_retry(&self, _err: &super::ServiceError) -> bool { + false + } +} + +#[derive(Debug, thiserror::Error)] +pub enum GetBasinConfigError { + #[error("Not found: {0}")] + NotFound(String), +} + +#[derive(Debug, Clone)] +pub struct ReconfigureBasinServiceRequest { + client: AccountServiceClient, +} + +impl ReconfigureBasinServiceRequest { + pub fn new(client: AccountServiceClient) -> Self { + Self { client } + } +} + +impl ServiceRequest for ReconfigureBasinServiceRequest { + type Request = types::ReconfigureBasinRequest; + type ApiRequest = api::ReconfigureBasinRequest; + type Response = (); + type ApiResponse = api::ReconfigureBasinResponse; + type Error = ReconfigureBasinError; + + const IDEMPOTENCY_LEVEL: IdempotencyLevel = IdempotencyLevel::Idempotent; + + fn prepare_request( + &self, + req: Self::Request, + ) -> Result, types::ConvertError> { + let req: api::ReconfigureBasinRequest = req.try_into()?; + Ok(req.into_request()) + } + + fn parse_response( + &self, + _resp: tonic::Response, + ) -> Result { + Ok(()) + } + + fn parse_status(&self, status: &tonic::Status) -> Option { + match status.code() { + tonic::Code::NotFound => Some(ReconfigureBasinError::NotFound( + status.message().to_string(), + )), + tonic::Code::InvalidArgument => Some(ReconfigureBasinError::InvalidArgument( + status.message().to_string(), + )), + _ => None, + } + } + + async fn send( + &mut self, + req: tonic::Request, + ) -> Result, tonic::Status> { + self.client.reconfigure_basin(req).await + } + + fn should_retry(&self, _err: &super::ServiceError) -> bool { + false + } +} + +#[derive(Debug, thiserror::Error)] +pub enum ReconfigureBasinError { + #[error("Not found: {0}")] + NotFound(String), + #[error("Invalid argument: {0}")] + InvalidArgument(String), +} diff --git a/src/service/basin.rs b/src/service/basin.rs index c90ba37..2a18bba 100644 --- a/src/service/basin.rs +++ b/src/service/basin.rs @@ -72,67 +72,6 @@ pub enum ListStreamsError { InvalidArgument(String), } -#[derive(Debug, Clone)] -pub struct GetBasinConfigServiceRequest { - client: BasinServiceClient, -} - -impl GetBasinConfigServiceRequest { - pub fn new(client: BasinServiceClient) -> Self { - Self { client } - } -} - -impl ServiceRequest for GetBasinConfigServiceRequest { - type Request = (); - type ApiRequest = api::GetBasinConfigRequest; - type Response = types::GetBasinConfigResponse; - type ApiResponse = api::GetBasinConfigResponse; - type Error = GetBasinConfigError; - - const IDEMPOTENCY_LEVEL: IdempotencyLevel = IdempotencyLevel::NoSideEffects; - - fn prepare_request( - &self, - _req: Self::Request, - ) -> Result, types::ConvertError> { - Ok(api::GetBasinConfigRequest {}.into_request()) - } - - fn parse_response( - &self, - resp: tonic::Response, - ) -> Result { - resp.into_inner().try_into() - } - - fn parse_status(&self, status: &tonic::Status) -> Option { - match status.code() { - tonic::Code::NotFound => { - Some(GetBasinConfigError::NotFound(status.message().to_string())) - } - _ => None, - } - } - - async fn send( - &mut self, - req: tonic::Request, - ) -> Result, tonic::Status> { - self.client.get_basin_config(req).await - } - - fn should_retry(&self, _err: &super::ServiceError) -> bool { - false - } -} - -#[derive(Debug, thiserror::Error)] -pub enum GetBasinConfigError { - #[error("Not found: {0}")] - NotFound(String), -} - #[derive(Debug, Clone)] pub struct GetStreamConfigServiceRequest { client: BasinServiceClient, @@ -339,73 +278,6 @@ pub enum DeleteStreamError { InvalidArgument(String), } -#[derive(Debug, Clone)] -pub struct ReconfigureBasinServiceRequest { - client: BasinServiceClient, -} - -impl ReconfigureBasinServiceRequest { - pub fn new(client: BasinServiceClient) -> Self { - Self { client } - } -} - -impl ServiceRequest for ReconfigureBasinServiceRequest { - type Request = types::ReconfigureBasinRequest; - type ApiRequest = api::ReconfigureBasinRequest; - type Response = (); - type ApiResponse = api::ReconfigureBasinResponse; - type Error = ReconfigureBasinError; - - const IDEMPOTENCY_LEVEL: IdempotencyLevel = IdempotencyLevel::IdempotencyUnknown; - - fn prepare_request( - &self, - req: Self::Request, - ) -> Result, types::ConvertError> { - let req: api::ReconfigureBasinRequest = req.try_into()?; - Ok(req.into_request()) - } - - fn parse_response( - &self, - _resp: tonic::Response, - ) -> Result { - Ok(()) - } - - fn parse_status(&self, status: &tonic::Status) -> Option { - match status.code() { - tonic::Code::NotFound => Some(ReconfigureBasinError::NotFound( - status.message().to_string(), - )), - tonic::Code::InvalidArgument => Some(ReconfigureBasinError::InvalidArgument( - status.message().to_string(), - )), - _ => None, - } - } - - async fn send( - &mut self, - req: tonic::Request, - ) -> Result, tonic::Status> { - self.client.reconfigure_basin(req).await - } - - fn should_retry(&self, _err: &super::ServiceError) -> bool { - false - } -} - -#[derive(Debug, thiserror::Error)] -pub enum ReconfigureBasinError { - #[error("Not found: {0}")] - NotFound(String), - #[error("Invalid argument: {0}")] - InvalidArgument(String), -} - #[derive(Debug, Clone)] pub struct ReconfigureStreamServiceRequest { client: BasinServiceClient, diff --git a/src/types.rs b/src/types.rs index dde10e6..26f9f22 100644 --- a/src/types.rs +++ b/src/types.rs @@ -185,45 +185,45 @@ impl From for RetentionPolicy { } #[derive(Debug, Clone, Copy, PartialEq, Eq)] -pub enum BasinStatus { +pub enum BasinState { Unspecified, Active, Creating, Deleting, } -impl From for api::BasinStatus { - fn from(value: BasinStatus) -> Self { +impl From for api::BasinState { + fn from(value: BasinState) -> Self { match value { - BasinStatus::Unspecified => Self::Unspecified, - BasinStatus::Active => Self::Active, - BasinStatus::Creating => Self::Creating, - BasinStatus::Deleting => Self::Deleting, + BasinState::Unspecified => Self::Unspecified, + BasinState::Active => Self::Active, + BasinState::Creating => Self::Creating, + BasinState::Deleting => Self::Deleting, } } } -impl From for BasinStatus { - fn from(value: api::BasinStatus) -> Self { +impl From for BasinState { + fn from(value: api::BasinState) -> Self { match value { - api::BasinStatus::Unspecified => Self::Unspecified, - api::BasinStatus::Active => Self::Active, - api::BasinStatus::Creating => Self::Creating, - api::BasinStatus::Deleting => Self::Deleting, + api::BasinState::Unspecified => Self::Unspecified, + api::BasinState::Active => Self::Active, + api::BasinState::Creating => Self::Creating, + api::BasinState::Deleting => Self::Deleting, } } } -impl From for i32 { - fn from(value: BasinStatus) -> Self { - api::BasinStatus::from(value).into() +impl From for i32 { + fn from(value: BasinState) -> Self { + api::BasinState::from(value).into() } } -impl TryFrom for BasinStatus { +impl TryFrom for BasinState { type Error = ConvertError; fn try_from(value: i32) -> Result { - api::BasinStatus::try_from(value) + api::BasinState::try_from(value) .map(Into::into) .map_err(|_| "invalid basin status value".into()) } @@ -238,7 +238,7 @@ pub struct BasinMetadata { #[builder(setter(into))] pub cell: String, #[builder(setter(into))] - pub status: BasinStatus, + pub state: BasinState, } impl From for api::BasinMetadata { @@ -247,13 +247,13 @@ impl From for api::BasinMetadata { name, scope, cell, - status, + state, } = value; Self { name, scope, cell, - status: status.into(), + state: state.into(), } } } @@ -265,13 +265,13 @@ impl TryFrom for BasinMetadata { name, scope, cell, - status, + state, } = value; Ok(Self { name, scope, cell, - status: status.try_into()?, + state: state.try_into()?, }) } } @@ -464,6 +464,20 @@ impl From for api::DeleteBasinRequest { } } +#[derive(Debug, Clone, TypedBuilder)] +pub struct GetBasinConfigRequest { + /// Name of the basin. + #[builder(setter(into))] + pub basin: String, +} + +impl From for api::GetBasinConfigRequest { + fn from(value: GetBasinConfigRequest) -> Self { + let GetBasinConfigRequest { basin } = value; + Self { basin } + } +} + #[derive(Debug, Clone, TypedBuilder)] pub struct DeleteStreamRequest { /// Name of the stream to delete. @@ -483,6 +497,9 @@ impl From for api::DeleteStreamRequest { #[derive(Debug, Clone, TypedBuilder)] pub struct ReconfigureBasinRequest { + /// Name of the basin. + #[builder(setter(into))] + pub basin: String, /// Updated configuration. #[builder(setter(strip_option))] pub config: Option, @@ -494,8 +511,13 @@ pub struct ReconfigureBasinRequest { impl TryFrom for api::ReconfigureBasinRequest { type Error = ConvertError; fn try_from(value: ReconfigureBasinRequest) -> Result { - let ReconfigureBasinRequest { config, mask } = value; + let ReconfigureBasinRequest { + basin, + config, + mask, + } = value; Ok(Self { + basin, config: config.map(TryInto::try_into).transpose()?, mask: mask.map(|paths| prost_types::FieldMask { paths }), })