Process the CommandRequest from the OpenAPI Spec in the execute handler

This is where the rubber starts to meet the road
This commit is contained in:
R Tyler Croy 2023-01-28 16:54:01 -08:00
parent cc8cc30b17
commit 6d963464cf
No known key found for this signature in database
GPG Key ID: E5C92681BEF6CEA2
2 changed files with 20 additions and 3 deletions

View File

@ -18,12 +18,29 @@ mod routes {
pub mod api {
use crate::caps::*;
use janky::CommandRequest;
use log::*;
use tide::{Body, Request};
pub fn register(app: &mut tide::Server<()>) {
app.at("/api/v1/capabilities").get(get_caps);
app.at("/api/v1/execute").put(execute);
}
/*
* PUT /execute
*
* This will take in the commands to actually execute
*/
pub async fn execute(mut req: Request<()>) -> Result<Body, tide::Error> {
let commands: CommandRequest = req.body_json().await?;
debug!("Commands to exec: {:?}", commands);
Ok("{}".into())
}
/*
* GET /capabilities
*/
pub async fn get_caps(_req: Request<()>) -> Result<Body, tide::Error> {
let response = json!({
"caps" : [

View File

@ -20,17 +20,17 @@ struct CapsResponse {
}
#[derive(Clone, Debug, Deserialize, Serialize, PartialEq)]
struct Command {
pub struct Command {
script: String,
}
#[derive(Clone, Debug, Deserialize, Serialize, PartialEq)]
struct CommandRequest {
pub struct CommandRequest {
commands: Vec<Command>,
}
#[derive(Clone, Debug, Deserialize, Serialize, PartialEq)]
struct CommandResponse {
pub struct CommandResponse {
uuid: Uuid,
stream_url: Option<Url>,
task_url: Url,