-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #72 from tmknight/develop
v0.8.0
- Loading branch information
Showing
13 changed files
with
375 additions
and
216 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,169 @@ | ||
use super::options::OptionsList; | ||
use crate::{log_message, ERROR, WARNING}; | ||
|
||
pub struct VariablesList { | ||
pub connection_type: String, | ||
pub container_label: String, | ||
pub stop_timeout: isize, | ||
pub interval: u64, | ||
pub start_delay: u64, | ||
pub tcp_address: String, | ||
pub tcp_timeout: u64, | ||
pub key_path: String, | ||
pub cert_path: String, | ||
pub ca_path: String, | ||
pub apprise_url: String, | ||
pub webhook_key: String, | ||
pub webhook_url: String, | ||
} | ||
|
||
// Get environment variable | ||
pub fn get_env(key: &str, default: &str) -> String { | ||
fn get_env(key: &str, default: &str) -> String { | ||
match std::env::var(key) { | ||
Ok(val) => val.to_lowercase(), | ||
Err(_e) => default.to_string().to_lowercase(), | ||
} | ||
} | ||
|
||
// Determine if we have valid arguments, need to check env, or use defaults | ||
pub async fn get_var(opt: OptionsList) -> VariablesList { | ||
let autoheal_connection_type: String = match opt.connection_type { | ||
None => { | ||
let allowed_connection_types: Vec<&str> = vec!["local", "socket", "http", "ssl"]; | ||
let env_connection_type = get_env("AUTOHEAL_CONNECTION_TYPE", "local"); | ||
match allowed_connection_types.contains(&env_connection_type.as_str()) { | ||
true => env_connection_type, | ||
false => { | ||
let msg0 = format!( | ||
"Unexpected connection-type ({}): {}", | ||
allowed_connection_types.join(","), | ||
env_connection_type | ||
); | ||
log_message(&msg0, ERROR).await; | ||
let msg1 = String::from("Attempting connection via default (local)"); | ||
log_message(&msg1, WARNING).await; | ||
"local".to_string() | ||
} | ||
} | ||
} | ||
Some(o) => o, | ||
}; | ||
let autoheal_container_label: String = match opt.container_label { | ||
None => get_env("AUTOHEAL_CONTAINER_LABEL", "autoheal"), | ||
Some(o) => o, | ||
}; | ||
let autoheal_stop_timeout: isize = match opt.stop_timeout { | ||
None => get_env("AUTOHEAL_STOP_TIMEOUT", "10").parse().unwrap(), | ||
Some(o) => match o.parse() { | ||
Ok(a) => a, | ||
Err(e) => { | ||
let msg0 = format!("Unexpected value; using default: {}", e); | ||
log_message(&msg0, WARNING).await; | ||
10 | ||
} | ||
}, | ||
}; | ||
let autoheal_interval: u64 = match opt.interval { | ||
None => get_env("AUTOHEAL_INTERVAL", "5").parse().unwrap(), | ||
Some(o) => match o.parse() { | ||
Ok(a) => a, | ||
Err(e) => { | ||
let msg0 = format!("Unexpected value; using default: {}", e); | ||
log_message(&msg0, WARNING).await; | ||
5 | ||
} | ||
}, | ||
}; | ||
let autoheal_start_delay: u64 = match opt.start_delay { | ||
None => get_env("AUTOHEAL_START_DELAY", "0").parse().unwrap(), | ||
Some(o) => match o.parse() { | ||
Ok(a) => a, | ||
Err(e) => { | ||
let msg0 = format!("Unexpected value; using default: {}", e); | ||
log_message(&msg0, WARNING).await; | ||
0 | ||
} | ||
}, | ||
}; | ||
|
||
// Autoheal tcp variables | ||
let autoheal_tcp_host: String = match opt.tcp_host { | ||
None => get_env("AUTOHEAL_TCP_HOST", "localhost"), | ||
Some(o) => o, | ||
}; | ||
let autoheal_tcp_port: u64 = match autoheal_connection_type.as_str() { | ||
"ssl" => match opt.tcp_port { | ||
None => get_env("AUTOHEAL_TCP_PORT", "2376").parse().unwrap(), | ||
Some(o) => match o.parse() { | ||
Ok(a) => a, | ||
Err(e) => { | ||
let msg0 = format!("Unexpected value; using default: {}", e); | ||
log_message(&msg0, WARNING).await; | ||
2376 | ||
} | ||
}, | ||
}, | ||
&_ => match opt.tcp_port { | ||
None => get_env("AUTOHEAL_TCP_PORT", "2375").parse().unwrap(), | ||
Some(o) => match o.parse() { | ||
Ok(a) => a, | ||
Err(e) => { | ||
let msg0 = format!("Unexpected value; using default: {}", e); | ||
log_message(&msg0, WARNING).await; | ||
2375 | ||
} | ||
}, | ||
}, | ||
}; | ||
let autoheal_tcp_address: String = format!("{}:{}", autoheal_tcp_host, autoheal_tcp_port); | ||
let autoheal_tcp_timeout: u64 = match opt.tcp_timeout { | ||
None => get_env("AUTOHEAL_TCP_TIMEOUT", "10").parse().unwrap(), | ||
Some(o) => match o.parse() { | ||
Ok(a) => a, | ||
Err(e) => { | ||
let msg0 = format!("Unexpected value; using default: {}", e); | ||
log_message(&msg0, WARNING).await; | ||
10 | ||
} | ||
}, | ||
}; | ||
|
||
// Autoheal ssl variables | ||
let autoheal_pem_path: String = match opt.key_path { | ||
None => get_env("AUTOHEAL_PEM_PATH", "/opt/docker-autoheal/tls"), | ||
Some(o) => o, | ||
}; | ||
let autoheal_key_path: String = format!("{}/key.pem", autoheal_pem_path); | ||
let autoheal_cert_path: String = format!("{}/cert.pem", autoheal_pem_path); | ||
let autoheal_ca_path: String = format!("{}/ca.pem", autoheal_pem_path); | ||
|
||
// Webhook variables | ||
let autoheal_apprise_url: String = match opt.apprise_url { | ||
None => get_env("AUTOHEAL_APPRISE_URL", ""), | ||
Some(o) => o, | ||
}; | ||
let autoheal_webhook_key: String = match opt.webhook_key { | ||
None => get_env("AUTOHEAL_WEBHOOK_KEY", ""), | ||
Some(o) => o, | ||
}; | ||
let autoheal_webhook_url: String = match opt.webhook_url { | ||
None => get_env("AUTOHEAL_WEBHOOK_URL", ""), | ||
Some(o) => o, | ||
}; | ||
|
||
VariablesList { | ||
connection_type: autoheal_connection_type, | ||
container_label: autoheal_container_label, | ||
stop_timeout: autoheal_stop_timeout, | ||
interval: autoheal_interval, | ||
start_delay: autoheal_start_delay, | ||
tcp_address: autoheal_tcp_address, | ||
tcp_timeout: autoheal_tcp_timeout, | ||
key_path: autoheal_key_path, | ||
cert_path: autoheal_cert_path, | ||
ca_path: autoheal_ca_path, | ||
apprise_url: autoheal_apprise_url, | ||
webhook_key: autoheal_webhook_key, | ||
webhook_url: autoheal_webhook_url, | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.