gendesign/scripts/auth/list_users.sh
Light1YT 7aced2a5e0 fix(auth): scripts/auth/*.sh — правильный SNIPPET path
Bug: `dirname` x2 от $0 даёт `<repo>/scripts`, не `<repo>` →
скрипт ищет snippet в `<repo>/scripts/caddy/...` (не существует)
вместо `<repo>/caddy/users.caddy.snippet`.

Discovered 2026-05-26 QA RBAC сессия:
> grep: /opt/gendesign/scripts/caddy/users.caddy.snippet: No such file
> ERROR: cannot find closing brace in /opt/gendesign/scripts/caddy/...

Все 3 скрипта (add_user.sh, list_users.sh, remove_user.sh) имели
одинаковый баг — теперь все используют explicit REPO_ROOT:

```bash
SCRIPT_DIR="$(cd "$(dirname "$(realpath "$0")")" && pwd)"
REPO_ROOT="$(cd "$SCRIPT_DIR/../.." && pwd)"
SNIPPET="$REPO_ROOT/caddy/users.caddy.snippet"
```

Так понятнее (explicit `../..` от script-dir) и устойчиво к любой
глубине перемещения файла.

PR #426 (2026-05-23) изначально создавал 11 юзеров через add_user.sh
— скрипт работал в той worktree-сессии (видимо запускался из dir
где realpath давал нужный depth, e.g. через `cd scripts/auth && bash add_user.sh`),
но после compaction worktree удалён, реальный run-context утерян.

Production runs 2026-05-23 → user1..user10 + admin + kopylov были добавлены.
После 2026-05-26 manual workflow (`awk ... > tmp && mv tmp; docker restart caddy`)
заменил bash скрипт; теперь скрипт снова работает.

Detail: vault [[Bug_AddUser_Sh_Snippet_Path_Fixed]].

Verified locally: `realpath` resolves к `/Users/anton/Птица/gendesign/caddy/users.caddy.snippet` (correct).
2026-05-26 13:39:01 +05:00

31 lines
1.1 KiB
Bash
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#!/usr/bin/env bash
# list_users.sh — показать текущих пользователей (имена + comment, без хешей)
# Usage: ./scripts/auth/list_users.sh
set -euo pipefail
# 3× dirname от $0 (.../scripts/auth/list_users.sh) → repo root. Bug fix 2026-05-26.
SCRIPT_DIR="$(cd "$(dirname "$(realpath "$0")")" && pwd)"
REPO_ROOT="$(cd "$SCRIPT_DIR/../.." && pwd)"
SNIPPET="$REPO_ROOT/caddy/users.caddy.snippet"
if [[ ! -f "$SNIPPET" ]]; then
echo "ERROR: snippet not found at $SNIPPET" >&2
exit 1
fi
echo "Users in $SNIPPET:"
echo ""
printf "%-12s %s\n" "USERNAME" "COMMENT"
printf "%-12s %s\n" "--------" "-------"
# Extract lines that look like user entries (indented username + base64 hash + optional comment)
# Format: <spaces> username <base64_hash> # comment
grep -P '^\s+[a-z][a-z0-9-]+\s+[A-Za-z0-9+/]+=*' "$SNIPPET" | \
sed -E 's/^\s+([a-z][a-z0-9-]+)\s+\S+\s*(#\s*)?(.*)$/\1\t\3/' | \
while IFS=$'\t' read -r user comment; do
printf "%-12s %s\n" "$user" "$comment"
done
echo ""
TOTAL=$(grep -cP '^\s+[a-z][a-z0-9-]+\s+[A-Za-z0-9+/]+=*' "$SNIPPET" || true)
echo "Total: $TOTAL user(s)"