Skip to content
Open
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
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
[package]
name = "famedly-zitadel-rust-client"
description = "HTTP client for Zitadel IdP built by Famedly"
version = "0.9.3"
version = "0.10.0"
authors = []
edition = "2024"
resolver = "2"
Expand Down
51 changes: 23 additions & 28 deletions src/v2/actions/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,9 @@ impl Zitadel {
/// [Create Target](https://zitadel.com/docs/apis/resources/action_service_v2/action-service-create-target)
pub async fn create_target(
&self,
req: &V2betaCreateTargetRequest,
) -> Result<V2betaCreateTargetResponse> {
let request =
self.client.post(self.make_url("v2beta/actions/targets")?).json(req).build()?;
req: &V2CreateTargetRequest,
) -> Result<V2CreateTargetResponse> {
let request = self.client.post(self.make_url("v2/actions/targets")?).json(req).build()?;
Ok(self.send_request(request).await?)
}

Expand All @@ -31,44 +30,41 @@ impl Zitadel {
&self,
id: &str,
req: &ActionServiceUpdateTargetBody,
) -> Result<V2betaUpdateTargetResponse> {
let request = self
.client
.post(self.make_url("v2beta/actions/targets/")?.join(id)?)
.json(req)
.build()?;
) -> Result<V2UpdateTargetResponse> {
let request =
self.client.post(self.make_url("v2/actions/targets/")?.join(id)?).json(req).build()?;
Ok(self.send_request(request).await?)
}

/// [Delete Target](https://zitadel.com/docs/apis/resources/action_service_v2/action-service-delete-target)
pub async fn delete_target(&self, id: &str) -> Result<V2betaDeleteTargetResponse> {
pub async fn delete_target(&self, id: &str) -> Result<V2DeleteTargetResponse> {
let request =
self.client.delete(self.make_url("v2beta/actions/targets/")?.join(id)?).build()?;
self.client.delete(self.make_url("v2/actions/targets/")?.join(id)?).build()?;
Ok(self.send_request(request).await?)
}

/// [List targets](https://zitadel.com/docs/apis/resources/action_service_v2/action-service-list-targets)
pub fn list_targets<'a>(
&'a self,
params: &'a Option<PaginationParams>,
sort_by: &'a Option<V2betaTargetFieldName>,
filters: &'a Option<Vec<V2betaTargetSearchFilter>>,
) -> impl Stream<Item = Result<V2betaTarget>> + Send {
sort_by: &'a Option<V2TargetFieldName>,
filters: &'a Option<Vec<V2TargetSearchFilter>>,
) -> impl Stream<Item = Result<V2Target>> + Send {
// TODO: factor out pagination. This endpoint is an exception because all others
// return `result` field, but this one returns `targets`. So it's a quick fix.
use crate::v2::pagination::PaginationRequest;
#[derive(Debug, Clone, serde::Deserialize)]
struct Response {
#[serde(default)]
targets: Vec<V2betaTarget>,
targets: Vec<V2Target>,
}
futures::stream::try_unfold((0, VecDeque::new()), async move |(mut page, mut buffered)| {
if let Some(x) = buffered.pop_front() {
return Ok(Some((x, (page, buffered))));
}

let url = self.make_url("v2beta/actions/targets/search")?;
let body: V2betaListTargetsRequest =
let url = self.make_url("v2/actions/targets/search")?;
let body: V2ListTargetsRequest =
(params.clone(), sort_by.clone(), filters.clone()).to_paginated_request(page);
let req = self.client.post(url.clone()).json(&body).build()?;
buffered = self.send_request::<Response>(req).await?.targets.into();
Expand All @@ -84,20 +80,19 @@ impl Zitadel {
/// [Set Execution | ZITADEL Docs](https://zitadel.com/docs/apis/resources/action_service_v2/action-service-set-execution)
pub async fn set_execution(
&self,
req: &V2betaSetExecutionRequest,
) -> Result<V2betaSetExecutionResponse> {
let request =
self.client.put(self.make_url("v2beta/actions/executions")?).json(req).build()?;
req: &V2SetExecutionRequest,
) -> Result<V2SetExecutionResponse> {
let request = self.client.put(self.make_url("v2/actions/executions")?).json(req).build()?;
Ok(self.send_request(request).await?)
}

/// [List Executions | ZITADEL Docs](https://zitadel.com/docs/apis/resources/action_service_v2/action-service-list-executions)
pub fn list_executions<'a>(
&'a self,
params: &'a Option<PaginationParams>,
sort_by: &'a Option<V2betaExecutionFieldName>,
filters: &'a Option<Vec<V2betaExecutionSearchFilter>>,
) -> impl Stream<Item = Result<V2betaExecution>> + Send + use<'a> {
sort_by: &'a Option<V2ExecutionFieldName>,
filters: &'a Option<Vec<V2ExecutionSearchFilter>>,
) -> impl Stream<Item = Result<V2Execution>> + Send + use<'a> {
// TODO: factor out pagination. This endpoint is an exception because all others
// accepts pagination parameters in the json body, this one as query params
use crate::v2::pagination::PaginationRequest;
Expand All @@ -107,12 +102,12 @@ impl Zitadel {
return Ok(Some((x, (page, buffered))));
}

let url = self.make_url("v2beta/actions/executions/search")?;
let body: V2betaListExecutionsRequest =
let url = self.make_url("v2/actions/executions/search")?;
let body: V2ListExecutionsRequest =
(params.clone(), sort_by.clone(), filters.clone()).to_paginated_request(page);
let req = self.client.post(url.clone()).json(&body).build()?;
buffered = self
.send_request::<V2betaListExecutionsResponse>(req)
.send_request::<V2ListExecutionsResponse>(req)
.await?
.executions
.unwrap_or_default()
Expand Down
53 changes: 38 additions & 15 deletions src/v2/actions/models/action_service_update_target_body.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,15 @@ pub struct ActionServiceUpdateTargetBody {
/// Wait for response but response body is ignored, status is checked, call
/// is sent as post.
#[serde(rename = "restWebhook")]
rest_webhook: Option<super::V2betaRestWebhook>,
rest_webhook: Option<super::V2RestWebhook>,
/// Wait for response and response body is used, status is checked, call is
/// sent as post.
#[serde(rename = "restCall")]
rest_call: Option<super::V2betaRestCall>,
rest_call: Option<super::V2RestCall>,
/// Call is executed in parallel to others, ZITADEL does not wait until the
/// call is finished. The state is ignored, call is sent as post.
#[serde(rename = "restAsync")]
rest_async: Option<super::V2betaRestAsync>,
rest_async: Option<super::V2RestAsync>,
/// Timeout defines the duration until ZITADEL cancels the execution. If the
/// target doesn't respond before this timeout expires, then the connection
/// is closed and the action fails. Depending on the target type and
Expand All @@ -52,6 +52,11 @@ pub struct ActionServiceUpdateTargetBody {
/// longer expirations in the future.
#[serde(rename = "expirationSigningKey")]
expiration_signing_key: Option<String>,
/// How the payload is formatted and secured when sent to the target.
/// Defaults to `PAYLOAD_TYPE_JSON` (plain JSON with a signature header).
/// Use `PAYLOAD_TYPE_JWT` for a signed JWT body.
#[serde(rename = "payloadType", skip_serializing_if = "Option::is_none")]
payload_type: Option<super::V2PayloadType>,
}

impl ActionServiceUpdateTargetBody {
Expand All @@ -64,9 +69,30 @@ impl ActionServiceUpdateTargetBody {
timeout: None,
endpoint: None,
expiration_signing_key: None,
payload_type: None,
}
}

pub fn set_payload_type(&mut self, payload_type: super::V2PayloadType) {
self.payload_type = Some(payload_type);
}

pub fn with_payload_type(
mut self,
payload_type: super::V2PayloadType,
) -> ActionServiceUpdateTargetBody {
self.payload_type = Some(payload_type);
self
}

pub fn payload_type(&self) -> Option<&super::V2PayloadType> {
self.payload_type.as_ref()
}

pub fn reset_payload_type(&mut self) {
self.payload_type = None;
}

pub fn set_name(&mut self, name: String) {
self.name = Some(name);
}
Expand All @@ -84,59 +110,56 @@ impl ActionServiceUpdateTargetBody {
self.name = None;
}

pub fn set_rest_webhook(&mut self, rest_webhook: super::V2betaRestWebhook) {
pub fn set_rest_webhook(&mut self, rest_webhook: super::V2RestWebhook) {
self.rest_webhook = Some(rest_webhook);
}

pub fn with_rest_webhook(
mut self,
rest_webhook: super::V2betaRestWebhook,
rest_webhook: super::V2RestWebhook,
) -> ActionServiceUpdateTargetBody {
self.rest_webhook = Some(rest_webhook);
self
}

pub fn rest_webhook(&self) -> Option<&super::V2betaRestWebhook> {
pub fn rest_webhook(&self) -> Option<&super::V2RestWebhook> {
self.rest_webhook.as_ref()
}

pub fn reset_rest_webhook(&mut self) {
self.rest_webhook = None;
}

pub fn set_rest_call(&mut self, rest_call: super::V2betaRestCall) {
pub fn set_rest_call(&mut self, rest_call: super::V2RestCall) {
self.rest_call = Some(rest_call);
}

pub fn with_rest_call(
mut self,
rest_call: super::V2betaRestCall,
) -> ActionServiceUpdateTargetBody {
pub fn with_rest_call(mut self, rest_call: super::V2RestCall) -> ActionServiceUpdateTargetBody {
self.rest_call = Some(rest_call);
self
}

pub fn rest_call(&self) -> Option<&super::V2betaRestCall> {
pub fn rest_call(&self) -> Option<&super::V2RestCall> {
self.rest_call.as_ref()
}

pub fn reset_rest_call(&mut self) {
self.rest_call = None;
}

pub fn set_rest_async(&mut self, rest_async: super::V2betaRestAsync) {
pub fn set_rest_async(&mut self, rest_async: super::V2RestAsync) {
self.rest_async = Some(rest_async);
}

pub fn with_rest_async(
mut self,
rest_async: super::V2betaRestAsync,
rest_async: super::V2RestAsync,
) -> ActionServiceUpdateTargetBody {
self.rest_async = Some(rest_async);
self
}

pub fn rest_async(&self) -> Option<&super::V2betaRestAsync> {
pub fn rest_async(&self) -> Option<&super::V2RestAsync> {
self.rest_async.as_ref()
}

Expand Down
Loading
Loading