Change builder methods for setting a parameter with type T to accept a TryInto<T> (#133)
This makes constrained types a bit more ergonomic and will allow us to accept fallible builders more easily
This commit is contained in:
parent
244972129b
commit
bfd194f39c
|
@ -208,8 +208,13 @@ impl Generator {
|
|||
#[allow(unused_imports)]
|
||||
use progenitor_client::{encode_path, RequestBuilderExt};
|
||||
|
||||
|
||||
pub mod types {
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
// This may be used by some impl Deserialize, but not all.
|
||||
#[allow(unused_imports)]
|
||||
use std::convert::TryFrom;
|
||||
#shared
|
||||
#(#types)*
|
||||
}
|
||||
|
@ -307,6 +312,8 @@ impl Generator {
|
|||
RequestBuilderExt,
|
||||
ResponseValue,
|
||||
};
|
||||
#[allow(unused_imports)]
|
||||
use std::convert::TryInto;
|
||||
|
||||
#(#builder_struct)*
|
||||
}
|
||||
|
|
|
@ -743,7 +743,7 @@ impl Generator {
|
|||
}),
|
||||
(
|
||||
OperationParameterKind::Body(
|
||||
BodyContentType::FormUrlencoded,
|
||||
BodyContentType::FormUrlencoded
|
||||
),
|
||||
OperationParameterType::Type(_),
|
||||
) => Some(quote! {
|
||||
|
@ -1111,27 +1111,36 @@ impl Generator {
|
|||
}
|
||||
}
|
||||
|
||||
/// Create the builder structs along with their impls
|
||||
/// Create the builder structs along with their impl bodies.
|
||||
///
|
||||
/// Builder structs are generally of this form:
|
||||
/// Builder structs are generally of this form for a mandatory `param_1`
|
||||
/// and an optional `param_2`:
|
||||
/// ```ignore
|
||||
/// struct OperationId<'a> {
|
||||
/// client: &'a super::Client,
|
||||
/// param_1: Option<SomeType>,
|
||||
/// param_2: Option<String>,
|
||||
/// param_1: Result<SomeType, String>,
|
||||
/// param_2: Result<Option<String>, String>,
|
||||
/// }
|
||||
/// ```
|
||||
///
|
||||
/// All parameters are present and all their types are Option<T>. Each
|
||||
/// parameter also has a corresponding method:
|
||||
/// All parameters are present and all their types are Result<T, String> or
|
||||
/// Result<Option<T>, String> for optional parameters. Each parameter also
|
||||
/// has a corresponding method:
|
||||
/// ```ignore
|
||||
/// impl<'a> OperationId<'a> {
|
||||
/// pub fn param_1(self, value: SomeType) {
|
||||
/// self.param_1 = Some(value);
|
||||
/// pub fn param_1<V>(self, value: V)
|
||||
/// where V: TryInto<SomeType>
|
||||
/// {
|
||||
/// self.param_1 = value.try_into()
|
||||
/// .map_err(|_| #err_msg.to_string());
|
||||
/// self
|
||||
/// }
|
||||
/// pub fn param_2<S: ToString>(self, value: S) {
|
||||
/// self.param_2 = Some(value.into());
|
||||
/// pub fn param_2<V>(self, value: V)
|
||||
/// where V: TryInto<SomeType>
|
||||
/// {
|
||||
/// self.param_2 = value.try_into()
|
||||
/// .map(Some)
|
||||
/// .map_err(|_| #err_msg.to_string());
|
||||
/// self
|
||||
/// }
|
||||
/// }
|
||||
|
@ -1144,15 +1153,15 @@ impl Generator {
|
|||
/// pub fn new(client: &'a super::Client) -> Self {
|
||||
/// Self {
|
||||
/// client,
|
||||
/// param_1: None,
|
||||
/// param_2: None,
|
||||
/// param_1: Err("param_1 was not initialized".to_string()),
|
||||
/// param_2: Ok(None),
|
||||
/// }
|
||||
/// }
|
||||
/// }
|
||||
/// ```
|
||||
///
|
||||
/// Finally, builders have methods to execute the method, which takes care
|
||||
/// to check that required parameters are specified:
|
||||
/// Finally, builders have methods to execute the operation. This simply
|
||||
/// resolves ach parameter with the ? (Try operator).
|
||||
/// ```ignore
|
||||
/// impl<'a> OperationId<'a> {
|
||||
/// pub fn send(self) -> Result<
|
||||
|
@ -1164,77 +1173,78 @@ impl Generator {
|
|||
/// param_1,
|
||||
/// param_2,
|
||||
/// } = self;
|
||||
///
|
||||
/// let param_1 = param_1.map_err(Error::InvalidRequest)?;
|
||||
/// let param_2 = param_1.map_err(Error::InvalidRequest)?;
|
||||
///
|
||||
/// let (param_1, param_2) = match (param_1, param_2) {
|
||||
/// (Some(param_1), Some(param_2)) => (param_1, param_2),
|
||||
/// (param_1, param_2) => {
|
||||
/// let mut missing = Vec::new();
|
||||
/// if param_1.is_none() {
|
||||
/// missing.push(stringify!(param_1));
|
||||
/// }
|
||||
/// if param_2.is_none() {
|
||||
/// missing.push(stringify!(param_2));
|
||||
/// }
|
||||
/// return Err(super::Error::InvalidRequest(format!(
|
||||
/// "the following parameters are required: {}",
|
||||
/// missing.join(", "),
|
||||
/// )));
|
||||
/// }
|
||||
/// };
|
||||
/// // ... execute the body (see `method_sig_body`) ...
|
||||
/// }
|
||||
/// }
|
||||
/// ```
|
||||
///
|
||||
/// Finally, paginated interfaces have a `stream()` method which uses the
|
||||
/// `send()` method above to fetch each page of results to assemble the
|
||||
/// items into a single impl Stream.
|
||||
/// items into a single `impl Stream`.
|
||||
pub(crate) fn builder_struct(
|
||||
&mut self,
|
||||
method: &OperationMethod,
|
||||
tag_style: TagStyle,
|
||||
) -> Result<TokenStream> {
|
||||
let mut cloneable = true;
|
||||
// Generate the builder structure properties, turning each type T into
|
||||
// an Option<T> (if it isn't already).
|
||||
let properties = method
|
||||
.params
|
||||
.iter()
|
||||
.map(|param| {
|
||||
let name = format_ident!("{}", param.name);
|
||||
let typ = match ¶m.typ {
|
||||
OperationParameterType::Type(type_id) => {
|
||||
// TODO currently we explicitly turn optional paramters
|
||||
// into Option types; we could probably defer this to
|
||||
// the code generation step to avoid the special
|
||||
// handling here.
|
||||
let ty = self.type_space.get_type(type_id)?;
|
||||
let t = ty.ident();
|
||||
let details = ty.details();
|
||||
if let typify::TypeDetails::Option(_) = details {
|
||||
t
|
||||
} else {
|
||||
quote! { Option<#t> }
|
||||
}
|
||||
}
|
||||
|
||||
OperationParameterType::RawBody => {
|
||||
cloneable = false;
|
||||
quote! { Option<reqwest::Body> }
|
||||
}
|
||||
};
|
||||
|
||||
Ok(quote! {
|
||||
#name: #typ
|
||||
})
|
||||
})
|
||||
.collect::<Result<Vec<_>>>()?;
|
||||
|
||||
let struct_name = sanitize(&method.operation_id, Case::Pascal);
|
||||
let struct_ident = format_ident!("{}", struct_name);
|
||||
|
||||
// Generate an ident for each parameter.
|
||||
let param_names = method
|
||||
.params
|
||||
.iter()
|
||||
.map(|param| format_ident!("{}", param.name))
|
||||
.collect::<Vec<_>>();
|
||||
|
||||
let mut cloneable = true;
|
||||
|
||||
// Generate the type for each parameter.
|
||||
let param_types = method
|
||||
.params
|
||||
.iter()
|
||||
.map(|param| match ¶m.typ {
|
||||
OperationParameterType::Type(type_id) => {
|
||||
let ty = self.type_space.get_type(type_id)?;
|
||||
let t = ty.ident();
|
||||
Ok(quote! { Result<#t, String> })
|
||||
}
|
||||
|
||||
OperationParameterType::RawBody => {
|
||||
cloneable = false;
|
||||
Ok(quote! { Result<reqwest::Body, String> })
|
||||
}
|
||||
})
|
||||
.collect::<Result<Vec<_>>>()?;
|
||||
|
||||
// Generate the devalue value for each parameter.
|
||||
let param_values = method
|
||||
.params
|
||||
.iter()
|
||||
.map(|param| {
|
||||
let opt = match ¶m.typ {
|
||||
OperationParameterType::Type(type_id) => {
|
||||
let ty = self.type_space.get_type(type_id)?;
|
||||
let details = ty.details();
|
||||
matches!(&details, typify::TypeDetails::Option(_))
|
||||
}
|
||||
OperationParameterType::RawBody => false,
|
||||
};
|
||||
if opt {
|
||||
Ok(quote! { Ok(None) })
|
||||
} else {
|
||||
let err_msg = format!("{} was not initialized", param.name);
|
||||
Ok(quote! { Err(#err_msg.to_string()) })
|
||||
}
|
||||
})
|
||||
.collect::<Result<Vec<_>>>()?;
|
||||
|
||||
// For each parameter, we need an impl for the builder to let consumers
|
||||
// provide a value for the parameter.
|
||||
let property_impls = method
|
||||
// provide a value.
|
||||
let param_impls = method
|
||||
.params
|
||||
.iter()
|
||||
.map(|param| {
|
||||
|
@ -1242,30 +1252,35 @@ impl Generator {
|
|||
match ¶m.typ {
|
||||
OperationParameterType::Type(type_id) => {
|
||||
let ty = self.type_space.get_type(type_id)?;
|
||||
let x = ty.details();
|
||||
match &x {
|
||||
typify::TypeDetails::String => {
|
||||
Ok(quote! {
|
||||
pub fn #param_name<S: ToString>(mut self, value: S) -> Self {
|
||||
self.#param_name = Some(value.to_string());
|
||||
self
|
||||
}
|
||||
})
|
||||
}
|
||||
let details = ty.details();
|
||||
let err_msg = format!("conversion to `{}` for {} failed", ty.name(), param.name);
|
||||
match &details {
|
||||
typify::TypeDetails::Option(ref opt_id) => {
|
||||
// TODO currently we explicitly turn optional
|
||||
// parameters into Option types; we could probably
|
||||
// defer this to the code generation step to avoid the
|
||||
// special handling here.
|
||||
let typ = self.type_space.get_type(opt_id)?.ident();
|
||||
Ok(quote!{
|
||||
pub fn #param_name(mut self, value: #typ) -> Self {
|
||||
self.#param_name = Some(value);
|
||||
Ok(quote! {
|
||||
pub fn #param_name<V>(mut self, value: V)
|
||||
-> Self
|
||||
where V: TryInto<#typ>
|
||||
{
|
||||
self.#param_name = value.try_into()
|
||||
.map(Some)
|
||||
.map_err(|_| #err_msg.to_string());
|
||||
self
|
||||
}
|
||||
})
|
||||
}
|
||||
_ => {
|
||||
_ => {
|
||||
let typ = ty.ident();
|
||||
Ok(quote! {
|
||||
pub fn #param_name(mut self, value: #typ) -> Self {
|
||||
self.#param_name = Some(value);
|
||||
pub fn #param_name<V>(mut self, value: V) -> Self
|
||||
where V: TryInto<#typ>,
|
||||
{
|
||||
self.#param_name = value.try_into()
|
||||
.map_err(|_| #err_msg.to_string());
|
||||
self
|
||||
}
|
||||
})
|
||||
|
@ -1274,9 +1289,15 @@ impl Generator {
|
|||
}
|
||||
|
||||
OperationParameterType::RawBody => {
|
||||
let err_msg =
|
||||
format!("conversion to `reqwest::Body` for {} failed", param.name);
|
||||
|
||||
Ok(quote! {
|
||||
pub fn #param_name<B: Into<reqwest::Body>>(mut self, value: B) -> Self {
|
||||
self.#param_name = Some(value.into());
|
||||
pub fn #param_name<B>(mut self, value: B) -> Self
|
||||
where B: TryInto<reqwest::Body>
|
||||
{
|
||||
self.#param_name = value.try_into()
|
||||
.map_err(|_| #err_msg.to_string());
|
||||
self
|
||||
}
|
||||
})
|
||||
|
@ -1285,67 +1306,6 @@ impl Generator {
|
|||
})
|
||||
.collect::<Result<Vec<_>>>()?;
|
||||
|
||||
let destructure = method
|
||||
.params
|
||||
.iter()
|
||||
.map(|param| format_ident!("{}", param.name))
|
||||
.collect::<Vec<_>>();
|
||||
|
||||
let req_names = method
|
||||
.params
|
||||
.iter()
|
||||
.filter_map(|param| match param.kind {
|
||||
OperationParameterKind::Path
|
||||
| OperationParameterKind::Query(true)
|
||||
| OperationParameterKind::Body(_) => {
|
||||
Some(format_ident!("{}", param.name))
|
||||
}
|
||||
OperationParameterKind::Query(false) => None,
|
||||
})
|
||||
.collect::<Vec<_>>();
|
||||
|
||||
let required_extract = (!req_names.is_empty()).then(|| {
|
||||
quote! {
|
||||
let ( #( #req_names, )* ) = match ( #( #req_names, )* ) {
|
||||
( #( Some(#req_names), )* ) => ( #( #req_names, )* ),
|
||||
( #( #req_names, )* ) => {
|
||||
let mut missing = Vec::new();
|
||||
|
||||
#(
|
||||
if #req_names.is_none() {
|
||||
missing.push(stringify!(#req_names));
|
||||
}
|
||||
)*
|
||||
|
||||
return Err(super::Error::InvalidRequest(format!(
|
||||
"the following parameters are required: {}",
|
||||
missing.join(", "),
|
||||
)));
|
||||
}
|
||||
};
|
||||
}
|
||||
});
|
||||
|
||||
let param_props = method
|
||||
.params
|
||||
.iter()
|
||||
.map(|param| {
|
||||
let name = format_ident!("{}", param.name);
|
||||
quote! {
|
||||
#name: None
|
||||
}
|
||||
})
|
||||
.collect::<Vec<_>>();
|
||||
|
||||
let new_impl = quote! {
|
||||
pub fn new(client: &'a super::Client) -> Self {
|
||||
Self {
|
||||
client,
|
||||
#(#param_props,)*
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
let MethodSigBody {
|
||||
success,
|
||||
error,
|
||||
|
@ -1358,27 +1318,6 @@ impl Generator {
|
|||
method.path.to_string(),
|
||||
);
|
||||
|
||||
let send_impl = quote! {
|
||||
#[doc = #send_doc]
|
||||
pub async fn send(self) -> Result<
|
||||
ResponseValue<#success>,
|
||||
Error<#error>,
|
||||
> {
|
||||
// Destructure the builder for convenience.
|
||||
let Self {
|
||||
client,
|
||||
#( #destructure ),*
|
||||
} = self;
|
||||
|
||||
// Extract parameters into variables, returning an error if
|
||||
// a value has not been provided for all required parameters.
|
||||
#required_extract
|
||||
|
||||
// Do the work.
|
||||
#body
|
||||
}
|
||||
};
|
||||
|
||||
let stream_impl = method.dropshot_paginated.as_ref().map(|page_data| {
|
||||
// We're now using futures.
|
||||
self.uses_futures = true;
|
||||
|
@ -1387,7 +1326,7 @@ impl Generator {
|
|||
if let OperationParameterKind::Query(_) = param.kind {
|
||||
let name = format_ident!("{}", param.name);
|
||||
Some(quote! {
|
||||
#name: None
|
||||
#name: Ok(None)
|
||||
})
|
||||
} else {
|
||||
None
|
||||
|
@ -1428,7 +1367,7 @@ impl Generator {
|
|||
.map_ok(move |page| {
|
||||
let page = page.into_inner();
|
||||
|
||||
// Create a stream from the items of the first page.
|
||||
// Create a stream from the first page of items.
|
||||
let first = futures::stream::iter(
|
||||
page.items.into_iter().map(Ok)
|
||||
);
|
||||
|
@ -1449,7 +1388,7 @@ impl Generator {
|
|||
// template (with query parameters set
|
||||
// to None), overriding page_token.
|
||||
Self {
|
||||
page_token: next_page,
|
||||
page_token: Ok(next_page),
|
||||
..next.clone()
|
||||
}
|
||||
.send()
|
||||
|
@ -1539,22 +1478,53 @@ impl Generator {
|
|||
}
|
||||
};
|
||||
|
||||
let ret = quote! {
|
||||
Ok(quote! {
|
||||
#[doc = #struct_doc]
|
||||
#maybe_clone
|
||||
pub struct #struct_ident<'a> {
|
||||
client: &'a super::Client,
|
||||
#( #properties ),*
|
||||
#( #param_names: #param_types, )*
|
||||
}
|
||||
|
||||
impl<'a> #struct_ident<'a> {
|
||||
#new_impl
|
||||
#( #property_impls )*
|
||||
#send_impl
|
||||
pub fn new(client: &'a super::Client) -> Self {
|
||||
Self {
|
||||
client,
|
||||
#( #param_names: #param_values, )*
|
||||
}
|
||||
}
|
||||
|
||||
#( #param_impls )*
|
||||
|
||||
#[doc = #send_doc]
|
||||
pub async fn send(self) -> Result<
|
||||
ResponseValue<#success>,
|
||||
Error<#error>,
|
||||
> {
|
||||
// Destructure the builder for convenience.
|
||||
let Self {
|
||||
client,
|
||||
#( #param_names, )*
|
||||
} = self;
|
||||
|
||||
// Extract parameters into variables, returning an error if
|
||||
// a value has not been provided or there was a conversion
|
||||
// error.
|
||||
//
|
||||
// TODO we could do something a bit nicer by collecting all
|
||||
// errors rather than just reporting the first one.
|
||||
#(
|
||||
let #param_names =
|
||||
#param_names.map_err(Error::InvalidRequest)?;
|
||||
)*
|
||||
|
||||
// Do the work.
|
||||
#body
|
||||
}
|
||||
|
||||
#stream_impl
|
||||
}
|
||||
};
|
||||
Ok(ret)
|
||||
})
|
||||
}
|
||||
|
||||
fn builder_helper(&self, method: &OperationMethod) -> BuilderImpl {
|
||||
|
|
|
@ -3,6 +3,8 @@ use progenitor_client::{encode_path, RequestBuilderExt};
|
|||
pub use progenitor_client::{ByteStream, Error, ResponseValue};
|
||||
pub mod types {
|
||||
use serde::{Deserialize, Serialize};
|
||||
#[allow(unused_imports)]
|
||||
use std::convert::TryFrom;
|
||||
#[derive(Clone, Debug, Deserialize, Serialize)]
|
||||
pub struct Task {
|
||||
pub id: String,
|
||||
|
@ -428,35 +430,31 @@ pub mod builder {
|
|||
#[derive(Clone)]
|
||||
pub struct TaskGet<'a> {
|
||||
client: &'a super::Client,
|
||||
task: Option<String>,
|
||||
task: Result<String, String>,
|
||||
}
|
||||
|
||||
impl<'a> TaskGet<'a> {
|
||||
pub fn new(client: &'a super::Client) -> Self {
|
||||
Self { client, task: None }
|
||||
Self {
|
||||
client,
|
||||
task: Err("task was not initialized".to_string()),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn task<S: ToString>(mut self, value: S) -> Self {
|
||||
self.task = Some(value.to_string());
|
||||
pub fn task<V>(mut self, value: V) -> Self
|
||||
where
|
||||
V: TryInto<String>,
|
||||
{
|
||||
self.task = value
|
||||
.try_into()
|
||||
.map_err(|_| "conversion to `String` for task failed".to_string());
|
||||
self
|
||||
}
|
||||
|
||||
///Sends a `GET` request to `/v1/task/{task}`
|
||||
pub async fn send(self) -> Result<ResponseValue<types::Task>, Error<()>> {
|
||||
let Self { client, task } = self;
|
||||
let (task,) = match (task,) {
|
||||
(Some(task),) => (task,),
|
||||
(task,) => {
|
||||
let mut missing = Vec::new();
|
||||
if task.is_none() {
|
||||
missing.push(stringify!(task));
|
||||
}
|
||||
return Err(super::Error::InvalidRequest(format!(
|
||||
"the following parameters are required: {}",
|
||||
missing.join(", "),
|
||||
)));
|
||||
}
|
||||
};
|
||||
let task = task.map_err(Error::InvalidRequest)?;
|
||||
let url = format!(
|
||||
"{}/v1/task/{}",
|
||||
client.baseurl,
|
||||
|
@ -505,35 +503,31 @@ pub mod builder {
|
|||
#[derive(Clone)]
|
||||
pub struct TaskSubmit<'a> {
|
||||
client: &'a super::Client,
|
||||
body: Option<types::TaskSubmit>,
|
||||
body: Result<types::TaskSubmit, String>,
|
||||
}
|
||||
|
||||
impl<'a> TaskSubmit<'a> {
|
||||
pub fn new(client: &'a super::Client) -> Self {
|
||||
Self { client, body: None }
|
||||
Self {
|
||||
client,
|
||||
body: Err("body was not initialized".to_string()),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn body(mut self, value: types::TaskSubmit) -> Self {
|
||||
self.body = Some(value);
|
||||
pub fn body<V>(mut self, value: V) -> Self
|
||||
where
|
||||
V: TryInto<types::TaskSubmit>,
|
||||
{
|
||||
self.body = value
|
||||
.try_into()
|
||||
.map_err(|_| "conversion to `TaskSubmit` for body failed".to_string());
|
||||
self
|
||||
}
|
||||
|
||||
///Sends a `POST` request to `/v1/tasks`
|
||||
pub async fn send(self) -> Result<ResponseValue<types::TaskSubmitResult>, Error<()>> {
|
||||
let Self { client, body } = self;
|
||||
let (body,) = match (body,) {
|
||||
(Some(body),) => (body,),
|
||||
(body,) => {
|
||||
let mut missing = Vec::new();
|
||||
if body.is_none() {
|
||||
missing.push(stringify!(body));
|
||||
}
|
||||
return Err(super::Error::InvalidRequest(format!(
|
||||
"the following parameters are required: {}",
|
||||
missing.join(", "),
|
||||
)));
|
||||
}
|
||||
};
|
||||
let body = body.map_err(Error::InvalidRequest)?;
|
||||
let url = format!("{}/v1/tasks", client.baseurl,);
|
||||
let request = client.client.post(url).json(&body).build()?;
|
||||
let result = client.client.execute(request).await;
|
||||
|
@ -551,26 +545,37 @@ pub mod builder {
|
|||
#[derive(Clone)]
|
||||
pub struct TaskEventsGet<'a> {
|
||||
client: &'a super::Client,
|
||||
task: Option<String>,
|
||||
minseq: Option<u32>,
|
||||
task: Result<String, String>,
|
||||
minseq: Result<Option<u32>, String>,
|
||||
}
|
||||
|
||||
impl<'a> TaskEventsGet<'a> {
|
||||
pub fn new(client: &'a super::Client) -> Self {
|
||||
Self {
|
||||
client,
|
||||
task: None,
|
||||
minseq: None,
|
||||
task: Err("task was not initialized".to_string()),
|
||||
minseq: Ok(None),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn task<S: ToString>(mut self, value: S) -> Self {
|
||||
self.task = Some(value.to_string());
|
||||
pub fn task<V>(mut self, value: V) -> Self
|
||||
where
|
||||
V: TryInto<String>,
|
||||
{
|
||||
self.task = value
|
||||
.try_into()
|
||||
.map_err(|_| "conversion to `String` for task failed".to_string());
|
||||
self
|
||||
}
|
||||
|
||||
pub fn minseq(mut self, value: u32) -> Self {
|
||||
self.minseq = Some(value);
|
||||
pub fn minseq<V>(mut self, value: V) -> Self
|
||||
where
|
||||
V: TryInto<u32>,
|
||||
{
|
||||
self.minseq = value
|
||||
.try_into()
|
||||
.map(Some)
|
||||
.map_err(|_| "conversion to `Option < u32 >` for minseq failed".to_string());
|
||||
self
|
||||
}
|
||||
|
||||
|
@ -581,19 +586,8 @@ pub mod builder {
|
|||
task,
|
||||
minseq,
|
||||
} = self;
|
||||
let (task,) = match (task,) {
|
||||
(Some(task),) => (task,),
|
||||
(task,) => {
|
||||
let mut missing = Vec::new();
|
||||
if task.is_none() {
|
||||
missing.push(stringify!(task));
|
||||
}
|
||||
return Err(super::Error::InvalidRequest(format!(
|
||||
"the following parameters are required: {}",
|
||||
missing.join(", "),
|
||||
)));
|
||||
}
|
||||
};
|
||||
let task = task.map_err(Error::InvalidRequest)?;
|
||||
let minseq = minseq.map_err(Error::InvalidRequest)?;
|
||||
let url = format!(
|
||||
"{}/v1/tasks/{}/events",
|
||||
client.baseurl,
|
||||
|
@ -619,35 +613,31 @@ pub mod builder {
|
|||
#[derive(Clone)]
|
||||
pub struct TaskOutputsGet<'a> {
|
||||
client: &'a super::Client,
|
||||
task: Option<String>,
|
||||
task: Result<String, String>,
|
||||
}
|
||||
|
||||
impl<'a> TaskOutputsGet<'a> {
|
||||
pub fn new(client: &'a super::Client) -> Self {
|
||||
Self { client, task: None }
|
||||
Self {
|
||||
client,
|
||||
task: Err("task was not initialized".to_string()),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn task<S: ToString>(mut self, value: S) -> Self {
|
||||
self.task = Some(value.to_string());
|
||||
pub fn task<V>(mut self, value: V) -> Self
|
||||
where
|
||||
V: TryInto<String>,
|
||||
{
|
||||
self.task = value
|
||||
.try_into()
|
||||
.map_err(|_| "conversion to `String` for task failed".to_string());
|
||||
self
|
||||
}
|
||||
|
||||
///Sends a `GET` request to `/v1/tasks/{task}/outputs`
|
||||
pub async fn send(self) -> Result<ResponseValue<Vec<types::TaskOutput>>, Error<()>> {
|
||||
let Self { client, task } = self;
|
||||
let (task,) = match (task,) {
|
||||
(Some(task),) => (task,),
|
||||
(task,) => {
|
||||
let mut missing = Vec::new();
|
||||
if task.is_none() {
|
||||
missing.push(stringify!(task));
|
||||
}
|
||||
return Err(super::Error::InvalidRequest(format!(
|
||||
"the following parameters are required: {}",
|
||||
missing.join(", "),
|
||||
)));
|
||||
}
|
||||
};
|
||||
let task = task.map_err(Error::InvalidRequest)?;
|
||||
let url = format!(
|
||||
"{}/v1/tasks/{}/outputs",
|
||||
client.baseurl,
|
||||
|
@ -669,26 +659,36 @@ pub mod builder {
|
|||
#[derive(Clone)]
|
||||
pub struct TaskOutputDownload<'a> {
|
||||
client: &'a super::Client,
|
||||
task: Option<String>,
|
||||
output: Option<String>,
|
||||
task: Result<String, String>,
|
||||
output: Result<String, String>,
|
||||
}
|
||||
|
||||
impl<'a> TaskOutputDownload<'a> {
|
||||
pub fn new(client: &'a super::Client) -> Self {
|
||||
Self {
|
||||
client,
|
||||
task: None,
|
||||
output: None,
|
||||
task: Err("task was not initialized".to_string()),
|
||||
output: Err("output was not initialized".to_string()),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn task<S: ToString>(mut self, value: S) -> Self {
|
||||
self.task = Some(value.to_string());
|
||||
pub fn task<V>(mut self, value: V) -> Self
|
||||
where
|
||||
V: TryInto<String>,
|
||||
{
|
||||
self.task = value
|
||||
.try_into()
|
||||
.map_err(|_| "conversion to `String` for task failed".to_string());
|
||||
self
|
||||
}
|
||||
|
||||
pub fn output<S: ToString>(mut self, value: S) -> Self {
|
||||
self.output = Some(value.to_string());
|
||||
pub fn output<V>(mut self, value: V) -> Self
|
||||
where
|
||||
V: TryInto<String>,
|
||||
{
|
||||
self.output = value
|
||||
.try_into()
|
||||
.map_err(|_| "conversion to `String` for output failed".to_string());
|
||||
self
|
||||
}
|
||||
|
||||
|
@ -699,22 +699,8 @@ pub mod builder {
|
|||
task,
|
||||
output,
|
||||
} = self;
|
||||
let (task, output) = match (task, output) {
|
||||
(Some(task), Some(output)) => (task, output),
|
||||
(task, output) => {
|
||||
let mut missing = Vec::new();
|
||||
if task.is_none() {
|
||||
missing.push(stringify!(task));
|
||||
}
|
||||
if output.is_none() {
|
||||
missing.push(stringify!(output));
|
||||
}
|
||||
return Err(super::Error::InvalidRequest(format!(
|
||||
"the following parameters are required: {}",
|
||||
missing.join(", "),
|
||||
)));
|
||||
}
|
||||
};
|
||||
let task = task.map_err(Error::InvalidRequest)?;
|
||||
let output = output.map_err(Error::InvalidRequest)?;
|
||||
let url = format!(
|
||||
"{}/v1/tasks/{}/outputs/{}",
|
||||
client.baseurl,
|
||||
|
@ -737,35 +723,31 @@ pub mod builder {
|
|||
#[derive(Clone)]
|
||||
pub struct UserCreate<'a> {
|
||||
client: &'a super::Client,
|
||||
body: Option<types::UserCreate>,
|
||||
body: Result<types::UserCreate, String>,
|
||||
}
|
||||
|
||||
impl<'a> UserCreate<'a> {
|
||||
pub fn new(client: &'a super::Client) -> Self {
|
||||
Self { client, body: None }
|
||||
Self {
|
||||
client,
|
||||
body: Err("body was not initialized".to_string()),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn body(mut self, value: types::UserCreate) -> Self {
|
||||
self.body = Some(value);
|
||||
pub fn body<V>(mut self, value: V) -> Self
|
||||
where
|
||||
V: TryInto<types::UserCreate>,
|
||||
{
|
||||
self.body = value
|
||||
.try_into()
|
||||
.map_err(|_| "conversion to `UserCreate` for body failed".to_string());
|
||||
self
|
||||
}
|
||||
|
||||
///Sends a `POST` request to `/v1/users`
|
||||
pub async fn send(self) -> Result<ResponseValue<types::UserCreateResult>, Error<()>> {
|
||||
let Self { client, body } = self;
|
||||
let (body,) = match (body,) {
|
||||
(Some(body),) => (body,),
|
||||
(body,) => {
|
||||
let mut missing = Vec::new();
|
||||
if body.is_none() {
|
||||
missing.push(stringify!(body));
|
||||
}
|
||||
return Err(super::Error::InvalidRequest(format!(
|
||||
"the following parameters are required: {}",
|
||||
missing.join(", "),
|
||||
)));
|
||||
}
|
||||
};
|
||||
let body = body.map_err(Error::InvalidRequest)?;
|
||||
let url = format!("{}/v1/users", client.baseurl,);
|
||||
let request = client.client.post(url).json(&body).build()?;
|
||||
let result = client.client.execute(request).await;
|
||||
|
@ -810,35 +792,31 @@ pub mod builder {
|
|||
#[derive(Clone)]
|
||||
pub struct WorkerBootstrap<'a> {
|
||||
client: &'a super::Client,
|
||||
body: Option<types::WorkerBootstrap>,
|
||||
body: Result<types::WorkerBootstrap, String>,
|
||||
}
|
||||
|
||||
impl<'a> WorkerBootstrap<'a> {
|
||||
pub fn new(client: &'a super::Client) -> Self {
|
||||
Self { client, body: None }
|
||||
Self {
|
||||
client,
|
||||
body: Err("body was not initialized".to_string()),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn body(mut self, value: types::WorkerBootstrap) -> Self {
|
||||
self.body = Some(value);
|
||||
pub fn body<V>(mut self, value: V) -> Self
|
||||
where
|
||||
V: TryInto<types::WorkerBootstrap>,
|
||||
{
|
||||
self.body = value
|
||||
.try_into()
|
||||
.map_err(|_| "conversion to `WorkerBootstrap` for body failed".to_string());
|
||||
self
|
||||
}
|
||||
|
||||
///Sends a `POST` request to `/v1/worker/bootstrap`
|
||||
pub async fn send(self) -> Result<ResponseValue<types::WorkerBootstrapResult>, Error<()>> {
|
||||
let Self { client, body } = self;
|
||||
let (body,) = match (body,) {
|
||||
(Some(body),) => (body,),
|
||||
(body,) => {
|
||||
let mut missing = Vec::new();
|
||||
if body.is_none() {
|
||||
missing.push(stringify!(body));
|
||||
}
|
||||
return Err(super::Error::InvalidRequest(format!(
|
||||
"the following parameters are required: {}",
|
||||
missing.join(", "),
|
||||
)));
|
||||
}
|
||||
};
|
||||
let body = body.map_err(Error::InvalidRequest)?;
|
||||
let url = format!("{}/v1/worker/bootstrap", client.baseurl,);
|
||||
let request = client.client.post(url).json(&body).build()?;
|
||||
let result = client.client.execute(request).await;
|
||||
|
@ -883,48 +861,44 @@ pub mod builder {
|
|||
#[derive(Clone)]
|
||||
pub struct WorkerTaskAppend<'a> {
|
||||
client: &'a super::Client,
|
||||
task: Option<String>,
|
||||
body: Option<types::WorkerAppendTask>,
|
||||
task: Result<String, String>,
|
||||
body: Result<types::WorkerAppendTask, String>,
|
||||
}
|
||||
|
||||
impl<'a> WorkerTaskAppend<'a> {
|
||||
pub fn new(client: &'a super::Client) -> Self {
|
||||
Self {
|
||||
client,
|
||||
task: None,
|
||||
body: None,
|
||||
task: Err("task was not initialized".to_string()),
|
||||
body: Err("body was not initialized".to_string()),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn task<S: ToString>(mut self, value: S) -> Self {
|
||||
self.task = Some(value.to_string());
|
||||
pub fn task<V>(mut self, value: V) -> Self
|
||||
where
|
||||
V: TryInto<String>,
|
||||
{
|
||||
self.task = value
|
||||
.try_into()
|
||||
.map_err(|_| "conversion to `String` for task failed".to_string());
|
||||
self
|
||||
}
|
||||
|
||||
pub fn body(mut self, value: types::WorkerAppendTask) -> Self {
|
||||
self.body = Some(value);
|
||||
pub fn body<V>(mut self, value: V) -> Self
|
||||
where
|
||||
V: TryInto<types::WorkerAppendTask>,
|
||||
{
|
||||
self.body = value
|
||||
.try_into()
|
||||
.map_err(|_| "conversion to `WorkerAppendTask` for body failed".to_string());
|
||||
self
|
||||
}
|
||||
|
||||
///Sends a `POST` request to `/v1/worker/task/{task}/append`
|
||||
pub async fn send(self) -> Result<ResponseValue<()>, Error<()>> {
|
||||
let Self { client, task, body } = self;
|
||||
let (task, body) = match (task, body) {
|
||||
(Some(task), Some(body)) => (task, body),
|
||||
(task, body) => {
|
||||
let mut missing = Vec::new();
|
||||
if task.is_none() {
|
||||
missing.push(stringify!(task));
|
||||
}
|
||||
if body.is_none() {
|
||||
missing.push(stringify!(body));
|
||||
}
|
||||
return Err(super::Error::InvalidRequest(format!(
|
||||
"the following parameters are required: {}",
|
||||
missing.join(", "),
|
||||
)));
|
||||
}
|
||||
};
|
||||
let task = task.map_err(Error::InvalidRequest)?;
|
||||
let body = body.map_err(Error::InvalidRequest)?;
|
||||
let url = format!(
|
||||
"{}/v1/worker/task/{}/append",
|
||||
client.baseurl,
|
||||
|
@ -945,48 +919,44 @@ pub mod builder {
|
|||
///[`Client::worker_task_upload_chunk`]: super::Client::worker_task_upload_chunk
|
||||
pub struct WorkerTaskUploadChunk<'a> {
|
||||
client: &'a super::Client,
|
||||
task: Option<String>,
|
||||
body: Option<reqwest::Body>,
|
||||
task: Result<String, String>,
|
||||
body: Result<reqwest::Body, String>,
|
||||
}
|
||||
|
||||
impl<'a> WorkerTaskUploadChunk<'a> {
|
||||
pub fn new(client: &'a super::Client) -> Self {
|
||||
Self {
|
||||
client,
|
||||
task: None,
|
||||
body: None,
|
||||
task: Err("task was not initialized".to_string()),
|
||||
body: Err("body was not initialized".to_string()),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn task<S: ToString>(mut self, value: S) -> Self {
|
||||
self.task = Some(value.to_string());
|
||||
pub fn task<V>(mut self, value: V) -> Self
|
||||
where
|
||||
V: TryInto<String>,
|
||||
{
|
||||
self.task = value
|
||||
.try_into()
|
||||
.map_err(|_| "conversion to `String` for task failed".to_string());
|
||||
self
|
||||
}
|
||||
|
||||
pub fn body<B: Into<reqwest::Body>>(mut self, value: B) -> Self {
|
||||
self.body = Some(value.into());
|
||||
pub fn body<B>(mut self, value: B) -> Self
|
||||
where
|
||||
B: TryInto<reqwest::Body>,
|
||||
{
|
||||
self.body = value
|
||||
.try_into()
|
||||
.map_err(|_| "conversion to `reqwest::Body` for body failed".to_string());
|
||||
self
|
||||
}
|
||||
|
||||
///Sends a `POST` request to `/v1/worker/task/{task}/chunk`
|
||||
pub async fn send(self) -> Result<ResponseValue<types::UploadedChunk>, Error<()>> {
|
||||
let Self { client, task, body } = self;
|
||||
let (task, body) = match (task, body) {
|
||||
(Some(task), Some(body)) => (task, body),
|
||||
(task, body) => {
|
||||
let mut missing = Vec::new();
|
||||
if task.is_none() {
|
||||
missing.push(stringify!(task));
|
||||
}
|
||||
if body.is_none() {
|
||||
missing.push(stringify!(body));
|
||||
}
|
||||
return Err(super::Error::InvalidRequest(format!(
|
||||
"the following parameters are required: {}",
|
||||
missing.join(", "),
|
||||
)));
|
||||
}
|
||||
};
|
||||
let task = task.map_err(Error::InvalidRequest)?;
|
||||
let body = body.map_err(Error::InvalidRequest)?;
|
||||
let url = format!(
|
||||
"{}/v1/worker/task/{}/chunk",
|
||||
client.baseurl,
|
||||
|
@ -1016,48 +986,44 @@ pub mod builder {
|
|||
#[derive(Clone)]
|
||||
pub struct WorkerTaskComplete<'a> {
|
||||
client: &'a super::Client,
|
||||
task: Option<String>,
|
||||
body: Option<types::WorkerCompleteTask>,
|
||||
task: Result<String, String>,
|
||||
body: Result<types::WorkerCompleteTask, String>,
|
||||
}
|
||||
|
||||
impl<'a> WorkerTaskComplete<'a> {
|
||||
pub fn new(client: &'a super::Client) -> Self {
|
||||
Self {
|
||||
client,
|
||||
task: None,
|
||||
body: None,
|
||||
task: Err("task was not initialized".to_string()),
|
||||
body: Err("body was not initialized".to_string()),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn task<S: ToString>(mut self, value: S) -> Self {
|
||||
self.task = Some(value.to_string());
|
||||
pub fn task<V>(mut self, value: V) -> Self
|
||||
where
|
||||
V: TryInto<String>,
|
||||
{
|
||||
self.task = value
|
||||
.try_into()
|
||||
.map_err(|_| "conversion to `String` for task failed".to_string());
|
||||
self
|
||||
}
|
||||
|
||||
pub fn body(mut self, value: types::WorkerCompleteTask) -> Self {
|
||||
self.body = Some(value);
|
||||
pub fn body<V>(mut self, value: V) -> Self
|
||||
where
|
||||
V: TryInto<types::WorkerCompleteTask>,
|
||||
{
|
||||
self.body = value
|
||||
.try_into()
|
||||
.map_err(|_| "conversion to `WorkerCompleteTask` for body failed".to_string());
|
||||
self
|
||||
}
|
||||
|
||||
///Sends a `POST` request to `/v1/worker/task/{task}/complete`
|
||||
pub async fn send(self) -> Result<ResponseValue<()>, Error<()>> {
|
||||
let Self { client, task, body } = self;
|
||||
let (task, body) = match (task, body) {
|
||||
(Some(task), Some(body)) => (task, body),
|
||||
(task, body) => {
|
||||
let mut missing = Vec::new();
|
||||
if task.is_none() {
|
||||
missing.push(stringify!(task));
|
||||
}
|
||||
if body.is_none() {
|
||||
missing.push(stringify!(body));
|
||||
}
|
||||
return Err(super::Error::InvalidRequest(format!(
|
||||
"the following parameters are required: {}",
|
||||
missing.join(", "),
|
||||
)));
|
||||
}
|
||||
};
|
||||
let task = task.map_err(Error::InvalidRequest)?;
|
||||
let body = body.map_err(Error::InvalidRequest)?;
|
||||
let url = format!(
|
||||
"{}/v1/worker/task/{}/complete",
|
||||
client.baseurl,
|
||||
|
@ -1079,48 +1045,44 @@ pub mod builder {
|
|||
#[derive(Clone)]
|
||||
pub struct WorkerTaskAddOutput<'a> {
|
||||
client: &'a super::Client,
|
||||
task: Option<String>,
|
||||
body: Option<types::WorkerAddOutput>,
|
||||
task: Result<String, String>,
|
||||
body: Result<types::WorkerAddOutput, String>,
|
||||
}
|
||||
|
||||
impl<'a> WorkerTaskAddOutput<'a> {
|
||||
pub fn new(client: &'a super::Client) -> Self {
|
||||
Self {
|
||||
client,
|
||||
task: None,
|
||||
body: None,
|
||||
task: Err("task was not initialized".to_string()),
|
||||
body: Err("body was not initialized".to_string()),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn task<S: ToString>(mut self, value: S) -> Self {
|
||||
self.task = Some(value.to_string());
|
||||
pub fn task<V>(mut self, value: V) -> Self
|
||||
where
|
||||
V: TryInto<String>,
|
||||
{
|
||||
self.task = value
|
||||
.try_into()
|
||||
.map_err(|_| "conversion to `String` for task failed".to_string());
|
||||
self
|
||||
}
|
||||
|
||||
pub fn body(mut self, value: types::WorkerAddOutput) -> Self {
|
||||
self.body = Some(value);
|
||||
pub fn body<V>(mut self, value: V) -> Self
|
||||
where
|
||||
V: TryInto<types::WorkerAddOutput>,
|
||||
{
|
||||
self.body = value
|
||||
.try_into()
|
||||
.map_err(|_| "conversion to `WorkerAddOutput` for body failed".to_string());
|
||||
self
|
||||
}
|
||||
|
||||
///Sends a `POST` request to `/v1/worker/task/{task}/output`
|
||||
pub async fn send(self) -> Result<ResponseValue<()>, Error<()>> {
|
||||
let Self { client, task, body } = self;
|
||||
let (task, body) = match (task, body) {
|
||||
(Some(task), Some(body)) => (task, body),
|
||||
(task, body) => {
|
||||
let mut missing = Vec::new();
|
||||
if task.is_none() {
|
||||
missing.push(stringify!(task));
|
||||
}
|
||||
if body.is_none() {
|
||||
missing.push(stringify!(body));
|
||||
}
|
||||
return Err(super::Error::InvalidRequest(format!(
|
||||
"the following parameters are required: {}",
|
||||
missing.join(", "),
|
||||
)));
|
||||
}
|
||||
};
|
||||
let task = task.map_err(Error::InvalidRequest)?;
|
||||
let body = body.map_err(Error::InvalidRequest)?;
|
||||
let url = format!(
|
||||
"{}/v1/worker/task/{}/output",
|
||||
client.baseurl,
|
||||
|
|
|
@ -3,6 +3,8 @@ use progenitor_client::{encode_path, RequestBuilderExt};
|
|||
pub use progenitor_client::{ByteStream, Error, ResponseValue};
|
||||
pub mod types {
|
||||
use serde::{Deserialize, Serialize};
|
||||
#[allow(unused_imports)]
|
||||
use std::convert::TryFrom;
|
||||
#[derive(Clone, Debug, Deserialize, Serialize, JsonSchema)]
|
||||
pub struct Task {
|
||||
pub id: String,
|
||||
|
@ -368,6 +370,8 @@ pub mod builder {
|
|||
use super::types;
|
||||
#[allow(unused_imports)]
|
||||
use super::{encode_path, ByteStream, Error, RequestBuilderExt, ResponseValue};
|
||||
#[allow(unused_imports)]
|
||||
use std::convert::TryInto;
|
||||
///Builder for [`Client::control_hold`]
|
||||
///
|
||||
///[`Client::control_hold`]: super::Client::control_hold
|
||||
|
@ -428,35 +432,31 @@ pub mod builder {
|
|||
#[derive(Clone)]
|
||||
pub struct TaskGet<'a> {
|
||||
client: &'a super::Client,
|
||||
task: Option<String>,
|
||||
task: Result<String, String>,
|
||||
}
|
||||
|
||||
impl<'a> TaskGet<'a> {
|
||||
pub fn new(client: &'a super::Client) -> Self {
|
||||
Self { client, task: None }
|
||||
Self {
|
||||
client,
|
||||
task: Err("task was not initialized".to_string()),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn task<S: ToString>(mut self, value: S) -> Self {
|
||||
self.task = Some(value.to_string());
|
||||
pub fn task<V>(mut self, value: V) -> Self
|
||||
where
|
||||
V: TryInto<String>,
|
||||
{
|
||||
self.task = value
|
||||
.try_into()
|
||||
.map_err(|_| "conversion to `String` for task failed".to_string());
|
||||
self
|
||||
}
|
||||
|
||||
///Sends a `GET` request to `/v1/task/{task}`
|
||||
pub async fn send(self) -> Result<ResponseValue<types::Task>, Error<()>> {
|
||||
let Self { client, task } = self;
|
||||
let (task,) = match (task,) {
|
||||
(Some(task),) => (task,),
|
||||
(task,) => {
|
||||
let mut missing = Vec::new();
|
||||
if task.is_none() {
|
||||
missing.push(stringify!(task));
|
||||
}
|
||||
return Err(super::Error::InvalidRequest(format!(
|
||||
"the following parameters are required: {}",
|
||||
missing.join(", "),
|
||||
)));
|
||||
}
|
||||
};
|
||||
let task = task.map_err(Error::InvalidRequest)?;
|
||||
let url = format!(
|
||||
"{}/v1/task/{}",
|
||||
client.baseurl,
|
||||
|
@ -505,35 +505,31 @@ pub mod builder {
|
|||
#[derive(Clone)]
|
||||
pub struct TaskSubmit<'a> {
|
||||
client: &'a super::Client,
|
||||
body: Option<types::TaskSubmit>,
|
||||
body: Result<types::TaskSubmit, String>,
|
||||
}
|
||||
|
||||
impl<'a> TaskSubmit<'a> {
|
||||
pub fn new(client: &'a super::Client) -> Self {
|
||||
Self { client, body: None }
|
||||
Self {
|
||||
client,
|
||||
body: Err("body was not initialized".to_string()),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn body(mut self, value: types::TaskSubmit) -> Self {
|
||||
self.body = Some(value);
|
||||
pub fn body<V>(mut self, value: V) -> Self
|
||||
where
|
||||
V: TryInto<types::TaskSubmit>,
|
||||
{
|
||||
self.body = value
|
||||
.try_into()
|
||||
.map_err(|_| "conversion to `TaskSubmit` for body failed".to_string());
|
||||
self
|
||||
}
|
||||
|
||||
///Sends a `POST` request to `/v1/tasks`
|
||||
pub async fn send(self) -> Result<ResponseValue<types::TaskSubmitResult>, Error<()>> {
|
||||
let Self { client, body } = self;
|
||||
let (body,) = match (body,) {
|
||||
(Some(body),) => (body,),
|
||||
(body,) => {
|
||||
let mut missing = Vec::new();
|
||||
if body.is_none() {
|
||||
missing.push(stringify!(body));
|
||||
}
|
||||
return Err(super::Error::InvalidRequest(format!(
|
||||
"the following parameters are required: {}",
|
||||
missing.join(", "),
|
||||
)));
|
||||
}
|
||||
};
|
||||
let body = body.map_err(Error::InvalidRequest)?;
|
||||
let url = format!("{}/v1/tasks", client.baseurl,);
|
||||
let request = client.client.post(url).json(&body).build()?;
|
||||
let result = client.client.execute(request).await;
|
||||
|
@ -551,26 +547,37 @@ pub mod builder {
|
|||
#[derive(Clone)]
|
||||
pub struct TaskEventsGet<'a> {
|
||||
client: &'a super::Client,
|
||||
task: Option<String>,
|
||||
minseq: Option<u32>,
|
||||
task: Result<String, String>,
|
||||
minseq: Result<Option<u32>, String>,
|
||||
}
|
||||
|
||||
impl<'a> TaskEventsGet<'a> {
|
||||
pub fn new(client: &'a super::Client) -> Self {
|
||||
Self {
|
||||
client,
|
||||
task: None,
|
||||
minseq: None,
|
||||
task: Err("task was not initialized".to_string()),
|
||||
minseq: Ok(None),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn task<S: ToString>(mut self, value: S) -> Self {
|
||||
self.task = Some(value.to_string());
|
||||
pub fn task<V>(mut self, value: V) -> Self
|
||||
where
|
||||
V: TryInto<String>,
|
||||
{
|
||||
self.task = value
|
||||
.try_into()
|
||||
.map_err(|_| "conversion to `String` for task failed".to_string());
|
||||
self
|
||||
}
|
||||
|
||||
pub fn minseq(mut self, value: u32) -> Self {
|
||||
self.minseq = Some(value);
|
||||
pub fn minseq<V>(mut self, value: V) -> Self
|
||||
where
|
||||
V: TryInto<u32>,
|
||||
{
|
||||
self.minseq = value
|
||||
.try_into()
|
||||
.map(Some)
|
||||
.map_err(|_| "conversion to `Option < u32 >` for minseq failed".to_string());
|
||||
self
|
||||
}
|
||||
|
||||
|
@ -581,19 +588,8 @@ pub mod builder {
|
|||
task,
|
||||
minseq,
|
||||
} = self;
|
||||
let (task,) = match (task,) {
|
||||
(Some(task),) => (task,),
|
||||
(task,) => {
|
||||
let mut missing = Vec::new();
|
||||
if task.is_none() {
|
||||
missing.push(stringify!(task));
|
||||
}
|
||||
return Err(super::Error::InvalidRequest(format!(
|
||||
"the following parameters are required: {}",
|
||||
missing.join(", "),
|
||||
)));
|
||||
}
|
||||
};
|
||||
let task = task.map_err(Error::InvalidRequest)?;
|
||||
let minseq = minseq.map_err(Error::InvalidRequest)?;
|
||||
let url = format!(
|
||||
"{}/v1/tasks/{}/events",
|
||||
client.baseurl,
|
||||
|
@ -619,35 +615,31 @@ pub mod builder {
|
|||
#[derive(Clone)]
|
||||
pub struct TaskOutputsGet<'a> {
|
||||
client: &'a super::Client,
|
||||
task: Option<String>,
|
||||
task: Result<String, String>,
|
||||
}
|
||||
|
||||
impl<'a> TaskOutputsGet<'a> {
|
||||
pub fn new(client: &'a super::Client) -> Self {
|
||||
Self { client, task: None }
|
||||
Self {
|
||||
client,
|
||||
task: Err("task was not initialized".to_string()),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn task<S: ToString>(mut self, value: S) -> Self {
|
||||
self.task = Some(value.to_string());
|
||||
pub fn task<V>(mut self, value: V) -> Self
|
||||
where
|
||||
V: TryInto<String>,
|
||||
{
|
||||
self.task = value
|
||||
.try_into()
|
||||
.map_err(|_| "conversion to `String` for task failed".to_string());
|
||||
self
|
||||
}
|
||||
|
||||
///Sends a `GET` request to `/v1/tasks/{task}/outputs`
|
||||
pub async fn send(self) -> Result<ResponseValue<Vec<types::TaskOutput>>, Error<()>> {
|
||||
let Self { client, task } = self;
|
||||
let (task,) = match (task,) {
|
||||
(Some(task),) => (task,),
|
||||
(task,) => {
|
||||
let mut missing = Vec::new();
|
||||
if task.is_none() {
|
||||
missing.push(stringify!(task));
|
||||
}
|
||||
return Err(super::Error::InvalidRequest(format!(
|
||||
"the following parameters are required: {}",
|
||||
missing.join(", "),
|
||||
)));
|
||||
}
|
||||
};
|
||||
let task = task.map_err(Error::InvalidRequest)?;
|
||||
let url = format!(
|
||||
"{}/v1/tasks/{}/outputs",
|
||||
client.baseurl,
|
||||
|
@ -669,26 +661,36 @@ pub mod builder {
|
|||
#[derive(Clone)]
|
||||
pub struct TaskOutputDownload<'a> {
|
||||
client: &'a super::Client,
|
||||
task: Option<String>,
|
||||
output: Option<String>,
|
||||
task: Result<String, String>,
|
||||
output: Result<String, String>,
|
||||
}
|
||||
|
||||
impl<'a> TaskOutputDownload<'a> {
|
||||
pub fn new(client: &'a super::Client) -> Self {
|
||||
Self {
|
||||
client,
|
||||
task: None,
|
||||
output: None,
|
||||
task: Err("task was not initialized".to_string()),
|
||||
output: Err("output was not initialized".to_string()),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn task<S: ToString>(mut self, value: S) -> Self {
|
||||
self.task = Some(value.to_string());
|
||||
pub fn task<V>(mut self, value: V) -> Self
|
||||
where
|
||||
V: TryInto<String>,
|
||||
{
|
||||
self.task = value
|
||||
.try_into()
|
||||
.map_err(|_| "conversion to `String` for task failed".to_string());
|
||||
self
|
||||
}
|
||||
|
||||
pub fn output<S: ToString>(mut self, value: S) -> Self {
|
||||
self.output = Some(value.to_string());
|
||||
pub fn output<V>(mut self, value: V) -> Self
|
||||
where
|
||||
V: TryInto<String>,
|
||||
{
|
||||
self.output = value
|
||||
.try_into()
|
||||
.map_err(|_| "conversion to `String` for output failed".to_string());
|
||||
self
|
||||
}
|
||||
|
||||
|
@ -699,22 +701,8 @@ pub mod builder {
|
|||
task,
|
||||
output,
|
||||
} = self;
|
||||
let (task, output) = match (task, output) {
|
||||
(Some(task), Some(output)) => (task, output),
|
||||
(task, output) => {
|
||||
let mut missing = Vec::new();
|
||||
if task.is_none() {
|
||||
missing.push(stringify!(task));
|
||||
}
|
||||
if output.is_none() {
|
||||
missing.push(stringify!(output));
|
||||
}
|
||||
return Err(super::Error::InvalidRequest(format!(
|
||||
"the following parameters are required: {}",
|
||||
missing.join(", "),
|
||||
)));
|
||||
}
|
||||
};
|
||||
let task = task.map_err(Error::InvalidRequest)?;
|
||||
let output = output.map_err(Error::InvalidRequest)?;
|
||||
let url = format!(
|
||||
"{}/v1/tasks/{}/outputs/{}",
|
||||
client.baseurl,
|
||||
|
@ -737,35 +725,31 @@ pub mod builder {
|
|||
#[derive(Clone)]
|
||||
pub struct UserCreate<'a> {
|
||||
client: &'a super::Client,
|
||||
body: Option<types::UserCreate>,
|
||||
body: Result<types::UserCreate, String>,
|
||||
}
|
||||
|
||||
impl<'a> UserCreate<'a> {
|
||||
pub fn new(client: &'a super::Client) -> Self {
|
||||
Self { client, body: None }
|
||||
Self {
|
||||
client,
|
||||
body: Err("body was not initialized".to_string()),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn body(mut self, value: types::UserCreate) -> Self {
|
||||
self.body = Some(value);
|
||||
pub fn body<V>(mut self, value: V) -> Self
|
||||
where
|
||||
V: TryInto<types::UserCreate>,
|
||||
{
|
||||
self.body = value
|
||||
.try_into()
|
||||
.map_err(|_| "conversion to `UserCreate` for body failed".to_string());
|
||||
self
|
||||
}
|
||||
|
||||
///Sends a `POST` request to `/v1/users`
|
||||
pub async fn send(self) -> Result<ResponseValue<types::UserCreateResult>, Error<()>> {
|
||||
let Self { client, body } = self;
|
||||
let (body,) = match (body,) {
|
||||
(Some(body),) => (body,),
|
||||
(body,) => {
|
||||
let mut missing = Vec::new();
|
||||
if body.is_none() {
|
||||
missing.push(stringify!(body));
|
||||
}
|
||||
return Err(super::Error::InvalidRequest(format!(
|
||||
"the following parameters are required: {}",
|
||||
missing.join(", "),
|
||||
)));
|
||||
}
|
||||
};
|
||||
let body = body.map_err(Error::InvalidRequest)?;
|
||||
let url = format!("{}/v1/users", client.baseurl,);
|
||||
let request = client.client.post(url).json(&body).build()?;
|
||||
let result = client.client.execute(request).await;
|
||||
|
@ -810,35 +794,31 @@ pub mod builder {
|
|||
#[derive(Clone)]
|
||||
pub struct WorkerBootstrap<'a> {
|
||||
client: &'a super::Client,
|
||||
body: Option<types::WorkerBootstrap>,
|
||||
body: Result<types::WorkerBootstrap, String>,
|
||||
}
|
||||
|
||||
impl<'a> WorkerBootstrap<'a> {
|
||||
pub fn new(client: &'a super::Client) -> Self {
|
||||
Self { client, body: None }
|
||||
Self {
|
||||
client,
|
||||
body: Err("body was not initialized".to_string()),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn body(mut self, value: types::WorkerBootstrap) -> Self {
|
||||
self.body = Some(value);
|
||||
pub fn body<V>(mut self, value: V) -> Self
|
||||
where
|
||||
V: TryInto<types::WorkerBootstrap>,
|
||||
{
|
||||
self.body = value
|
||||
.try_into()
|
||||
.map_err(|_| "conversion to `WorkerBootstrap` for body failed".to_string());
|
||||
self
|
||||
}
|
||||
|
||||
///Sends a `POST` request to `/v1/worker/bootstrap`
|
||||
pub async fn send(self) -> Result<ResponseValue<types::WorkerBootstrapResult>, Error<()>> {
|
||||
let Self { client, body } = self;
|
||||
let (body,) = match (body,) {
|
||||
(Some(body),) => (body,),
|
||||
(body,) => {
|
||||
let mut missing = Vec::new();
|
||||
if body.is_none() {
|
||||
missing.push(stringify!(body));
|
||||
}
|
||||
return Err(super::Error::InvalidRequest(format!(
|
||||
"the following parameters are required: {}",
|
||||
missing.join(", "),
|
||||
)));
|
||||
}
|
||||
};
|
||||
let body = body.map_err(Error::InvalidRequest)?;
|
||||
let url = format!("{}/v1/worker/bootstrap", client.baseurl,);
|
||||
let request = client.client.post(url).json(&body).build()?;
|
||||
let result = client.client.execute(request).await;
|
||||
|
@ -883,48 +863,44 @@ pub mod builder {
|
|||
#[derive(Clone)]
|
||||
pub struct WorkerTaskAppend<'a> {
|
||||
client: &'a super::Client,
|
||||
task: Option<String>,
|
||||
body: Option<types::WorkerAppendTask>,
|
||||
task: Result<String, String>,
|
||||
body: Result<types::WorkerAppendTask, String>,
|
||||
}
|
||||
|
||||
impl<'a> WorkerTaskAppend<'a> {
|
||||
pub fn new(client: &'a super::Client) -> Self {
|
||||
Self {
|
||||
client,
|
||||
task: None,
|
||||
body: None,
|
||||
task: Err("task was not initialized".to_string()),
|
||||
body: Err("body was not initialized".to_string()),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn task<S: ToString>(mut self, value: S) -> Self {
|
||||
self.task = Some(value.to_string());
|
||||
pub fn task<V>(mut self, value: V) -> Self
|
||||
where
|
||||
V: TryInto<String>,
|
||||
{
|
||||
self.task = value
|
||||
.try_into()
|
||||
.map_err(|_| "conversion to `String` for task failed".to_string());
|
||||
self
|
||||
}
|
||||
|
||||
pub fn body(mut self, value: types::WorkerAppendTask) -> Self {
|
||||
self.body = Some(value);
|
||||
pub fn body<V>(mut self, value: V) -> Self
|
||||
where
|
||||
V: TryInto<types::WorkerAppendTask>,
|
||||
{
|
||||
self.body = value
|
||||
.try_into()
|
||||
.map_err(|_| "conversion to `WorkerAppendTask` for body failed".to_string());
|
||||
self
|
||||
}
|
||||
|
||||
///Sends a `POST` request to `/v1/worker/task/{task}/append`
|
||||
pub async fn send(self) -> Result<ResponseValue<()>, Error<()>> {
|
||||
let Self { client, task, body } = self;
|
||||
let (task, body) = match (task, body) {
|
||||
(Some(task), Some(body)) => (task, body),
|
||||
(task, body) => {
|
||||
let mut missing = Vec::new();
|
||||
if task.is_none() {
|
||||
missing.push(stringify!(task));
|
||||
}
|
||||
if body.is_none() {
|
||||
missing.push(stringify!(body));
|
||||
}
|
||||
return Err(super::Error::InvalidRequest(format!(
|
||||
"the following parameters are required: {}",
|
||||
missing.join(", "),
|
||||
)));
|
||||
}
|
||||
};
|
||||
let task = task.map_err(Error::InvalidRequest)?;
|
||||
let body = body.map_err(Error::InvalidRequest)?;
|
||||
let url = format!(
|
||||
"{}/v1/worker/task/{}/append",
|
||||
client.baseurl,
|
||||
|
@ -945,48 +921,44 @@ pub mod builder {
|
|||
///[`Client::worker_task_upload_chunk`]: super::Client::worker_task_upload_chunk
|
||||
pub struct WorkerTaskUploadChunk<'a> {
|
||||
client: &'a super::Client,
|
||||
task: Option<String>,
|
||||
body: Option<reqwest::Body>,
|
||||
task: Result<String, String>,
|
||||
body: Result<reqwest::Body, String>,
|
||||
}
|
||||
|
||||
impl<'a> WorkerTaskUploadChunk<'a> {
|
||||
pub fn new(client: &'a super::Client) -> Self {
|
||||
Self {
|
||||
client,
|
||||
task: None,
|
||||
body: None,
|
||||
task: Err("task was not initialized".to_string()),
|
||||
body: Err("body was not initialized".to_string()),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn task<S: ToString>(mut self, value: S) -> Self {
|
||||
self.task = Some(value.to_string());
|
||||
pub fn task<V>(mut self, value: V) -> Self
|
||||
where
|
||||
V: TryInto<String>,
|
||||
{
|
||||
self.task = value
|
||||
.try_into()
|
||||
.map_err(|_| "conversion to `String` for task failed".to_string());
|
||||
self
|
||||
}
|
||||
|
||||
pub fn body<B: Into<reqwest::Body>>(mut self, value: B) -> Self {
|
||||
self.body = Some(value.into());
|
||||
pub fn body<B>(mut self, value: B) -> Self
|
||||
where
|
||||
B: TryInto<reqwest::Body>,
|
||||
{
|
||||
self.body = value
|
||||
.try_into()
|
||||
.map_err(|_| "conversion to `reqwest::Body` for body failed".to_string());
|
||||
self
|
||||
}
|
||||
|
||||
///Sends a `POST` request to `/v1/worker/task/{task}/chunk`
|
||||
pub async fn send(self) -> Result<ResponseValue<types::UploadedChunk>, Error<()>> {
|
||||
let Self { client, task, body } = self;
|
||||
let (task, body) = match (task, body) {
|
||||
(Some(task), Some(body)) => (task, body),
|
||||
(task, body) => {
|
||||
let mut missing = Vec::new();
|
||||
if task.is_none() {
|
||||
missing.push(stringify!(task));
|
||||
}
|
||||
if body.is_none() {
|
||||
missing.push(stringify!(body));
|
||||
}
|
||||
return Err(super::Error::InvalidRequest(format!(
|
||||
"the following parameters are required: {}",
|
||||
missing.join(", "),
|
||||
)));
|
||||
}
|
||||
};
|
||||
let task = task.map_err(Error::InvalidRequest)?;
|
||||
let body = body.map_err(Error::InvalidRequest)?;
|
||||
let url = format!(
|
||||
"{}/v1/worker/task/{}/chunk",
|
||||
client.baseurl,
|
||||
|
@ -1016,48 +988,44 @@ pub mod builder {
|
|||
#[derive(Clone)]
|
||||
pub struct WorkerTaskComplete<'a> {
|
||||
client: &'a super::Client,
|
||||
task: Option<String>,
|
||||
body: Option<types::WorkerCompleteTask>,
|
||||
task: Result<String, String>,
|
||||
body: Result<types::WorkerCompleteTask, String>,
|
||||
}
|
||||
|
||||
impl<'a> WorkerTaskComplete<'a> {
|
||||
pub fn new(client: &'a super::Client) -> Self {
|
||||
Self {
|
||||
client,
|
||||
task: None,
|
||||
body: None,
|
||||
task: Err("task was not initialized".to_string()),
|
||||
body: Err("body was not initialized".to_string()),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn task<S: ToString>(mut self, value: S) -> Self {
|
||||
self.task = Some(value.to_string());
|
||||
pub fn task<V>(mut self, value: V) -> Self
|
||||
where
|
||||
V: TryInto<String>,
|
||||
{
|
||||
self.task = value
|
||||
.try_into()
|
||||
.map_err(|_| "conversion to `String` for task failed".to_string());
|
||||
self
|
||||
}
|
||||
|
||||
pub fn body(mut self, value: types::WorkerCompleteTask) -> Self {
|
||||
self.body = Some(value);
|
||||
pub fn body<V>(mut self, value: V) -> Self
|
||||
where
|
||||
V: TryInto<types::WorkerCompleteTask>,
|
||||
{
|
||||
self.body = value
|
||||
.try_into()
|
||||
.map_err(|_| "conversion to `WorkerCompleteTask` for body failed".to_string());
|
||||
self
|
||||
}
|
||||
|
||||
///Sends a `POST` request to `/v1/worker/task/{task}/complete`
|
||||
pub async fn send(self) -> Result<ResponseValue<()>, Error<()>> {
|
||||
let Self { client, task, body } = self;
|
||||
let (task, body) = match (task, body) {
|
||||
(Some(task), Some(body)) => (task, body),
|
||||
(task, body) => {
|
||||
let mut missing = Vec::new();
|
||||
if task.is_none() {
|
||||
missing.push(stringify!(task));
|
||||
}
|
||||
if body.is_none() {
|
||||
missing.push(stringify!(body));
|
||||
}
|
||||
return Err(super::Error::InvalidRequest(format!(
|
||||
"the following parameters are required: {}",
|
||||
missing.join(", "),
|
||||
)));
|
||||
}
|
||||
};
|
||||
let task = task.map_err(Error::InvalidRequest)?;
|
||||
let body = body.map_err(Error::InvalidRequest)?;
|
||||
let url = format!(
|
||||
"{}/v1/worker/task/{}/complete",
|
||||
client.baseurl,
|
||||
|
@ -1079,48 +1047,44 @@ pub mod builder {
|
|||
#[derive(Clone)]
|
||||
pub struct WorkerTaskAddOutput<'a> {
|
||||
client: &'a super::Client,
|
||||
task: Option<String>,
|
||||
body: Option<types::WorkerAddOutput>,
|
||||
task: Result<String, String>,
|
||||
body: Result<types::WorkerAddOutput, String>,
|
||||
}
|
||||
|
||||
impl<'a> WorkerTaskAddOutput<'a> {
|
||||
pub fn new(client: &'a super::Client) -> Self {
|
||||
Self {
|
||||
client,
|
||||
task: None,
|
||||
body: None,
|
||||
task: Err("task was not initialized".to_string()),
|
||||
body: Err("body was not initialized".to_string()),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn task<S: ToString>(mut self, value: S) -> Self {
|
||||
self.task = Some(value.to_string());
|
||||
pub fn task<V>(mut self, value: V) -> Self
|
||||
where
|
||||
V: TryInto<String>,
|
||||
{
|
||||
self.task = value
|
||||
.try_into()
|
||||
.map_err(|_| "conversion to `String` for task failed".to_string());
|
||||
self
|
||||
}
|
||||
|
||||
pub fn body(mut self, value: types::WorkerAddOutput) -> Self {
|
||||
self.body = Some(value);
|
||||
pub fn body<V>(mut self, value: V) -> Self
|
||||
where
|
||||
V: TryInto<types::WorkerAddOutput>,
|
||||
{
|
||||
self.body = value
|
||||
.try_into()
|
||||
.map_err(|_| "conversion to `WorkerAddOutput` for body failed".to_string());
|
||||
self
|
||||
}
|
||||
|
||||
///Sends a `POST` request to `/v1/worker/task/{task}/output`
|
||||
pub async fn send(self) -> Result<ResponseValue<()>, Error<()>> {
|
||||
let Self { client, task, body } = self;
|
||||
let (task, body) = match (task, body) {
|
||||
(Some(task), Some(body)) => (task, body),
|
||||
(task, body) => {
|
||||
let mut missing = Vec::new();
|
||||
if task.is_none() {
|
||||
missing.push(stringify!(task));
|
||||
}
|
||||
if body.is_none() {
|
||||
missing.push(stringify!(body));
|
||||
}
|
||||
return Err(super::Error::InvalidRequest(format!(
|
||||
"the following parameters are required: {}",
|
||||
missing.join(", "),
|
||||
)));
|
||||
}
|
||||
};
|
||||
let task = task.map_err(Error::InvalidRequest)?;
|
||||
let body = body.map_err(Error::InvalidRequest)?;
|
||||
let url = format!(
|
||||
"{}/v1/worker/task/{}/output",
|
||||
client.baseurl,
|
||||
|
|
|
@ -3,6 +3,8 @@ use progenitor_client::{encode_path, RequestBuilderExt};
|
|||
pub use progenitor_client::{ByteStream, Error, ResponseValue};
|
||||
pub mod types {
|
||||
use serde::{Deserialize, Serialize};
|
||||
#[allow(unused_imports)]
|
||||
use std::convert::TryFrom;
|
||||
#[derive(Clone, Debug, Deserialize, Serialize)]
|
||||
pub struct Task {
|
||||
pub id: String,
|
||||
|
|
|
@ -3,6 +3,8 @@ use progenitor_client::{encode_path, RequestBuilderExt};
|
|||
pub use progenitor_client::{ByteStream, Error, ResponseValue};
|
||||
pub mod types {
|
||||
use serde::{Deserialize, Serialize};
|
||||
#[allow(unused_imports)]
|
||||
use std::convert::TryFrom;
|
||||
#[derive(Clone, Debug, Deserialize, Serialize)]
|
||||
pub struct EnrolBody {
|
||||
pub host: String,
|
||||
|
@ -182,35 +184,31 @@ pub mod builder {
|
|||
#[derive(Clone)]
|
||||
pub struct Enrol<'a> {
|
||||
client: &'a super::Client,
|
||||
body: Option<types::EnrolBody>,
|
||||
body: Result<types::EnrolBody, String>,
|
||||
}
|
||||
|
||||
impl<'a> Enrol<'a> {
|
||||
pub fn new(client: &'a super::Client) -> Self {
|
||||
Self { client, body: None }
|
||||
Self {
|
||||
client,
|
||||
body: Err("body was not initialized".to_string()),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn body(mut self, value: types::EnrolBody) -> Self {
|
||||
self.body = Some(value);
|
||||
pub fn body<V>(mut self, value: V) -> Self
|
||||
where
|
||||
V: TryInto<types::EnrolBody>,
|
||||
{
|
||||
self.body = value
|
||||
.try_into()
|
||||
.map_err(|_| "conversion to `EnrolBody` for body failed".to_string());
|
||||
self
|
||||
}
|
||||
|
||||
///Sends a `POST` request to `/enrol`
|
||||
pub async fn send(self) -> Result<ResponseValue<()>, Error<()>> {
|
||||
let Self { client, body } = self;
|
||||
let (body,) = match (body,) {
|
||||
(Some(body),) => (body,),
|
||||
(body,) => {
|
||||
let mut missing = Vec::new();
|
||||
if body.is_none() {
|
||||
missing.push(stringify!(body));
|
||||
}
|
||||
return Err(super::Error::InvalidRequest(format!(
|
||||
"the following parameters are required: {}",
|
||||
missing.join(", "),
|
||||
)));
|
||||
}
|
||||
};
|
||||
let body = body.map_err(Error::InvalidRequest)?;
|
||||
let url = format!("{}/enrol", client.baseurl,);
|
||||
let request = client.client.post(url).json(&body).build()?;
|
||||
let result = client.client.execute(request).await;
|
||||
|
@ -282,35 +280,31 @@ pub mod builder {
|
|||
#[derive(Clone)]
|
||||
pub struct ReportFinish<'a> {
|
||||
client: &'a super::Client,
|
||||
body: Option<types::ReportFinishBody>,
|
||||
body: Result<types::ReportFinishBody, String>,
|
||||
}
|
||||
|
||||
impl<'a> ReportFinish<'a> {
|
||||
pub fn new(client: &'a super::Client) -> Self {
|
||||
Self { client, body: None }
|
||||
Self {
|
||||
client,
|
||||
body: Err("body was not initialized".to_string()),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn body(mut self, value: types::ReportFinishBody) -> Self {
|
||||
self.body = Some(value);
|
||||
pub fn body<V>(mut self, value: V) -> Self
|
||||
where
|
||||
V: TryInto<types::ReportFinishBody>,
|
||||
{
|
||||
self.body = value
|
||||
.try_into()
|
||||
.map_err(|_| "conversion to `ReportFinishBody` for body failed".to_string());
|
||||
self
|
||||
}
|
||||
|
||||
///Sends a `POST` request to `/report/finish`
|
||||
pub async fn send(self) -> Result<ResponseValue<types::ReportResult>, Error<()>> {
|
||||
let Self { client, body } = self;
|
||||
let (body,) = match (body,) {
|
||||
(Some(body),) => (body,),
|
||||
(body,) => {
|
||||
let mut missing = Vec::new();
|
||||
if body.is_none() {
|
||||
missing.push(stringify!(body));
|
||||
}
|
||||
return Err(super::Error::InvalidRequest(format!(
|
||||
"the following parameters are required: {}",
|
||||
missing.join(", "),
|
||||
)));
|
||||
}
|
||||
};
|
||||
let body = body.map_err(Error::InvalidRequest)?;
|
||||
let url = format!("{}/report/finish", client.baseurl,);
|
||||
let request = client.client.post(url).json(&body).build()?;
|
||||
let result = client.client.execute(request).await;
|
||||
|
@ -328,35 +322,31 @@ pub mod builder {
|
|||
#[derive(Clone)]
|
||||
pub struct ReportOutput<'a> {
|
||||
client: &'a super::Client,
|
||||
body: Option<types::ReportOutputBody>,
|
||||
body: Result<types::ReportOutputBody, String>,
|
||||
}
|
||||
|
||||
impl<'a> ReportOutput<'a> {
|
||||
pub fn new(client: &'a super::Client) -> Self {
|
||||
Self { client, body: None }
|
||||
Self {
|
||||
client,
|
||||
body: Err("body was not initialized".to_string()),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn body(mut self, value: types::ReportOutputBody) -> Self {
|
||||
self.body = Some(value);
|
||||
pub fn body<V>(mut self, value: V) -> Self
|
||||
where
|
||||
V: TryInto<types::ReportOutputBody>,
|
||||
{
|
||||
self.body = value
|
||||
.try_into()
|
||||
.map_err(|_| "conversion to `ReportOutputBody` for body failed".to_string());
|
||||
self
|
||||
}
|
||||
|
||||
///Sends a `POST` request to `/report/output`
|
||||
pub async fn send(self) -> Result<ResponseValue<types::ReportResult>, Error<()>> {
|
||||
let Self { client, body } = self;
|
||||
let (body,) = match (body,) {
|
||||
(Some(body),) => (body,),
|
||||
(body,) => {
|
||||
let mut missing = Vec::new();
|
||||
if body.is_none() {
|
||||
missing.push(stringify!(body));
|
||||
}
|
||||
return Err(super::Error::InvalidRequest(format!(
|
||||
"the following parameters are required: {}",
|
||||
missing.join(", "),
|
||||
)));
|
||||
}
|
||||
};
|
||||
let body = body.map_err(Error::InvalidRequest)?;
|
||||
let url = format!("{}/report/output", client.baseurl,);
|
||||
let request = client.client.post(url).json(&body).build()?;
|
||||
let result = client.client.execute(request).await;
|
||||
|
@ -374,35 +364,31 @@ pub mod builder {
|
|||
#[derive(Clone)]
|
||||
pub struct ReportStart<'a> {
|
||||
client: &'a super::Client,
|
||||
body: Option<types::ReportStartBody>,
|
||||
body: Result<types::ReportStartBody, String>,
|
||||
}
|
||||
|
||||
impl<'a> ReportStart<'a> {
|
||||
pub fn new(client: &'a super::Client) -> Self {
|
||||
Self { client, body: None }
|
||||
Self {
|
||||
client,
|
||||
body: Err("body was not initialized".to_string()),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn body(mut self, value: types::ReportStartBody) -> Self {
|
||||
self.body = Some(value);
|
||||
pub fn body<V>(mut self, value: V) -> Self
|
||||
where
|
||||
V: TryInto<types::ReportStartBody>,
|
||||
{
|
||||
self.body = value
|
||||
.try_into()
|
||||
.map_err(|_| "conversion to `ReportStartBody` for body failed".to_string());
|
||||
self
|
||||
}
|
||||
|
||||
///Sends a `POST` request to `/report/start`
|
||||
pub async fn send(self) -> Result<ResponseValue<types::ReportResult>, Error<()>> {
|
||||
let Self { client, body } = self;
|
||||
let (body,) = match (body,) {
|
||||
(Some(body),) => (body,),
|
||||
(body,) => {
|
||||
let mut missing = Vec::new();
|
||||
if body.is_none() {
|
||||
missing.push(stringify!(body));
|
||||
}
|
||||
return Err(super::Error::InvalidRequest(format!(
|
||||
"the following parameters are required: {}",
|
||||
missing.join(", "),
|
||||
)));
|
||||
}
|
||||
};
|
||||
let body = body.map_err(Error::InvalidRequest)?;
|
||||
let url = format!("{}/report/start", client.baseurl,);
|
||||
let request = client.client.post(url).json(&body).build()?;
|
||||
let result = client.client.execute(request).await;
|
||||
|
|
|
@ -3,6 +3,8 @@ use progenitor_client::{encode_path, RequestBuilderExt};
|
|||
pub use progenitor_client::{ByteStream, Error, ResponseValue};
|
||||
pub mod types {
|
||||
use serde::{Deserialize, Serialize};
|
||||
#[allow(unused_imports)]
|
||||
use std::convert::TryFrom;
|
||||
#[derive(Clone, Debug, Deserialize, Serialize, JsonSchema)]
|
||||
pub struct EnrolBody {
|
||||
pub host: String,
|
||||
|
@ -176,41 +178,39 @@ pub mod builder {
|
|||
use super::types;
|
||||
#[allow(unused_imports)]
|
||||
use super::{encode_path, ByteStream, Error, RequestBuilderExt, ResponseValue};
|
||||
#[allow(unused_imports)]
|
||||
use std::convert::TryInto;
|
||||
///Builder for [`Client::enrol`]
|
||||
///
|
||||
///[`Client::enrol`]: super::Client::enrol
|
||||
#[derive(Clone)]
|
||||
pub struct Enrol<'a> {
|
||||
client: &'a super::Client,
|
||||
body: Option<types::EnrolBody>,
|
||||
body: Result<types::EnrolBody, String>,
|
||||
}
|
||||
|
||||
impl<'a> Enrol<'a> {
|
||||
pub fn new(client: &'a super::Client) -> Self {
|
||||
Self { client, body: None }
|
||||
Self {
|
||||
client,
|
||||
body: Err("body was not initialized".to_string()),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn body(mut self, value: types::EnrolBody) -> Self {
|
||||
self.body = Some(value);
|
||||
pub fn body<V>(mut self, value: V) -> Self
|
||||
where
|
||||
V: TryInto<types::EnrolBody>,
|
||||
{
|
||||
self.body = value
|
||||
.try_into()
|
||||
.map_err(|_| "conversion to `EnrolBody` for body failed".to_string());
|
||||
self
|
||||
}
|
||||
|
||||
///Sends a `POST` request to `/enrol`
|
||||
pub async fn send(self) -> Result<ResponseValue<()>, Error<()>> {
|
||||
let Self { client, body } = self;
|
||||
let (body,) = match (body,) {
|
||||
(Some(body),) => (body,),
|
||||
(body,) => {
|
||||
let mut missing = Vec::new();
|
||||
if body.is_none() {
|
||||
missing.push(stringify!(body));
|
||||
}
|
||||
return Err(super::Error::InvalidRequest(format!(
|
||||
"the following parameters are required: {}",
|
||||
missing.join(", "),
|
||||
)));
|
||||
}
|
||||
};
|
||||
let body = body.map_err(Error::InvalidRequest)?;
|
||||
let url = format!("{}/enrol", client.baseurl,);
|
||||
let request = client.client.post(url).json(&body).build()?;
|
||||
let result = client.client.execute(request).await;
|
||||
|
@ -282,35 +282,31 @@ pub mod builder {
|
|||
#[derive(Clone)]
|
||||
pub struct ReportFinish<'a> {
|
||||
client: &'a super::Client,
|
||||
body: Option<types::ReportFinishBody>,
|
||||
body: Result<types::ReportFinishBody, String>,
|
||||
}
|
||||
|
||||
impl<'a> ReportFinish<'a> {
|
||||
pub fn new(client: &'a super::Client) -> Self {
|
||||
Self { client, body: None }
|
||||
Self {
|
||||
client,
|
||||
body: Err("body was not initialized".to_string()),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn body(mut self, value: types::ReportFinishBody) -> Self {
|
||||
self.body = Some(value);
|
||||
pub fn body<V>(mut self, value: V) -> Self
|
||||
where
|
||||
V: TryInto<types::ReportFinishBody>,
|
||||
{
|
||||
self.body = value
|
||||
.try_into()
|
||||
.map_err(|_| "conversion to `ReportFinishBody` for body failed".to_string());
|
||||
self
|
||||
}
|
||||
|
||||
///Sends a `POST` request to `/report/finish`
|
||||
pub async fn send(self) -> Result<ResponseValue<types::ReportResult>, Error<()>> {
|
||||
let Self { client, body } = self;
|
||||
let (body,) = match (body,) {
|
||||
(Some(body),) => (body,),
|
||||
(body,) => {
|
||||
let mut missing = Vec::new();
|
||||
if body.is_none() {
|
||||
missing.push(stringify!(body));
|
||||
}
|
||||
return Err(super::Error::InvalidRequest(format!(
|
||||
"the following parameters are required: {}",
|
||||
missing.join(", "),
|
||||
)));
|
||||
}
|
||||
};
|
||||
let body = body.map_err(Error::InvalidRequest)?;
|
||||
let url = format!("{}/report/finish", client.baseurl,);
|
||||
let request = client.client.post(url).json(&body).build()?;
|
||||
let result = client.client.execute(request).await;
|
||||
|
@ -328,35 +324,31 @@ pub mod builder {
|
|||
#[derive(Clone)]
|
||||
pub struct ReportOutput<'a> {
|
||||
client: &'a super::Client,
|
||||
body: Option<types::ReportOutputBody>,
|
||||
body: Result<types::ReportOutputBody, String>,
|
||||
}
|
||||
|
||||
impl<'a> ReportOutput<'a> {
|
||||
pub fn new(client: &'a super::Client) -> Self {
|
||||
Self { client, body: None }
|
||||
Self {
|
||||
client,
|
||||
body: Err("body was not initialized".to_string()),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn body(mut self, value: types::ReportOutputBody) -> Self {
|
||||
self.body = Some(value);
|
||||
pub fn body<V>(mut self, value: V) -> Self
|
||||
where
|
||||
V: TryInto<types::ReportOutputBody>,
|
||||
{
|
||||
self.body = value
|
||||
.try_into()
|
||||
.map_err(|_| "conversion to `ReportOutputBody` for body failed".to_string());
|
||||
self
|
||||
}
|
||||
|
||||
///Sends a `POST` request to `/report/output`
|
||||
pub async fn send(self) -> Result<ResponseValue<types::ReportResult>, Error<()>> {
|
||||
let Self { client, body } = self;
|
||||
let (body,) = match (body,) {
|
||||
(Some(body),) => (body,),
|
||||
(body,) => {
|
||||
let mut missing = Vec::new();
|
||||
if body.is_none() {
|
||||
missing.push(stringify!(body));
|
||||
}
|
||||
return Err(super::Error::InvalidRequest(format!(
|
||||
"the following parameters are required: {}",
|
||||
missing.join(", "),
|
||||
)));
|
||||
}
|
||||
};
|
||||
let body = body.map_err(Error::InvalidRequest)?;
|
||||
let url = format!("{}/report/output", client.baseurl,);
|
||||
let request = client.client.post(url).json(&body).build()?;
|
||||
let result = client.client.execute(request).await;
|
||||
|
@ -374,35 +366,31 @@ pub mod builder {
|
|||
#[derive(Clone)]
|
||||
pub struct ReportStart<'a> {
|
||||
client: &'a super::Client,
|
||||
body: Option<types::ReportStartBody>,
|
||||
body: Result<types::ReportStartBody, String>,
|
||||
}
|
||||
|
||||
impl<'a> ReportStart<'a> {
|
||||
pub fn new(client: &'a super::Client) -> Self {
|
||||
Self { client, body: None }
|
||||
Self {
|
||||
client,
|
||||
body: Err("body was not initialized".to_string()),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn body(mut self, value: types::ReportStartBody) -> Self {
|
||||
self.body = Some(value);
|
||||
pub fn body<V>(mut self, value: V) -> Self
|
||||
where
|
||||
V: TryInto<types::ReportStartBody>,
|
||||
{
|
||||
self.body = value
|
||||
.try_into()
|
||||
.map_err(|_| "conversion to `ReportStartBody` for body failed".to_string());
|
||||
self
|
||||
}
|
||||
|
||||
///Sends a `POST` request to `/report/start`
|
||||
pub async fn send(self) -> Result<ResponseValue<types::ReportResult>, Error<()>> {
|
||||
let Self { client, body } = self;
|
||||
let (body,) = match (body,) {
|
||||
(Some(body),) => (body,),
|
||||
(body,) => {
|
||||
let mut missing = Vec::new();
|
||||
if body.is_none() {
|
||||
missing.push(stringify!(body));
|
||||
}
|
||||
return Err(super::Error::InvalidRequest(format!(
|
||||
"the following parameters are required: {}",
|
||||
missing.join(", "),
|
||||
)));
|
||||
}
|
||||
};
|
||||
let body = body.map_err(Error::InvalidRequest)?;
|
||||
let url = format!("{}/report/start", client.baseurl,);
|
||||
let request = client.client.post(url).json(&body).build()?;
|
||||
let result = client.client.execute(request).await;
|
||||
|
|
|
@ -3,6 +3,8 @@ use progenitor_client::{encode_path, RequestBuilderExt};
|
|||
pub use progenitor_client::{ByteStream, Error, ResponseValue};
|
||||
pub mod types {
|
||||
use serde::{Deserialize, Serialize};
|
||||
#[allow(unused_imports)]
|
||||
use std::convert::TryFrom;
|
||||
#[derive(Clone, Debug, Deserialize, Serialize)]
|
||||
pub struct EnrolBody {
|
||||
pub host: String,
|
||||
|
|
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
|
@ -3,6 +3,8 @@ use progenitor_client::{encode_path, RequestBuilderExt};
|
|||
pub use progenitor_client::{ByteStream, Error, ResponseValue};
|
||||
pub mod types {
|
||||
use serde::{Deserialize, Serialize};
|
||||
#[allow(unused_imports)]
|
||||
use std::convert::TryFrom;
|
||||
#[derive(Clone, Debug, Deserialize, Serialize)]
|
||||
pub struct BlockSize(i64);
|
||||
impl std::ops::Deref for BlockSize {
|
||||
|
|
|
@ -3,6 +3,8 @@ use progenitor_client::{encode_path, RequestBuilderExt};
|
|||
pub use progenitor_client::{ByteStream, Error, ResponseValue};
|
||||
pub mod types {
|
||||
use serde::{Deserialize, Serialize};
|
||||
#[allow(unused_imports)]
|
||||
use std::convert::TryFrom;
|
||||
mod defaults {
|
||||
pub(super) fn default_u64<T, const V: u64>() -> T
|
||||
where
|
||||
|
|
|
@ -3,6 +3,8 @@ use progenitor_client::{encode_path, RequestBuilderExt};
|
|||
pub use progenitor_client::{ByteStream, Error, ResponseValue};
|
||||
pub mod types {
|
||||
use serde::{Deserialize, Serialize};
|
||||
#[allow(unused_imports)]
|
||||
use std::convert::TryFrom;
|
||||
///Error information from a response.
|
||||
#[derive(Clone, Debug, Deserialize, Serialize)]
|
||||
pub struct Error {
|
||||
|
|
|
@ -3,6 +3,8 @@ use progenitor_client::{encode_path, RequestBuilderExt};
|
|||
pub use progenitor_client::{ByteStream, Error, ResponseValue};
|
||||
pub mod types {
|
||||
use serde::{Deserialize, Serialize};
|
||||
#[allow(unused_imports)]
|
||||
use std::convert::TryFrom;
|
||||
///Error information from a response.
|
||||
#[derive(Clone, Debug, Deserialize, Serialize)]
|
||||
pub struct Error {
|
||||
|
|
|
@ -34,15 +34,15 @@ mod builder_untagged {
|
|||
);
|
||||
}
|
||||
|
||||
use nexus_client::{types, Client};
|
||||
use nexus_client::Client;
|
||||
|
||||
pub fn _ignore() {
|
||||
let client = Client::new("");
|
||||
let stream = client
|
||||
.instance_disk_list()
|
||||
.organization_name(types::Name::try_from("org").unwrap())
|
||||
.project_name(types::Name::try_from("project").unwrap())
|
||||
.instance_name(types::Name::try_from("instance").unwrap())
|
||||
.organization_name("org")
|
||||
.project_name("project")
|
||||
.instance_name("instance")
|
||||
.stream();
|
||||
let _ = stream.collect::<Vec<_>>();
|
||||
}
|
||||
|
@ -59,15 +59,15 @@ mod builder_tagged {
|
|||
);
|
||||
}
|
||||
|
||||
use nexus_client::{types, Client, ClientInstancesExt};
|
||||
use nexus_client::{Client, ClientInstancesExt};
|
||||
|
||||
fn _ignore() {
|
||||
let client = Client::new("");
|
||||
let stream = client
|
||||
.instance_disk_list()
|
||||
.organization_name(types::Name::try_from("org").unwrap())
|
||||
.project_name(types::Name::try_from("project").unwrap())
|
||||
.instance_name(types::Name::try_from("instance").unwrap())
|
||||
.organization_name("org")
|
||||
.project_name("project")
|
||||
.instance_name("instance")
|
||||
.stream();
|
||||
let _ = stream.collect::<Vec<_>>();
|
||||
}
|
||||
|
|
|
@ -7830,7 +7830,8 @@
|
|||
"user_data": {
|
||||
"description": "User data for instance initialization systems (such as cloud-init). Must be a Base64-encoded string, as specified in RFC 4648 § 4 (+ and / characters with padding). Maximum 32 KiB unencoded data.",
|
||||
"default": "",
|
||||
"type": "string"
|
||||
"type": "string",
|
||||
"format": "byte"
|
||||
}
|
||||
},
|
||||
"required": [
|
||||
|
|
Loading…
Reference in New Issue