Skip to content

Commit

Permalink
fix(docker): preserve command line argument quotes
Browse files Browse the repository at this point in the history
Ensure that quoting inside command line parameters is forwarded
correctly to the manager container.

Signed-off-by: Thomas Fossati <[email protected]>
  • Loading branch information
thomas-fossati committed Dec 9, 2024
1 parent 3095339 commit 33e8633
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 17 deletions.
12 changes: 9 additions & 3 deletions deployments/docker/src/manager-dispatcher
Original file line number Diff line number Diff line change
Expand Up @@ -49,17 +49,23 @@ function clear_logs() {
}

function cocli() {
local cmd="$_utils_dir/cocli $*"
local -a args
for arg in "$@"; do args+=("'$arg'"); done
local cmd="$_utils_dir/cocli ${args[@]}"
/bin/bash -c "$cmd"
}

function evcli() {
local cmd="$_utils_dir/evcli $*"
local -a args
for arg in "$@"; do args+=("'$arg'"); done
local cmd="$_utils_dir/evcli ${args[@]}"
/bin/bash -c "$cmd"
}

function pocli() {
local cmd="$_utils_dir/pocli $*"
local -a args
for arg in "$@"; do args+=("'$arg'"); done
local cmd="$_utils_dir/pocli ${args[@]}"
/bin/bash -c "$cmd"
}

Expand Down
42 changes: 28 additions & 14 deletions deployments/docker/veraison
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@
# SPDX-License-Identifier: Apache-2.0
set -eo pipefail

# We need to make this a global variable because bash functions cannot return
# arrays.
declare -a translated_args

function status() {
_check_installed jq

Expand Down Expand Up @@ -269,20 +273,26 @@ function kill_tmux_session() {
}

function cocli() {
local -r -a args=$(printf '"%s" ' "$@")
local -r -a translated_args=$(_translate_host_paths "${args[@]}")
local -a args
for arg in "$@"; do args+=("$arg"); done
# Note: calling _translated_host_paths sets translated_args
_translate_host_paths "${args[@]}"
manager cocli "${translated_args[@]}"
}

function evcli() {
local -r -a args=$(printf '"%s" ' "$@")
local -r -a translated_args=$(_translate_host_paths "${args[@]}")
local -a args
for arg in "$@"; do args+=("$arg"); done
# Note: calling _translated_host_paths sets translated_args
_translate_host_paths "${args[@]}"
manager evcli "${translated_args[@]}"
}

function pocli() {
local -r -a args=$(printf '"%s" ' "$@")
local -r -a translated_args=$(_translate_host_paths "${args[@]}")
local -a args
for arg in "$@"; do args+=("$arg"); done
# Note: calling _translated_host_paths sets translated_args
_translate_host_paths "${args[@]}"
manager pocli "${translated_args[@]}"
}

Expand Down Expand Up @@ -384,29 +394,33 @@ function _strip_color() {
echo "$*" | sed -r "s/$_bash_color//g"
}

# Note: this function manipulates the global variable "translated_args"
function _translate_host_paths() {
local -r split_args=$(echo "$@" | sed 's/=\// \//g')
local -a split_args
for arg in "$@"; do
split_args+=("$(echo "$arg" | sed 's/=\// \//g')")
done

for part in $split_args; do
translated_args=()

for part in "${split_args[@]}"; do
if [[ $part == /* ]]; then
local -r realpart=$(realpath -q "$part")
local realpart=$(realpath -q "$part")
if [[ "$OSTYPE" == "darwin"* ]]; then
# Terrible, horrible, no good, very bad CLUDGE for MocOS X:
# On MacOS, all top-level locations in the file system are in
# fact symlinks (or something) to locations under /host_mnt/.
# These do not get resolved by realpath, so we have to do it
# manually. Hopefully, this doesn't break for different MacOS
# versions...
ammended+=("${_host_root}/host_mnt$realpart")
translated_args+=("${_host_root}/host_mnt$realpart")
else
ammended+=("$_host_root$realpart")
translated_args+=("$_host_root$realpart")
fi
else
ammended+=("$part")
translated_args+=("$part")
fi
done

echo "${ammended[@]}";
}

_this_dir=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )
Expand Down

0 comments on commit 33e8633

Please sign in to comment.