Skip to content

Commit

Permalink
rust: Remove some manual changes after codegen
Browse files Browse the repository at this point in the history
  • Loading branch information
svix-jplatte committed Jan 8, 2025
1 parent d7a851a commit 9785c2f
Show file tree
Hide file tree
Showing 12 changed files with 108 additions and 43 deletions.
3 changes: 3 additions & 0 deletions ChangeLog.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@
* Libs/Kotlin **(Breaking)**: Update `sendExample` to return `MessageOut` (instead of nothing)
* Libs/Kotlin: Fix the parameter names of `Endpoint.get` - `appId` and `endpointId` were swapped
* Libs/Kotlin: Fix a bug in `EventType.list` where `options.order` was not getting honored
* Libs/Rust **(Breaking)**: Add optional `EventTypeDeleteOptions` parameter to `EventType::delete`
* Libs/Rust **(Breaking)**: Add optional `PostOptions` parameter to `Endpoint::recover`,
`Endpoint::rotate_secret`, `Integration::rotate_key` and `MessageAttempt::resend`

## Version 1.56.0
* Skipping versions: we had an issue with our CI that created duplicated Go
Expand Down
5 changes: 5 additions & 0 deletions rust/src/api/authentication.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,11 @@ impl<'a> Authentication<'a> {
.await
}

/// DEPRECATED: Please use `app-portal-access` instead.
///
/// Use this function to get magic links (and authentication codes) for
/// connecting your users to the Consumer Application Portal.
#[deprecated]
pub async fn dashboard_access(
&self,
app_id: String,
Expand Down
8 changes: 8 additions & 0 deletions rust/src/api/endpoint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -200,14 +200,18 @@ impl<'a> Endpoint<'a> {
app_id: String,
endpoint_id: String,
recover_in: RecoverIn,
options: Option<PostOptions>,
) -> Result<RecoverOut> {
let PostOptions { idempotency_key } = options.unwrap_or_default();

crate::request::Request::new(
http1::Method::POST,
"/api/v1/app/{app_id}/endpoint/{endpoint_id}/recover",
)
.with_path_param("app_id", app_id)
.with_path_param("endpoint_id", endpoint_id)
.with_body_param(recover_in)
.with_optional_header_param("idempotency-key", idempotency_key)
.execute(self.cfg)
.await
}
Expand Down Expand Up @@ -264,14 +268,18 @@ impl<'a> Endpoint<'a> {
app_id: String,
endpoint_id: String,
endpoint_secret_rotate_in: EndpointSecretRotateIn,
options: Option<PostOptions>,
) -> Result<()> {
let PostOptions { idempotency_key } = options.unwrap_or_default();

crate::request::Request::new(
http1::Method::POST,
"/api/v1/app/{app_id}/endpoint/{endpoint_id}/secret/rotate",
)
.with_path_param("app_id", app_id)
.with_path_param("endpoint_id", endpoint_id)
.with_body_param(endpoint_secret_rotate_in)
.with_optional_header_param("idempotency-key", idempotency_key)
.returns_nothing()
.execute(self.cfg)
.await
Expand Down
16 changes: 15 additions & 1 deletion rust/src/api/event_type.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,13 @@ pub struct EventTypeListOptions {
pub with_content: Option<bool>,
}

#[derive(Default)]
pub struct EventTypeDeleteOptions {
/// By default event types are archived when "deleted". Passing this to
/// `true` deletes them entirely.
pub expunge: Option<bool>,
}

pub struct EventType<'a> {
cfg: &'a Configuration,
}
Expand Down Expand Up @@ -119,12 +126,19 @@ impl<'a> EventType<'a> {
/// do so after archival. However, new messages can not be sent with it
/// and endpoints can not filter on it. An event type can be unarchived
/// with the [create operation][Self::create].
pub async fn delete(&self, event_type_name: String) -> Result<()> {
pub async fn delete(
&self,
event_type_name: String,
options: Option<EventTypeDeleteOptions>,
) -> Result<()> {
let EventTypeDeleteOptions { expunge } = options.unwrap_or_default();

crate::request::Request::new(
http1::Method::DELETE,
"/api/v1/event-type/{event_type_name}",
)
.with_path_param("event_type_name", event_type_name)
.with_optional_query_param("expunge", expunge)
.returns_nothing()
.execute(self.cfg)
.await
Expand Down
11 changes: 10 additions & 1 deletion rust/src/api/integration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ impl<'a> Integration<'a> {
}

/// Get an integration's key.
#[deprecated]
pub async fn get_key(&self, app_id: String, integ_id: String) -> Result<IntegrationKeyOut> {
crate::request::Request::new(
http1::Method::GET,
Expand All @@ -117,13 +118,21 @@ impl<'a> Integration<'a> {

/// Rotate the integration's key. The previous key will be immediately
/// revoked.
pub async fn rotate_key(&self, app_id: String, integ_id: String) -> Result<IntegrationKeyOut> {
pub async fn rotate_key(
&self,
app_id: String,
integ_id: String,
options: Option<PostOptions>,
) -> Result<IntegrationKeyOut> {
let PostOptions { idempotency_key } = options.unwrap_or_default();

crate::request::Request::new(
http1::Method::POST,
"/api/v1/app/{app_id}/integration/{integ_id}/key/rotate",
)
.with_path_param("app_id", app_id)
.with_path_param("integ_id", integ_id)
.with_optional_header_param("idempotency-key", idempotency_key)
.execute(self.cfg)
.await
}
Expand Down
12 changes: 11 additions & 1 deletion rust/src/api/message_attempt.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use itertools::Itertools;

use super::PostOptions;
use crate::{error::Result, models::*, Configuration};

#[derive(Default)]
Expand Down Expand Up @@ -401,14 +402,23 @@ impl<'a> MessageAttempt<'a> {
}

/// Resend a message to the specified endpoint.
pub async fn resend(&self, app_id: String, msg_id: String, endpoint_id: String) -> Result<()> {
pub async fn resend(
&self,
app_id: String,
msg_id: String,
endpoint_id: String,
options: Option<PostOptions>,
) -> Result<()> {
let PostOptions { idempotency_key } = options.unwrap_or_default();

crate::request::Request::new(
http1::Method::POST,
"/api/v1/app/{app_id}/msg/{msg_id}/endpoint/{endpoint_id}/resend",
)
.with_path_param("app_id", app_id)
.with_path_param("msg_id", msg_id)
.with_path_param("endpoint_id", endpoint_id)
.with_optional_header_param("idempotency-key", idempotency_key)
.returns_nothing()
.execute(self.cfg)
.await
Expand Down
2 changes: 1 addition & 1 deletion rust/src/api/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ pub use self::{
authentication::Authentication,
background_task::{BackgroundTask, BackgroundTaskListOptions},
endpoint::{Endpoint, EndpointGetStatsOptions, EndpointListOptions},
event_type::{EventType, EventTypeListOptions},
event_type::{EventType, EventTypeDeleteOptions, EventTypeListOptions},
integration::{Integration, IntegrationListOptions},
message::{Message, MessageListOptions},
message_attempt::{
Expand Down
7 changes: 1 addition & 6 deletions svix-cli/src/cmds/api/application.rs
Original file line number Diff line number Diff line change
Expand Up @@ -110,12 +110,7 @@ impl ApplicationCommands {
} => {
let resp = client
.application()
.patch(
id,
application_patch
.map(|x| x.into_inner())
.unwrap_or_default(),
)
.patch(id, application_patch.unwrap_or_default().into_inner())
.await?;
crate::json::print_json_output(&resp, color_mode)?;
}
Expand Down
8 changes: 2 additions & 6 deletions svix-cli/src/cmds/api/authentication.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,9 +52,7 @@ impl AuthenticationCommands {
.authentication()
.app_portal_access(
app_id,
app_portal_access_in
.map(|x| x.into_inner())
.unwrap_or_default(),
app_portal_access_in.unwrap_or_default().into_inner(),
post_options.map(Into::into),
)
.await?;
Expand All @@ -69,9 +67,7 @@ impl AuthenticationCommands {
.authentication()
.expire_all(
app_id,
application_token_expire_in
.map(|x| x.into_inner())
.unwrap_or_default(),
application_token_expire_in.unwrap_or_default().into_inner(),
post_options.map(Into::into),
)
.await?;
Expand Down
28 changes: 16 additions & 12 deletions svix-cli/src/cmds/api/endpoint.rs
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,8 @@ pub enum EndpointCommands {
app_id: String,
id: String,
recover_in: JsonOf<RecoverIn>,
#[clap(flatten)]
post_options: Option<PostOptions>,
},
/// Replays messages to the endpoint.
///
Expand All @@ -139,6 +141,8 @@ pub enum EndpointCommands {
app_id: String,
id: String,
endpoint_secret_rotate_in: Option<JsonOf<EndpointSecretRotateIn>>,
#[clap(flatten)]
post_options: Option<PostOptions>,
},
/// Send an example message for an event.
SendExample {
Expand Down Expand Up @@ -217,11 +221,7 @@ impl EndpointCommands {
} => {
let resp = client
.endpoint()
.patch(
app_id,
id,
endpoint_patch.map(|x| x.into_inner()).unwrap_or_default(),
)
.patch(app_id, id, endpoint_patch.unwrap_or_default().into_inner())
.await?;
crate::json::print_json_output(&resp, color_mode)?;
}
Expand Down Expand Up @@ -253,10 +253,16 @@ impl EndpointCommands {
app_id,
id,
recover_in,
post_options,
} => {
let resp = client
.endpoint()
.recover(app_id, id, recover_in.into_inner())
.recover(
app_id,
id,
recover_in.into_inner(),
post_options.map(Into::into),
)
.await?;
crate::json::print_json_output(&resp, color_mode)?;
}
Expand Down Expand Up @@ -285,15 +291,15 @@ impl EndpointCommands {
app_id,
id,
endpoint_secret_rotate_in,
post_options,
} => {
client
.endpoint()
.rotate_secret(
app_id,
id,
endpoint_secret_rotate_in
.map(|x| x.into_inner())
.unwrap_or_default(),
endpoint_secret_rotate_in.unwrap_or_default().into_inner(),
post_options.map(Into::into),
)
.await?;
}
Expand Down Expand Up @@ -339,9 +345,7 @@ impl EndpointCommands {
.transformation_partial_update(
app_id,
id,
endpoint_transformation_in
.map(|x| x.into_inner())
.unwrap_or_default(),
endpoint_transformation_in.unwrap_or_default().into_inner(),
)
.await?;
}
Expand Down
32 changes: 20 additions & 12 deletions svix-cli/src/cmds/api/event_type.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,19 @@ impl From<EventTypeListOptions> for svix::api::EventTypeListOptions {
}
}

#[derive(Args, Clone)]
pub struct EventTypeDeleteOptions {
/// By default event types are archived when "deleted". Passing this to `true` deletes them entirely.
#[arg(long)]
pub expunge: Option<bool>,
}

impl From<EventTypeDeleteOptions> for svix::api::EventTypeDeleteOptions {
fn from(EventTypeDeleteOptions { expunge }: EventTypeDeleteOptions) -> Self {
Self { expunge }
}
}

#[derive(Args)]
#[command(args_conflicts_with_subcommands = true)]
#[command(flatten_help = true)]
Expand Down Expand Up @@ -92,9 +105,8 @@ pub enum EventTypeCommands {
/// [create operation](#operation/create_event_type_api_v1_event_type__post).
Delete {
event_type_name: String,
// FIXME: need to get the options happening in the SDK for this
// #[clap(flatten)]
// options: EventTypeDeleteOptions,
#[clap(flatten)]
options: EventTypeDeleteOptions,
},
/// Partially update an event type.
Patch {
Expand Down Expand Up @@ -132,8 +144,8 @@ impl EventTypeCommands {
.event_type()
.import_openapi(
event_type_import_open_api_in
.map(|x| x.into_inner())
.unwrap_or_default(),
.unwrap_or_default()
.into_inner(),
post_options.map(Into::into),
)
.await?;
Expand All @@ -155,15 +167,11 @@ impl EventTypeCommands {
}
Self::Delete {
event_type_name,
// FIXME: need to get the options happening in the SDK for this
// options,
options,
} => {
client
.event_type()
.delete(
event_type_name,
// Some(options.into())
)
.delete(event_type_name, Some(options.into()))
.await?;
}
Self::Patch {
Expand All @@ -174,7 +182,7 @@ impl EventTypeCommands {
.event_type()
.patch(
event_type_name,
event_type_patch.map(|x| x.into_inner()).unwrap_or_default(),
event_type_patch.unwrap_or_default().into_inner(),
)
.await?;
crate::json::print_json_output(&resp, color_mode)?;
Expand Down
19 changes: 16 additions & 3 deletions svix-cli/src/cmds/api/integration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,12 @@ pub enum IntegrationCommands {
/// Get an integration's key.
GetKey { app_id: String, id: String },
/// Rotate the integration's key. The previous key will be immediately revoked.
RotateKey { app_id: String, id: String },
RotateKey {
app_id: String,
id: String,
#[clap(flatten)]
post_options: Option<PostOptions>,
},
}

impl IntegrationCommands {
Expand Down Expand Up @@ -120,11 +125,19 @@ impl IntegrationCommands {
client.integration().delete(app_id, id).await?;
}
Self::GetKey { app_id, id } => {
#[allow(deprecated)]
let resp = client.integration().get_key(app_id, id).await?;
crate::json::print_json_output(&resp, color_mode)?;
}
Self::RotateKey { app_id, id } => {
let resp = client.integration().rotate_key(app_id, id).await?;
Self::RotateKey {
app_id,
id,
post_options,
} => {
let resp = client
.integration()
.rotate_key(app_id, id, post_options.map(Into::into))
.await?;
crate::json::print_json_output(&resp, color_mode)?;
}
}
Expand Down

0 comments on commit 9785c2f

Please sign in to comment.