Skip to content
Merged
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: 9 additions & 7 deletions files/usr/local/bin/apl-aggregator
Original file line number Diff line number Diff line change
Expand Up @@ -1052,15 +1052,17 @@ _fr24_acquire_binary() {
rm -rf "$tmp"
}

# _fr24_write_ini <ini> <key>: configure fr24feed as a BEAST-TCP consumer of
# the local decoder with the operator's sharing key (MLAT off, per the
# adapter's FR24-MLAT-default-off contract).
# _fr24_write_ini <ini> <key> <decoder-addr>: configure fr24feed as a BEAST-TCP
# consumer of the local decoder at <decoder-addr> with the operator's sharing
# key (MLAT off, per the adapter's FR24-MLAT-default-off contract). The address
# is the same AGG_DECODER_ADDR the reachability probe checks, so fr24feed feeds
# from exactly what was verified rather than a separately hardcoded endpoint.
_fr24_write_ini() {
local ini="$1" key="$2" tmp
local ini="$1" key="$2" addr="$3" tmp
tmp="$(mktemp "${ini}.XXXXXX")" || return 1
if ! cat >"$tmp" <<EOF
receiver="beast-tcp"
host="127.0.0.1:30005"
host="$addr"
fr24key="$key"
bs="no"
raw="no"
Expand Down Expand Up @@ -1175,7 +1177,7 @@ _enable_fr24() {
_worker_progress configuring
install -d -m 0750 "$(dirname "$ini")" 2>/dev/null || true
if [[ -n "$key" ]]; then
_fr24_write_ini "$ini" "$key" || { _emit_error state_error "failed to write fr24feed.ini"; exit 3; }
_fr24_write_ini "$ini" "$key" "$AGG_DECODER_ADDR" || { _emit_error state_error "failed to write fr24feed.ini"; exit 3; }
else
if ! _fr24_signup "$bin" "$ini" "$email" "$lat" "$lon" "$alt"; then
_emit_error signup_failed "fr24 signup did not return a sharing key"; exit 2
Expand All @@ -1185,7 +1187,7 @@ _enable_fr24() {
# The wizard writes its own receiver config (dvbt/auto); overwrite it so the
# signup and keyed paths produce identical BEAST-TCP-to-local config. Only
# the minted key is kept from the wizard's run.
_fr24_write_ini "$ini" "$key" || { _emit_error state_error "failed to write fr24feed.ini"; exit 3; }
_fr24_write_ini "$ini" "$key" "$AGG_DECODER_ADDR" || { _emit_error state_error "failed to write fr24feed.ini"; exit 3; }
fi
_fr24_finalize_perms "$ini"

Expand Down
11 changes: 11 additions & 0 deletions test/bats/test_aggregator_enable.bats
Original file line number Diff line number Diff line change
Expand Up @@ -294,6 +294,17 @@ EOF
grep -q 'fr24key="KEYONLY1234"' "$AGG_FR24_INI"
}

@test "fr24 ini feeds from the configured decoder address" {
# AGG_DECODER_STATE=up (setup) bypasses the live probe; a non-default
# AGG_DECODER_ADDR must still flow into fr24feed.ini so fr24 feeds from
# exactly the decoder the reachability probe checks.
export AGG_DECODER_ADDR="10.9.8.7:31005"
agg enable '{"id":"fr24","lat":47.0,"lon":8.0,"alt":400,"fields":{"email":"a@b.c","sharing_key":"PROVIDEDKEY1"}}'
[ "$status" -eq 0 ]
grep -q 'host="10.9.8.7:31005"' "$AGG_FR24_INI"
! grep -q 'host="127.0.0.1:30005"' "$AGG_FR24_INI"
}

@test "enable fails cleanly when the local decoder is unreachable" {
export AGG_DECODER_STATE=down
agg enable '{"id":"fr24","lat":47.0,"lon":8.0,"alt":400,"fields":{"email":"a@b.c","sharing_key":"VALIDKEY12"}}'
Expand Down