Three-layer access scheme: owner -> reader account -> scoped API token. Includes 6 automation scripts, config template, EN/RU docs, and manual curl guide. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
46 lines
1.2 KiB
Bash
Executable File
46 lines
1.2 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
set -euo pipefail
|
|
|
|
SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
|
|
CONFIG="${SCRIPT_DIR}/../config.ini"
|
|
|
|
if [[ $# -lt 1 ]]; then
|
|
echo "Usage: $0 <repo-name> [config.ini]"
|
|
echo "Revoke reader access from a repository."
|
|
exit 1
|
|
fi
|
|
|
|
REPO="$1"
|
|
[[ -n "${2:-}" ]] && CONFIG="$2"
|
|
|
|
if [[ ! -f "$CONFIG" ]]; then
|
|
echo "ERROR: config file not found: $CONFIG"
|
|
exit 1
|
|
fi
|
|
|
|
# --- Parse INI ---
|
|
parse_ini() {
|
|
local file="$1" section="$2" key="$3"
|
|
sed -n "/^\[$section\]/,/^\[/p" "$file" | grep "^${key}\s*=" | head -1 | sed 's/^[^=]*=\s*//' | sed 's/\s*$//'
|
|
}
|
|
|
|
GITEA_API=$(parse_ini "$CONFIG" gitea api_url)
|
|
OWNER_USER=$(parse_ini "$CONFIG" owner username)
|
|
OWNER_PASS=$(parse_ini "$CONFIG" owner password)
|
|
READER_USER=$(parse_ini "$CONFIG" reader username)
|
|
|
|
echo "=== Revoke Access: $OWNER_USER/$REPO -> $READER_USER ==="
|
|
|
|
HTTP_CODE=$(curl -s -o /dev/null -w "%{http_code}" \
|
|
-X DELETE "$GITEA_API/repos/$OWNER_USER/$REPO/collaborators/$READER_USER" \
|
|
-u "$OWNER_USER:$OWNER_PASS")
|
|
|
|
if [[ "$HTTP_CODE" == "204" || "$HTTP_CODE" == "200" ]]; then
|
|
echo "-> Access revoked successfully."
|
|
elif [[ "$HTTP_CODE" == "404" ]]; then
|
|
echo "-> User was not a collaborator (404)."
|
|
else
|
|
echo "-> ERROR: HTTP $HTTP_CODE"
|
|
exit 1
|
|
fi
|