LibrePortal/scripts/app/auth_adapter.sh
librelad 898068a390 refactor(apps): make app tools + helpers fully self-contained per app
Each app now carries everything under containers/<app>/: Tools-tab actions in
tools/ (declaration <app>.tools.json + function <app>_<tool_id>.sh) and logic
helpers in scripts/ (e.g. <app>_auth.sh). The container scan live-sources every
.sh under the app (maxdepth 3, prunes only resources/) and webui_tools.sh
auto-merges the .tools.json, so an app is a true drop-in — no central edit, no
array regen.

- Empty the central webui_tools.sh heredoc; all 34 tools across 11 apps now
  come from per-app declarations (verified byte-identical to the old output).
- Retire the orphaned mattermost tool scripts to scripts/unused (there is no
  containers/mattermost; its install fn already lived in unused).
- Update the dispatch comment/error path, the auth-adapter doc, and
  DEVELOPMENT.md to the new convention.
- Regenerate static arrays (files_app.sh no longer lists app/containers/*).

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
Signed-off-by: librelad <librelad@digitalangels.vip>
2026-05-25 22:45:33 +01:00

53 lines
1.7 KiB
Bash

#!/bin/bash
# Universal user/credential adapter for app tools.
#
# Each app declares an auth profile in its config:
# CFG_<APP>_AUTH_PROFILE = single_password | user_password | multi_user | none
#
# And implements adapter functions in containers/<app>/scripts/<app>_auth.sh:
# authAdapter_<app>_setPassword "$user" "$password"
# authAdapter_<app>_createUser "$user" "$password" "$email" "$isAdmin"
# authAdapter_<app>_listUsers
#
# Tool wrappers call authAdapterCall <app> <method> <args...>. The
# dispatcher checks the function exists, runs it, and refreshes apps.json
# via webuiPatchAppConfigJson so new admin creds surface in the WebUI.
authAdapterCanDo() {
local app="$1" method="$2"
declare -F "authAdapter_${app}_${method}" >/dev/null 2>&1
}
authAdapterCall() {
local app="$1" method="$2"
shift 2
local fn="authAdapter_${app}_${method}"
if ! declare -F "$fn" >/dev/null 2>&1; then
isError "Auth adapter for '$app' does not implement '$method'."
return 1
fi
"$fn" "$@"
local rc=$?
if (( rc == 0 )) && declare -F webuiPatchAppConfigJson >/dev/null 2>&1; then
webuiPatchAppConfigJson "$app" >/dev/null 2>&1 || true
fi
return $rc
}
# Persist a value to CFG_<APP>_<KEY> in the per-app config file.
authPersistCfg() {
local app="$1" key="$2" value="$3"
local cfg="${containers_dir}${app}/${app}.config"
[[ ! -f "$cfg" ]] && cfg="${install_containers_dir}/${app}/${app}.config"
[[ ! -f "$cfg" ]] && return 1
updateConfigOption "CFG_${app^^}_${key}" "$value" "$cfg"
}
# Read a tool-modal arg (pipe-encoded) and unescape pipes.
authToolArg() {
local v
v=$(toolArgsGet "$1" "$2") || true
printf '%s' "${v//%7C/|}"
}