Support invoking a task with a file-based script via an args file
Basically the first parameter to the invoked task-file will be an args-file of JSON-encoded parameters and values. ./my-special-script ._zap_args
This commit is contained in:
parent
eda6f523a3
commit
d765cc5703
|
@ -140,12 +140,6 @@ dependencies = [
|
|||
"typenum",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "glob"
|
||||
version = "0.3.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "9b919933a397b79c37e33b77bb2aa3dc8eb6e165ad809e58ff75bc7db2e34574"
|
||||
|
||||
[[package]]
|
||||
name = "gumdrop"
|
||||
version = "0.8.0"
|
||||
|
@ -617,9 +611,7 @@ name = "zap"
|
|||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"colored",
|
||||
"glob",
|
||||
"gumdrop",
|
||||
"handlebars",
|
||||
"log",
|
||||
"pretty_env_logger",
|
||||
"serde",
|
||||
|
|
|
@ -6,9 +6,7 @@ edition = "2018"
|
|||
|
||||
[dependencies]
|
||||
colored = "2"
|
||||
glob = "0.3"
|
||||
gumdrop = "~0.8.0"
|
||||
handlebars = "~3.5"
|
||||
log = "0.4"
|
||||
pretty_env_logger = "0.4"
|
||||
# Needed for deserializing JSON messages _and_ managing our configuration
|
||||
|
|
|
@ -82,7 +82,32 @@ impl Transport for Ssh {
|
|||
let mut channel = sess.channel_session().unwrap();
|
||||
let stderr = channel.stderr();
|
||||
|
||||
channel.exec(&format!("./{}", remote_script)).unwrap();
|
||||
if command.task.script.has_file() {
|
||||
let args = serde_json::to_string(&command.parameters)
|
||||
.expect("Failed to serialize parameters for task");
|
||||
let args_file = "._zap_args.json";
|
||||
let mut remote_file = sess
|
||||
.scp_send(
|
||||
Path::new(args_file),
|
||||
0o400,
|
||||
args.len().try_into().expect(
|
||||
"Failed converting the size of the generated args file, yikes!",
|
||||
),
|
||||
None,
|
||||
)
|
||||
.unwrap();
|
||||
remote_file.write(&args.as_bytes()).unwrap();
|
||||
// Close the channel and wait for the whole content to be tranferred
|
||||
remote_file.send_eof().unwrap();
|
||||
remote_file.wait_eof().unwrap();
|
||||
remote_file.close().unwrap();
|
||||
remote_file.wait_close().unwrap();
|
||||
channel
|
||||
.exec(&format!("./{} {}", remote_script, args_file))
|
||||
.unwrap();
|
||||
} else {
|
||||
channel.exec(&format!("./{}", remote_script)).unwrap();
|
||||
}
|
||||
|
||||
let reader = BufReader::new(stderr);
|
||||
for line in reader.lines() {
|
||||
|
|
|
@ -41,6 +41,10 @@ impl Script {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn has_file(&self) -> bool {
|
||||
self.file.is_some()
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the script's contents as bytes
|
||||
*
|
||||
|
|
Loading…
Reference in New Issue