From 03c397fb4c201a721d199555371d031bdc877761 Mon Sep 17 00:00:00 2001 From: Dmitry Smirnov Date: Thu, 28 Nov 2024 18:56:50 +0200 Subject: [PATCH] fix worker_config module --- lib/worker_config.sh | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/lib/worker_config.sh b/lib/worker_config.sh index 0e9afdfe..bd827b80 100644 --- a/lib/worker_config.sh +++ b/lib/worker_config.sh @@ -83,14 +83,10 @@ export_variables_from_config() { return 0 fi - # Export each variable - echo "$variables" | jq -r 'to_entries[] | "\(.key)=\(.value)"' | while IFS= read -r line; do - # Use `eval` to safely split the key=value pair - local key="${line%%=*}" - local value="${line#*=}" - export "$key=$value" - log_info "Exported: $key=$value" - done + # Iterate over variables and export them into the main shell + while IFS="=" read -r key value; do + eval "export $key=\"$value\"" + done < <(echo "$variables" | jq -r 'to_entries[] | "\(.key)=\(.value)"') } # Function to extract a specific section from the JSON configuration @@ -104,10 +100,13 @@ get_config_section() { fi # Attempt to extract the section and handle missing/null cases - if ! extracted_section=$(echo "$config_json" | jq -r ".config.${section} // empty" 2>/dev/null); then + local extracted_section + extracted_section=$(echo "$config_json" | jq -r ".config.${section} // empty" 2>/dev/null) + + if [[ $? -ne 0 ]]; then log_error "Failed to parse section '${section}' from configuration." return 1 fi echo "$extracted_section" -} +} \ No newline at end of file