selector: --org and --business in case2-unit's outer and serve scopes
This commit is contained in:
1 parent
7f882a905d
commit
4b7ddbcb43
2 files changed
+110
-8
No files matched your search
+43
-6
@@ -9,6 +9,12 @@
|
||||
# [--profile factory|library] [--proxy] [--pm] [--claude PATH]
|
||||
# -- SERVE FLAGS
|
||||
#
|
||||
# --org ID is the same option as --business ID (rename design r2), in each of
|
||||
# two scopes: this script's own flags before --, and the serve flags after it.
|
||||
# Each scope takes each spelling once, and a second spelling the same value;
|
||||
# nothing is counted across --. The serve flags must name the selector, it must
|
||||
# be the unit's business, and the unit renders it as --business ID.
|
||||
#
|
||||
# Root runs it from a root-owned checkout of the reviewed commit outside
|
||||
# <home>, never from the release, because <user> can write the release. It
|
||||
# writes the bus and Console units (and the proxy unit under --proxy) under
|
||||
@@ -77,14 +83,35 @@ abs_plain() {
|
||||
[ "$1" = / ] || [ "${1%/}" = "$1" ] || die "$2 must not end in /: $1"
|
||||
}
|
||||
|
||||
# shellcheck source=scripts/selector.sh
|
||||
. "$REPO/scripts/selector.sh"
|
||||
business_id_ok() { [[ "$1" =~ ^[a-z0-9][a-z0-9._-]{0,63}$ ]]; }
|
||||
# The outer selector: a missing value is a usage error, a flag-shaped or invalid one the
|
||||
# business-id refusal, and a repeated or conflicting one a usage error that says why.
|
||||
outer_refused() {
|
||||
case "$1" in
|
||||
missing) usage ;;
|
||||
flag|invalid) die "--business must be a business id: $BUSINESS" ;;
|
||||
*) echo "case2-unit: $2" >&2; exit 4 ;;
|
||||
esac
|
||||
}
|
||||
# The serve selector: every refusal names the serve flag, as the other serve flags do.
|
||||
serve_refused() {
|
||||
case "$1" in
|
||||
missing) die "serve flag $SERVE_NAME needs a value" ;;
|
||||
flag|invalid) die "serve $SERVE_NAME $SERVE_VALUE is not the unit's business $BUSINESS" ;;
|
||||
*) die "serve $2" ;;
|
||||
esac
|
||||
}
|
||||
PROFILE=library USER_NAME='' HOME_DIR='' BUSINESS='' COPY_ID='' NODE='' PROXY=0 PM=0 CLAUDE='' CLAUDE_SET=0
|
||||
while [ $# -gt 0 ]; do
|
||||
case "$1" in
|
||||
--profile|--user|--home|--business|--copy|--node|--claude)
|
||||
--business|--org) BUSINESS="${2-}"; selector_take outer id outer_refused business_id_ok "$1" "${@:2:1}"; shift 2 ;;
|
||||
--profile|--user|--home|--copy|--node|--claude)
|
||||
[ $# -ge 2 ] || usage
|
||||
case "$1" in
|
||||
--profile) PROFILE="$2" ;; --user) USER_NAME="$2" ;; --home) HOME_DIR="$2" ;;
|
||||
--business) BUSINESS="$2" ;; --copy) COPY_ID="$2" ;; --node) NODE="$2" ;;
|
||||
--copy) COPY_ID="$2" ;; --node) NODE="$2" ;;
|
||||
--claude) CLAUDE="$2"; CLAUDE_SET=1 ;;
|
||||
esac
|
||||
shift 2 ;;
|
||||
@@ -346,7 +373,7 @@ tester_location() {
|
||||
serve_flags() {
|
||||
local -A seen=()
|
||||
local flags='' name value
|
||||
local port='' public_host='' auth_header='' allow_user='' proof_header='' proof_file='' tester_socket=0 sso=0
|
||||
local port='' public_host='' auth_header='' allow_user='' proof_header='' proof_file='' tester_socket=0 sso=0 selected=0
|
||||
local i=0 n=${#SERVE[@]}
|
||||
while [ "$i" -lt "$n" ]; do
|
||||
name="${SERVE[$i]}"
|
||||
@@ -357,7 +384,7 @@ serve_flags() {
|
||||
--board) die "refusing --board: Case 2 runs no control board" ;;
|
||||
--sso) [ "$PROFILE" = factory ] || die "refusing --sso: the Console signs people in through the proxy, with the preview set and the proof pair (Q175 phase 2 is a follow-up)" ;;
|
||||
--send) [ "$PROFILE" = factory ] || die "the library profile is read-only; refusing --send until Case 2 supports --sso (#412)" ;;
|
||||
--port|--business) ;;
|
||||
--port|--business|--org) ;;
|
||||
--public-host|--auth-header|--allow-user|--proof-header|--proof-file)
|
||||
[ "$PROFILE" = library ] || die "the factory profile refuses $name: its host has no proxy" ;;
|
||||
*) die "unknown serve flag: $name" ;;
|
||||
@@ -369,10 +396,20 @@ serve_flags() {
|
||||
if [ "$name" = --send ]; then flags="$flags --send"; i=$((i + 1)); continue; fi
|
||||
[ $((i + 1)) -lt "$n" ] || die "serve flag $name needs a value"
|
||||
value="${SERVE[$((i + 1))]}"
|
||||
if [ "$name" = --business ] || [ "$name" = --org ]; then
|
||||
# One selector in the serve scope, bound to the unit's business, rendered once
|
||||
# as --business where it first appears.
|
||||
SERVE_NAME="$name" SERVE_VALUE="$value"
|
||||
selector_take serve id serve_refused business_id_ok "$name" "$value"
|
||||
[ "$value" = "$BUSINESS" ] || die "serve $name $value is not the unit's business $BUSINESS"
|
||||
[ "$selected" = 1 ] || flags="$flags --business $value"
|
||||
selected=1
|
||||
i=$((i + 2))
|
||||
continue
|
||||
fi
|
||||
case "$name" in
|
||||
--port) port="$value"
|
||||
[[ "$port" =~ ^[1-9][0-9]{0,3}$ ]] && [ "$port" -le 1023 ] || die "--port must be 1..1023, so only the unit's capability can bind it: $port" ;;
|
||||
--business) [ "$value" = "$BUSINESS" ] || die "serve --business $value is not the unit's business $BUSINESS" ;;
|
||||
--public-host) public_host="$value"
|
||||
case "$value" in [A-Za-z0-9]*) ;; *) die "public host must be a hostname, no port or scheme: $value" ;; esac
|
||||
case "$value" in *[!A-Za-z0-9.-]*) die "public host must be a hostname, no port or scheme: $value" ;; esac ;;
|
||||
@@ -392,7 +429,7 @@ serve_flags() {
|
||||
local required=(--port --business)
|
||||
[ "$PROFILE" = factory ] || required+=(--public-host --auth-header --allow-user --proof-header --proof-file)
|
||||
for name in "${required[@]}"; do
|
||||
[ -n "${seen[$name]:-}" ] || die "serve flag $name is required"
|
||||
[ -n "${seen[$name]:-}" ] || { [ "$name" = --business ] && [ -n "${seen[--org]:-}" ]; } || die "serve flag $name is required"
|
||||
done
|
||||
if [ "$PROFILE" = factory ]; then
|
||||
# #415: only the paired owner sign-in and writes. No preview header or
|
||||
|
||||
Reference in new issue
Block a user