Skip to content

Commit

Permalink
Restructuring the file tree to make it easier to start adding "native…
Browse files Browse the repository at this point in the history
… tasks"

Some number of tasks I will want to be "builtin" and need to know a little bit
more about the transport in order to make that work.

The traits, they are coming.

See #1
  • Loading branch information
rtyler committed Jan 1, 2021
1 parent a3d6980 commit 50ab1a5
Show file tree
Hide file tree
Showing 11 changed files with 41 additions and 31 deletions.
13 changes: 8 additions & 5 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 2 additions & 8 deletions cli/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "zap-cli"
version = "0.1.1"
version = "0.2.0"
authors = ["R. Tyler Croy <[email protected]>"]
edition = "2018"
description = "A simple configuration management and orchestration tool"
Expand All @@ -13,17 +13,11 @@ keywords = ["sysadmin", "management"]
name = "zap"
path = "src/main.rs"


[dependencies]
colored = "2"
gumdrop = "~0.8.0"
log = "0.4"
pretty_env_logger = "0.4"
# Needed for deserializing JSON messages _and_ managing our configuration
# effectively
serde = { version = "~1.0", features = ["derive", "rc"] }
serde_derive = "~1.0"
serde_json = "~1.0"
serde_yaml = "~0.8"
ssh2 = "~0.9.0"
zap-model = { version = "~0.1", path = "../model" }
zap-model = { version = "~0.2", path = "../model" }
20 changes: 8 additions & 12 deletions cli/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,9 @@ use std::collections::HashMap;
use std::io::BufReader;
use std::path::PathBuf;

mod inventory;
mod transport;

use crate::inventory::*;
use crate::transport::ssh::Ssh;
use zap_model::plan::Plan;
use zap_model::task::Task;
use zap_model::inventory::Inventory;
use zap_model::transport::ssh::Ssh;
use zap_model::{Plan, Task, Transport};
use zap_model::ExecutableTask;

fn main() {
Expand All @@ -29,7 +25,7 @@ fn main() {
let inventory: Inventory = serde_yaml::from_reader(reader).expect("Failed to read intenvory");

let mut runner = match &inventory.config.transport {
crate::inventory::Transport::Ssh => Ssh::default(),
zap_model::inventory::Transport::Ssh => Ssh::default(),
};

match opts.command.unwrap() {
Expand Down Expand Up @@ -63,7 +59,7 @@ fn handle_check(opts: CheckOpts) {
/**
* This function will parse and execute a plan
*/
fn handle_plan(opts: PlanOpts, runner: &mut dyn crate::transport::Transport, inventory: Inventory) {
fn handle_plan(opts: PlanOpts, runner: &mut dyn Transport, inventory: Inventory) {
println!("{}", format!("Running plan with: {:?}", opts).green());
let mut exit: i32 = -1;

Expand Down Expand Up @@ -91,7 +87,7 @@ fn handle_plan(opts: PlanOpts, runner: &mut dyn crate::transport::Transport, inv
fn execute_task_on(
targets: String,
task: &ExecutableTask,
runner: &mut dyn crate::transport::Transport,
runner: &mut dyn Transport,
inventory: &Inventory,
dry_run: bool,
) -> i32 {
Expand All @@ -109,7 +105,7 @@ fn execute_task_on(
/**
* This function will handle a task
*/
fn handle_task(opts: TaskOpts, runner: &mut dyn crate::transport::Transport, inventory: Inventory) {
fn handle_task(opts: TaskOpts, runner: &mut dyn Transport, inventory: Inventory) {
println!("{}", format!("Running task with: {:?}", opts).green());

match Task::from_path(&opts.task) {
Expand Down Expand Up @@ -154,7 +150,7 @@ fn handle_task(opts: TaskOpts, runner: &mut dyn crate::transport::Transport, inv
* In the case of multiple targets, any non-zero status code will be used to exit
* non-zero.
*/
fn handle_cmd(opts: CmdOpts, runner: &mut dyn crate::transport::Transport, inventory: Inventory) {
fn handle_cmd(opts: CmdOpts, runner: &mut dyn Transport, inventory: Inventory) {
let mut task = ExecutableTask::new(Task::new("Dynamic"), HashMap::new());
task.task.script.inline = Some(opts.command);
std::process::exit(execute_task_on(
Expand Down
10 changes: 9 additions & 1 deletion model/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "zap-model"
version = "0.1.1"
version = "0.2.0"
authors = ["R. Tyler Croy <[email protected]>"]
edition = "2018"
description = "Internal models for zap, a simple configuration management tool"
Expand All @@ -10,7 +10,15 @@ license = "AGPL-3.0+"
keywords = ["sysadmin", "management"]

[dependencies]
colored = "2"
handlebars = "~3.5"
log = "0.4"
pest = "~2.1"
pest_derive = "~2.1"
# Needed for deserializing JSON messages _and_ managing our configuration
# effectively
serde = { version = "~1.0", features = ["derive", "rc"] }
serde_derive = "~1.0"
serde_json = "~1.0"
serde_yaml = "~0.8"
ssh2 = "~0.9.0"
File renamed without changes.
11 changes: 9 additions & 2 deletions model/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,21 +5,28 @@ extern crate pest_derive;

use std::collections::HashMap;

pub mod inventory;
pub mod plan;
pub mod task;
pub mod tasks;
pub mod transport;

pub use crate::transport::Transport;
pub use crate::plan::Plan;
pub use crate::task::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 task: Task,
pub parameters: HashMap<String, String>,
}

impl ExecutableTask {
pub fn new(task: task::Task, parameters: HashMap<String, String>) -> Self {
pub fn new(task: Task, parameters: HashMap<String, String>) -> Self {
Self { task, parameters }
}
}
File renamed without changes.
File renamed without changes.
1 change: 1 addition & 0 deletions model/src/tasks/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@

3 changes: 2 additions & 1 deletion cli/src/transport/mod.rs → model/src/transport/mod.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use crate::ExecutableTask;
use crate::inventory::{Group, Inventory, Target};

use std::path::Path;
use zap_model::ExecutableTask;

pub mod ssh;

Expand Down
4 changes: 2 additions & 2 deletions cli/src/transport/ssh.rs → model/src/transport/ssh.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
use crate::inventory::{Group, Inventory, Target};
use crate::transport::Transport;
use crate::ExecutableTask;

use colored::*;

use log::*;
Expand All @@ -10,8 +12,6 @@ use std::io::BufReader;
use std::net::TcpStream;
use std::path::Path;

use zap_model::ExecutableTask;

#[derive(Clone)]
pub struct Ssh {
session: Session,
Expand Down

0 comments on commit 50ab1a5

Please sign in to comment.