From 4537e29b55e2ce8e1a2508353be9baa14b65ddd4 Mon Sep 17 00:00:00 2001 From: Gerald Pinder Date: Thu, 20 Mar 2025 23:40:27 -0400 Subject: [PATCH] Add check for using askpass --- process/drivers/podman_driver.rs | 65 ++++++++++++-------------------- utils/src/constants.rs | 1 + 2 files changed, 25 insertions(+), 41 deletions(-) diff --git a/process/drivers/podman_driver.rs b/process/drivers/podman_driver.rs index 854a748..c40e6d6 100644 --- a/process/drivers/podman_driver.rs +++ b/process/drivers/podman_driver.rs @@ -5,7 +5,10 @@ use std::{ time::Duration, }; -use blue_build_utils::{credentials::Credentials, running_as_root, semver::Version}; +use blue_build_utils::{ + constants::SUDO_ASKPASS, credentials::Credentials, has_env_var, running_as_root, + semver::Version, +}; use cached::proc_macro::cached; use colored::Colorize; use comlexr::{cmd, pipe}; @@ -141,10 +144,8 @@ impl BuildDriver for PodmanDriver { } else { "podman" }, - if use_sudo => [ - "-A", - "podman", - ], + if use_sudo && has_env_var(SUDO_ASKPASS) => "-A", + if use_sudo => "podman", "build", if !matches!(opts.platform, Platform::Native) => [ "--platform", @@ -185,10 +186,8 @@ impl BuildDriver for PodmanDriver { } else { "podman" }, - if use_sudo => [ - "-A", - "podman", - ], + if use_sudo && has_env_var(SUDO_ASKPASS) => "-A", + if use_sudo => "podman", "tag", opts.src_image.to_string(), &dest_image_str @@ -217,10 +216,8 @@ impl BuildDriver for PodmanDriver { } else { "podman" }, - if use_sudo => [ - "-A", - "podman", - ], + if use_sudo && has_env_var(SUDO_ASKPASS) => "-A", + if use_sudo => "podman", "push", format!( "--compression-format={}", @@ -386,10 +383,8 @@ impl ContainerMountDriver for PodmanDriver { } else { "podman" }, - if use_sudo => [ - "-A", - "podman", - ], + if use_sudo && has_env_var(SUDO_ASKPASS) => "-A", + if use_sudo => "podman", "mount", opts.container_id, ); @@ -417,10 +412,8 @@ impl ContainerMountDriver for PodmanDriver { } else { "podman" }, - if use_sudo => [ - "-A", - "podman", - ], + if use_sudo && has_env_var(SUDO_ASKPASS) => "-A", + if use_sudo => "podman", "unmount", opts.container_id ); @@ -446,10 +439,8 @@ impl ContainerMountDriver for PodmanDriver { } else { "podman" }, - if use_sudo => [ - "-A", - "podman", - ], + if use_sudo && has_env_var(SUDO_ASKPASS) => "-A", + if use_sudo => "podman", "volume", "rm", &*opts.volume_id @@ -519,10 +510,8 @@ impl RunDriver for PodmanDriver { } else { "podman" }, - if use_sudo => [ - "-A", - "podman", - ], + if use_sudo && has_env_var(SUDO_ASKPASS) => "-A", + if use_sudo => "podman", "create", opts.image.to_string(), "bash" @@ -553,10 +542,8 @@ impl RunDriver for PodmanDriver { } else { "podman" }, - if use_sudo => [ - "-A", - "podman", - ], + if use_sudo && has_env_var(SUDO_ASKPASS) => "-A", + if use_sudo => "podman", "rm", opts.container_id, ); @@ -584,10 +571,8 @@ impl RunDriver for PodmanDriver { } else { "podman" }, - if use_sudo => [ - "-A", - "podman", - ], + if use_sudo && has_env_var(SUDO_ASKPASS) => "-A", + if use_sudo => "podman", "rmi", opts.image.to_string() ); @@ -621,10 +606,8 @@ impl RunDriver for PodmanDriver { } else { "podman" }, - if use_sudo => [ - "-A", - "podman", - ], + if use_sudo && has_env_var(SUDO_ASKPASS) => "-A", + if use_sudo => "podman", "images", "--format", "json" diff --git a/utils/src/constants.rs b/utils/src/constants.rs index e34bbf2..c8563b1 100644 --- a/utils/src/constants.rs +++ b/utils/src/constants.rs @@ -73,6 +73,7 @@ pub const LC_TERMINAL: &str = "LC_TERMINAL"; pub const TERM_PROGRAM_VERSION: &str = "TERM_PROGRAM_VERSION"; pub const LC_TERMINAL_VERSION: &str = "LC_TERMINAL_VERSION"; pub const XDG_RUNTIME_DIR: &str = "XDG_RUNTIME_DIR"; +pub const SUDO_ASKPASS: &str = "SUDO_ASKPASS"; // Misc pub const BUILD_SCRIPTS_IMAGE_REF: &str = "ghcr.io/blue-build/cli/build-scripts";