|
|
|
@ -29,12 +29,16 @@ macro_rules! build_url_by_method { |
|
|
|
|
ptype = $($param_type:ty)?, |
|
|
|
|
urlparam = $($url_param:ty)? |
|
|
|
|
) => { |
|
|
|
|
|instance: &ClientHandler $(, param: &$param_type)?| { |
|
|
|
|
| |
|
|
|
|
instance: &ClientHandler |
|
|
|
|
$(, param: &$param_type)? |
|
|
|
|
$(, url: &$url_param)? |
|
|
|
|
| { |
|
|
|
|
let request = ClientHandler::build_post( |
|
|
|
|
instance, |
|
|
|
|
&format!("{}/{}", |
|
|
|
|
stringify!($path), |
|
|
|
|
String::new() $(+ stringify!($url_param))? |
|
|
|
|
String::new() $(+ &(url as &$url_param).to_string())? |
|
|
|
|
) |
|
|
|
|
); |
|
|
|
|
request |
|
|
|
@ -47,12 +51,16 @@ macro_rules! build_url_by_method { |
|
|
|
|
ptype = $($param_type:ty)?, |
|
|
|
|
urlparam = $($url_param:ty)? |
|
|
|
|
) => { |
|
|
|
|
|instance: &ClientHandler $(, param: &$param_type)?| { |
|
|
|
|
| |
|
|
|
|
instance: &ClientHandler |
|
|
|
|
$(, param: &$param_type)? |
|
|
|
|
$(, url: &$url_param)? |
|
|
|
|
| { |
|
|
|
|
let request = ClientHandler::build_get( |
|
|
|
|
instance, |
|
|
|
|
&format!("{}/{}", |
|
|
|
|
stringify!($path), |
|
|
|
|
String::new() $(+ stringify!($url_param))? |
|
|
|
|
String::new() $(+ &(url as &$url_param).to_string())? |
|
|
|
|
) |
|
|
|
|
); |
|
|
|
|
request |
|
|
|
@ -73,12 +81,14 @@ macro_rules! build_handler { |
|
|
|
|
) => { |
|
|
|
|
impl ClientHandler { |
|
|
|
|
pub async fn $path( |
|
|
|
|
&self $(, param: &$param_type)? // $(, url_param: &$url_param)?
|
|
|
|
|
&self |
|
|
|
|
$(, param: &$param_type)? |
|
|
|
|
$(, url_param: &$url_param)? |
|
|
|
|
) -> UResult<$result> { |
|
|
|
|
let request = $crate::build_url_by_method!( |
|
|
|
|
$method $path, |
|
|
|
|
pname = $($param_name)?, ptype = $($param_type)?, urlparam = $($url_param)? |
|
|
|
|
)(self $(, param as &$param_type)? ); |
|
|
|
|
)(self $(, param as &$param_type)? $(, url_param as &$url_param)?); |
|
|
|
|
let response = request.send().await?; |
|
|
|
|
match response.error_for_status() { |
|
|
|
|
Ok(r) => r.json::<BaseMessage<$result>>() |
|
|
|
@ -146,20 +156,20 @@ impl ClientHandler { |
|
|
|
|
// client listing (A)
|
|
|
|
|
build_handler!(GET get_agents() -> Vec<Agent>); |
|
|
|
|
// get jobs for client (agent_id=Uuid)
|
|
|
|
|
build_handler!(GET get_jobs("agent_id":Uuid) -> Vec<JobMeta>); |
|
|
|
|
build_handler!(GET get_agent_jobs/Uuid() -> Vec<JobMeta>); |
|
|
|
|
// get all available jobs (A)
|
|
|
|
|
build_handler!(GET get_jobs/Uuid() -> Vec<JobMeta>); |
|
|
|
|
// add client to server's db
|
|
|
|
|
build_handler!(POST init(IAgent) -> RawMsg); |
|
|
|
|
build_handler!(POST init(IAgent) -> String); |
|
|
|
|
// create and upload job (A)
|
|
|
|
|
build_handler!(POST add_jobs(Vec<JobMeta>) -> ()); |
|
|
|
|
build_handler!(POST upload_jobs(Vec<JobMeta>) -> ()); |
|
|
|
|
// delete something (A)
|
|
|
|
|
build_handler!(GET del/Uuid() -> ()); |
|
|
|
|
/* |
|
|
|
|
// set jobs for client (A)
|
|
|
|
|
// POST /set_jobs/Uuid json: JobMetaStorage
|
|
|
|
|
build_handler!(POST set_jobs(JobMetaStorage; Uuid) -> ()); |
|
|
|
|
// POST /set_jobs/Uuid json: Vec<Uuid>
|
|
|
|
|
build_handler!(POST set_jobs/Uuid(Vec<Uuid>) -> ()); |
|
|
|
|
// get results (A)
|
|
|
|
|
// GET /get_job_results?job_id=Uuid
|
|
|
|
|
build_handler!(GET get_job_results("job_id":Uuid) -> Vec<JobResult>); |
|
|
|
|
// GET /get_job_results/Uuid
|
|
|
|
|
build_handler!(GET get_job_results/Uuid() -> Vec<JobResult>); |
|
|
|
|
// report job result
|
|
|
|
|
build_handler!(POST report(Vec<JobResult>) -> ()); |
|
|
|
|
*/ |