mirror of
https://github.com/block/buzz.git
synced 2026-11-25 10:42:26 +00:00
feat(push): make gateway origin configurable (#7261)
Make the push gateway origin configurable across the relay, gateway, mobile client, and deployment chart. This is a fresh deployment. The gateway has only run on personal development infrastructure, and push has no existing enabled users. Legacy migration, configured-to-unconfigured mobile transitions, and rolling upgrades from pre-launch gateway binaries are not supported. Populated pre-launch databases are rejected with an informative error before migrations run; their data is untouched. Mobile builds may omit the gateway URL, leaving push unavailable. Once push is enabled, subsequent builds must retain that configuration. ### Validation - All applicable CI checks pass at `5f546cfaf403f0386f146d213adfb4392f4ec29c`, including Rust, mobile/Swift, desktop/integration, security, image builds, and Helm checks. An unrelated agent cancellation test passed on retry. - PostgreSQL CI passed 384 tests, including the production-entry-point regression for refusing populated pre-launch databases before migrations, fresh initialization, and subsequent initialized deployments. - Focused local validation passed all 10 gateway PostgreSQL tests under the CI discovery filter and all 3 unconfigured-mobile tests. Repository-wide PostgreSQL discovery validation and the complete pre-push hooks passed. - Physical-device APNs/App Attest behavior and deployment to a live cluster were not verified in this work. --------- Signed-off-by: Tom Brow <tomb@block.xyz> Co-authored-by: Codex <noreply@openai.com>
This commit is contained in:
55
mobile/scripts/require-push-gateway-origin.sh
Normal file
55
mobile/scripts/require-push-gateway-origin.sh
Normal file
@@ -0,0 +1,55 @@
|
||||
#!/bin/sh
|
||||
set -eu
|
||||
|
||||
gateway_origin=
|
||||
has_dart_define=false
|
||||
old_ifs=$IFS
|
||||
IFS=','
|
||||
for encoded in ${DART_DEFINES:-}; do
|
||||
decoded=$(printf '%s' "$encoded" | base64 --decode 2>/dev/null || printf '%s' "$encoded" | base64 -D 2>/dev/null || true)
|
||||
case "$decoded" in
|
||||
BUZZ_PUSH_GATEWAY_URL=*)
|
||||
if [ "$has_dart_define" = true ]; then
|
||||
echo "error: BUZZ_PUSH_GATEWAY_URL must be supplied at most once." >&2
|
||||
exit 1
|
||||
fi
|
||||
has_dart_define=true
|
||||
gateway_origin=${decoded#BUZZ_PUSH_GATEWAY_URL=}
|
||||
;;
|
||||
esac
|
||||
done
|
||||
IFS=$old_ifs
|
||||
|
||||
if [ "$has_dart_define" = false ] && [ -n "${BUZZ_PUSH_GATEWAY_URL:-}" ]; then
|
||||
gateway_origin=$BUZZ_PUSH_GATEWAY_URL
|
||||
encoded=$(printf '%s' "BUZZ_PUSH_GATEWAY_URL=$gateway_origin" | base64 | tr -d '\n')
|
||||
DART_DEFINES=${DART_DEFINES:+$DART_DEFINES,}$encoded
|
||||
export DART_DEFINES
|
||||
fi
|
||||
|
||||
if [ "$has_dart_define" = false ] && [ -z "$gateway_origin" ]; then
|
||||
# An unconfigured artifact deliberately has no push capability.
|
||||
return 0 2>/dev/null || exit 0
|
||||
fi
|
||||
|
||||
if [ -n "${SRCROOT:-}" ]; then
|
||||
script_dir=$SRCROOT/../scripts
|
||||
else
|
||||
script_dir=$(CDPATH= cd -- "$(dirname -- "$0")" && pwd)
|
||||
fi
|
||||
dart_bin=${FLUTTER_ROOT:+$FLUTTER_ROOT/bin/dart}
|
||||
if [ -z "$dart_bin" ] || [ ! -x "$dart_bin" ]; then
|
||||
dart_bin=$(command -v dart || true)
|
||||
fi
|
||||
if [ -z "$dart_bin" ]; then
|
||||
echo "error: Dart is required to validate BUZZ_PUSH_GATEWAY_URL." >&2
|
||||
exit 1
|
||||
fi
|
||||
case ${CONFIGURATION:-Release} in
|
||||
Debug*)
|
||||
"$dart_bin" "$script_dir/validate_push_gateway_origin.dart" "$gateway_origin"
|
||||
;;
|
||||
*)
|
||||
"$dart_bin" "$script_dir/validate_push_gateway_origin.dart" --require-https "$gateway_origin"
|
||||
;;
|
||||
esac
|
||||
37
mobile/scripts/validate_push_gateway_origin.dart
Normal file
37
mobile/scripts/validate_push_gateway_origin.dart
Normal file
@@ -0,0 +1,37 @@
|
||||
import 'dart:io';
|
||||
|
||||
bool isValidPushGatewayOrigin(String value, {bool requireHttps = false}) {
|
||||
try {
|
||||
final uri = Uri.parse(value);
|
||||
if (requireHttps
|
||||
? uri.scheme != 'https'
|
||||
: uri.scheme != 'http' && uri.scheme != 'https') {
|
||||
return false;
|
||||
}
|
||||
if (!uri.hasAuthority || uri.host.isEmpty || uri.userInfo.isNotEmpty) {
|
||||
return false;
|
||||
}
|
||||
if (uri.path.isNotEmpty && uri.path != '/') return false;
|
||||
if (uri.hasQuery || uri.hasFragment) return false;
|
||||
if (requireHttps && uri.hasPort) return false;
|
||||
final port = uri.port;
|
||||
return port >= 1 && port <= 65535;
|
||||
} on FormatException {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
void main(List<String> arguments) {
|
||||
final requireHttps =
|
||||
arguments.isNotEmpty && arguments.first == '--require-https';
|
||||
final values = requireHttps ? arguments.skip(1).toList() : arguments;
|
||||
if (values.length == 1 &&
|
||||
isValidPushGatewayOrigin(values.single, requireHttps: requireHttps)) {
|
||||
return;
|
||||
}
|
||||
final requirement = requireHttps
|
||||
? 'an HTTPS origin without an explicit port, credentials, path, query, or fragment'
|
||||
: 'an HTTP(S) origin without credentials, path, query, or fragment';
|
||||
stderr.writeln('error: BUZZ_PUSH_GATEWAY_URL must be $requirement.');
|
||||
exitCode = 1;
|
||||
}
|
||||
Reference in New Issue
Block a user