Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# EditorConfig is awesome: https://EditorConfig.org

# top-most EditorConfig file
root = true

# Unix-style newlines with a newline ending every file
[*]
end_of_line = lf
insert_final_newline = true
charset = utf-8
trim_trailing_whitespace = true

# Nginx configuration files
[*.{conf,conf.template}]
indent_style = space
indent_size = 4
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ docker-compose.override.yml

# IDE
.idea/
.vscode/
*.swp
*.swo
.DS_Store
Expand Down
5 changes: 5 additions & 0 deletions .vscode/extensions.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"recommendations": [
"ahmadalli.vscode-nginx-conf"
]
}
9 changes: 9 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"files.associations": {
"*.conf.template": "nginx",
"*.conf": "nginx"
},
"editor.detectIndentation": true,
"editor.insertSpaces": true,
"editor.tabSize": 4
}
12 changes: 8 additions & 4 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,16 @@ RUN apt-get update && apt-get install --no-install-recommends -y \
dos2unix \
&& rm -rf /var/lib/apt/lists/*

COPY nginx.conf /etc/nginx/nginx.conf.template
RUN mkdir -p /etc/nginx/includes /etc/nginx/templates

WORKDIR /
COPY start.sh /
COPY templates /etc/nginx/templates
COPY scripts /usr/local/bin/scripts
COPY travelfusion.lua /

RUN chmod -R +x /usr/local/bin/scripts

WORKDIR /

STOPSIGNAL SIGTERM

CMD ["bash", "-x", "/start.sh"]
CMD ["/usr/local/bin/scripts/setup_nginx.sh", "start"]
17 changes: 17 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ services:
- WP_CHANNELS_TRAVELFUSION_LOGIN_ID=test-login
- WP_CHANNELS_TRAVELFUSION_XML_LOGIN_ID=test-login
- 'WP_CHANNELS_TRAVELFUSION_SUPPLIER_PARAMETERS={"test-iata": {"test-supplier": {"test-login-key": "test-login-value"}}}'
# Farelogix legacy config for backwards compatibility
# Comment out the following lines if you want to use the new config
- WP_CHANNELS_FARELOGIX_AA_HOST=mockserver
- WP_CHANNELS_FARELOGIX_AA_PROXY_PASS=http://mockserver:80
- WP_CHANNELS_FARELOGIX_AA_API_KEY=test-aa-key
Expand All @@ -24,6 +26,18 @@ services:
- WP_CHANNELS_FARELOGIX_AA_PASSWORD=test-pass
- WP_CHANNELS_FARELOGIX_AA_AGENT_USER=test-agent-user
- WP_CHANNELS_FARELOGIX_AA_AGENT_PASSWORD=test-agent-pass
# Farelogix new config with multiple account IDs
# Comment out the following lines if you want to use the old config
# Also, make sure to set the WP_CHANNELS_FARELOGIX_USE_ACCOUNT_IDS environment variable on the test container
# - WP_CHANNELS_FARELOGIX_USE_ACCOUNT_IDS=true
# - WP_CHANNELS_FARELOGIX_AA_CAD_HOST=mockserver
# - WP_CHANNELS_FARELOGIX_AA_CAD_PROXY_PASS=http://mockserver:80
# - WP_CHANNELS_FARELOGIX_AA_CAD_API_KEY=test-aa-key
# - WP_CHANNELS_FARELOGIX_AA_CAD_AGENT=test-agent
# - WP_CHANNELS_FARELOGIX_AA_CAD_USERNAME=test-user
# - WP_CHANNELS_FARELOGIX_AA_CAD_PASSWORD=test-pass
# - WP_CHANNELS_FARELOGIX_AA_CAD_AGENT_USER=test-agent-user
# - WP_CHANNELS_FARELOGIX_AA_CAD_AGENT_PASSWORD=test-agent-pass
depends_on:
mockserver:
condition: service_healthy
Expand Down Expand Up @@ -62,6 +76,9 @@ services:
environment:
- PROXY_HOST=proxy
- PROXY_PORT=8080
# Make sure this matches the WP_CHANNELS_FARELOGIX_USE_ACCOUNT_IDS environment variable on the proxy container
# Uncomment this line if you want to use the new config
# - WP_CHANNELS_FARELOGIX_USE_ACCOUNT_IDS=true
depends_on:
proxy:
condition: service_healthy
Expand Down
Empty file modified run_tests.sh
100644 → 100755
Empty file.
34 changes: 34 additions & 0 deletions scripts/channels/britishairways.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
#!/bin/bash

# shellcheck source=/dev/null
. "$(dirname "$0")/common.sh"

setup_britishairways() {
debug_log "Setting up British Airways configuration"

if check_any_vars "WP_CHANNELS_BA_API_KEY"; then
info_log "Found British Airways API key, proceeding with setup"

if ! validate_env_vars "WP_CHANNELS_BA_API_KEY"; then
error_log "Failed to validate required environment variables"
fi

export WP_CHANNELS_BA_HOST=${WP_CHANNELS_BA_HOST:-api.ba.com}
export WP_CHANNELS_BA_PROXY_PASS=${WP_CHANNELS_BA_PROXY_PASS:-${WP_SERVER_PROXY_PASS:-"https://${WP_CHANNELS_BA_HOST}"}}

debug_log "Using host: ${WP_CHANNELS_BA_HOST}"
debug_log "Using proxy pass: ${WP_CHANNELS_BA_PROXY_PASS}"

debug_log "Generating nginx configuration file"
# shellcheck disable=SC2016
generate_nginx_config \
"/etc/nginx/templates/channels/britishairways.conf.template" \
"/etc/nginx/includes/britishairways.conf" \
'${WP_CHANNELS_BA_PROXY_PASS} ${WP_CHANNELS_BA_HOST} ${WP_CHANNELS_BA_API_KEY}'
debug_log "Nginx configuration generated successfully"
else
info_log "No British Airways API key found, skipping setup"
fi
}

setup_britishairways
114 changes: 114 additions & 0 deletions scripts/channels/farelogix.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
#!/bin/bash

# shellcheck source=/dev/null
. "$(dirname "$0")/common.sh"

generate_farelogix_config() {
local airline_code=$1
local account_id=$2
local prefix="WP_CHANNELS_FARELOGIX"

info_log "Generating Farelogix config for airline_code: $airline_code, account_id: ${account_id:-none}"

if [ -n "$account_id" ]; then
prefix="${prefix}_${airline_code}_${account_id}"
else
prefix="${prefix}_${airline_code}"
fi

debug_log "Using environment variable prefix: $prefix"

local host_var="${prefix}_HOST"
local proxy_pass_var="${prefix}_PROXY_PASS"
local host="${!host_var:-${airline_code,,}.farelogix.com}"
local proxy_pass="${!proxy_pass_var:-https://${host}}"

debug_log "Host: $host"
debug_log "Proxy pass: $proxy_pass"

local auth_vars=(
"${prefix}_API_KEY"
"${prefix}_AGENT"
"${prefix}_USERNAME"
"${prefix}_PASSWORD"
"${prefix}_AGENT_USER"
"${prefix}_AGENT_PASSWORD"
)

if check_any_vars "${auth_vars[@]}"; then
debug_log "Found authentication variables for $prefix"
if ! validate_env_vars "${auth_vars[@]}"; then
error_log "Failed to validate environment variables for $prefix"
fi

(
export HOST="$host"
export PROXY_PASS="$proxy_pass"
local api_key_var="${prefix}_API_KEY"
local agent_var="${prefix}_AGENT"
local username_var="${prefix}_USERNAME"
local password_var="${prefix}_PASSWORD"
local agent_user_var="${prefix}_AGENT_USER"
local agent_password_var="${prefix}_AGENT_PASSWORD"

export API_KEY="${!api_key_var}"
export AGENT="${!agent_var}"
export USERNAME="${!username_var}"
export PASSWORD="${!password_var}"
export AGENT_USER="${!agent_user_var}"
export AGENT_PASSWORD="${!agent_password_var}"

local airline_code_lower
local account_id_lower
airline_code_lower="$(echo "$airline_code" | tr '[:upper:]' '[:lower:]')"
account_id_lower="$(echo "$account_id" | tr '[:upper:]' '[:lower:]')"

if [ -n "$account_id" ]; then
export LOCATION_PATH="${airline_code_lower}/${account_id_lower}"
else
export LOCATION_PATH="${airline_code_lower}"
fi

local output_file="/etc/nginx/includes/farelogix_${airline_code_lower}"
[ -n "$account_id" ] && output_file="${output_file}_${account_id_lower}"
output_file="${output_file}.conf"

debug_log "Generating config file: $output_file"
debug_log "Location path: $LOCATION_PATH"

# shellcheck disable=SC2016
generate_nginx_config \
"/etc/nginx/templates/channels/farelogix.conf.template" \
"$output_file" \
'${LOCATION_PATH} ${HOST} ${PROXY_PASS} ${API_KEY} ${AGENT} ${USERNAME} ${PASSWORD} ${AGENT_USER} ${AGENT_PASSWORD}'

debug_log "Config file generated successfully: $output_file"
)
else
debug_log "No authentication variables found for $prefix"
fi
}

debug_log "WP_CHANNELS_FARELOGIX_USE_ACCOUNT_IDS=${WP_CHANNELS_FARELOGIX_USE_ACCOUNT_IDS:-false}"

if [ "${WP_CHANNELS_FARELOGIX_USE_ACCOUNT_IDS:-false}" = "false" ]; then
info_log "Running in legacy mode (no account IDs)"
mapfile -t airline_codes < <(env | grep '^WP_CHANNELS_FARELOGIX_' | grep -v '_USE_ACCOUNT_IDS' | cut -d'_' -f4 | sort -u)
for airline_code in "${airline_codes[@]}"; do
debug_log "Found airline code: $airline_code"
if ! generate_farelogix_config "$airline_code"; then
error_log "Failed to generate config for airline code: $airline_code"
fi
done
else
info_log "Running in new mode with account IDs"
mapfile -t combinations < <(env | grep '^WP_CHANNELS_FARELOGIX_' | grep -v '_USE_ACCOUNT_IDS' | grep '_[^_]*_[^_]*_' | cut -d'_' -f4,5 | sort -u)
for line in "${combinations[@]}"; do
airline_code=$(echo "$line" | cut -d'_' -f1)
account_id=$(echo "$line" | cut -d'_' -f2)
debug_log "Found airline code: $airline_code with account ID: $account_id"
if ! generate_farelogix_config "$airline_code" "$account_id"; then
error_log "Failed to generate config for airline code: $airline_code with account ID: $account_id"
fi
done
fi
37 changes: 37 additions & 0 deletions scripts/channels/travelfusion.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
#!/bin/bash

# shellcheck source=/dev/null
. "$(dirname "$0")/common.sh"

setup_travelfusion() {
debug_log "Setting up Travelfusion configuration"

if [ -n "${WP_CHANNELS_TRAVELFUSION_LOGIN_ID}" ] || [ -n "${WP_CHANNELS_TRAVELFUSION_XML_LOGIN_ID}" ]; then
info_log "Found Travelfusion credentials, proceeding with setup"

if ! validate_env_vars "WP_CHANNELS_TRAVELFUSION_LOGIN_ID" "WP_CHANNELS_TRAVELFUSION_XML_LOGIN_ID" "WP_CHANNELS_TRAVELFUSION_SUPPLIER_PARAMETERS"; then
error_log "Failed to validate required environment variables"
fi

export WP_CHANNELS_TRAVELFUSION_HOST=${WP_CHANNELS_TRAVELFUSION_HOST:-api.travelfusion.com}
export WP_CHANNELS_TRAVELFUSION_PROXY_PASS=${WP_CHANNELS_TRAVELFUSION_PROXY_PASS:-${WP_SERVER_PROXY_PASS:-"https://${WP_CHANNELS_TRAVELFUSION_HOST}"}}

debug_log "Using host: ${WP_CHANNELS_TRAVELFUSION_HOST}"
debug_log "Using proxy pass: ${WP_CHANNELS_TRAVELFUSION_PROXY_PASS}"

debug_log "Writing supplier parameters to tf_config.json"
echo "${WP_CHANNELS_TRAVELFUSION_SUPPLIER_PARAMETERS:-}" > tf_config.json

debug_log "Generating nginx configuration file"
# shellcheck disable=SC2016
generate_nginx_config \
"/etc/nginx/templates/channels/travelfusion.conf.template" \
"/etc/nginx/includes/travelfusion.conf" \
'${WP_CHANNELS_TRAVELFUSION_LOGIN_ID} ${WP_CHANNELS_TRAVELFUSION_XML_LOGIN_ID} ${WP_CHANNELS_TRAVELFUSION_HOST} ${WP_CHANNELS_TRAVELFUSION_PROXY_PASS}'
debug_log "Nginx configuration generated successfully"
else
info_log "No Travelfusion credentials found, skipping setup"
fi
}

setup_travelfusion
72 changes: 72 additions & 0 deletions scripts/common.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
#!/bin/bash

export WP_SERVER_DEBUG=${WP_SERVER_DEBUG:-false}

generate_nginx_config() {
local template="$1"
local output="$2"
local vars="$3"

envsubst "$vars" < "$template" > "$output"
}

validate_env_vars() {
local vars=("$@")
local missing=()

debug_log "Validating required environment variables: ${vars[*]}"

for var in "${vars[@]}"; do
debug_log "Checking variable '$var' with value '${!var}'"
if [ -z "${!var}" ]; then
missing+=("$var")
debug_log "Variable '$var' is missing or empty"
else
debug_log "Variable '$var' is valid"
fi
done

if [ ${#missing[@]} -gt 0 ]; then
warning_log "Validation failed - missing variables: ${missing[*]}"
return 1
fi

debug_log "All required variables are valid"
return 0
}

check_any_vars() {
local vars=("$@")

debug_log "Checking if any of these variables are set: ${vars[*]}"

for var in "${vars[@]}"; do
debug_log "Checking variable '$var' with value '${!var}'"
if [ -n "${!var}" ]; then
debug_log "Found set variable '$var'"
return 0
fi
done

debug_log "None of the variables are set"
return 1
}

debug_log() {
if [ "${WP_SERVER_DEBUG}" = true ]; then
echo "[DEBUG] $1"
fi
}

info_log() {
echo "[INFO] $1"
}

warning_log() {
echo "[WARNING] $1"
}

error_log() {
echo "[ERROR] $1"
exit 1
}
Loading