Compare commits
4 Commits
fc1f951c19
...
872157ce98
Author | SHA1 | Date |
---|---|---|
R Tyler Croy | 872157ce98 | |
R Tyler Croy | a3accf213a | |
R Tyler Croy | 5003d5eeff | |
R Tyler Croy | a39a994062 |
|
@ -619,11 +619,11 @@ dependencies = [
|
|||
"serde_json",
|
||||
"serde_yaml",
|
||||
"ssh2",
|
||||
"zap-parser",
|
||||
"zap-model",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "zap-parser"
|
||||
name = "zap-model"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"handlebars",
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
[workspace]
|
||||
members = [
|
||||
'cli',
|
||||
'parser',
|
||||
'model',
|
||||
]
|
||||
|
|
|
@ -16,4 +16,4 @@ serde_derive = "~1.0"
|
|||
serde_json = "~1.0"
|
||||
serde_yaml = "~0.8"
|
||||
ssh2 = "~0.9.0"
|
||||
zap-parser = { path = "../parser" }
|
||||
zap-model = { path = "../model" }
|
||||
|
|
|
@ -10,8 +10,9 @@ mod transport;
|
|||
|
||||
use crate::inventory::*;
|
||||
use crate::transport::ssh::Ssh;
|
||||
use zap_parser::plan::{ExecutableTask, Plan};
|
||||
use zap_parser::task::Task;
|
||||
use zap_model::plan::Plan;
|
||||
use zap_model::task::Task;
|
||||
use zap_model::ExecutableTask;
|
||||
|
||||
fn main() {
|
||||
pretty_env_logger::init();
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
use crate::inventory::{Group, Inventory, Target};
|
||||
use std::path::Path;
|
||||
use zap_parser::plan::ExecutableTask;
|
||||
use zap_model::ExecutableTask;
|
||||
|
||||
pub mod ssh;
|
||||
|
||||
|
|
|
@ -10,7 +10,7 @@ use std::io::BufReader;
|
|||
use std::net::TcpStream;
|
||||
use std::path::Path;
|
||||
|
||||
use zap_parser::plan::ExecutableTask;
|
||||
use zap_model::ExecutableTask;
|
||||
|
||||
#[derive(Clone)]
|
||||
pub struct Ssh {
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
[package]
|
||||
name = "zap-parser"
|
||||
name = "zap-model"
|
||||
version = "0.1.0"
|
||||
authors = ["R. Tyler Croy <rtyler@brokenco.de>"]
|
||||
edition = "2018"
|
|
@ -0,0 +1,25 @@
|
|||
#[macro_use]
|
||||
extern crate pest;
|
||||
#[macro_use]
|
||||
extern crate pest_derive;
|
||||
|
||||
use std::collections::HashMap;
|
||||
|
||||
pub mod plan;
|
||||
pub mod task;
|
||||
|
||||
/**
|
||||
* An ExecutableTask is a light container over a Task execpt with user-provided information and is
|
||||
* therefore ready for execution
|
||||
*/
|
||||
#[derive(Clone, Debug)]
|
||||
pub struct ExecutableTask {
|
||||
pub task: task::Task,
|
||||
pub parameters: HashMap<String, String>,
|
||||
}
|
||||
|
||||
impl ExecutableTask {
|
||||
pub fn new(task: task::Task, parameters: HashMap<String, String>) -> Self {
|
||||
Self { task, parameters }
|
||||
}
|
||||
}
|
|
@ -6,22 +6,12 @@ use pest::Parser;
|
|||
use std::collections::HashMap;
|
||||
use std::path::PathBuf;
|
||||
|
||||
use crate::ExecutableTask;
|
||||
|
||||
#[derive(Parser)]
|
||||
#[grammar = "plan.pest"]
|
||||
struct PlanParser;
|
||||
|
||||
#[derive(Clone, Debug)]
|
||||
pub struct ExecutableTask {
|
||||
pub task: crate::task::Task,
|
||||
pub parameters: HashMap<String, String>,
|
||||
}
|
||||
|
||||
impl ExecutableTask {
|
||||
pub fn new(task: crate::task::Task, parameters: HashMap<String, String>) -> Self {
|
||||
Self { task, parameters }
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug)]
|
||||
pub struct Plan {
|
||||
pub tasks: Vec<ExecutableTask>,
|
|
@ -162,7 +162,7 @@ impl Task {
|
|||
}
|
||||
|
||||
pub fn from_str(buf: &str) -> Result<Self, PestError<Rule>> {
|
||||
let mut parser = TaskParser::parse(Rule::task, buf)?;
|
||||
let mut parser = TaskParser::parse(Rule::taskfile, buf)?;
|
||||
while let Some(parsed) = parser.next() {
|
||||
match parsed.as_rule() {
|
||||
Rule::task => {
|
||||
|
@ -245,6 +245,22 @@ fn parse_str(parser: &mut Pairs<Rule>) -> Result<String, PestError<Rule>> {
|
|||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
#[test]
|
||||
fn parse_task_with_comments() {
|
||||
let buf = r#"
|
||||
/*
|
||||
* This is a simple one
|
||||
*/
|
||||
task Hey {
|
||||
script {
|
||||
inline = 'echo "hi"'
|
||||
}
|
||||
}"#;
|
||||
let _task = TaskParser::parse(Rule::taskfile, buf)
|
||||
.unwrap()
|
||||
.next()
|
||||
.unwrap();
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn parse_simple_script_task() {
|
|
@ -1,7 +0,0 @@
|
|||
#[macro_use]
|
||||
extern crate pest;
|
||||
#[macro_use]
|
||||
extern crate pest_derive;
|
||||
|
||||
pub mod plan;
|
||||
pub mod task;
|
|
@ -1,3 +1,8 @@
|
|||
/*
|
||||
* The echo test takes a string and just uses the shell `echo` on the target
|
||||
* to echo it back
|
||||
*/
|
||||
|
||||
task Echo {
|
||||
parameters {
|
||||
msg {
|
||||
|
|
|
@ -1,3 +1,7 @@
|
|||
/*
|
||||
* Invoke pkg-install(8) on the FreeBSD machine
|
||||
*/
|
||||
|
||||
task FreeBSDPkgInstall {
|
||||
parameters {
|
||||
packages {
|
||||
|
|
|
@ -1,3 +1,7 @@
|
|||
/*
|
||||
* Invoke zypper install on a openSUSE/SLES target
|
||||
*/
|
||||
|
||||
task ZypperInstall {
|
||||
parameters {
|
||||
packages {
|
||||
|
|
|
@ -1,3 +1,10 @@
|
|||
/*
|
||||
* The bash task is a simple passthrough to bash.
|
||||
*
|
||||
* Since bash is not guaranteed to be in the same location on every machine
|
||||
* This relies on /usr/bin/env to help find bash in the $PATH on the target
|
||||
*/
|
||||
|
||||
task Bash {
|
||||
parameters {
|
||||
script {
|
||||
|
|
|
@ -1,3 +1,7 @@
|
|||
/*
|
||||
* The sh task is a simple passthrough to /bin/sh on the target machine
|
||||
*/
|
||||
|
||||
task Sh {
|
||||
parameters {
|
||||
script {
|
||||
|
|
Loading…
Reference in New Issue