Tidy up the invocation file format to actually follow the spec that I wrote 🤦
This consolidates the run loop to use the same basic structure that the steps will use to deserialize, which is valuable
This commit is contained in:
parent
842248b29e
commit
1001ee6be8
|
@ -39,12 +39,12 @@ pub async fn run(sender: Sender<Request>) -> tide::Result<()> {
|
|||
|
||||
if let Err(e) = std::fs::remove_file(&sock) {
|
||||
warn!(
|
||||
"Failed while trying to remove any previous {}, this might be okay",
|
||||
&sock
|
||||
"Failed while trying to remove any previous {:?}, this might be okay: {}",
|
||||
&sock, e
|
||||
);
|
||||
}
|
||||
|
||||
app.listen(format!("http+unix://{}", sock)).await?;
|
||||
app.listen(format!("http+unix://{}", sock.to_string_lossy())).await?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
@ -52,9 +52,9 @@ pub async fn run(sender: Sender<Request>) -> tide::Result<()> {
|
|||
/**
|
||||
* Return a string representing the absolute path of this agent's control socket
|
||||
*/
|
||||
pub fn agent_socket() -> String {
|
||||
pub fn agent_socket() -> std::path::PathBuf {
|
||||
let path = std::env::current_dir().expect("Failed to get current directory");
|
||||
path.join("agent.sock").to_string_lossy().into_owned()
|
||||
path.join("agent.sock").to_path_buf()
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
|
@ -64,6 +64,6 @@ mod tests {
|
|||
#[test]
|
||||
fn test_agent_sock() {
|
||||
let buf = agent_socket();
|
||||
assert!(buf.ends_with("agent.sock"));
|
||||
assert!(buf.to_string_lossy().ends_with("agent.sock"));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -163,15 +163,18 @@ pub fn run(
|
|||
let entrypoint = runner.path.join(&runner.manifest.entrypoint.path);
|
||||
|
||||
let mut file = NamedTempFile::new()?;
|
||||
let mut step_args = HashMap::new();
|
||||
|
||||
// TODO: This is going to be wrong on nested steps
|
||||
let sock = Value::String(control::agent_socket());
|
||||
let sock = control::agent_socket();
|
||||
let configuration = step::Configuration {
|
||||
ipc: sock,
|
||||
};
|
||||
let invocation: step::Invocation<Value> = step::Invocation {
|
||||
configuration,
|
||||
parameters: step.parameters.clone(),
|
||||
};
|
||||
|
||||
step_args.insert("control", &sock);
|
||||
step_args.insert("parameters", &step.parameters);
|
||||
|
||||
serde_yaml::to_writer(&mut file, &step_args)
|
||||
serde_yaml::to_writer(&mut file, &invocation)
|
||||
.expect("Failed to write temporary file for script");
|
||||
|
||||
use os_pipe::pipe;
|
||||
|
|
|
@ -13,11 +13,24 @@ use serde::{Deserialize, Serialize};
|
|||
* Steps should define their own parameter structs which can be passed in as a
|
||||
* generic parameter.
|
||||
*/
|
||||
#[derive(Clone, Debug, Deserialize)]
|
||||
#[derive(Clone, Debug, Deserialize, Serialize)]
|
||||
pub struct Invocation<P> {
|
||||
/// Configuration contains general configuration for the step to utilize
|
||||
pub configuration: Configuration,
|
||||
/// Parameters are to be a step-defined type
|
||||
pub parameters: P,
|
||||
}
|
||||
|
||||
/**
|
||||
* The Configuration struct will carry important information about the Otto
|
||||
* system into the step, such as the IPC path or endpoints where it can put data
|
||||
* as needed
|
||||
*/
|
||||
#[derive(Clone, Debug, Deserialize, Serialize)]
|
||||
pub struct Configuration {
|
||||
pub ipc: std::path::PathBuf,
|
||||
}
|
||||
|
||||
/**
|
||||
* This function will handle parsing the command line arguments passed to the step
|
||||
* and return the desired Invocation struct
|
||||
|
|
Loading…
Reference in New Issue