Skip to content

Commit

Permalink
chore: Update proto (#93)
Browse files Browse the repository at this point in the history
Signed-off-by: Vaibhav Rabber <vaibhav@s2.dev>
  • Loading branch information
vrongmeal authored Dec 4, 2024
1 parent 53a6bac commit fdfa539
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 53 deletions.
2 changes: 1 addition & 1 deletion proto
Submodule proto updated 2 files
+3 −1 buf.yaml
+12 −7 s2/v1alpha/s2.proto
4 changes: 2 additions & 2 deletions src/service/account.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ impl ServiceRequest for CreateBasinServiceRequest {
const IDEMPOTENCY_LEVEL: IdempotencyLevel = IdempotencyLevel::Idempotent;

fn prepare_request(&mut self) -> Result<tonic::Request<Self::ApiRequest>, types::ConvertError> {
let req: api::CreateBasinRequest = self.req.clone().try_into()?;
let req: api::CreateBasinRequest = self.req.clone().into();
let mut tonic_req = req.into_request();
add_s2_request_token_header(tonic_req.metadata_mut(), &self.s2_request_token)?;
Ok(tonic_req)
Expand Down Expand Up @@ -192,7 +192,7 @@ impl ServiceRequest for ReconfigureBasinServiceRequest {
const IDEMPOTENCY_LEVEL: IdempotencyLevel = IdempotencyLevel::Idempotent;

fn prepare_request(&mut self) -> Result<tonic::Request<Self::ApiRequest>, types::ConvertError> {
let req: api::ReconfigureBasinRequest = self.req.clone().try_into()?;
let req: api::ReconfigureBasinRequest = self.req.clone().into();
Ok(req.into_request())
}

Expand Down
4 changes: 2 additions & 2 deletions src/service/basin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ impl ServiceRequest for CreateStreamServiceRequest {
const IDEMPOTENCY_LEVEL: IdempotencyLevel = IdempotencyLevel::Idempotent;

fn prepare_request(&mut self) -> Result<tonic::Request<Self::ApiRequest>, types::ConvertError> {
let req: api::CreateStreamRequest = self.req.clone().try_into()?;
let req: api::CreateStreamRequest = self.req.clone().into();
let mut tonic_req = req.into_request();
add_s2_request_token_header(tonic_req.metadata_mut(), &self.s2_request_token)?;
Ok(tonic_req)
Expand Down Expand Up @@ -195,7 +195,7 @@ impl ServiceRequest for ReconfigureStreamServiceRequest {
const IDEMPOTENCY_LEVEL: IdempotencyLevel = IdempotencyLevel::IdempotencyUnknown;

fn prepare_request(&mut self) -> Result<tonic::Request<Self::ApiRequest>, types::ConvertError> {
let req: api::ReconfigureStreamRequest = self.req.clone().try_into()?;
let req: api::ReconfigureStreamRequest = self.req.clone().into();
Ok(req.into_request())
}

Expand Down
82 changes: 34 additions & 48 deletions src/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,15 +73,14 @@ impl CreateBasinRequest {
}
}

impl TryFrom<CreateBasinRequest> for api::CreateBasinRequest {
type Error = ConvertError;
fn try_from(value: CreateBasinRequest) -> Result<Self, Self::Error> {
impl From<CreateBasinRequest> for api::CreateBasinRequest {
fn from(value: CreateBasinRequest) -> Self {
let CreateBasinRequest { basin, config } = value;
Ok(Self {
Self {
basin: basin.0,
config: config.map(TryInto::try_into).transpose()?,
config: config.map(Into::into),
assignment: None,
})
}
}
}

Expand All @@ -104,15 +103,14 @@ impl BasinConfig {
}
}

impl TryFrom<BasinConfig> for api::BasinConfig {
type Error = ConvertError;
fn try_from(value: BasinConfig) -> Result<Self, Self::Error> {
impl From<BasinConfig> for api::BasinConfig {
fn from(value: BasinConfig) -> Self {
let BasinConfig {
default_stream_config,
} = value;
Ok(Self {
default_stream_config: default_stream_config.map(TryInto::try_into).transpose()?,
})
Self {
default_stream_config: default_stream_config.map(Into::into),
}
}
}

Expand Down Expand Up @@ -156,17 +154,16 @@ impl StreamConfig {
}
}

impl TryFrom<StreamConfig> for api::StreamConfig {
type Error = ConvertError;
fn try_from(value: StreamConfig) -> Result<Self, Self::Error> {
impl From<StreamConfig> for api::StreamConfig {
fn from(value: StreamConfig) -> Self {
let StreamConfig {
storage_class,
retention_policy,
} = value;
Ok(Self {
Self {
storage_class: storage_class.into(),
retention_policy: retention_policy.map(TryInto::try_into).transpose()?,
})
retention_policy: retention_policy.map(Into::into),
}
}
}

Expand Down Expand Up @@ -248,26 +245,18 @@ pub enum RetentionPolicy {
Age(Duration),
}

impl TryFrom<RetentionPolicy> for api::stream_config::RetentionPolicy {
type Error = ConvertError;
fn try_from(value: RetentionPolicy) -> Result<Self, Self::Error> {
impl From<RetentionPolicy> for api::stream_config::RetentionPolicy {
fn from(value: RetentionPolicy) -> Self {
match value {
RetentionPolicy::Age(duration) => Ok(Self::AgeMillis(
duration
.as_millis()
.try_into()
.map_err(|_| "age duration overflow in milliseconds")?,
)),
RetentionPolicy::Age(duration) => Self::Age(duration.as_secs()),
}
}
}

impl From<api::stream_config::RetentionPolicy> for RetentionPolicy {
fn from(value: api::stream_config::RetentionPolicy) -> Self {
match value {
api::stream_config::RetentionPolicy::AgeMillis(millis) => {
Self::Age(Duration::from_millis(millis))
}
api::stream_config::RetentionPolicy::Age(secs) => Self::Age(Duration::from_secs(secs)),
}
}
}
Expand Down Expand Up @@ -515,14 +504,13 @@ impl CreateStreamRequest {
}
}

impl TryFrom<CreateStreamRequest> for api::CreateStreamRequest {
type Error = ConvertError;
fn try_from(value: CreateStreamRequest) -> Result<Self, Self::Error> {
impl From<CreateStreamRequest> for api::CreateStreamRequest {
fn from(value: CreateStreamRequest) -> Self {
let CreateStreamRequest { stream, config } = value;
Ok(Self {
Self {
stream,
config: config.map(TryInto::try_into).transpose()?,
})
config: config.map(Into::into),
}
}
}

Expand Down Expand Up @@ -693,19 +681,18 @@ impl ReconfigureBasinRequest {
}
}

impl TryFrom<ReconfigureBasinRequest> for api::ReconfigureBasinRequest {
type Error = ConvertError;
fn try_from(value: ReconfigureBasinRequest) -> Result<Self, Self::Error> {
impl From<ReconfigureBasinRequest> for api::ReconfigureBasinRequest {
fn from(value: ReconfigureBasinRequest) -> Self {
let ReconfigureBasinRequest {
basin,
config,
mask,
} = value;
Ok(Self {
Self {
basin: basin.0,
config: config.map(TryInto::try_into).transpose()?,
config: config.map(Into::into),
mask: mask.map(|paths| prost_types::FieldMask { paths }),
})
}
}
}

Expand Down Expand Up @@ -742,19 +729,18 @@ impl ReconfigureStreamRequest {
}
}

impl TryFrom<ReconfigureStreamRequest> for api::ReconfigureStreamRequest {
type Error = ConvertError;
fn try_from(value: ReconfigureStreamRequest) -> Result<Self, Self::Error> {
impl From<ReconfigureStreamRequest> for api::ReconfigureStreamRequest {
fn from(value: ReconfigureStreamRequest) -> Self {
let ReconfigureStreamRequest {
stream,
config,
mask,
} = value;
Ok(Self {
Self {
stream,
config: config.map(TryInto::try_into).transpose()?,
config: config.map(Into::into),
mask: mask.map(|paths| prost_types::FieldMask { paths }),
})
}
}
}

Expand Down

0 comments on commit fdfa539

Please sign in to comment.