devzone 2.0.0 → 3.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (90) hide show
  1. package/.devcontainer/agent-errors.sh +6 -6
  2. package/.devcontainer/agent-pod-manifest.sh +4 -4
  3. package/.devcontainer/agent-session.sh +2 -2
  4. package/.devcontainer/agent-state-json.sh +2 -2
  5. package/.devcontainer/agent-workspace.sh +1 -1
  6. package/.devcontainer/agent.sh +7 -7
  7. package/.devcontainer/ai/host-models.sh +2 -2
  8. package/.devcontainer/ai/plugins/devzone-guard-v2.js +3 -3
  9. package/.devcontainer/ai/plugins/devzone-guard.js +3 -3
  10. package/.devcontainer/argocd/argocd.sh +90 -89
  11. package/.devcontainer/argocd/catalog-argocd.sh +2 -2
  12. package/.devcontainer/argocd/services-hook.sh +3 -3
  13. package/.devcontainer/argocd/services.sh +1 -1
  14. package/.devcontainer/catalog/app.sh +114 -116
  15. package/.devcontainer/catalog/catalog-watcher.sh +62 -62
  16. package/.devcontainer/catalog/mysql/app.conf +1 -1
  17. package/.devcontainer/catalog/mysql/install.sh +40 -40
  18. package/.devcontainer/catalog/mysql/mysql.sh +141 -141
  19. package/.devcontainer/catalog/mysql/volume.sh +39 -39
  20. package/.devcontainer/catalog.sh +112 -112
  21. package/.devcontainer/chart-direct.sh +1 -1
  22. package/.devcontainer/cluster.sh +216 -218
  23. package/.devcontainer/clusters.sh +41 -41
  24. package/.devcontainer/devzone +92 -1495
  25. package/.devcontainer/devzone-ai-guard.sh +76 -0
  26. package/.devcontainer/devzone-ai.sh +201 -0
  27. package/.devcontainer/devzone-cluster.sh +210 -0
  28. package/.devcontainer/devzone-modules.sh +126 -0
  29. package/.devcontainer/devzone-platform.sh +189 -0
  30. package/.devcontainer/devzone-repair.sh +94 -0
  31. package/.devcontainer/devzone-services.sh +241 -0
  32. package/.devcontainer/devzone-skill.sh +97 -0
  33. package/.devcontainer/devzone-status.sh +140 -0
  34. package/.devcontainer/devzone-version.sh +78 -0
  35. package/.devcontainer/git-identity.sh +28 -0
  36. package/.devcontainer/gitlab/chart.sh +2 -2
  37. package/.devcontainer/gitlab/gitlab.sh +81 -82
  38. package/.devcontainer/gitlab/installation.sh +109 -109
  39. package/.devcontainer/gitlab/secrets.sh +47 -47
  40. package/.devcontainer/gitlab/seed.sh +77 -77
  41. package/.devcontainer/gitlab/test-gitlab.sh +242 -243
  42. package/.devcontainer/help.sh +1 -1
  43. package/.devcontainer/isolation.sh +30 -30
  44. package/.devcontainer/kind-wrapper.sh +17 -17
  45. package/.devcontainer/kube-account.sh +112 -113
  46. package/.devcontainer/kube-config.sh +45 -46
  47. package/.devcontainer/{invite-kube.sh → kube-prompt.sh} +6 -6
  48. package/.devcontainer/kube-reachable.sh +40 -40
  49. package/.devcontainer/memory.sh +1 -1
  50. package/.devcontainer/metrics-server.sh +2 -2
  51. package/.devcontainer/opencode.jsonc +2 -2
  52. package/.devcontainer/packages.sh +136 -135
  53. package/.devcontainer/password.sh +1 -1
  54. package/.devcontainer/ports-auto.sh +152 -153
  55. package/.devcontainer/ports-json.sh +16 -15
  56. package/.devcontainer/ports.sh +126 -122
  57. package/.devcontainer/post-create.sh +52 -52
  58. package/.devcontainer/postgres/postgres.sh +174 -174
  59. package/.devcontainer/rename-legacy-files.sh +103 -0
  60. package/.devcontainer/services-admin.sh +3 -3
  61. package/.devcontainer/skills/devzone/SKILL.md +40 -41
  62. package/.devcontainer/startup.sh +48 -49
  63. package/.devcontainer/state-gitops.sh +1 -1
  64. package/.devcontainer/state-json.sh +36 -62
  65. package/.devcontainer/state.sh +2 -2
  66. package/.devcontainer/workspace-init.sh +16 -2
  67. package/Makefile +1 -1
  68. package/README.md +195 -194
  69. package/charts/devzone-workspace/templates/statefulset.yaml +1 -1
  70. package/manage/devzone +5 -7
  71. package/manage/scripts/argocd-workspace.sh +1 -1
  72. package/manage/scripts/check-names.sh +6 -5
  73. package/manage/scripts/create-cluster.sh +1 -1
  74. package/manage/scripts/create-mode.sh +2 -2
  75. package/manage/scripts/devzone-create.sh +3 -3
  76. package/manage/scripts/devzone-manifest.sh +1 -1
  77. package/manage/scripts/devzone-update.sh +12 -8
  78. package/manage/scripts/launch.sh +7 -48
  79. package/manage/scripts/migrate-revert.sh +3 -3
  80. package/manage/scripts/migrate.sh +7 -13
  81. package/manage/scripts/ports-apps.sh +1 -1
  82. package/manage/scripts/ports-workspace.sh +7 -7
  83. package/manage/scripts/uninstall.sh +8 -8
  84. package/manage/scripts/workspace-egress.sh +2 -2
  85. package/manage/scripts/workspace-update.sh +5 -2
  86. package/manage/scripts/workspace-wait.sh +2 -2
  87. package/package.json +1 -1
  88. package/.devcontainer/docker-relay.sh +0 -149
  89. package/.devcontainer/docker-without-host.sh +0 -12
  90. package/.devcontainer/git-identite.sh +0 -28
@@ -1,87 +1,87 @@
1
1
  #!/usr/bin/env bash
2
- # Installation MySQL (#440) : secret, chart et réinstallation sur un volume.
2
+ # MySQL installation (#440): secret, chart and reinstallation on a volume.
3
3
  # shellcheck source=SCRIPTDIR/../../chart-direct.sh
4
4
  # shellcheck disable=SC1091
5
5
  . "$ICI/../../chart-direct.sh"
6
6
 
7
- # Secret admin (mysql-admin) : root.env ou secret existant, jamais régénéré.
7
+ # Admin secret (mysql-admin): root.env or existing secret, never regenerated.
8
8
  mysql_secret() {
9
- local mdp fichier="$SECRETS/admin-password"
9
+ local password file="$SECRETS/admin-password"
10
10
  mkdir -p "$SECRETS"
11
11
  chmod 700 "$SECRETS"
12
12
  if k get secret mysql-admin >/dev/null 2>&1; then
13
- mdp="$(k get secret mysql-admin -o jsonpath='{.data.password}' | base64 -d | tr -d '\n')"
14
- (umask 077 && printf '%s' "$mdp" >"$fichier")
13
+ password="$(k get secret mysql-admin -o jsonpath='{.data.password}' | base64 -d | tr -d '\n')"
14
+ (umask 077 && printf '%s' "$password" >"$file")
15
15
  return 0
16
16
  fi
17
- mdp="$(sed -n 's/^MYSQL_PASSWORD=//p' "$SECRETS/root.env" 2>/dev/null | tail -1 || true)"
18
- if [ -z "$mdp" ] && [ -s "$fichier" ]; then mdp="$(cat "$fichier")"; fi
19
- if [ -z "$mdp" ]; then
20
- (umask 077 && openssl rand -hex 24 | tr -d '\n' >"$fichier")
21
- k create secret generic mysql-admin --from-file=password="$fichier" >/dev/null
22
- elif [ ! -s "$fichier" ]; then
23
- (umask 077 && printf '%s' "$mdp" >"$fichier")
17
+ password="$(sed -n 's/^MYSQL_PASSWORD=//p' "$SECRETS/root.env" 2>/dev/null | tail -1 || true)"
18
+ if [ -z "$password" ] && [ -s "$file" ]; then password="$(cat "$file")"; fi
19
+ if [ -z "$password" ]; then
20
+ (umask 077 && openssl rand -hex 24 | tr -d '\n' >"$file")
21
+ k create secret generic mysql-admin --from-file=password="$file" >/dev/null
22
+ elif [ ! -s "$file" ]; then
23
+ (umask 077 && printf '%s' "$password" >"$file")
24
24
  fi
25
25
  }
26
26
 
27
- # Attente du StatefulSet posé par Argo CD (#538) : la synchronisation est en
28
- # tâche de fond, le rollout est sondé jusqu'à MYSQL_ATTENTE
29
- mysql_attendre() {
30
- local fin=$((SECONDS + MYSQL_ATTENTE))
31
- while [ "$SECONDS" -lt "$fin" ]; do
27
+ # Wait for the StatefulSet created by Argo CD (#538): the sync runs in the
28
+ # background, the rollout is polled up to MYSQL_ATTENTE
29
+ mysql_wait() {
30
+ local end=$((SECONDS + MYSQL_ATTENTE))
31
+ while [ "$SECONDS" -lt "$end" ]; do
32
32
  if k rollout status statefulset/mysql --timeout=10s >/dev/null 2>&1; then
33
33
  return 0
34
34
  fi
35
35
  sleep 5
36
36
  done
37
- echo "devzone : catalogue mysql : pas prêt après ${MYSQL_ATTENTE}s : kubectl --context $1 -n $NS describe pod mysql-0" >&2
37
+ echo "devzone : catalog mysql : not ready after ${MYSQL_ATTENTE}s: kubectl --context $1 -n $NS describe pod mysql-0" >&2
38
38
  return 1
39
39
  }
40
40
 
41
- # Installation MySQL par Argo CD (#538) : Application devzone-mysql (chart
42
- # charts/devzone-mysql du dépôt devzone), namespace et secret créés à part ;
43
- # le claim suit les volumes existants, comme le chemin manifeste
44
- mysql_installer_argocd() {
41
+ # MySQL installation by Argo CD (#538): Application devzone-mysql (chart
42
+ # charts/devzone-mysql of the devzone repository), namespace and secret created
43
+ # apart; the claim follows the existing volumes, as the manifest path does
44
+ mysql_install_argocd() {
45
45
  local CTX="$1" claim extra=""
46
46
  mysql_secret
47
- claim="$(mysql_claim_choisir "$NS")" || return 2
47
+ claim="$(mysql_claim_choose "$NS")" || return 2
48
48
  [ "$claim" = donnees ] || extra="claim=$claim"
49
49
  catalogue_argocd_apply mysql "$NS" "$MYSQL_IMAGE" "$MYSQL_PORT" \
50
50
  "$MYSQL_MEMOIRE" "$MYSQL_TAILLE" "$extra" || return 1
51
- mysql_attendre "$CTX" || return 1
51
+ mysql_wait "$CTX" || return 1
52
52
  mysql_secret
53
- relais_lancer mysql "$CTX" "$NS" svc/mysql 3306:3306
54
- echo "✔ MySQL prêt : 127.0.0.1:$MYSQL_PORT dans le conteneur"
53
+ relay_start mysql "$CTX" "$NS" svc/mysql 3306:3306
54
+ echo "✔ MySQL ready: 127.0.0.1:$MYSQL_PORT in the container"
55
55
  regenerer_identifiants
56
56
  }
57
57
 
58
- # Installe le chart charts/devzone-mysql avec le claim choisi (#440, #559)
59
- mysql_appliquer_chart() {
58
+ # Installs the chart charts/devzone-mysql with the chosen claim (#440, #559)
59
+ mysql_apply_chart() {
60
60
  local ns="$1" claim="$2"
61
61
  chart_install mysql "$ns" "image=$MYSQL_IMAGE" "port=$MYSQL_PORT" \
62
62
  "memory=$MYSQL_MEMOIRE" "size=$MYSQL_TAILLE" "claim=$claim"
63
63
  }
64
64
 
65
- # (Ré)installe MySQL sur le claim demandé, données du PVC gardées (#440)
66
- mysql_installer_claim() {
65
+ # (Re)installs MySQL on the requested claim, PVC data kept (#440)
66
+ mysql_install_claim() {
67
67
  local ns="$1" claim="$2" CTX
68
- CTX="$(contexte)"
69
- if ! contexte_devzone_poser "$CTX"; then
70
- echo "devzone : catalogue mysql : impossible de poser le contexte devzone sur $CTX" >&2
68
+ CTX="$(module_context)"
69
+ if ! devzone_context_set "$CTX"; then
70
+ echo "devzone : catalog mysql : cannot set the devzone context on $CTX" >&2
71
71
  return 1
72
72
  fi
73
- echo "▶ MySQL sur le cluster $CTX (namespace $ns, volume ${claim}-mysql-0)…"
74
- compte_namespace "$CTX" "$ns"
75
- namespace_isoler "$ns" >/dev/null
73
+ echo "▶ MySQL on cluster $CTX (namespace $ns, volume ${claim}-mysql-0)…"
74
+ account_namespace "$CTX" "$ns"
75
+ namespace_isolate "$ns" >/dev/null
76
76
  mysql_secret
77
77
  k delete statefulset mysql --ignore-not-found >/dev/null 2>&1 || true
78
- mysql_appliquer_chart "$ns" "$claim" || return 1
78
+ mysql_apply_chart "$ns" "$claim" || return 1
79
79
  if ! k rollout status statefulset/mysql --timeout="${MYSQL_ATTENTE}s" >/dev/null; then
80
- echo "devzone : catalogue mysql : pas prêt après ${MYSQL_ATTENTE}s : kubectl --context $CTX -n $ns describe pod mysql-0" >&2
80
+ echo "devzone : catalog mysql : not ready after ${MYSQL_ATTENTE}s: kubectl --context $CTX -n $ns describe pod mysql-0" >&2
81
81
  return 1
82
82
  fi
83
83
  mysql_secret
84
- relais_lancer mysql "$CTX" "$ns" svc/mysql 3306:3306
85
- echo "✔ MySQL prêt : 127.0.0.1:$MYSQL_PORT dans le conteneur"
84
+ relay_start mysql "$CTX" "$ns" svc/mysql 3306:3306
85
+ echo "✔ MySQL ready: 127.0.0.1:$MYSQL_PORT in the container"
86
86
  regenerer_identifiants
87
87
  }
@@ -1,9 +1,9 @@
1
1
  #!/usr/bin/env bash
2
- # MySQL du catalogue (#414) : create, list, delete, status, relay-start, relay-stop, install, delete-data.
2
+ # MySQL of the catalog (#414): create, list, delete, status, relay-start, relay-stop, install, delete-data.
3
3
  set -euo pipefail
4
4
  ICI="$(cd "$(dirname "$0")" && pwd)"
5
- RACINE="${DEVZONE_RACINE:-$(dirname "$(dirname "$(dirname "$ICI")")")}"
6
- ETAT="${DEVZONE_ETAT:-$RACINE/.devzone.modules}"
5
+ RACINE="${DEVZONE_ROOT:-$(dirname "$(dirname "$(dirname "$ICI")")")}"
6
+ ETAT="${DEVZONE_STATE:-$RACINE/.devzone.modules}"
7
7
  # shellcheck source=SCRIPTDIR/../../cluster.sh
8
8
  # shellcheck disable=SC1091
9
9
  . "$ICI/../../cluster.sh"
@@ -19,7 +19,7 @@ ETAT="${DEVZONE_ETAT:-$RACINE/.devzone.modules}"
19
19
  # shellcheck source=SCRIPTDIR/install.sh
20
20
  # shellcheck disable=SC1091
21
21
  . "$ICI/install.sh"
22
- # Le module argocd actif : MySQL installé par une Application (#538)
22
+ # The argocd module on: MySQL installed by an Application (#538)
23
23
  # shellcheck source=SCRIPTDIR/../../argocd/catalog-argocd.sh
24
24
  # shellcheck disable=SC1091
25
25
  . "$ICI/../../argocd/catalog-argocd.sh"
@@ -30,233 +30,233 @@ MYSQL_IMAGE="${MYSQL_IMAGE:-mysql:8.4}"
30
30
  MYSQL_MEMOIRE="${MYSQL_MEMOIRE:-1Gi}"
31
31
  MYSQL_TAILLE="${MYSQL_TAILLE:-5Gi}"
32
32
  MYSQL_ATTENTE="${MYSQL_ATTENTE:-300}"
33
- # Refus standard avec message et code 2
34
- refuse() { echo "devzone : catalogue mysql : $*" >&2; exit 2; }
35
- # Secret mysql-admin du hook services.sh : le même que l'installation directe
33
+ # Standard refusal with a message and code 2
34
+ refuse() { echo "devzone : catalog mysql : $*" >&2; exit 2; }
35
+ # Secret mysql-admin of the services.sh hook: the same as the direct installation
36
36
  services_secret_mysql() { mysql_secret; }
37
- # Régénère la vue .password (échec non bloquant)
37
+ # Regenerates the .password view (non-blocking failure)
38
38
  regenerer_identifiants() {
39
39
  password_regenerate ||
40
- echo "devzone : catalogue mysql : identifiants regroupés non mis à jour (devzone passwords)" >&2
40
+ echo "devzone : catalog mysql : grouped credentials not updated (devzone passwords)" >&2
41
41
  }
42
- # Raccourci kubectl dans le namespace devzone-mysql
42
+ # Shortcut for kubectl in the devzone-mysql namespace
43
43
  k() { kubectl --context devzone -n "$NS" "$@"; }
44
- # Le namespace devzone-mysql existe-t-il ? Lecture des namespaces réservée à
45
- # l'administrateur (#430)
46
- installe() { compte_admin "$(compte_ctx)" get namespace "$NS" >/dev/null 2>&1; }
47
- # Contexte du module : celui du cluster de devzone
48
- contexte() {
44
+ # Does the devzone-mysql namespace exist? Administrator only (#430)
45
+ installed() { account_admin "$(account_context)" get namespace "$NS" >/dev/null 2>&1; }
46
+ # Context of the module: the one of the devzone cluster
47
+ module_context() {
49
48
  local c
50
- c="$(cluster_lu)"
51
- [ -n "$c" ] || refuse "aucun cluster choisi : devzone enable mysql"
49
+ c="$(cluster_saved)"
50
+ [ -n "$c" ] || refuse "no cluster chosen: devzone enable mysql"
52
51
  echo "$c"
53
52
  }
54
- # Marque d'échec du module (même schéma que fichier_echec de devzone)
55
- fichier_echec() { echo "$ETAT-echec-mysql"; }
56
- # Nom de projet : identifiant SQL simple, jamais à échapper, pas un nom réservé
57
- valider_projet() {
53
+ # Failure marker of the module (same scheme as devzone's failure_file)
54
+ failure_file() { echo "$ETAT-failed-mysql"; }
55
+ # Project name: a simple SQL identifier, never escaped, not a reserved name
56
+ check_project_name() {
58
57
  local p="${1:-}"
59
- [ -n "$p" ] || refuse "nom de projet manquant"
60
- [[ "$p" =~ ^[a-z][a-z0-9_]{0,62}$ ]] || refuse "nom de projet invalide : $p (minuscules, chiffres, _ ; commence par une lettre)"
58
+ [ -n "$p" ] || refuse "missing project name"
59
+ [[ "$p" =~ ^[a-z][a-z0-9_]{0,62}$ ]] || refuse "invalid project name: $p (lowercase, digits, _; starts with a letter)"
61
60
  case "$p" in
62
- mysql | information_schema | performance_schema | sys) refuse "nom réservé : $p" ;;
61
+ mysql | information_schema | performance_schema | sys) refuse "reserved name: $p" ;;
63
62
  esac
64
63
  }
65
- # Mot de passe aléatoire pour un nouveau projet
66
- mot_de_passe() { openssl rand -hex 24; }
67
- # Mot de passe root : root.env d'une installation existante, sinon admin-password
64
+ # Random password for a new project
65
+ new_password() { openssl rand -hex 24; }
66
+ # Root password: from root.env of an existing installation, else admin-password
68
67
  root_password() {
69
- local mdp
70
- mdp="$(sed -n 's/^MYSQL_PASSWORD=//p' "$SECRETS/root.env" 2>/dev/null | tail -1 || true)"
71
- [ -z "$mdp" ] && [ -f "$SECRETS/admin-password" ] && mdp="$(cat "$SECRETS/admin-password" 2>/dev/null || true)"
72
- [ -n "$mdp" ] || refuse "mot de passe root MySQL introuvable (workspace/.mysql/root.env)"
73
- echo "$mdp"
68
+ local password
69
+ password="$(sed -n 's/^MYSQL_PASSWORD=//p' "$SECRETS/root.env" 2>/dev/null | tail -1 || true)"
70
+ [ -z "$password" ] && [ -f "$SECRETS/admin-password" ] && password="$(cat "$SECRETS/admin-password" 2>/dev/null || true)"
71
+ [ -n "$password" ] || refuse "MySQL root password not found (workspace/.mysql/root.env)"
72
+ echo "$password"
74
73
  }
75
- # mysql en superutilisateur dans le pod ; le mot de passe n'est jamais affiché
74
+ # mysql as superuser in the pod; the password is never shown
76
75
  mysql_admin() { k exec -i mysql-0 -c mysql -- mysql -uroot -p"$(root_password)" "$@"; }
77
- # Nombre de bases hors bases système
78
- nombre_bases() {
76
+ # Number of databases, system databases excluded
77
+ database_count() {
79
78
  local n
80
79
  n="$(mysql_admin -N -B -e "SHOW DATABASES" 2>/dev/null | grep -vE '^(information_schema|mysql|performance_schema|sys)$' | grep -c . || true)"
81
80
  echo "${n:-0}"
82
81
  }
83
- installer() {
82
+ # Installs the module (the Argo CD path when the argocd module is on)
83
+ install_module() {
84
84
  local CTX claim
85
- CTX="$(contexte)"
86
- if ! contexte_devzone_poser "$CTX"; then
87
- echo "devzone : catalogue mysql : impossible de poser le contexte devzone sur $CTX" >&2
85
+ CTX="$(module_context)"
86
+ if ! devzone_context_set "$CTX"; then
87
+ echo "devzone : catalog mysql : cannot set the devzone context on $CTX" >&2
88
88
  return 1
89
89
  fi
90
- echo "▶ MySQL sur le cluster $CTX (namespace $NS)…"
90
+ echo "▶ MySQL on cluster $CTX (namespace $NS)…"
91
91
  if catalogue_argocd_active mysql; then
92
- mysql_installer_argocd "$CTX"
92
+ mysql_install_argocd "$CTX"
93
93
  return
94
94
  fi
95
- compte_namespace "$CTX" "$NS"
96
- namespace_isoler "$NS" >/dev/null
95
+ account_namespace "$CTX" "$NS"
96
+ namespace_isolate "$NS" >/dev/null
97
97
  if k get statefulset mysql >/dev/null 2>&1; then
98
- echo "devzone : catalogue mysql : installation existante dans $NS, adoptée (volume et root.env gardés)"
98
+ echo "devzone : catalog mysql : existing installation in $NS, adopted (volume and root.env kept)"
99
99
  else
100
100
  mysql_secret
101
- claim="$(mysql_claim_choisir "$NS")" || return 2
102
- mysql_appliquer_chart "$NS" "$claim" || return 1
101
+ claim="$(mysql_claim_choose "$NS")" || return 2
102
+ mysql_apply_chart "$NS" "$claim" || return 1
103
103
  if ! k rollout status statefulset/mysql --timeout="${MYSQL_ATTENTE}s" >/dev/null; then
104
- echo "devzone : catalogue mysql : pas prêt après ${MYSQL_ATTENTE}s : kubectl --context $CTX -n $NS describe pod mysql-0" >&2
104
+ echo "devzone : catalog mysql : not ready after ${MYSQL_ATTENTE}s: kubectl --context $CTX -n $NS describe pod mysql-0" >&2
105
105
  return 1
106
106
  fi
107
107
  fi
108
108
  mysql_secret
109
- relais_lancer mysql "$CTX" "$NS" svc/mysql 3306:3306
110
- echo "✔ MySQL prêt : 127.0.0.1:$MYSQL_PORT dans le conteneur"
109
+ relay_start mysql "$CTX" "$NS" svc/mysql 3306:3306
110
+ echo "✔ MySQL ready: 127.0.0.1:$MYSQL_PORT in the container"
111
111
  regenerer_identifiants
112
112
  }
113
- # Supprime le namespace (donc les PVC), garde workspace/.mysql (#441) :
114
- # confirmation en terminal [o/N], --yes obligatoire sinon (refus, code 2)
115
- supprimer_donnees() {
116
- local CTX oui="" arg reponse
113
+ # Deletes the namespace (so the PVCs), keeps workspace/.mysql (#441):
114
+ # terminal confirmation [y/N], --yes required otherwise (refusal, code 2)
115
+ delete_data() {
116
+ local CTX yes="" arg answer
117
117
  for arg in "$@"; do
118
118
  case "$arg" in
119
- --yes) oui=1 ;;
120
- *) refuse "argument inconnu : $arg" ;;
119
+ --yes) yes=1 ;;
120
+ *) refuse "unknown argument: $arg" ;;
121
121
  esac
122
122
  done
123
- if [ -z "$oui" ]; then
124
- cluster_interactif || refuse "confirmation impossible sans terminal : devzone mysql delete-data --yes"
125
- printf 'Supprimer le namespace %s et tous ses volumes ? [o/N] ' "$NS" >&2
126
- read -r reponse || reponse=""
127
- case "$reponse" in
128
- o | O | oui) ;;
129
- *) echo "Abandon : rien n'a été supprimé."; return 0 ;;
123
+ if [ -z "$yes" ]; then
124
+ cluster_interactive || refuse "confirmation needs a terminal: devzone mysql delete-data --yes"
125
+ printf 'Delete namespace %s and all its volumes? [y/N] ' "$NS" >&2
126
+ read -r answer || answer=""
127
+ case "$answer" in
128
+ y | Y | yes) ;;
129
+ *) echo "Aborted: nothing was deleted."; return 0 ;;
130
130
  esac
131
131
  fi
132
- CTX="$(cluster_lu)"
133
- [ -n "$CTX" ] || refuse "aucun cluster choisi : devzone enable mysql"
134
- installe || refuse "module inactif : devzone enable mysql"
135
- echo "▶ Suppression de MySQL et de ses volumes sur ${CTX}…"
136
- # L'Application part d'abord (#538) : sinon Argo CD recrée le namespace
132
+ CTX="$(cluster_saved)"
133
+ [ -n "$CTX" ] || refuse "no cluster chosen: devzone enable mysql"
134
+ installed || refuse "module disabled: devzone enable mysql"
135
+ echo "▶ Deleting MySQL and its volumes on ${CTX}…"
136
+ # The Application goes first (#538): otherwise Argo CD recreates the namespace
137
137
  catalogue_argocd_delete mysql >/dev/null 2>&1 || true
138
- # RoleBinding retiré puis namespace supprimé par l'administrateur (#430)
139
- compte_retirer "$CTX" "$NS" >/dev/null 2>&1 || true
140
- compte_admin "$CTX" delete namespace "$NS" --wait=true >/dev/null
141
- relais_arreter mysql
142
- rm -f "$(fichier_echec)"
143
- echo "✔ namespace $NS et volume supprimés ; workspace/.mysql/root.env gardé"
138
+ # RoleBinding removed, then the namespace deleted by the administrator (#430)
139
+ account_remove "$CTX" "$NS" >/dev/null 2>&1 || true
140
+ account_admin "$CTX" delete namespace "$NS" --wait=true >/dev/null
141
+ relay_stop mysql
142
+ rm -f "$(failure_file)"
143
+ echo "✔ namespace $NS and volume deleted; workspace/.mysql/root.env kept"
144
144
  regenerer_identifiants
145
145
  }
146
- # État : désactivé, en échec, prêt, relais arrêté
147
- etat() {
146
+ # State (disabled, failed, ready, relay stopped): read by devzone, keep the words
147
+ module_status() {
148
148
  local CTX
149
- CTX="$(cluster_lu)"
150
- if [ -z "$CTX" ] || ! installe; then
151
- echo "désactivé"
149
+ CTX="$(cluster_saved)"
150
+ if [ -z "$CTX" ] || ! installed; then
151
+ echo "disabled"
152
152
  return 0
153
153
  fi
154
154
  if [ "$(k get statefulset mysql -o jsonpath='{.status.readyReplicas}' 2>/dev/null || true)" != 1 ]; then
155
- echo "en échec sur $CTX : devzone apply"
155
+ echo "failed on $CTX: devzone apply"
156
156
  return 0
157
157
  fi
158
- if ! relais_actif mysql; then
159
- echo "prêt sur $CTX, relais arrêté : devzone apply"
158
+ if ! relay_active mysql; then
159
+ echo "ready on $CTX, relay stopped: devzone apply"
160
160
  return 0
161
161
  fi
162
- echo "prêt sur $CTX : 127.0.0.1:$MYSQL_PORT, $(nombre_bases) base(s)"
162
+ echo "ready on $CTX: 127.0.0.1:$MYSQL_PORT, $(database_count) database(s)"
163
163
  }
164
- # Crée l'utilisateur et la base d'un projet ; .env en 600, mot de passe gardé
165
- creer() {
166
- local projet="${1:-}" nouveau="" fichier mdp arg
167
- valider_projet "$projet"
164
+ # Creates the user and the database of a project; .env in 600, password kept
165
+ create_project() {
166
+ local project="${1:-}" renew="" file password arg
167
+ check_project_name "$project"
168
168
  for arg in "${@:2}"; do
169
169
  case "$arg" in
170
- --new-password) nouveau=1 ;;
171
- *) refuse "argument inconnu : $arg" ;;
170
+ --new-password) renew=1 ;;
171
+ *) refuse "unknown argument: $arg" ;;
172
172
  esac
173
173
  done
174
- CTX="$(contexte)"
175
- installe || refuse "module inactif : devzone enable mysql"
176
- fichier="$SECRETS/$projet.env"
177
- if [ -z "$nouveau" ] && [ -s "$fichier" ]; then
178
- mdp="$(sed -n 's/^MYSQL_PASSWORD=//p' "$fichier" 2>/dev/null | tail -1)"
174
+ CTX="$(module_context)"
175
+ installed || refuse "module disabled: devzone enable mysql"
176
+ file="$SECRETS/$project.env"
177
+ if [ -z "$renew" ] && [ -s "$file" ]; then
178
+ password="$(sed -n 's/^MYSQL_PASSWORD=//p' "$file" 2>/dev/null | tail -1)"
179
179
  else
180
- mdp="$(mot_de_passe)"
180
+ password="$(new_password)"
181
181
  fi
182
182
  mysql_admin <<SQL
183
- CREATE USER IF NOT EXISTS '$projet'@'%' IDENTIFIED BY '$mdp';
184
- ALTER USER '$projet'@'%' IDENTIFIED BY '$mdp';
185
- CREATE DATABASE IF NOT EXISTS $projet;
186
- GRANT ALL ON $projet.* TO '$projet'@'%';
183
+ CREATE USER IF NOT EXISTS '$project'@'%' IDENTIFIED BY '$password';
184
+ ALTER USER '$project'@'%' IDENTIFIED BY '$password';
185
+ CREATE DATABASE IF NOT EXISTS $project;
186
+ GRANT ALL ON $project.* TO '$project'@'%';
187
187
  SQL
188
188
  mkdir -p "$SECRETS"
189
189
  chmod 700 "$SECRETS"
190
190
  (
191
191
  umask 077
192
- cat >"$fichier" <<ENV
192
+ cat >"$file" <<ENV
193
193
  MYSQL_HOST=127.0.0.1
194
194
  MYSQL_PORT=$MYSQL_PORT
195
- MYSQL_USER=$projet
196
- MYSQL_PASSWORD=$mdp
197
- MYSQL_URL=jdbc:mysql://127.0.0.1:$MYSQL_PORT/$projet
195
+ MYSQL_USER=$project
196
+ MYSQL_PASSWORD=$password
197
+ MYSQL_URL=jdbc:mysql://127.0.0.1:$MYSQL_PORT/$project
198
198
  ENV
199
199
  )
200
- echo "✔ base $projet prête ; identifiants : $fichier"
200
+ echo "✔ database $project ready; credentials: $file"
201
201
  regenerer_identifiants
202
202
  }
203
- # Liste les bases du serveur
204
- liste() {
203
+ # Lists the databases of the server
204
+ list_databases() {
205
205
  local CTX
206
- CTX="$(contexte)"
207
- installe || refuse "module inactif : devzone enable mysql"
208
- # grep -v sort 1 sans base utilisateur : sous pipefail, liste reste à 0
206
+ CTX="$(module_context)"
207
+ installed || refuse "module disabled: devzone enable mysql"
208
+ # grep -v exits 1 with no user database: under pipefail, the list stays at 0
209
209
  mysql_admin -N -B -e "SHOW DATABASES" 2>/dev/null |
210
210
  { grep -vE '^(information_schema|mysql|performance_schema|sys)$' || true; } |
211
- awk 'BEGIN { n = 0 } { printf " %-30s\n", $1; n++ } END { if (n == 0) print " (aucune base : devzone mysql create <projet>)" }'
211
+ awk 'BEGIN { n = 0 } { printf " %-30s\n", $1; n++ } END { if (n == 0) print " (no database: devzone mysql create <project>)" }'
212
212
  }
213
- # Supprime la base et l'utilisateur d'un projet (confirmation sans --yes)
214
- supprimer() {
215
- local projet="${1:-}" oui="" arg reponse
216
- valider_projet "$projet"
213
+ # Deletes the database and the user of a project (confirmation without --yes)
214
+ delete_project() {
215
+ local project="${1:-}" yes="" arg answer
216
+ check_project_name "$project"
217
217
  for arg in "${@:2}"; do
218
218
  case "$arg" in
219
- --yes) oui=1 ;;
220
- *) refuse "argument inconnu : $arg" ;;
219
+ --yes) yes=1 ;;
220
+ *) refuse "unknown argument: $arg" ;;
221
221
  esac
222
222
  done
223
- CTX="$(contexte)"
224
- installe || refuse "module inactif : devzone enable mysql"
225
- if [ -z "$oui" ]; then
226
- cluster_interactif || refuse "confirmation impossible sans terminal : devzone mysql delete $projet --yes"
227
- printf 'Supprimer la base %s et son utilisateur ? [o/N] ' "$projet" >&2
228
- read -r reponse || reponse=""
229
- case "$reponse" in
230
- o | O | oui) ;;
231
- *) echo "Abandon : rien n'a été supprimé."; return 0 ;;
223
+ CTX="$(module_context)"
224
+ installed || refuse "module disabled: devzone enable mysql"
225
+ if [ -z "$yes" ]; then
226
+ cluster_interactive || refuse "confirmation needs a terminal: devzone mysql delete $project --yes"
227
+ printf 'Delete database %s and its user? [y/N] ' "$project" >&2
228
+ read -r answer || answer=""
229
+ case "$answer" in
230
+ y | Y | yes) ;;
231
+ *) echo "Aborted: nothing was deleted."; return 0 ;;
232
232
  esac
233
233
  fi
234
234
  mysql_admin <<SQL
235
- DROP DATABASE IF EXISTS $projet;
236
- DROP USER IF EXISTS '$projet'@'%';
235
+ DROP DATABASE IF EXISTS $project;
236
+ DROP USER IF EXISTS '$project'@'%';
237
237
  SQL
238
- rm -f "$SECRETS/$projet.env"
239
- echo "✔ base $projet supprimée"
238
+ rm -f "$SECRETS/$project.env"
239
+ echo "✔ database $project deleted"
240
240
  regenerer_identifiants
241
241
  }
242
- # Relance le relais 127.0.0.1:3306 si le namespace existe
243
- relais() {
242
+ # Restarts the relay 127.0.0.1:3306 if the namespace exists
243
+ relay_restart() {
244
244
  local CTX
245
- CTX="$(cluster_lu)"
246
- [ -n "$CTX" ] && installe && relais_lancer mysql "$CTX" "$NS" svc/mysql 3306:3306
245
+ CTX="$(cluster_saved)"
246
+ [ -n "$CTX" ] && installed && relay_start mysql "$CTX" "$NS" svc/mysql 3306:3306
247
247
  }
248
248
  case "${1:-}" in
249
- install) installer ;;
250
- delete-data) supprimer_donnees "${@:2}" ;;
251
- status) etat ;;
252
- create) creer "${@:2}" ;;
253
- list) liste ;;
254
- delete) supprimer "${@:2}" ;;
249
+ install) install_module ;;
250
+ delete-data) delete_data "${@:2}" ;;
251
+ status) module_status ;;
252
+ create) create_project "${@:2}" ;;
253
+ list) list_databases ;;
254
+ delete) delete_project "${@:2}" ;;
255
255
  volume) mysql_volume "$NS" "${@:2}" ;;
256
- relay-start) relais ;;
257
- relay-stop) relais_arreter mysql ;;
256
+ relay-start) relay_restart ;;
257
+ relay-stop) relay_stop mysql ;;
258
258
  *)
259
- echo "devzone : catalogue mysql : create <projet> [--new-password] | list | delete <projet> [--yes] | volume [<nom>] [--delete <nom>] [--yes] | delete-data [--yes]" >&2
259
+ echo "devzone : catalog mysql : create <project> [--new-password] | list | delete <project> [--yes] | volume [<name>] [--delete <name>] [--yes] | delete-data [--yes]" >&2
260
260
  exit 1
261
261
  ;;
262
262
  esac