mirror of
https://github.com/docker-mailserver/docker-mailserver.git
synced 2025-07-28 14:45:34 +02:00
Apply suggestions from code review
This commit is contained in:
parent
efa4563d54
commit
22bf742a33
2 changed files with 12 additions and 9 deletions
|
@ -249,26 +249,29 @@ function __environment_variables_export() {
|
|||
# This function sets any environment variable with a value from a referenced file
|
||||
# when an equivalent ENV with a `__FILE` suffix exists with a valid file path as the value.
|
||||
function __environment_variables_from_files() {
|
||||
# Iterate through all ENV found with a `__FILE` suffix:
|
||||
while read -r ENV_WITH_FILE_REF; do
|
||||
# Store the ENV name without the `__FILE` suffix:
|
||||
local TARGET_ENV_NAME="${ENV_WITH_FILE_REF/__FILE/}"
|
||||
local -n TARGET_ENV="${ENV_WITH_FILE_REF/__FILE/}"
|
||||
# Store the value of the `__FILE` ENV:
|
||||
local FILE_PATH="${!ENV_WITH_FILE_REF}"
|
||||
# Store the ENV name without the `__FILE` suffix:
|
||||
local TARGET_ENV_NAME="${ENV_WITH_FILE_REF/__FILE/}"
|
||||
# Assign a value representing a variable name,
|
||||
# `-n` will alias `TARGET_ENV` so that it is treated as if it were the referenced variable:
|
||||
local -n TARGET_ENV="${TARGET_ENV_NAME}"
|
||||
|
||||
# Skip sourcing from `__FILE` if ENV is already set:
|
||||
# Skip if the target ENV is already set:
|
||||
if [[ -v TARGET_ENV ]]; then
|
||||
_log 'warn' "ENV value will not be sourced from '${ENV_WITH_FILE_REF}' since '${TARGET_ENV_NAME}' is already set"
|
||||
_log 'warn' "Ignoring '${TARGET_ENV_NAME}' since '${ENV_WITH_FILE_REF}' is also set"
|
||||
continue
|
||||
fi
|
||||
|
||||
# Otherwise, retrieve the value from a file and set
|
||||
# the ENV, or fail if the reference is invalid:
|
||||
# Skip if the file path provided is invalid:
|
||||
if [[ ! -f ${FILE_PATH} ]]; then
|
||||
_log 'warn' "File defined for secret '${TARGET_ENV_NAME}' with path '${FILE_PATH}' does not exist"
|
||||
continue
|
||||
fi
|
||||
|
||||
# Read the value from a file and assign it to the intended ENV:
|
||||
_log 'info' "Getting secret '${TARGET_ENV_NAME}' from '${FILE_PATH}'"
|
||||
TARGET_ENV="$(< "${FILE_PATH}")"
|
||||
done < <(env | grep -Po '^.+?__FILE')
|
||||
|
|
|
@ -45,7 +45,7 @@ function setup_file() {
|
|||
CONTAINER_NAME=${CONTAINER3_NAME}
|
||||
_init_with_defaults
|
||||
local CUSTOM_SETUP_ARGUMENTS=(
|
||||
--env TEST__FILE="${FILEPATH_INVALID}"
|
||||
--env ENABLE_POP3__FILE="${FILEPATH_INVALID}"
|
||||
)
|
||||
_common_container_setup 'CUSTOM_SETUP_ARGUMENTS'
|
||||
}
|
||||
|
@ -85,5 +85,5 @@ function teardown_file() {
|
|||
# Relevant log content only available via docker logs:
|
||||
run docker logs "${CONTAINER_NAME}"
|
||||
assert_success
|
||||
assert_line --partial "File defined for secret 'TEST' with path '${FILEPATH_INVALID}' does not exist"
|
||||
assert_line --partial "File defined for secret 'ENABLE_POP3' with path '${FILEPATH_INVALID}' does not exist"
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue