mirror of
https://github.com/MaksTinyWorkshop/_Assistant_Lead_Tech
synced 2026-04-06 21:41:42 +02:00
fix(scripts): remplacer parsing CSV bash par python3 — gère les champs multilignes
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -46,33 +46,38 @@ EOF
|
||||
return 1
|
||||
}
|
||||
|
||||
local loaded=0
|
||||
# Parser le CSV avec python3 — gère les champs multilignes et les virgules dans les valeurs
|
||||
local pairs
|
||||
pairs=$(python3 - <<'PYEOF' <<< "$csv"
|
||||
import sys, csv, re
|
||||
|
||||
while IFS=',' read -r group title username password rest; do
|
||||
group="${group//\"/}"
|
||||
title="${title//\"/}"
|
||||
password="${password//\"/}"
|
||||
reader = csv.DictReader(sys.stdin)
|
||||
for row in reader:
|
||||
group = row.get("Group", "")
|
||||
title = row.get("Title", "")
|
||||
password = row.get("Password", "")
|
||||
if group != "Racine/global" and not group.startswith("Racine/global/"):
|
||||
continue
|
||||
if not re.match(r'^[A-Z_][A-Z0-9_]*$', title):
|
||||
continue
|
||||
if not password:
|
||||
continue
|
||||
print(f"{title}={password}")
|
||||
PYEOF
|
||||
)
|
||||
|
||||
[[ "$group" != "Racine/global" && "$group" != "Racine/global/"* ]] && continue
|
||||
|
||||
local var_name="$title"
|
||||
if ! printf '%s' "$var_name" | grep -Eq '^[A-Z_][A-Z0-9_]*$'; then
|
||||
echo "Nom invalide ignoré : $var_name" >&2
|
||||
continue
|
||||
fi
|
||||
|
||||
[ -z "$password" ] && { echo "Valeur vide ignorée : $var_name" >&2; continue; }
|
||||
|
||||
export "$var_name=$password"
|
||||
loaded=$((loaded + 1))
|
||||
|
||||
done <<< "$csv"
|
||||
|
||||
if [ "$loaded" -eq 0 ]; then
|
||||
if [ -z "$pairs" ]; then
|
||||
echo "Aucun secret global chargé." >&2
|
||||
return 1
|
||||
fi
|
||||
|
||||
local loaded=0
|
||||
while IFS='=' read -r var_name value; do
|
||||
[ -z "$var_name" ] && continue
|
||||
export "$var_name=$value"
|
||||
loaded=$((loaded + 1))
|
||||
done <<< "$pairs"
|
||||
|
||||
echo "Secrets chargés : $loaded"
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user