use super::{ContentType, Error, configuration};
use crate::clients::rest::{apis::ResponseContent, models};
use reqwest;
use serde::{Deserialize, Serialize, de::Error as _};
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum CronWorkflowTriggerCreateError {
Status400(models::V1TaskGet400Response),
Status429(models::V1TaskGet400Response),
Status403(models::V1TaskGet400Response),
Status404(models::V1TaskGet400Response),
UnknownValue(serde_json::Value),
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum ScheduledWorkflowRunCreateError {
Status400(models::V1TaskGet400Response),
Status429(models::V1TaskGet400Response),
Status403(models::V1TaskGet400Response),
Status404(models::V1TaskGet400Response),
UnknownValue(serde_json::Value),
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum WorkflowRunCancelError {
Status400(models::V1TaskGet400Response),
Status403(models::V1TaskGet400Response),
UnknownValue(serde_json::Value),
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum WorkflowRunCreateError {
Status400(models::V1TaskGet400Response),
Status429(models::V1TaskGet400Response),
Status403(models::V1TaskGet400Response),
Status404(models::V1TaskGet400Response),
UnknownValue(serde_json::Value),
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum WorkflowRunGetInputError {
Status400(models::V1TaskGet400Response),
Status403(models::V1TaskGet400Response),
Status404(models::V1TaskGet400Response),
UnknownValue(serde_json::Value),
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(untagged)]
pub enum WorkflowRunUpdateReplayError {
Status400(models::V1TaskGet400Response),
Status403(models::V1TaskGet400Response),
Status429(models::V1TaskGet400Response),
UnknownValue(serde_json::Value),
}
pub async fn cron_workflow_trigger_create(
configuration: &configuration::Configuration,
tenant: &str,
workflow: &str,
cron_workflow_trigger_create_request: models::CronWorkflowTriggerCreateRequest,
) -> Result<models::CronWorkflowTriggerCreate200Response, Error<CronWorkflowTriggerCreateError>> {
let p_tenant = tenant;
let p_workflow = workflow;
let p_cron_workflow_trigger_create_request = cron_workflow_trigger_create_request;
let uri_str = format!(
"{}/api/v1/tenants/{tenant}/workflows/{workflow}/crons",
configuration.base_path,
tenant = crate::clients::rest::apis::urlencode(p_tenant),
workflow = crate::clients::rest::apis::urlencode(p_workflow)
);
let mut req_builder = configuration
.client
.request(reqwest::Method::POST, &uri_str);
if let Some(ref user_agent) = configuration.user_agent {
req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
}
if let Some(ref token) = configuration.bearer_access_token {
req_builder = req_builder.bearer_auth(token.to_owned());
};
req_builder = req_builder.json(&p_cron_workflow_trigger_create_request);
let req = req_builder.build()?;
let resp = configuration.client.execute(req).await?;
let status = resp.status();
let content_type = resp
.headers()
.get("content-type")
.and_then(|v| v.to_str().ok())
.unwrap_or("application/octet-stream");
let content_type = super::ContentType::from(content_type);
if !status.is_client_error() && !status.is_server_error() {
let content = resp.text().await?;
match content_type {
ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
ContentType::Text => {
return Err(Error::from(serde_json::Error::custom(
"Received `text/plain` content type response that cannot be converted to `models::CronWorkflowTriggerCreate200Response`",
)));
}
ContentType::Unsupported(unknown_type) => {
return Err(Error::from(serde_json::Error::custom(format!(
"Received `{unknown_type}` content type response that cannot be converted to `models::CronWorkflowTriggerCreate200Response`"
))));
}
}
} else {
let content = resp.text().await?;
let entity: Option<CronWorkflowTriggerCreateError> = serde_json::from_str(&content).ok();
Err(Error::ResponseError(ResponseContent {
status,
content,
entity,
}))
}
}
pub async fn scheduled_workflow_run_create(
configuration: &configuration::Configuration,
tenant: &str,
workflow: &str,
scheduled_workflow_run_create_request: models::ScheduledWorkflowRunCreateRequest,
) -> Result<models::ScheduledWorkflowRunCreate200Response, Error<ScheduledWorkflowRunCreateError>> {
let p_tenant = tenant;
let p_workflow = workflow;
let p_scheduled_workflow_run_create_request = scheduled_workflow_run_create_request;
let uri_str = format!(
"{}/api/v1/tenants/{tenant}/workflows/{workflow}/scheduled",
configuration.base_path,
tenant = crate::clients::rest::apis::urlencode(p_tenant),
workflow = crate::clients::rest::apis::urlencode(p_workflow)
);
let mut req_builder = configuration
.client
.request(reqwest::Method::POST, &uri_str);
if let Some(ref user_agent) = configuration.user_agent {
req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
}
if let Some(ref token) = configuration.bearer_access_token {
req_builder = req_builder.bearer_auth(token.to_owned());
};
req_builder = req_builder.json(&p_scheduled_workflow_run_create_request);
let req = req_builder.build()?;
let resp = configuration.client.execute(req).await?;
let status = resp.status();
let content_type = resp
.headers()
.get("content-type")
.and_then(|v| v.to_str().ok())
.unwrap_or("application/octet-stream");
let content_type = super::ContentType::from(content_type);
if !status.is_client_error() && !status.is_server_error() {
let content = resp.text().await?;
match content_type {
ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
ContentType::Text => {
return Err(Error::from(serde_json::Error::custom(
"Received `text/plain` content type response that cannot be converted to `models::ScheduledWorkflowRunCreate200Response`",
)));
}
ContentType::Unsupported(unknown_type) => {
return Err(Error::from(serde_json::Error::custom(format!(
"Received `{unknown_type}` content type response that cannot be converted to `models::ScheduledWorkflowRunCreate200Response`"
))));
}
}
} else {
let content = resp.text().await?;
let entity: Option<ScheduledWorkflowRunCreateError> = serde_json::from_str(&content).ok();
Err(Error::ResponseError(ResponseContent {
status,
content,
entity,
}))
}
}
pub async fn workflow_run_cancel(
configuration: &configuration::Configuration,
tenant: &str,
workflow_run_cancel_request: models::WorkflowRunCancelRequest,
) -> Result<models::EventUpdateCancel200Response, Error<WorkflowRunCancelError>> {
let p_tenant = tenant;
let p_workflow_run_cancel_request = workflow_run_cancel_request;
let uri_str = format!(
"{}/api/v1/tenants/{tenant}/workflows/cancel",
configuration.base_path,
tenant = crate::clients::rest::apis::urlencode(p_tenant)
);
let mut req_builder = configuration
.client
.request(reqwest::Method::POST, &uri_str);
if let Some(ref user_agent) = configuration.user_agent {
req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
}
if let Some(ref token) = configuration.bearer_access_token {
req_builder = req_builder.bearer_auth(token.to_owned());
};
req_builder = req_builder.json(&p_workflow_run_cancel_request);
let req = req_builder.build()?;
let resp = configuration.client.execute(req).await?;
let status = resp.status();
let content_type = resp
.headers()
.get("content-type")
.and_then(|v| v.to_str().ok())
.unwrap_or("application/octet-stream");
let content_type = super::ContentType::from(content_type);
if !status.is_client_error() && !status.is_server_error() {
let content = resp.text().await?;
match content_type {
ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
ContentType::Text => {
return Err(Error::from(serde_json::Error::custom(
"Received `text/plain` content type response that cannot be converted to `models::EventUpdateCancel200Response`",
)));
}
ContentType::Unsupported(unknown_type) => {
return Err(Error::from(serde_json::Error::custom(format!(
"Received `{unknown_type}` content type response that cannot be converted to `models::EventUpdateCancel200Response`"
))));
}
}
} else {
let content = resp.text().await?;
let entity: Option<WorkflowRunCancelError> = serde_json::from_str(&content).ok();
Err(Error::ResponseError(ResponseContent {
status,
content,
entity,
}))
}
}
pub async fn workflow_run_create(
configuration: &configuration::Configuration,
workflow: &str,
workflow_run_create_request: models::WorkflowRunCreateRequest,
version: Option<&str>,
) -> Result<models::WorkflowRunCreate200Response, Error<WorkflowRunCreateError>> {
let p_workflow = workflow;
let p_workflow_run_create_request = workflow_run_create_request;
let p_version = version;
let uri_str = format!(
"{}/api/v1/workflows/{workflow}/trigger",
configuration.base_path,
workflow = crate::clients::rest::apis::urlencode(p_workflow)
);
let mut req_builder = configuration
.client
.request(reqwest::Method::POST, &uri_str);
if let Some(ref param_value) = p_version {
req_builder = req_builder.query(&[("version", ¶m_value.to_string())]);
}
if let Some(ref user_agent) = configuration.user_agent {
req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
}
if let Some(ref token) = configuration.bearer_access_token {
req_builder = req_builder.bearer_auth(token.to_owned());
};
req_builder = req_builder.json(&p_workflow_run_create_request);
let req = req_builder.build()?;
let resp = configuration.client.execute(req).await?;
let status = resp.status();
let content_type = resp
.headers()
.get("content-type")
.and_then(|v| v.to_str().ok())
.unwrap_or("application/octet-stream");
let content_type = super::ContentType::from(content_type);
if !status.is_client_error() && !status.is_server_error() {
let content = resp.text().await?;
match content_type {
ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
ContentType::Text => {
return Err(Error::from(serde_json::Error::custom(
"Received `text/plain` content type response that cannot be converted to `models::WorkflowRunCreate200Response`",
)));
}
ContentType::Unsupported(unknown_type) => {
return Err(Error::from(serde_json::Error::custom(format!(
"Received `{unknown_type}` content type response that cannot be converted to `models::WorkflowRunCreate200Response`"
))));
}
}
} else {
let content = resp.text().await?;
let entity: Option<WorkflowRunCreateError> = serde_json::from_str(&content).ok();
Err(Error::ResponseError(ResponseContent {
status,
content,
entity,
}))
}
}
pub async fn workflow_run_get_input(
configuration: &configuration::Configuration,
tenant: &str,
workflow_run: &str,
) -> Result<std::collections::HashMap<String, serde_json::Value>, Error<WorkflowRunGetInputError>> {
let p_tenant = tenant;
let p_workflow_run = workflow_run;
let uri_str = format!(
"{}/api/v1/tenants/{tenant}/workflow-runs/{workflow_run}/input",
configuration.base_path,
tenant = crate::clients::rest::apis::urlencode(p_tenant),
workflow_run = crate::clients::rest::apis::urlencode(p_workflow_run)
);
let mut req_builder = configuration.client.request(reqwest::Method::GET, &uri_str);
if let Some(ref user_agent) = configuration.user_agent {
req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
}
if let Some(ref token) = configuration.bearer_access_token {
req_builder = req_builder.bearer_auth(token.to_owned());
};
let req = req_builder.build()?;
let resp = configuration.client.execute(req).await?;
let status = resp.status();
let content_type = resp
.headers()
.get("content-type")
.and_then(|v| v.to_str().ok())
.unwrap_or("application/octet-stream");
let content_type = super::ContentType::from(content_type);
if !status.is_client_error() && !status.is_server_error() {
let content = resp.text().await?;
match content_type {
ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
ContentType::Text => {
return Err(Error::from(serde_json::Error::custom(
"Received `text/plain` content type response that cannot be converted to `std::collections::HashMap<String, serde_json::Value>`",
)));
}
ContentType::Unsupported(unknown_type) => {
return Err(Error::from(serde_json::Error::custom(format!(
"Received `{unknown_type}` content type response that cannot be converted to `std::collections::HashMap<String, serde_json::Value>`"
))));
}
}
} else {
let content = resp.text().await?;
let entity: Option<WorkflowRunGetInputError> = serde_json::from_str(&content).ok();
Err(Error::ResponseError(ResponseContent {
status,
content,
entity,
}))
}
}
pub async fn workflow_run_update_replay(
configuration: &configuration::Configuration,
tenant: &str,
workflow_run_update_replay_request: models::WorkflowRunUpdateReplayRequest,
) -> Result<models::WorkflowRunUpdateReplay200Response, Error<WorkflowRunUpdateReplayError>> {
let p_tenant = tenant;
let p_workflow_run_update_replay_request = workflow_run_update_replay_request;
let uri_str = format!(
"{}/api/v1/tenants/{tenant}/workflow-runs/replay",
configuration.base_path,
tenant = crate::clients::rest::apis::urlencode(p_tenant)
);
let mut req_builder = configuration
.client
.request(reqwest::Method::POST, &uri_str);
if let Some(ref user_agent) = configuration.user_agent {
req_builder = req_builder.header(reqwest::header::USER_AGENT, user_agent.clone());
}
if let Some(ref token) = configuration.bearer_access_token {
req_builder = req_builder.bearer_auth(token.to_owned());
};
req_builder = req_builder.json(&p_workflow_run_update_replay_request);
let req = req_builder.build()?;
let resp = configuration.client.execute(req).await?;
let status = resp.status();
let content_type = resp
.headers()
.get("content-type")
.and_then(|v| v.to_str().ok())
.unwrap_or("application/octet-stream");
let content_type = super::ContentType::from(content_type);
if !status.is_client_error() && !status.is_server_error() {
let content = resp.text().await?;
match content_type {
ContentType::Json => serde_json::from_str(&content).map_err(Error::from),
ContentType::Text => {
return Err(Error::from(serde_json::Error::custom(
"Received `text/plain` content type response that cannot be converted to `models::WorkflowRunUpdateReplay200Response`",
)));
}
ContentType::Unsupported(unknown_type) => {
return Err(Error::from(serde_json::Error::custom(format!(
"Received `{unknown_type}` content type response that cannot be converted to `models::WorkflowRunUpdateReplay200Response`"
))));
}
}
} else {
let content = resp.text().await?;
let entity: Option<WorkflowRunUpdateReplayError> = serde_json::from_str(&content).ok();
Err(Error::ResponseError(ResponseContent {
status,
content,
entity,
}))
}
}