#[allow(unused_imports)] use progenitor_client::{encode_path, RequestBuilderExt}; pub use progenitor_client::{ByteStream, Error, ResponseValue}; #[allow(unused_imports)] use reqwest::header::{HeaderMap, HeaderValue}; pub mod types { use serde::{Deserialize, Serialize}; #[allow(unused_imports)] use std::convert::TryFrom; ///Task /// ///
JSON schema /// /// ```json ///{ /// "type": "object", /// "required": [ /// "id", /// "name", /// "output_rules", /// "script", /// "state" /// ], /// "properties": { /// "id": { /// "type": "string" /// }, /// "name": { /// "type": "string" /// }, /// "output_rules": { /// "type": "array", /// "items": { /// "type": "string" /// } /// }, /// "script": { /// "type": "string" /// }, /// "state": { /// "type": "string" /// } /// } ///} /// ``` ///
#[derive(Clone, Debug, Deserialize, Serialize)] pub struct Task { pub id: String, pub name: String, pub output_rules: Vec, pub script: String, pub state: String, } impl From<&Task> for Task { fn from(value: &Task) -> Self { value.clone() } } ///TaskEvent /// ///
JSON schema /// /// ```json ///{ /// "type": "object", /// "required": [ /// "payload", /// "seq", /// "stream", /// "time" /// ], /// "properties": { /// "payload": { /// "type": "string" /// }, /// "seq": { /// "type": "integer", /// "format": "uint", /// "minimum": 0.0 /// }, /// "stream": { /// "type": "string" /// }, /// "time": { /// "type": "string", /// "format": "date-time" /// } /// } ///} /// ``` ///
#[derive(Clone, Debug, Deserialize, Serialize)] pub struct TaskEvent { pub payload: String, pub seq: u32, pub stream: String, pub time: chrono::DateTime, } impl From<&TaskEvent> for TaskEvent { fn from(value: &TaskEvent) -> Self { value.clone() } } ///TaskOutput /// ///
JSON schema /// /// ```json ///{ /// "type": "object", /// "required": [ /// "id", /// "path", /// "size" /// ], /// "properties": { /// "id": { /// "type": "string" /// }, /// "path": { /// "type": "string" /// }, /// "size": { /// "type": "integer", /// "format": "uint64", /// "minimum": 0.0 /// } /// } ///} /// ``` ///
#[derive(Clone, Debug, Deserialize, Serialize)] pub struct TaskOutput { pub id: String, pub path: String, pub size: u64, } impl From<&TaskOutput> for TaskOutput { fn from(value: &TaskOutput) -> Self { value.clone() } } ///TaskSubmit /// ///
JSON schema /// /// ```json ///{ /// "type": "object", /// "required": [ /// "name", /// "script" /// ], /// "properties": { /// "name": { /// "type": "string" /// }, /// "output_rules": { /// "type": "array", /// "items": { /// "type": "string" /// } /// }, /// "script": { /// "type": "string" /// } /// } ///} /// ``` ///
#[derive(Clone, Debug, Deserialize, Serialize)] pub struct TaskSubmit { pub name: String, #[serde(default, skip_serializing_if = "Vec::is_empty")] pub output_rules: Vec, pub script: String, } impl From<&TaskSubmit> for TaskSubmit { fn from(value: &TaskSubmit) -> Self { value.clone() } } ///TaskSubmitResult /// ///
JSON schema /// /// ```json ///{ /// "type": "object", /// "required": [ /// "id" /// ], /// "properties": { /// "id": { /// "type": "string" /// } /// } ///} /// ``` ///
#[derive(Clone, Debug, Deserialize, Serialize)] pub struct TaskSubmitResult { pub id: String, } impl From<&TaskSubmitResult> for TaskSubmitResult { fn from(value: &TaskSubmitResult) -> Self { value.clone() } } ///UploadedChunk /// ///
JSON schema /// /// ```json ///{ /// "type": "object", /// "required": [ /// "id" /// ], /// "properties": { /// "id": { /// "type": "string" /// } /// } ///} /// ``` ///
#[derive(Clone, Debug, Deserialize, Serialize)] pub struct UploadedChunk { pub id: String, } impl From<&UploadedChunk> for UploadedChunk { fn from(value: &UploadedChunk) -> Self { value.clone() } } ///UserCreate /// ///
JSON schema /// /// ```json ///{ /// "type": "object", /// "required": [ /// "name" /// ], /// "properties": { /// "name": { /// "type": "string" /// } /// } ///} /// ``` ///
#[derive(Clone, Debug, Deserialize, Serialize)] pub struct UserCreate { pub name: String, } impl From<&UserCreate> for UserCreate { fn from(value: &UserCreate) -> Self { value.clone() } } ///UserCreateResult /// ///
JSON schema /// /// ```json ///{ /// "type": "object", /// "required": [ /// "id", /// "name", /// "token" /// ], /// "properties": { /// "id": { /// "type": "string" /// }, /// "name": { /// "type": "string" /// }, /// "token": { /// "type": "string" /// } /// } ///} /// ``` ///
#[derive(Clone, Debug, Deserialize, Serialize)] pub struct UserCreateResult { pub id: String, pub name: String, pub token: String, } impl From<&UserCreateResult> for UserCreateResult { fn from(value: &UserCreateResult) -> Self { value.clone() } } ///WhoamiResult /// ///
JSON schema /// /// ```json ///{ /// "type": "object", /// "required": [ /// "id", /// "name" /// ], /// "properties": { /// "id": { /// "type": "string" /// }, /// "name": { /// "type": "string" /// } /// } ///} /// ``` ///
#[derive(Clone, Debug, Deserialize, Serialize)] pub struct WhoamiResult { pub id: String, pub name: String, } impl From<&WhoamiResult> for WhoamiResult { fn from(value: &WhoamiResult) -> Self { value.clone() } } ///Worker /// ///
JSON schema /// /// ```json ///{ /// "type": "object", /// "required": [ /// "deleted", /// "id", /// "recycle", /// "tasks" /// ], /// "properties": { /// "deleted": { /// "type": "boolean" /// }, /// "id": { /// "type": "string" /// }, /// "instance_id": { /// "type": "string" /// }, /// "lastping": { /// "type": "string", /// "format": "date-time" /// }, /// "recycle": { /// "type": "boolean" /// }, /// "tasks": { /// "type": "array", /// "items": { /// "$ref": "#/components/schemas/WorkerTask" /// } /// } /// } ///} /// ``` ///
#[derive(Clone, Debug, Deserialize, Serialize)] pub struct Worker { pub deleted: bool, pub id: String, #[serde(default, skip_serializing_if = "Option::is_none")] pub instance_id: Option, #[serde(default, skip_serializing_if = "Option::is_none")] pub lastping: Option>, pub recycle: bool, pub tasks: Vec, } impl From<&Worker> for Worker { fn from(value: &Worker) -> Self { value.clone() } } ///WorkerAddOutput /// ///
JSON schema /// /// ```json ///{ /// "type": "object", /// "required": [ /// "chunks", /// "path", /// "size" /// ], /// "properties": { /// "chunks": { /// "type": "array", /// "items": { /// "type": "string" /// } /// }, /// "path": { /// "type": "string" /// }, /// "size": { /// "type": "integer", /// "format": "int64" /// } /// } ///} /// ``` ///
#[derive(Clone, Debug, Deserialize, Serialize)] pub struct WorkerAddOutput { pub chunks: Vec, pub path: String, pub size: i64, } impl From<&WorkerAddOutput> for WorkerAddOutput { fn from(value: &WorkerAddOutput) -> Self { value.clone() } } ///WorkerAppendTask /// ///
JSON schema /// /// ```json ///{ /// "type": "object", /// "required": [ /// "payload", /// "stream", /// "time" /// ], /// "properties": { /// "payload": { /// "type": "string" /// }, /// "stream": { /// "type": "string" /// }, /// "time": { /// "type": "string", /// "format": "date-time" /// } /// } ///} /// ``` ///
#[derive(Clone, Debug, Deserialize, Serialize)] pub struct WorkerAppendTask { pub payload: String, pub stream: String, pub time: chrono::DateTime, } impl From<&WorkerAppendTask> for WorkerAppendTask { fn from(value: &WorkerAppendTask) -> Self { value.clone() } } ///WorkerBootstrap /// ///
JSON schema /// /// ```json ///{ /// "type": "object", /// "required": [ /// "bootstrap", /// "token" /// ], /// "properties": { /// "bootstrap": { /// "type": "string" /// }, /// "token": { /// "type": "string" /// } /// } ///} /// ``` ///
#[derive(Clone, Debug, Deserialize, Serialize)] pub struct WorkerBootstrap { pub bootstrap: String, pub token: String, } impl From<&WorkerBootstrap> for WorkerBootstrap { fn from(value: &WorkerBootstrap) -> Self { value.clone() } } ///WorkerBootstrapResult /// ///
JSON schema /// /// ```json ///{ /// "type": "object", /// "required": [ /// "id" /// ], /// "properties": { /// "id": { /// "type": "string" /// } /// } ///} /// ``` ///
#[derive(Clone, Debug, Deserialize, Serialize)] pub struct WorkerBootstrapResult { pub id: String, } impl From<&WorkerBootstrapResult> for WorkerBootstrapResult { fn from(value: &WorkerBootstrapResult) -> Self { value.clone() } } ///WorkerCompleteTask /// ///
JSON schema /// /// ```json ///{ /// "type": "object", /// "required": [ /// "failed" /// ], /// "properties": { /// "failed": { /// "type": "boolean" /// } /// } ///} /// ``` ///
#[derive(Clone, Debug, Deserialize, Serialize)] pub struct WorkerCompleteTask { pub failed: bool, } impl From<&WorkerCompleteTask> for WorkerCompleteTask { fn from(value: &WorkerCompleteTask) -> Self { value.clone() } } ///WorkerPingResult /// ///
JSON schema /// /// ```json ///{ /// "type": "object", /// "required": [ /// "poweroff" /// ], /// "properties": { /// "poweroff": { /// "type": "boolean" /// }, /// "task": { /// "$ref": "#/components/schemas/WorkerPingTask" /// } /// } ///} /// ``` ///
#[derive(Clone, Debug, Deserialize, Serialize)] pub struct WorkerPingResult { pub poweroff: bool, #[serde(default, skip_serializing_if = "Option::is_none")] pub task: Option, } impl From<&WorkerPingResult> for WorkerPingResult { fn from(value: &WorkerPingResult) -> Self { value.clone() } } ///WorkerPingTask /// ///
JSON schema /// /// ```json ///{ /// "type": "object", /// "required": [ /// "id", /// "output_rules", /// "script" /// ], /// "properties": { /// "id": { /// "type": "string" /// }, /// "output_rules": { /// "type": "array", /// "items": { /// "type": "string" /// } /// }, /// "script": { /// "type": "string" /// } /// } ///} /// ``` ///
#[derive(Clone, Debug, Deserialize, Serialize)] pub struct WorkerPingTask { pub id: String, pub output_rules: Vec, pub script: String, } impl From<&WorkerPingTask> for WorkerPingTask { fn from(value: &WorkerPingTask) -> Self { value.clone() } } ///WorkerTask /// ///
JSON schema /// /// ```json ///{ /// "type": "object", /// "required": [ /// "id", /// "name", /// "owner" /// ], /// "properties": { /// "id": { /// "type": "string" /// }, /// "name": { /// "type": "string" /// }, /// "owner": { /// "type": "string" /// } /// } ///} /// ``` ///
#[derive(Clone, Debug, Deserialize, Serialize)] pub struct WorkerTask { pub id: String, pub name: String, pub owner: String, } impl From<&WorkerTask> for WorkerTask { fn from(value: &WorkerTask) -> Self { value.clone() } } ///WorkersResult /// ///
JSON schema /// /// ```json ///{ /// "type": "object", /// "required": [ /// "workers" /// ], /// "properties": { /// "workers": { /// "type": "array", /// "items": { /// "$ref": "#/components/schemas/Worker" /// } /// } /// } ///} /// ``` ///
#[derive(Clone, Debug, Deserialize, Serialize)] pub struct WorkersResult { pub workers: Vec, } impl From<&WorkersResult> for WorkersResult { fn from(value: &WorkersResult) -> Self { value.clone() } } } #[derive(Clone, Debug)] ///Client for Buildomat /// ///Version: 1.0 pub struct Client { pub(crate) baseurl: String, pub(crate) client: reqwest::Client, } impl Client { /// Create a new client. /// /// `baseurl` is the base URL provided to the internal /// `reqwest::Client`, and should include a scheme and hostname, /// as well as port and a path stem if applicable. pub fn new(baseurl: &str) -> Self { #[cfg(not(target_arch = "wasm32"))] let client = { let dur = std::time::Duration::from_secs(15); reqwest::ClientBuilder::new() .connect_timeout(dur) .timeout(dur) }; #[cfg(target_arch = "wasm32")] let client = reqwest::ClientBuilder::new(); Self::new_with_client(baseurl, client.build().unwrap()) } /// Construct a new client with an existing `reqwest::Client`, /// allowing more control over its configuration. /// /// `baseurl` is the base URL provided to the internal /// `reqwest::Client`, and should include a scheme and hostname, /// as well as port and a path stem if applicable. pub fn new_with_client(baseurl: &str, client: reqwest::Client) -> Self { Self { baseurl: baseurl.to_string(), client, } } /// Get the base URL to which requests are made. pub fn baseurl(&self) -> &String { &self.baseurl } /// Get the internal `reqwest::Client` used to make requests. pub fn client(&self) -> &reqwest::Client { &self.client } /// Get the version of this API. /// /// This string is pulled directly from the source OpenAPI /// document and may be in any format the API selects. pub fn api_version(&self) -> &'static str { "1.0" } } impl Client { ///Sends a `POST` request to `/v1/control/hold` pub async fn control_hold<'a>(&'a self) -> Result, Error<()>> { let url = format!("{}/v1/control/hold", self.baseurl,); let request = self .client .post(url) .header( reqwest::header::ACCEPT, reqwest::header::HeaderValue::from_static("application/json"), ) .build()?; let result = self.client.execute(request).await; let response = result?; match response.status().as_u16() { 200u16 => ResponseValue::from_response(response).await, _ => Err(Error::UnexpectedResponse(response)), } } ///Sends a `POST` request to `/v1/control/resume` pub async fn control_resume<'a>(&'a self) -> Result, Error<()>> { let url = format!("{}/v1/control/resume", self.baseurl,); let request = self.client.post(url).build()?; let result = self.client.execute(request).await; let response = result?; match response.status().as_u16() { 200u16 => Ok(ResponseValue::empty(response)), _ => Err(Error::UnexpectedResponse(response)), } } ///Sends a `GET` request to `/v1/task/{task}` pub async fn task_get<'a>( &'a self, task: &'a str, ) -> Result, Error<()>> { let url = format!( "{}/v1/task/{}", self.baseurl, encode_path(&task.to_string()), ); let request = self .client .get(url) .header( reqwest::header::ACCEPT, reqwest::header::HeaderValue::from_static("application/json"), ) .build()?; let result = self.client.execute(request).await; let response = result?; match response.status().as_u16() { 200u16 => ResponseValue::from_response(response).await, _ => Err(Error::UnexpectedResponse(response)), } } ///Sends a `GET` request to `/v1/tasks` pub async fn tasks_get<'a>(&'a self) -> Result>, Error<()>> { let url = format!("{}/v1/tasks", self.baseurl,); let request = self .client .get(url) .header( reqwest::header::ACCEPT, reqwest::header::HeaderValue::from_static("application/json"), ) .build()?; let result = self.client.execute(request).await; let response = result?; match response.status().as_u16() { 200u16 => ResponseValue::from_response(response).await, _ => Err(Error::UnexpectedResponse(response)), } } ///Sends a `POST` request to `/v1/tasks` pub async fn task_submit<'a>( &'a self, body: &'a types::TaskSubmit, ) -> Result, Error<()>> { let url = format!("{}/v1/tasks", self.baseurl,); let request = self .client .post(url) .header( reqwest::header::ACCEPT, reqwest::header::HeaderValue::from_static("application/json"), ) .json(&body) .build()?; let result = self.client.execute(request).await; let response = result?; match response.status().as_u16() { 201u16 => ResponseValue::from_response(response).await, _ => Err(Error::UnexpectedResponse(response)), } } ///Sends a `GET` request to `/v1/tasks/{task}/events` pub async fn task_events_get<'a>( &'a self, task: &'a str, minseq: Option, ) -> Result>, Error<()>> { let url = format!( "{}/v1/tasks/{}/events", self.baseurl, encode_path(&task.to_string()), ); let mut query = Vec::with_capacity(1usize); if let Some(v) = &minseq { query.push(("minseq", v.to_string())); } let request = self .client .get(url) .header( reqwest::header::ACCEPT, reqwest::header::HeaderValue::from_static("application/json"), ) .query(&query) .build()?; let result = self.client.execute(request).await; let response = result?; match response.status().as_u16() { 200u16 => ResponseValue::from_response(response).await, _ => Err(Error::UnexpectedResponse(response)), } } ///Sends a `GET` request to `/v1/tasks/{task}/outputs` pub async fn task_outputs_get<'a>( &'a self, task: &'a str, ) -> Result>, Error<()>> { let url = format!( "{}/v1/tasks/{}/outputs", self.baseurl, encode_path(&task.to_string()), ); let request = self .client .get(url) .header( reqwest::header::ACCEPT, reqwest::header::HeaderValue::from_static("application/json"), ) .build()?; let result = self.client.execute(request).await; let response = result?; match response.status().as_u16() { 200u16 => ResponseValue::from_response(response).await, _ => Err(Error::UnexpectedResponse(response)), } } ///Sends a `GET` request to `/v1/tasks/{task}/outputs/{output}` pub async fn task_output_download<'a>( &'a self, task: &'a str, output: &'a str, ) -> Result, Error<()>> { let url = format!( "{}/v1/tasks/{}/outputs/{}", self.baseurl, encode_path(&task.to_string()), encode_path(&output.to_string()), ); let request = self.client.get(url).build()?; let result = self.client.execute(request).await; let response = result?; match response.status().as_u16() { 200..=299 => Ok(ResponseValue::stream(response)), _ => Err(Error::UnexpectedResponse(response)), } } ///Sends a `POST` request to `/v1/users` pub async fn user_create<'a>( &'a self, body: &'a types::UserCreate, ) -> Result, Error<()>> { let url = format!("{}/v1/users", self.baseurl,); let request = self .client .post(url) .header( reqwest::header::ACCEPT, reqwest::header::HeaderValue::from_static("application/json"), ) .json(&body) .build()?; let result = self.client.execute(request).await; let response = result?; match response.status().as_u16() { 201u16 => ResponseValue::from_response(response).await, _ => Err(Error::UnexpectedResponse(response)), } } ///Sends a `GET` request to `/v1/whoami` pub async fn whoami<'a>(&'a self) -> Result, Error<()>> { let url = format!("{}/v1/whoami", self.baseurl,); let request = self .client .get(url) .header( reqwest::header::ACCEPT, reqwest::header::HeaderValue::from_static("application/json"), ) .build()?; let result = self.client.execute(request).await; let response = result?; match response.status().as_u16() { 200u16 => ResponseValue::from_response(response).await, _ => Err(Error::UnexpectedResponse(response)), } } ///Sends a `PUT` request to `/v1/whoami/name` pub async fn whoami_put_name<'a>( &'a self, body: String, ) -> Result, Error<()>> { let url = format!("{}/v1/whoami/name", self.baseurl,); let request = self .client .put(url) .header( reqwest::header::CONTENT_TYPE, reqwest::header::HeaderValue::from_static("text/plain"), ) .body(body) .build()?; let result = self.client.execute(request).await; let response = result?; match response.status().as_u16() { 200u16 => Ok(ResponseValue::empty(response)), _ => Err(Error::UnexpectedResponse(response)), } } ///Sends a `POST` request to `/v1/worker/bootstrap` pub async fn worker_bootstrap<'a>( &'a self, body: &'a types::WorkerBootstrap, ) -> Result, Error<()>> { let url = format!("{}/v1/worker/bootstrap", self.baseurl,); let request = self .client .post(url) .header( reqwest::header::ACCEPT, reqwest::header::HeaderValue::from_static("application/json"), ) .json(&body) .build()?; let result = self.client.execute(request).await; let response = result?; match response.status().as_u16() { 201u16 => ResponseValue::from_response(response).await, _ => Err(Error::UnexpectedResponse(response)), } } ///Sends a `GET` request to `/v1/worker/ping` pub async fn worker_ping<'a>( &'a self, ) -> Result, Error<()>> { let url = format!("{}/v1/worker/ping", self.baseurl,); let request = self .client .get(url) .header( reqwest::header::ACCEPT, reqwest::header::HeaderValue::from_static("application/json"), ) .build()?; let result = self.client.execute(request).await; let response = result?; match response.status().as_u16() { 200u16 => ResponseValue::from_response(response).await, _ => Err(Error::UnexpectedResponse(response)), } } ///Sends a `POST` request to `/v1/worker/task/{task}/append` pub async fn worker_task_append<'a>( &'a self, task: &'a str, body: &'a types::WorkerAppendTask, ) -> Result, Error<()>> { let url = format!( "{}/v1/worker/task/{}/append", self.baseurl, encode_path(&task.to_string()), ); let request = self.client.post(url).json(&body).build()?; let result = self.client.execute(request).await; let response = result?; match response.status().as_u16() { 201u16 => Ok(ResponseValue::empty(response)), _ => Err(Error::UnexpectedResponse(response)), } } ///Sends a `POST` request to `/v1/worker/task/{task}/chunk` pub async fn worker_task_upload_chunk<'a, B: Into>( &'a self, task: &'a str, body: B, ) -> Result, Error<()>> { let url = format!( "{}/v1/worker/task/{}/chunk", self.baseurl, encode_path(&task.to_string()), ); let request = self .client .post(url) .header( reqwest::header::ACCEPT, reqwest::header::HeaderValue::from_static("application/json"), ) .header( reqwest::header::CONTENT_TYPE, reqwest::header::HeaderValue::from_static("application/octet-stream"), ) .body(body) .build()?; let result = self.client.execute(request).await; let response = result?; match response.status().as_u16() { 201u16 => ResponseValue::from_response(response).await, _ => Err(Error::UnexpectedResponse(response)), } } ///Sends a `POST` request to `/v1/worker/task/{task}/complete` pub async fn worker_task_complete<'a>( &'a self, task: &'a str, body: &'a types::WorkerCompleteTask, ) -> Result, Error<()>> { let url = format!( "{}/v1/worker/task/{}/complete", self.baseurl, encode_path(&task.to_string()), ); let request = self.client.post(url).json(&body).build()?; let result = self.client.execute(request).await; let response = result?; match response.status().as_u16() { 200u16 => Ok(ResponseValue::empty(response)), _ => Err(Error::UnexpectedResponse(response)), } } ///Sends a `POST` request to `/v1/worker/task/{task}/output` pub async fn worker_task_add_output<'a>( &'a self, task: &'a str, body: &'a types::WorkerAddOutput, ) -> Result, Error<()>> { let url = format!( "{}/v1/worker/task/{}/output", self.baseurl, encode_path(&task.to_string()), ); let request = self.client.post(url).json(&body).build()?; let result = self.client.execute(request).await; let response = result?; match response.status().as_u16() { 201u16 => Ok(ResponseValue::empty(response)), _ => Err(Error::UnexpectedResponse(response)), } } ///Sends a `GET` request to `/v1/workers` pub async fn workers_list<'a>( &'a self, ) -> Result, Error<()>> { let url = format!("{}/v1/workers", self.baseurl,); let request = self .client .get(url) .header( reqwest::header::ACCEPT, reqwest::header::HeaderValue::from_static("application/json"), ) .build()?; let result = self.client.execute(request).await; let response = result?; match response.status().as_u16() { 200u16 => ResponseValue::from_response(response).await, _ => Err(Error::UnexpectedResponse(response)), } } ///Sends a `POST` request to `/v1/workers/recycle` pub async fn workers_recycle<'a>(&'a self) -> Result, Error<()>> { let url = format!("{}/v1/workers/recycle", self.baseurl,); let request = self.client.post(url).build()?; let result = self.client.execute(request).await; let response = result?; match response.status().as_u16() { 200u16 => Ok(ResponseValue::empty(response)), _ => Err(Error::UnexpectedResponse(response)), } } } pub mod prelude { pub use super::Client; }