From 53b9fde9ed9c655a4a3f7025e3929c4a697bcef1 Mon Sep 17 00:00:00 2001 From: TMKnight <548588+tmknight@users.noreply.github.com> Date: Thu, 8 Feb 2024 07:43:29 -0500 Subject: [PATCH 1/8] Update github-release.yml --- .github/workflows/github-release.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/github-release.yml b/.github/workflows/github-release.yml index 06502bb..b98f3fe 100644 --- a/.github/workflows/github-release.yml +++ b/.github/workflows/github-release.yml @@ -88,6 +88,6 @@ jobs: uses: actions/checkout@v4 - name: "Release draft" - run: gh release edit "${GITHUB_REF#refs/tags/${{ needs.get-version.outputs.pkg-version }}}" --draft=false + run: gh release edit ${{ needs.get-version.outputs.pkg-version }}} --draft=false env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} From e7921e5ee68a2845fd430e3d033000c0294c6280 Mon Sep 17 00:00:00 2001 From: TMKnight <548588+tmknight@users.noreply.github.com> Date: Thu, 8 Feb 2024 07:51:37 -0500 Subject: [PATCH 2/8] Update github-release.yml --- .github/workflows/github-release.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/github-release.yml b/.github/workflows/github-release.yml index b98f3fe..d79d404 100644 --- a/.github/workflows/github-release.yml +++ b/.github/workflows/github-release.yml @@ -77,7 +77,7 @@ jobs: token: ${{ secrets.GITHUB_TOKEN }} promote-release: - name: "Promote release" + name: "Publish release" if: ${{ github.event.workflow_run.conclusion == 'success' }} needs: - "get-version" @@ -88,6 +88,6 @@ jobs: uses: actions/checkout@v4 - name: "Release draft" - run: gh release edit ${{ needs.get-version.outputs.pkg-version }}} --draft=false + run: gh release edit ${{ needs.get-version.outputs.pkg-version }} --draft=false env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} From 02a507c4dbaeff8965e0025e74c1ce0aaf8ff6c4 Mon Sep 17 00:00:00 2001 From: TMKnight <548588+tmknight@users.noreply.github.com> Date: Fri, 9 Feb 2024 07:44:15 -0500 Subject: [PATCH 3/8] Update CHANGELOG.md --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index b829292..f4c8ddb 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,7 +11,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/). ### Changed -- Small change to how webhook and/or apprise are called for the sake of efficiency +- Small change to how webhook and apprise are called for the sake of efficiency - Updated license to GPL-3.0 ## 0.8.0 From 46b971e44cedf6dd08d9b34b6bdaa669b2fd4110 Mon Sep 17 00:00:00 2001 From: TMKnight <548588+tmknight@users.noreply.github.com> Date: Fri, 9 Feb 2024 09:47:50 -0500 Subject: [PATCH 4/8] Update github-release.yml --- .github/workflows/github-release.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/github-release.yml b/.github/workflows/github-release.yml index d79d404..34e46bb 100644 --- a/.github/workflows/github-release.yml +++ b/.github/workflows/github-release.yml @@ -76,7 +76,7 @@ jobs: ref: refs/tags/${{ needs.get-version.outputs.pkg-version }} token: ${{ secrets.GITHUB_TOKEN }} - promote-release: + publish-release: name: "Publish release" if: ${{ github.event.workflow_run.conclusion == 'success' }} needs: From bc102b7859f8c195bcdd9aebdc5fc5d466613724 Mon Sep 17 00:00:00 2001 From: TMKnight <548588+tmknight@users.noreply.github.com> Date: Fri, 9 Feb 2024 09:49:34 -0500 Subject: [PATCH 5/8] Update docker-publish.yml --- .github/workflows/docker-publish.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/docker-publish.yml b/.github/workflows/docker-publish.yml index 95366b5..9fbb1f4 100644 --- a/.github/workflows/docker-publish.yml +++ b/.github/workflows/docker-publish.yml @@ -31,7 +31,7 @@ jobs: push-to-registry: name: "Publish Docker image" - if: ${{ github.event.workflow_run.conclusion == 'success' || github.event_name == 'workflow_dispatch' || github.event_name == 'schedule' }} + if: ${{ github.event.workflow_run.conclusion == 'success' || github.event_name == 'workflow_dispatch' || github.event_name == 'schedule' }} needs: - "get-version" runs-on: ubuntu-latest From e4fe1761d31c2dbeeb543d28604817a1b64f16bf Mon Sep 17 00:00:00 2001 From: tmknight Date: Fri, 9 Feb 2024 13:10:21 -0500 Subject: [PATCH 6/8] v0.8.2 --- CHANGELOG.md | 6 ++++++ Cargo.lock | 2 +- Cargo.toml | 2 +- src/execute/connect.rs | 33 ++++++++++++++------------------- src/inquire/environment.rs | 9 ++++----- src/inquire/options.rs | 5 ++--- src/main.rs | 3 +++ 7 files changed, 31 insertions(+), 29 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index f4c8ddb..1c01206 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,12 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/). ## [Unreleased] +## 0.8.2 + +### Changed + +- Small change to how connection type assessed and reported for the sake of efficiency + ## 0.8.1 ### Changed diff --git a/Cargo.lock b/Cargo.lock index 75c20d2..c2b5dbc 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -188,7 +188,7 @@ dependencies = [ [[package]] name = "docker-autoheal" -version = "0.8.1" +version = "0.8.2" dependencies = [ "bollard", "chrono", diff --git a/Cargo.toml b/Cargo.toml index 7696847..7f75032 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "docker-autoheal" -version = "0.8.1" +version = "0.8.2" authors = ["Travis M Knight"] license = "GPL-3.0" description = "A cross-platform tool to monitor and remediate unhealthy Docker containers" diff --git a/src/execute/connect.rs b/src/execute/connect.rs index 6b18b23..42d7df1 100644 --- a/src/execute/connect.rs +++ b/src/execute/connect.rs @@ -12,11 +12,15 @@ pub async fn connect_docker( // Log final connection paramaters let msg0 = format!("Monitoring Docker via {}", connection_type); log_message(&msg0, INFO).await; - match connection_type.as_str() { + + // Connect to Docker as specified + let docker = match connection_type.as_str() { "http" => { let msg1 = format!("Connecting to {}", tcp_address); log_message(&msg1, INFO).await; + Docker::connect_with_http(&tcp_address, tcp_timeout, API_DEFAULT_VERSION) } + "socket" => Docker::connect_with_socket_defaults(), "ssl" => { let msg1 = format!("Connecting to {}", tcp_address); log_message(&msg1, INFO).await; @@ -25,27 +29,18 @@ pub async fn connect_docker( key_path, cert_path, ca_path ); log_message(&msg2, INFO).await; + Docker::connect_with_ssl( + &tcp_address, + std::path::Path::new(&key_path), + std::path::Path::new(&cert_path), + std::path::Path::new(&ca_path), + tcp_timeout, + API_DEFAULT_VERSION, + ) } - &_ => {} - } - // Connect to Docker as specified - let docker = match connection_type.as_str() { - "http" => Docker::connect_with_http( - &tcp_address, - tcp_timeout, - API_DEFAULT_VERSION, - ), - "socket" => Docker::connect_with_socket_defaults(), - "ssl" => Docker::connect_with_ssl( - &tcp_address, - std::path::Path::new(&key_path), - std::path::Path::new(&cert_path), - std::path::Path::new(&ca_path), - tcp_timeout, - API_DEFAULT_VERSION, - ), &_ => Docker::connect_with_local_defaults(), }; + match docker { Ok(docker) => docker, Err(e) => { diff --git a/src/inquire/environment.rs b/src/inquire/environment.rs index 15426c8..22a7ba6 100644 --- a/src/inquire/environment.rs +++ b/src/inquire/environment.rs @@ -1,5 +1,5 @@ use super::options::OptionsList; -use crate::{log_message, ERROR, WARNING}; +use crate::{log_message, ALLOWED_CONNECTION_TYPES, ERROR, WARNING}; pub struct VariablesList { pub connection_type: String, @@ -29,14 +29,13 @@ fn get_env(key: &str, default: &str) -> String { 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()) { + 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(","), + "Unexpected connection-type ({}): Expected one of {}", + ALLOWED_CONNECTION_TYPES.join(","), env_connection_type ); log_message(&msg0, ERROR).await; diff --git a/src/inquire/options.rs b/src/inquire/options.rs index 6f29e67..cfac401 100644 --- a/src/inquire/options.rs +++ b/src/inquire/options.rs @@ -1,4 +1,4 @@ -use crate::report::logging::print_version; +use crate::{report::logging::print_version, ALLOWED_CONNECTION_TYPES}; use getopts::Options; pub struct OptionsList { @@ -105,11 +105,10 @@ pub fn get_opts(args: Vec) -> OptionsList { } // Ensure acceptable connection type arguments - let allowed_connection_types: Vec<&str> = vec!["local", "socket", "http", "ssl"]; match matches.opt_str("c").is_some() { true => { let opt_connection_type = matches.opt_str("c").unwrap(); - match allowed_connection_types.contains(&opt_connection_type.as_str()) { + match ALLOWED_CONNECTION_TYPES.contains(&opt_connection_type.as_str()) { true => {} false => { println!("Unexpected connection-type: {}", opt_connection_type); diff --git a/src/main.rs b/src/main.rs index 20b9b91..05ac75e 100644 --- a/src/main.rs +++ b/src/main.rs @@ -26,6 +26,9 @@ pub const INFO: i8 = 0; pub const WARNING: i8 = 1; pub const ERROR: i8 = 2; +// Allowed connection types +pub const ALLOWED_CONNECTION_TYPES: [&str; 4] = ["local", "socket", "http", "ssl"]; + #[tokio::main] async fn main() -> Result<(), Box> { // Collect binary arguments From 233d0b58270cc40d47067c26ae9c4387246c9c69 Mon Sep 17 00:00:00 2001 From: tmknight Date: Sat, 10 Feb 2024 09:08:25 -0500 Subject: [PATCH 7/8] Fix connection type error msg order; cleanup --- src/execute/looper.rs | 4 ++-- src/inquire/environment.rs | 4 ++-- src/main.rs | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/execute/looper.rs b/src/execute/looper.rs index 234a030..c42da5f 100644 --- a/src/execute/looper.rs +++ b/src/execute/looper.rs @@ -31,7 +31,7 @@ pub async fn start_loop( // Determine if stop override label let s = "autoheal.stop.timeout".to_string(); - let autoheal_stop_timeout: isize = match container.labels { + let autoheal_stop_timeout = match container.labels { Some(label) => match label.get(&s) { Some(v) => v.parse().unwrap_or(autoheal_stop_timeout), None => autoheal_stop_timeout, @@ -53,7 +53,7 @@ pub async fn start_loop( let name = name_tmp.trim_matches('/').trim(); // Get id of container - let id: String = match container.id { + let id = match container.id { Some(id) => id.chars().take(12).collect(), None => { let msg0 = String::from("Could not reliably determine container id"); diff --git a/src/inquire/environment.rs b/src/inquire/environment.rs index 22a7ba6..2e29ed7 100644 --- a/src/inquire/environment.rs +++ b/src/inquire/environment.rs @@ -35,8 +35,8 @@ pub async fn get_var(opt: OptionsList) -> VariablesList { false => { let msg0 = format!( "Unexpected connection-type ({}): Expected one of {}", - ALLOWED_CONNECTION_TYPES.join(","), - env_connection_type + env_connection_type, + ALLOWED_CONNECTION_TYPES.join(",") ); log_message(&msg0, ERROR).await; let msg1 = String::from("Attempting connection via default (local)"); diff --git a/src/main.rs b/src/main.rs index 05ac75e..6221bcb 100644 --- a/src/main.rs +++ b/src/main.rs @@ -32,7 +32,7 @@ pub const ALLOWED_CONNECTION_TYPES: [&str; 4] = ["local", "socket", "http", "ssl #[tokio::main] async fn main() -> Result<(), Box> { // Collect binary arguments - let args: Vec = std::env::args().collect(); + let args = std::env::args().collect(); let opt = get_opts(args); // Get Autoheal core variables From 9eb46a0635073c048150f024ac894188f30227c9 Mon Sep 17 00:00:00 2001 From: tmknight Date: Sat, 10 Feb 2024 09:11:33 -0500 Subject: [PATCH 8/8] Update CHANGELOG.md --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 1c01206..9e28845 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,6 +12,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/). ### Changed - Small change to how connection type assessed and reported for the sake of efficiency +- Minor code cleanup ## 0.8.1