Compare commits
2 Commits
ed96899c6c
...
6d963464cf
Author | SHA1 | Date |
---|---|---|
R Tyler Croy | 6d963464cf | |
R Tyler Croy | cc8cc30b17 |
|
@ -26,13 +26,36 @@ paths:
|
|||
application/json:
|
||||
schema:
|
||||
$ref: '#/components/schemas/CapsResponse'
|
||||
/execute:
|
||||
put:
|
||||
summary: "Execute a series of commands on this agent"
|
||||
description:
|
||||
requestBody:
|
||||
content:
|
||||
application/json:
|
||||
schema:
|
||||
$ref: '#/components/schemas/CommandRequest'
|
||||
example:
|
||||
commands:
|
||||
- script: 'echo "Hi"'
|
||||
responses:
|
||||
200:
|
||||
description: 'Successfully accepted the commands for execution'
|
||||
content:
|
||||
application/json:
|
||||
schema:
|
||||
$ref: '#/components/schemas/CommandResponse'
|
||||
409:
|
||||
description: 'Returned when the agent is busy with another series of commands'
|
||||
|
||||
components:
|
||||
schemas:
|
||||
CapsResponse:
|
||||
type: array
|
||||
type: object
|
||||
properties:
|
||||
caps:
|
||||
type: array
|
||||
items:
|
||||
$ref: '#/components/schemas/Capability'
|
||||
Capability:
|
||||
type: object
|
||||
|
@ -43,3 +66,28 @@ components:
|
|||
type: string
|
||||
data:
|
||||
type: object
|
||||
Command:
|
||||
type: object
|
||||
properties:
|
||||
script:
|
||||
type: string
|
||||
description: "A script that can be exec()'d on the agent"
|
||||
CommandRequest:
|
||||
type: object
|
||||
properties:
|
||||
commands:
|
||||
type: array
|
||||
items:
|
||||
$ref: '#/components/schemas/Command'
|
||||
CommandResponse:
|
||||
type: object
|
||||
properties:
|
||||
uuid:
|
||||
type: string
|
||||
format: uuid
|
||||
stream:
|
||||
description: 'URL to streaming WebSockets logs'
|
||||
type: string
|
||||
task:
|
||||
description: 'URL to the task metadata'
|
||||
type: string
|
||||
|
|
|
@ -1 +1 @@
|
|||
{"openapi":"3.0.0","info":{"description":"Janky Agent API defintion\n","version":"1.0.0","title":"Janky APIs","contact":{"email":"rtyler+janky@brokenco.de"},"license":{"name":"AGPL v3.0","url":"https://www.gnu.org/licenses/agpl-3.0.en.html"}},"servers":[{"url":"http://localhost:9000/api/v1","description":"Local dev agent (APIv1)"}],"paths":{"/capabilities":{"get":{"summary":"Retrieve a list of capabilities of this agent","description":null,"responses":{"200":{"description":"Getting capabilities","content":{"application/json":{"schema":{"$ref":"#/components/schemas/CapsResponse"}}}}}}}},"components":{"schemas":{"CapsResponse":{"type":"array","properties":{"caps":{"$ref":"#/components/schemas/Capability"}}},"Capability":{"type":"object","properties":{"name":{"type":"string"},"path":{"type":"string"},"data":{"type":"object"}}}}}}
|
||||
{"openapi":"3.0.0","info":{"description":"Janky Agent API defintion\n","version":"1.0.0","title":"Janky APIs","contact":{"email":"rtyler+janky@brokenco.de"},"license":{"name":"AGPL v3.0","url":"https://www.gnu.org/licenses/agpl-3.0.en.html"}},"servers":[{"url":"http://localhost:9000/api/v1","description":"Local dev agent (APIv1)"}],"paths":{"/capabilities":{"get":{"summary":"Retrieve a list of capabilities of this agent","description":null,"responses":{"200":{"description":"Getting capabilities","content":{"application/json":{"schema":{"$ref":"#/components/schemas/CapsResponse"}}}}}}},"/execute":{"put":{"summary":"Execute a series of commands on this agent","description":null,"requestBody":{"content":{"application/json":{"schema":{"$ref":"#/components/schemas/CommandRequest"},"example":{"commands":[{"script":"echo \"Hi\""}]}}}},"responses":{"200":{"description":"Successfully accepted the commands for execution","content":{"application/json":{"schema":{"$ref":"#/components/schemas/CommandResponse"}}}},"409":{"description":"Returned when the agent is busy with another series of commands"}}}}},"components":{"schemas":{"CapsResponse":{"type":"object","properties":{"caps":{"type":"array","items":{"$ref":"#/components/schemas/Capability"}}}},"Capability":{"type":"object","properties":{"name":{"type":"string"},"path":{"type":"string"},"data":{"type":"object"}}},"Command":{"type":"object","properties":{"script":{"type":"string","description":"A script that can be exec()'d on the agent"}}},"CommandRequest":{"type":"object","properties":{"commands":{"type":"array","items":{"$ref":"#/components/schemas/Command"}}}},"CommandResponse":{"type":"object","properties":{"uuid":{"type":"string","format":"uuid"},"stream":{"description":"URL to streaming WebSockets logs","type":"string"},"task":{"description":"URL to the task metadata","type":"string"}}}}}}
|
||||
|
|
|
@ -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" : [
|
||||
|
|
|
@ -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,
|
||||
|
|
Loading…
Reference in New Issue