Knock out the bunk agent implementations which are no longer relevant
This commit is contained in:
parent
7c1fc95f93
commit
de7f474696
|
@ -1,2 +0,0 @@
|
||||||
node_modules/
|
|
||||||
build/
|
|
File diff suppressed because it is too large
Load Diff
|
@ -1,30 +0,0 @@
|
||||||
{
|
|
||||||
"name": "otto-agent",
|
|
||||||
"version": "1.0.0",
|
|
||||||
"description": "A basic Otto agent implemented in Node",
|
|
||||||
"repository": "git://git.brokenco.de/rtyler/otto.git",
|
|
||||||
"bin": "build/agent.js",
|
|
||||||
"scripts": {
|
|
||||||
"build": "tsc && pkg --targets node10-linux --out-path build .",
|
|
||||||
"lint": "tslint --project .",
|
|
||||||
"test": "jest"
|
|
||||||
},
|
|
||||||
"author": "R Tyler Croy",
|
|
||||||
"license": "AGPL-3.0",
|
|
||||||
"devDependencies": {
|
|
||||||
"@types/feathersjs__feathers": "^3.1.1",
|
|
||||||
"jest": "^24.5.0",
|
|
||||||
"pkg": "^4.3.7",
|
|
||||||
"tslint": "^5.14.0",
|
|
||||||
"typescript": "^3.3.4000"
|
|
||||||
},
|
|
||||||
"dependencies": {
|
|
||||||
"@feathersjs/client": "^3.7.8",
|
|
||||||
"@feathersjs/feathers": "^3.3.1",
|
|
||||||
"@feathersjs/rest-client": "^1.4.7",
|
|
||||||
"request": "^2.88.0",
|
|
||||||
"tmp": "^0.1.0",
|
|
||||||
"tslib": "^1.9.3",
|
|
||||||
"winston": "^3.2.1"
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,44 +0,0 @@
|
||||||
/*
|
|
||||||
* The agent module is the main entry point for the TypeScript Otto agent
|
|
||||||
*/
|
|
||||||
|
|
||||||
import child_process from 'child_process';
|
|
||||||
import fs from 'fs';
|
|
||||||
|
|
||||||
import feathers from '@feathersjs/feathers';
|
|
||||||
import rest from '@feathersjs/rest-client';
|
|
||||||
import request from 'request';
|
|
||||||
import tmp from 'tmp';
|
|
||||||
|
|
||||||
import logger from './logger';
|
|
||||||
|
|
||||||
logger.info('Agent starting up..');
|
|
||||||
|
|
||||||
const app = feathers();
|
|
||||||
const requestClient = request.defaults();
|
|
||||||
const restClient = rest('http://localhost:3030');
|
|
||||||
|
|
||||||
app.configure(restClient.request(requestClient));
|
|
||||||
|
|
||||||
app.service('/v1/manifest').get('agentname').then((manifest) => {
|
|
||||||
const promises = manifest.ops.map((operation) => {
|
|
||||||
if (operation.type === 'RUNPROC') {
|
|
||||||
return new Promise((resolve, reject) => {
|
|
||||||
logger.info(`I have been instructed to run: ${operation.data.script}`);
|
|
||||||
const tmpFile = tmp.fileSync();
|
|
||||||
fs.writeFileSync(tmpFile.fd, '#!/bin/sh\n', { encoding: 'utf8' });
|
|
||||||
fs.writeFileSync(tmpFile.fd, operation.data.script, { encoding: 'utf8' });
|
|
||||||
logger.debug(`Wrote command to: ${tmpFile.name}`);
|
|
||||||
const sub = child_process.spawn('sh', [tmpFile.name]);
|
|
||||||
sub.stdout.on('data', data => logger.info(data));
|
|
||||||
sub.stderr.on('data', data => logger.error(data));
|
|
||||||
sub.on('close', rc => resolve(rc));
|
|
||||||
sub.on('error', e => reject(e));
|
|
||||||
});
|
|
||||||
} else {
|
|
||||||
return Promise.resolve(null);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
// Execution is not chained at the moment
|
|
||||||
return Promise.all(promises);
|
|
||||||
});
|
|
|
@ -1,13 +0,0 @@
|
||||||
import { createLogger, format, transports } from 'winston';
|
|
||||||
|
|
||||||
export default createLogger({
|
|
||||||
// To see more detailed errors, change this to 'debug'
|
|
||||||
level: 'info',
|
|
||||||
format: format.combine(
|
|
||||||
format.splat(),
|
|
||||||
format.simple(),
|
|
||||||
),
|
|
||||||
transports: [
|
|
||||||
new transports.Console(),
|
|
||||||
],
|
|
||||||
});
|
|
|
@ -1,23 +0,0 @@
|
||||||
{
|
|
||||||
"compilerOptions": {
|
|
||||||
"alwaysStrict" : true,
|
|
||||||
"outDir": "./build",
|
|
||||||
"module" : "commonjs",
|
|
||||||
"skipLibCheck": true,
|
|
||||||
"lib" : ["es2017"],
|
|
||||||
"module": "commonjs",
|
|
||||||
"moduleResolution": "node",
|
|
||||||
"esModuleInterop": true,
|
|
||||||
"importHelpers" : true,
|
|
||||||
"target": "es2015",
|
|
||||||
"sourceMap": true,
|
|
||||||
"typeRoots" : [
|
|
||||||
"./node_modules/@types",
|
|
||||||
"./node_modules/@sentry/node",
|
|
||||||
"./node_modules/@sentry/types"
|
|
||||||
]
|
|
||||||
},
|
|
||||||
"include": [
|
|
||||||
"./src/**/*"
|
|
||||||
]
|
|
||||||
}
|
|
|
@ -1,23 +0,0 @@
|
||||||
{
|
|
||||||
"defaultSeverity": "error",
|
|
||||||
"extends": [
|
|
||||||
"tslint:recommended"
|
|
||||||
],
|
|
||||||
"jsRules": {},
|
|
||||||
"rules": {
|
|
||||||
"quotemark": [
|
|
||||||
true,
|
|
||||||
"single"
|
|
||||||
],
|
|
||||||
"indent": [
|
|
||||||
true
|
|
||||||
],
|
|
||||||
"interface-name": [
|
|
||||||
false
|
|
||||||
],
|
|
||||||
"arrow-parens": false,
|
|
||||||
// Pending fix for shorthand property names.
|
|
||||||
"object-literal-sort-keys": false
|
|
||||||
},
|
|
||||||
"rulesDirectory": []
|
|
||||||
}
|
|
|
@ -1 +0,0 @@
|
||||||
target/
|
|
|
@ -1,12 +0,0 @@
|
||||||
[package]
|
|
||||||
name = "otto-agent"
|
|
||||||
version = "0.1.0"
|
|
||||||
authors = ["R. Tyler Croy <rtyler@brokenco.de>"]
|
|
||||||
edition = "2018"
|
|
||||||
|
|
||||||
[dependencies]
|
|
||||||
hyper = "0.12"
|
|
||||||
serde = "1.0.38"
|
|
||||||
serde_json = "1.0.38"
|
|
||||||
serde_derive = "1.0.38"
|
|
||||||
tempfile = "3"
|
|
|
@ -1,4 +0,0 @@
|
||||||
= Otto Basic Agent
|
|
||||||
|
|
||||||
The basic agent is the simplest reference implementation of an Otto agent, and
|
|
||||||
supports no streaming or other advanced functionalities.
|
|
|
@ -1,80 +0,0 @@
|
||||||
extern crate hyper;
|
|
||||||
|
|
||||||
#[macro_use]
|
|
||||||
extern crate serde_derive;
|
|
||||||
extern crate serde;
|
|
||||||
extern crate serde_json;
|
|
||||||
|
|
||||||
|
|
||||||
extern crate tempfile;
|
|
||||||
use tempfile::NamedTempFile;
|
|
||||||
use std::io::Write;
|
|
||||||
|
|
||||||
use std::process::Command;
|
|
||||||
|
|
||||||
use hyper::Client;
|
|
||||||
use hyper::rt::{self, Future, Stream};
|
|
||||||
|
|
||||||
mod manifest;
|
|
||||||
use manifest::{Manifest, Operation};
|
|
||||||
|
|
||||||
fn run_process(op: Operation) {
|
|
||||||
let mut tmpfile = NamedTempFile::new().unwrap();
|
|
||||||
write!(tmpfile, "#!/bin/sh\n{}", op.data["script"].as_str().unwrap()).unwrap();
|
|
||||||
let mut proc = Command::new("sh");
|
|
||||||
proc.arg(tmpfile.path().to_str().unwrap());
|
|
||||||
let output = proc.output().expect("Failed to run subprocess");
|
|
||||||
println!("executed ({}):\n{}", output.status, String::from_utf8(output.stdout).unwrap());
|
|
||||||
}
|
|
||||||
|
|
||||||
fn main() {
|
|
||||||
println!("Starting agent");
|
|
||||||
rt::run(rt::lazy(|| {
|
|
||||||
let client = Client::new();
|
|
||||||
let uri = "http://localhost:3030/v1/manifest/rusty".parse().unwrap();
|
|
||||||
|
|
||||||
client
|
|
||||||
.get(uri)
|
|
||||||
.and_then(|res| {
|
|
||||||
println!("Response: {}", res.status());
|
|
||||||
res.into_body().concat2()
|
|
||||||
})
|
|
||||||
.from_err::<FetchError>()
|
|
||||||
.and_then(|body| {
|
|
||||||
let manifest: Manifest = serde_json::from_slice(&body)?;
|
|
||||||
println!("okie doke {}, let's get started", manifest.agent);
|
|
||||||
for operation in manifest.ops {
|
|
||||||
println!("op: {}", operation.op_type);
|
|
||||||
if operation.op_type == "RUNPROC" {
|
|
||||||
run_process(operation);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Ok(())
|
|
||||||
})
|
|
||||||
.map_err(|e| {
|
|
||||||
match e {
|
|
||||||
FetchError::Http(e) => eprintln!("http error: {}", e),
|
|
||||||
FetchError::Json(e) => eprintln!("json parsing error: {}", e),
|
|
||||||
}
|
|
||||||
})
|
|
||||||
}));
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// Define a type so we can return multiple types of errors
|
|
||||||
enum FetchError {
|
|
||||||
Http(hyper::Error),
|
|
||||||
Json(serde_json::Error),
|
|
||||||
}
|
|
||||||
|
|
||||||
impl From<hyper::Error> for FetchError {
|
|
||||||
fn from(err: hyper::Error) -> FetchError {
|
|
||||||
FetchError::Http(err)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl From<serde_json::Error> for FetchError {
|
|
||||||
fn from(err: serde_json::Error) -> FetchError {
|
|
||||||
FetchError::Json(err)
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,17 +0,0 @@
|
||||||
use std::collections::HashMap;
|
|
||||||
|
|
||||||
#[derive(Deserialize, Debug)]
|
|
||||||
pub struct Manifest {
|
|
||||||
#[serde(rename(deserialize = "self"))]
|
|
||||||
pub agent : String,
|
|
||||||
pub services: HashMap<String, String>,
|
|
||||||
pub ops : Vec<Operation>,
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Deserialize, Debug)]
|
|
||||||
pub struct Operation {
|
|
||||||
pub op_id: String,
|
|
||||||
#[serde(rename(deserialize = "type"))]
|
|
||||||
pub op_type : String,
|
|
||||||
pub data : serde_json::Map<String, serde_json::Value>,
|
|
||||||
}
|
|
Loading…
Reference in New Issue