Skip to content

Commit

Permalink
added worker vars->env logic
Browse files Browse the repository at this point in the history
  • Loading branch information
fqjony committed Nov 28, 2024
1 parent 8539c61 commit bc86c5e
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 0 deletions.
7 changes: 7 additions & 0 deletions lib/environment.sh
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,13 @@ configure_environment() {

log_info "Worker configuration loaded successfully."

# Export variables from the configuration
log_info "Exporting variables from configuration to environment..."
if ! export_variables_from_config "$resolved_config"; then
log_error "Failed to export variables."
return 1
fi

# Extract and authenticate actors
local actors
actors=$(get_config_section "$resolved_config" "actors")
Expand Down
21 changes: 21 additions & 0 deletions lib/worker_config.sh
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,27 @@ load_and_parse_config() {
echo "$json_output"
}

# Export variables from the configuration
export_variables_from_config() {
local config_json="$1"

log_info "Exporting variables from configuration..."

# Extract the `variables` section
local variables
variables=$(echo "$config_json" | jq -r '.config.variables // empty')
if [[ -z "$variables" || "$variables" == "null" ]]; then
log_info "No variables found in the configuration."
return 0
fi

# Export each variable
echo "$variables" | jq -r 'to_entries[] | "\(.key)=\(.value)"' | while IFS= read -r line; do
export "$line"
log_info "Exported: $line"
done
}

# Function to extract a specific section from the JSON configuration
get_config_section() {
local config_json="$1"
Expand Down

0 comments on commit bc86c5e

Please sign in to comment.