Skip to content

Commit 486298c

Browse files
committed
feat(apl-feed): resolve website URL from feed.env; rename --server-url
Renames APL_FEED_SERVER_URL to APL_FEED_WEBSITE_URL and adds a resolver that reads the value from /etc/airplanes/feed.env when no env override is present. systemd-launched timers (claim, diagnostics, config-sync) and manual apl-feed invocations now uniformly pick up a non-prod backend pointer set via the on-disk feed.env, without needing per-unit EnvironmentFile= directives that would leak unrelated keys into the unit environment. CLI flag --server-url is renamed to --website-url to align the flag/env/key naming triple.
1 parent 6e61e73 commit 486298c

15 files changed

Lines changed: 195 additions & 74 deletions

scripts/apl-feed/backup.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ config_backup() {
2626
--force)
2727
die "unknown flag for backup: --force"
2828
;;
29-
--root|--server-url|--max-retry-time|-h|--help)
29+
--root|--website-url|--max-retry-time|-h|--help)
3030
if parse_common_option "$@"; then opt_rc=0; else opt_rc=$?; fi
3131
case "$opt_rc" in
3232
1) shift ;;
@@ -120,7 +120,7 @@ config_restore() {
120120
uuid_arg="$2"
121121
shift 2
122122
;;
123-
--root|--server-url|--max-retry-time|-h|--help)
123+
--root|--website-url|--max-retry-time|-h|--help)
124124
if parse_common_option "$@"; then opt_rc=0; else opt_rc=$?; fi
125125
case "$opt_rc" in
126126
1) shift ;;

scripts/apl-feed/claim.sh

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#!/usr/bin/env bash
22

33
claim_page_url() {
4-
printf '%s/feeder/claim' "${SERVER_URL%/}"
4+
printf '%s/feeder/claim' "${WEBSITE_URL%/}"
55
}
66

77
print_claim_instructions() {
@@ -62,7 +62,7 @@ claim_register() {
6262
echo "Feeder ID: $uuid"
6363
if (( DRY_RUN )); then
6464
echo "SECRET: $secret"
65-
echo "(dry-run; would POST to $SERVER_URL/api/feeders/secret)"
65+
echo "(dry-run; would POST to $WEBSITE_URL/api/feeders/secret)"
6666
exit 0
6767
fi
6868

@@ -91,7 +91,7 @@ claim_register() {
9191
return 2
9292
;;
9393
*)
94-
echo "ERROR: curl rc=$curl_rc - $SERVER_URL/api/feeders/secret unreachable" >&2
94+
echo "ERROR: curl rc=$curl_rc - $WEBSITE_URL/api/feeders/secret unreachable" >&2
9595
return 2
9696
;;
9797
esac
@@ -160,7 +160,7 @@ claim_register() {
160160
echo "INFO: 429 rate-limited; sleeping ${sleep_for}s (server retry_after)" >&2
161161
;;
162162
404)
163-
echo "ERROR: 404 from API - endpoint disabled or wrong server URL ($SERVER_URL) - $preview" >&2
163+
echo "ERROR: 404 from API - endpoint disabled or wrong website URL ($WEBSITE_URL) - $preview" >&2
164164
return 1
165165
;;
166166
5*)

scripts/apl-feed/common.sh

Lines changed: 37 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,40 @@
11
#!/usr/bin/env bash
22

33
ROOT='/'
4-
# shellcheck disable=SC2034 # SERVER_URL/MAX_RETRY_TIME/DRY_RUN/FORCE are read by sibling modules sourced from apl-feed.sh
5-
SERVER_URL="${APL_FEED_SERVER_URL:-https://airplanes.live}"
4+
5+
# Precedence: CLI flag (--website-url) > APL_FEED_WEBSITE_URL env > on-disk
6+
# feed.env > built-in default. systemd-launched timers run without env vars,
7+
# so the feed.env grep is the only way they pick up a non-prod backend set
8+
# via airplanes-config.txt's WEBSITE_URL key. feed.env is parsed (not
9+
# sourced) because the file is operator-editable and apl-feed runs as root.
10+
# shellcheck disable=SC2120 # production call site uses default; bats overrides
11+
_resolve_website_url() {
12+
local feed_env="${1:-/etc/airplanes/feed.env}"
13+
if [[ -n "${APL_FEED_WEBSITE_URL:-}" ]]; then
14+
printf '%s' "$APL_FEED_WEBSITE_URL"
15+
return 0
16+
fi
17+
if [[ -r "$feed_env" ]]; then
18+
local val
19+
val="$(awk -F= '
20+
/^APL_FEED_WEBSITE_URL=/ {
21+
v = substr($0, length($1) + 2)
22+
sub(/^"/, "", v)
23+
sub(/"$/, "", v)
24+
last = v
25+
}
26+
END { if (last != "") print last }
27+
' "$feed_env" 2>/dev/null)"
28+
if [[ -n "$val" ]]; then
29+
printf '%s' "$val"
30+
return 0
31+
fi
32+
fi
33+
printf 'https://airplanes.live'
34+
}
35+
36+
# shellcheck disable=SC2034 # WEBSITE_URL/MAX_RETRY_TIME/DRY_RUN/FORCE are read by sibling modules sourced from apl-feed.sh
37+
WEBSITE_URL="$(_resolve_website_url)"
638
# shellcheck disable=SC2034
739
MAX_RETRY_TIME="${APL_FEED_MAX_RETRY_TIME:-60}"
840
# shellcheck disable=SC2034
@@ -453,10 +485,10 @@ parse_common_option() {
453485
ROOT="$2"
454486
return 2
455487
;;
456-
--server-url)
457-
[[ $# -ge 2 ]] || die "--server-url requires URL"
488+
--website-url)
489+
[[ $# -ge 2 ]] || die "--website-url requires URL"
458490
# shellcheck disable=SC2034 # consumed by http.sh/claim.sh after parse
459-
SERVER_URL="$2"
491+
WEBSITE_URL="$2"
460492
return 2
461493
;;
462494
--max-retry-time)

scripts/apl-feed/http.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ post_json() {
1515
--data-binary @- \
1616
--output "$response_file" \
1717
--write-out '%{http_code}' \
18-
"$SERVER_URL$path"
18+
"$WEBSITE_URL$path"
1919
}
2020

2121
# post_json_bearer <token> <path> <body> <response_file>
@@ -71,7 +71,7 @@ post_json_bearer() {
7171
--data-binary @- \
7272
--output "$response_file" \
7373
--write-out '%{http_code}' \
74-
"$SERVER_URL$path"
74+
"$WEBSITE_URL$path"
7575
rc=$?
7676
rm -f "$cfg"
7777
return "$rc"

scripts/apl-feed/import.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ apl_feed_import_legacy_config() {
9090
break
9191
;;
9292
-*)
93-
# parse_common_option owns --root, --server-url, etc.
93+
# parse_common_option owns --root, --website-url, etc.
9494
# Check it BEFORE rejecting as unknown so chroot / build /
9595
# test callers can pass `--root /mnt` to redirect paths.
9696
local opt_rc

scripts/apl-feed/mlat.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,7 @@ apl_feed_mlat_geo() {
214214
case "$1" in
215215
-[0-9]*|-.[0-9]*)
216216
positional+=("$1"); shift ;;
217-
--|-h|--help|--root|--server-url|--max-retry-time)
217+
--|-h|--help|--root|--website-url|--max-retry-time)
218218
local opt_rc
219219
if parse_common_option "$@"; then opt_rc=0; else opt_rc=$?; fi
220220
case "$opt_rc" in

test/script-install.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ done
129129
[[ "$ready" -eq 1 ]] || { echo "mock HTTP server did not become ready" >&2; exit 1; }
130130

131131
export PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"
132-
export APL_FEED_SERVER_URL="http://127.0.0.1:18080"
132+
export APL_FEED_WEBSITE_URL="http://127.0.0.1:18080"
133133
export APL_FEED_MAX_RETRY_TIME=5
134134
export AIRPLANES_PACKAGE_MANAGER=apt
135135

test/script-upgrade.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ done
150150
[[ "$ready" -eq 1 ]] || { echo "mock HTTP server did not become ready" >&2; exit 1; }
151151

152152
export PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"
153-
export APL_FEED_SERVER_URL="http://127.0.0.1:18080"
153+
export APL_FEED_WEBSITE_URL="http://127.0.0.1:18080"
154154
export APL_FEED_MAX_RETRY_TIME=5
155155
export AIRPLANES_PACKAGE_MANAGER=apt
156156

test/test_airplanes_diagnostics.bats

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@ run_script() {
174174
AIRPLANES_DIAGNOSTICS_ROOT="$ROOT_DIR" \
175175
AIRPLANES_DIAGNOSTICS_LAST_SUCCESS="$LAST_SUCCESS" \
176176
AIRPLANES_DIAGNOSTICS_INTENT_ACK_FILE="$INTENT_ACK" \
177-
APL_FEED_SERVER_URL='http://127.0.0.1:0' \
177+
APL_FEED_WEBSITE_URL='http://127.0.0.1:0' \
178178
COMMAND_LOG="$COMMAND_LOG" \
179179
BODY_LOG="$BODY_LOG" \
180180
HEADER_LOG="$HEADER_LOG" \

test/test_apl_feed_cli.bats

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -236,7 +236,7 @@ PY
236236
echo "ABCDEFGHIJKLMNOP" > "$ROOT_DIR/etc/airplanes/feeder-claim-secret"
237237
chmod 600 "$ROOT_DIR/etc/airplanes/feeder-claim-secret"
238238

239-
run "$SCRIPT" claim show --root "$ROOT_DIR" --server-url "https://staging.airplanes.test/"
239+
run "$SCRIPT" claim show --root "$ROOT_DIR" --website-url "https://staging.airplanes.test/"
240240

241241
[ "$status" -eq 0 ]
242242
[[ "$output" =~ "Claim page: https://staging.airplanes.test/feeder/claim" ]]
@@ -247,7 +247,7 @@ PY
247247
chmod 600 "$ROOT_DIR/etc/airplanes/feeder-claim-secret"
248248
start_fixed_server 200 "$(contract_body status authenticated_recent)"
249249

250-
run "$SCRIPT" status --root "$ROOT_DIR" --server-url "$(mock_url)"
250+
run "$SCRIPT" status --root "$ROOT_DIR" --website-url "$(mock_url)"
251251

252252
[ "$status" -eq 0 ]
253253
[[ "$output" =~ "Website claim" ]]
@@ -276,7 +276,7 @@ EOF
276276
chmod 600 "$ROOT_DIR/etc/airplanes/feeder-claim-secret"
277277
start_fixed_server 200 "$(contract_body status authenticated_recent)"
278278

279-
run "$SCRIPT" status --root "$ROOT_DIR" --server-url "$(mock_url)"
279+
run "$SCRIPT" status --root "$ROOT_DIR" --website-url "$(mock_url)"
280280

281281
[ "$status" -eq 0 ]
282282
[[ "$output" =~ "Receiver input" ]]
@@ -289,7 +289,7 @@ EOF
289289
chmod 600 "$ROOT_DIR/etc/airplanes/feeder-claim-secret"
290290
start_fixed_server 200 "$(contract_body status authenticated_recent)"
291291

292-
run "$SCRIPT" status --json --root "$ROOT_DIR" --server-url "$(mock_url)"
292+
run "$SCRIPT" status --json --root "$ROOT_DIR" --website-url "$(mock_url)"
293293

294294
[ "$status" -eq 0 ]
295295
[ "$(jq -r '.schema_version' <<< "$output")" = "1" ]
@@ -305,7 +305,7 @@ EOF
305305
chmod 600 "$ROOT_DIR/etc/airplanes/feeder-claim-secret"
306306
start_fixed_server 200 '{"version": 2}'
307307

308-
run "$SCRIPT" claim rotate --root "$ROOT_DIR" --server-url "$(mock_url)"
308+
run "$SCRIPT" claim rotate --root "$ROOT_DIR" --website-url "$(mock_url)"
309309

310310
[ "$status" -eq 0 ]
311311
[[ "$output" =~ "Rotation complete (v2)" ]]
@@ -323,7 +323,7 @@ EOF
323323
start_claim_server 200 '{"version": 2}' \
324324
"ABCDEFGHIJKLMNOP" 1 "" 0
325325

326-
run "$SCRIPT" claim rotate --root "$ROOT_DIR" --server-url "$(mock_url)"
326+
run "$SCRIPT" claim rotate --root "$ROOT_DIR" --website-url "$(mock_url)"
327327
[ "$status" -eq 0 ]
328328
# Filter to the /secret POST line; /status probes are not relevant here
329329
# but may also appear in the capture if the rotate flow probes.
@@ -346,7 +346,7 @@ EOF
346346
start_claim_server 409 '{"error": "rotation_rejected"}' \
347347
"ABCDEFGHIJKLMNOP" 1 "QRSTUVWXYZ012345" 3
348348

349-
run "$SCRIPT" claim rotate --root "$ROOT_DIR" --server-url "$(mock_url)"
349+
run "$SCRIPT" claim rotate --root "$ROOT_DIR" --website-url "$(mock_url)"
350350

351351
[ "$status" -eq 0 ]
352352
[[ "$output" =~ "Rotation finalized (v3)" ]]
@@ -361,7 +361,7 @@ EOF
361361
start_claim_server 200 '{"version": 1}' \
362362
"ABCDEFGHIJKLMNOP" 1 "NO_MATCH_PENDING1" 2
363363

364-
run "$SCRIPT" claim rotate --abort --root "$ROOT_DIR" --server-url "$(mock_url)"
364+
run "$SCRIPT" claim rotate --abort --root "$ROOT_DIR" --website-url "$(mock_url)"
365365

366366
[ "$status" -eq 0 ]
367367
[[ "$output" =~ "Pending rotation aborted" ]]
@@ -424,7 +424,7 @@ EOF
424424
echo "ABCDEFGHIJKLMNOP" > "$ROOT_DIR/etc/airplanes/feeder-claim-secret"
425425
chmod 600 "$ROOT_DIR/etc/airplanes/feeder-claim-secret"
426426

427-
run "$SCRIPT" claim rotate --dry-run --root "$ROOT_DIR" --server-url "http://127.0.0.1:1"
427+
run "$SCRIPT" claim rotate --dry-run --root "$ROOT_DIR" --website-url "http://127.0.0.1:1"
428428

429429
[ "$status" -ne 0 ]
430430
[[ "$output" =~ "unknown flag for claim rotate: --dry-run" ]]
@@ -827,7 +827,7 @@ SH
827827
chmod +x "$bin_dir/curl"
828828

829829
run env PATH="$bin_dir:$PATH" CURL_ARGS_FILE="$args_file" CURL_STDIN_FILE="$stdin_file" \
830-
"$SCRIPT" claim register --root "$ROOT_DIR" --server-url "http://example.invalid"
830+
"$SCRIPT" claim register --root "$ROOT_DIR" --website-url "http://example.invalid"
831831

832832
[ "$status" -eq 0 ]
833833
local secret

0 commit comments

Comments
 (0)