feat: ajout du script mint-token.sh et documentation associee
This commit is contained in:
1 parent
bf8d8c7e78
commit
51c8ebe7a2
2 files changed
+67
No files matched your search
Executable
+60
@@ -0,0 +1,60 @@
|
||||
#!/usr/bin/env bash
|
||||
set -euo pipefail
|
||||
|
||||
if [ "$#" -ne 2 ]; then
|
||||
echo "Usage: $0 <identité> <fichier-sortie>" >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
IDENTITY="$1"
|
||||
OUTFILE="$2"
|
||||
|
||||
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
||||
TOKENS_FILE="${TOKENS_FILE:-$SCRIPT_DIR/tokens/tokens.json}"
|
||||
|
||||
# Vérification que l'identité appartient à la table autorisée
|
||||
ALLOWED_IDENTITIES=("hermes-tt" "agno-tt" "hermes-nyora" "hermes-perso" "openclaw-perso" "hermes-nabil" "dsh" "opencode-cli" "claude" "test-pilote" "test-pilote-b")
|
||||
VALID=0
|
||||
for id in "${ALLOWED_IDENTITIES[@]}"; do
|
||||
if [ "$id" = "$IDENTITY" ]; then
|
||||
VALID=1
|
||||
break
|
||||
fi
|
||||
done
|
||||
|
||||
if [ "$VALID" -ne 1 ]; then
|
||||
echo "Erreur: identité '$IDENTITY' inconnue ou non autorisée" >&2
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# Génération aléatoire d'un jeton de 48 caractères hexadécimaux (24 octets)
|
||||
TOKEN="$(openssl rand -hex 24)"
|
||||
HASH="$(echo -n "$TOKEN" | sha256sum | awk '{print $1}')"
|
||||
|
||||
# Écriture du jeton dans le fichier de sortie en mode 600 (jamais affiché)
|
||||
mkdir -p "$(dirname "$OUTFILE")"
|
||||
touch "$OUTFILE"
|
||||
chmod 600 "$OUTFILE"
|
||||
echo -n "$TOKEN" > "$OUTFILE"
|
||||
|
||||
# Inscription atomique de l'empreinte sha256 dans tokens.json
|
||||
python3 -c "
|
||||
import json, os, sys
|
||||
path = '$TOKENS_FILE'
|
||||
hash_val = '$HASH'
|
||||
identity = '$IDENTITY'
|
||||
data = {}
|
||||
if os.path.exists(path):
|
||||
with open(path, 'r', encoding='utf-8') as f:
|
||||
try:
|
||||
data = json.load(f)
|
||||
except Exception:
|
||||
data = {}
|
||||
data[hash_val] = identity
|
||||
tmp_path = path + '.tmp'
|
||||
with open(tmp_path, 'w', encoding='utf-8') as f:
|
||||
json.dump(data, f, indent=2)
|
||||
os.replace(tmp_path, path)
|
||||
"
|
||||
|
||||
echo "Jeton généré pour $IDENTITY et enregistré dans $OUTFILE (sha256: $HASH)"
|
||||
Reference in new issue
Block a user