Enhance tenant management script: switch to bash, enforce strict mode, and validate port input

This commit is contained in:
2026-04-28 16:54:42 +02:00
parent 7873c45cfc
commit 43406c29d1
2 changed files with 14 additions and 10 deletions
+13 -10
View File
@@ -1,4 +1,6 @@
#!/bin/sh #!/usr/bin/env bash
set -euo pipefail
IFS=$'\n\t'
# Script to manage multitenant deployment # Script to manage multitenant deployment
# Allows adding, removing, and restarting tenants without downtime for others # Allows adding, removing, and restarting tenants without downtime for others
@@ -76,6 +78,16 @@ case "$COMMAND" in
echo "Error: Please provide a tenant_id." echo "Error: Please provide a tenant_id."
exit 1 exit 1
fi fi
PORT_ARG="$3"
if [ -n "$PORT_ARG" ]; then
if ! printf '%s\n' "$PORT_ARG" | grep -qE '^[0-9]+$'; then
echo "Error: Port must be a numeric value."
exit 1
fi
register_tenant_port "$TENANT_ID" "$PORT_ARG"
fi
echo "Adding new tenant '$TENANT_ID'..." echo "Adding new tenant '$TENANT_ID'..."
# Initialize tenant database via Python inside container # Initialize tenant database via Python inside container
echo "Initializing database for $TENANT_ID..." echo "Initializing database for $TENANT_ID..."
@@ -94,15 +106,6 @@ print(f'Tenant {sys.argv[1]} database initialized. Default admin: admin / admin1
echo "Warning: Application container is not running. Please start the multi-tenant system first." echo "Warning: Application container is not running. Please start the multi-tenant system first."
echo "Data will be initialized upon first access by the tenant." echo "Data will be initialized upon first access by the tenant."
fi fi
PORT_ARG="$3"
if [ -n "$PORT_ARG" ]; then
if ! printf '%s\n' "$PORT_ARG" | grep -qE '^[0-9]+$'; then
echo "Error: Port must be a numeric value."
exit 1
fi
register_tenant_port "$TENANT_ID" "$PORT_ARG"
fi
;; ;;
remove) remove)
+1
View File
@@ -418,6 +418,7 @@ parse_port_list() {
configure_host_ports() { configure_host_ports() {
local requested_http local requested_http
local requested_ports local requested_ports
local ports=()
requested_http="" requested_http=""
requested_ports="" requested_ports=""