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,18 +1,18 @@
1
1
  #!/usr/bin/env bash
2
- # Module postgres (#280) : PostgreSQL partagé dans le cluster de devzone
3
- # (cluster.sh), une base et un utilisateur par projet.
2
+ # Module postgres (#280): shared PostgreSQL in the devzone cluster (cluster.sh),
3
+ # one database and one user per project.
4
4
  # postgres.sh install | uninstall | status | relay-start | relay-stop
5
- # postgres.sh create <projet> [--new-password] base, rôle, workspace/.postgres/<projet>.env
6
- # postgres.sh list bases et propriétaires
7
- # postgres.sh psql [<projet>] console dans le pod
8
- # postgres.sh delete <projet> [--yes] base, rôle et fichier .env
9
- # Secrets dans workspace/.postgres/ (600, ignorés par git), jamais affichés.
5
+ # postgres.sh create <project> [--new-password] database, role, workspace/.postgres/<project>.env
6
+ # postgres.sh list databases and owners
7
+ # postgres.sh psql [<project>] console in the pod
8
+ # postgres.sh delete <project> [--yes] database, role and .env file
9
+ # Secrets in workspace/.postgres/ (600, ignored by git), never displayed.
10
10
  set -euo pipefail
11
11
 
12
12
  ICI="$(cd "$(dirname "$0")" && pwd)"
13
- RACINE="${DEVZONE_RACINE:-$(dirname "$(dirname "$ICI")")}"
14
- # shellcheck disable=SC2034 # lu par cluster.sh (bibliothèque sourcée)
15
- ETAT="${DEVZONE_ETAT:-$RACINE/.devzone.modules}"
13
+ RACINE="${DEVZONE_ROOT:-$(dirname "$(dirname "$ICI")")}"
14
+ # shellcheck disable=SC2034 # read by cluster.sh (sourced library)
15
+ ETAT="${DEVZONE_STATE:-$RACINE/.devzone.modules}"
16
16
  # shellcheck source=SCRIPTDIR/../cluster.sh
17
17
  . "$ICI/../cluster.sh"
18
18
  # shellcheck source=SCRIPTDIR/../password.sh
@@ -21,32 +21,32 @@ ETAT="${DEVZONE_ETAT:-$RACINE/.devzone.modules}"
21
21
  # shellcheck source=SCRIPTDIR/../chart-direct.sh
22
22
  # shellcheck disable=SC1091
23
23
  . "$ICI/../chart-direct.sh"
24
- # Isolation réseau : namespace_isoler, d'où viennent les NetworkPolicies
24
+ # Network isolation: namespace_isolate, which provides the NetworkPolicies
25
25
  # shellcheck source=SCRIPTDIR/../isolation.sh
26
26
  # shellcheck disable=SC1091
27
27
  . "$ICI/../isolation.sh"
28
28
 
29
29
  NS=devzone-postgres
30
30
  SECRETS="$RACINE/workspace/.postgres"
31
- # Port du conteneur où le relais rend PostgreSQL joignable
31
+ # Container port where the relay makes PostgreSQL reachable
32
32
  POSTGRES_PORT="${POSTGRES_PORT:-5432}"
33
33
  POSTGRES_ATTENTE="${POSTGRES_ATTENTE:-300}"
34
34
  POSTGRES_TAILLE="${POSTGRES_TAILLE:-5Gi}"
35
35
 
36
36
  refuse() { echo "devzone : postgres : $*" >&2; exit 2; }
37
37
 
38
- # Vue regroupée des identifiants : un échec n'empêche jamais l'opération
39
- regenerer_identifiants() {
38
+ # Grouped credentials view: a failure never blocks the operation
39
+ regenerate_credentials() {
40
40
  password_regenerate ||
41
- echo "devzone : postgres : identifiants regroupés non mis à jour (devzone passwords)" >&2
41
+ echo "devzone : postgres : grouped credentials not updated (devzone passwords)" >&2
42
42
  }
43
43
 
44
- # Contexte du module : celui du cluster de devzone ; sans choix, rien n'est
45
- # installé (devzone enable postgres le fixe)
46
- contexte() {
44
+ # Module context: the devzone cluster; without a choice nothing is
45
+ # installed (devzone enable postgres sets it)
46
+ module_context() {
47
47
  local c
48
- c="$(cluster_lu)"
49
- [ -n "$c" ] || refuse "aucun cluster choisi : devzone enable postgres"
48
+ c="$(cluster_saved)"
49
+ [ -n "$c" ] || refuse "no cluster chosen: devzone enable postgres"
50
50
  echo "$c"
51
51
  }
52
52
 
@@ -54,256 +54,256 @@ k() {
54
54
  kubectl --context devzone -n "$NS" "$@"
55
55
  }
56
56
 
57
- # Namespace présent dans le cluster des services : lecture des namespaces
58
- # réservée à l'administrateur (#430)
59
- installe() {
60
- compte_admin "$(compte_ctx)" get namespace "$NS" >/dev/null 2>&1
57
+ # Namespace present in the services cluster: reading namespaces is
58
+ # reserved to the administrator (#430)
59
+ is_installed() {
60
+ account_admin "$(account_context)" get namespace "$NS" >/dev/null 2>&1
61
61
  }
62
62
 
63
- # psql en superutilisateur dans le pod : connexion locale (socket), sans mot
64
- # de passe ; le script SQL passe par stdin, jamais en argument visible
63
+ # psql as superuser in the pod: local connection (socket), no password;
64
+ # the SQL script goes through stdin, never as a visible argument
65
65
  psql_admin() {
66
66
  k exec -i postgres-0 -c postgres -- psql -v ON_ERROR_STOP=1 -X -q -U postgres "$@"
67
67
  }
68
68
 
69
- # Nom de projet = nom du rôle et de la base : identifiant SQL simple, jamais
70
- # à échapper, et pas un nom réservé
71
- valider_projet() {
69
+ # Project name = role name and database name: simple SQL identifier, never
70
+ # to escape, and not a reserved name
71
+ validate_project() {
72
72
  local p="${1:-}"
73
- [ -n "$p" ] || refuse "nom de projet manquant"
74
- [[ "$p" =~ ^[a-z][a-z0-9_]{0,62}$ ]] || refuse "nom de projet invalide : $p (minuscules, chiffres, _ ; commence par une lettre)"
73
+ [ -n "$p" ] || refuse "project name missing"
74
+ [[ "$p" =~ ^[a-z][a-z0-9_]{0,62}$ ]] || refuse "invalid project name: $p (lowercase, digits, _; starts with a letter)"
75
75
  case "$p" in
76
- postgres | template0 | template1) refuse "nom réservé : $p" ;;
76
+ postgres | template0 | template1) refuse "reserved name: $p" ;;
77
77
  esac
78
78
  }
79
79
 
80
- mot_de_passe() {
80
+ new_password() {
81
81
  openssl rand -hex 24
82
82
  }
83
83
 
84
- # Mot de passe du superutilisateur : celui du secret s'il existe déjà dans le
85
- # cluster (jamais régénéré : la base garde le sien), sinon le fichier local,
86
- # sinon un nouveau
87
- secret_admin() {
88
- local fichier="$SECRETS/admin-password" mdp
84
+ # Superuser password: the one in the secret if it already exists in the
85
+ # cluster (never regenerated: the database keeps its own), otherwise the local
86
+ # file, otherwise a new one
87
+ admin_secret() {
88
+ local file="$SECRETS/admin-password" pw
89
89
  mkdir -p "$SECRETS"
90
90
  chmod 700 "$SECRETS"
91
91
  if k get secret postgres-admin >/dev/null 2>&1; then
92
- mdp="$(k get secret postgres-admin -o jsonpath='{.data.password}' | base64 -d)"
93
- (umask 077 && printf '%s' "$mdp" >"$fichier")
92
+ pw="$(k get secret postgres-admin -o jsonpath='{.data.password}' | base64 -d)"
93
+ (umask 077 && printf '%s' "$pw" >"$file")
94
94
  return 0
95
95
  fi
96
- if [ ! -s "$fichier" ]; then
97
- (umask 077 && mot_de_passe | tr -d '\n' >"$fichier")
96
+ if [ ! -s "$file" ]; then
97
+ (umask 077 && new_password | tr -d '\n' >"$file")
98
98
  fi
99
- k create secret generic postgres-admin --from-file=password="$fichier" >/dev/null
99
+ k create secret generic postgres-admin --from-file=password="$file" >/dev/null
100
100
  }
101
101
 
102
- installer() {
103
- CTX="$(contexte)"
104
- cluster_preparer "$CTX"
105
- # Sur une machine neuve, le contexte devzone doit viser le cluster choisi
106
- # avant toute pose de ressource (#396) ; sinon, tout s'arrête : message et code
107
- if ! contexte_devzone_poser "$CTX"; then
108
- echo "devzone : postgres : impossible de poser le contexte devzone sur $CTX" >&2
102
+ do_install() {
103
+ CTX="$(module_context)"
104
+ cluster_prepare "$CTX"
105
+ # On a new machine, the devzone context must point to the chosen cluster
106
+ # before any resource is created (#396); otherwise, everything stops: message and code
107
+ if ! devzone_context_set "$CTX"; then
108
+ echo "devzone : postgres : cannot set the devzone context on $CTX" >&2
109
109
  return 1
110
110
  fi
111
- echo "▶ PostgreSQL sur le cluster $CTX (namespace $NS)…"
112
- # Namespace créé et étiqueté par l'administrateur (#430) : le compte limité
113
- # n'a pas le droit de créer d'objets hors des namespaces devzone-*
114
- compte_admin "$CTX" create namespace "$NS" --dry-run=client -o yaml |
115
- compte_admin "$CTX" apply -f - >/dev/null
116
- compte_admin "$CTX" label namespace "$NS" "$CLUSTER_ETIQUETTE" --overwrite >/dev/null
117
- # Compte limité autorisé dans le namespace : RoleBinding vers edit
118
- compte_autoriser "$CTX" "$NS"
119
- secret_admin
111
+ echo "▶ PostgreSQL on cluster $CTX (namespace $NS)…"
112
+ # Namespace created and labeled by the administrator (#430): the limited
113
+ # account may not create objects outside the devzone-* namespaces
114
+ account_admin "$CTX" create namespace "$NS" --dry-run=client -o yaml |
115
+ account_admin "$CTX" apply -f - >/dev/null
116
+ account_admin "$CTX" label namespace "$NS" "$CLUSTER_LABEL" --overwrite >/dev/null
117
+ # Limited account allowed in the namespace: RoleBinding to edit
118
+ account_allow "$CTX" "$NS"
119
+ admin_secret
120
120
  chart_install postgres "$NS" "size=$POSTGRES_TAILLE" || return 1
121
- echo "▶ Attente de PostgreSQL (timeout ${POSTGRES_ATTENTE}s)…"
121
+ echo "▶ Waiting for PostgreSQL (timeout ${POSTGRES_ATTENTE}s)…"
122
122
  if ! k rollout status statefulset/postgres --timeout="${POSTGRES_ATTENTE}s" >/dev/null; then
123
- echo "devzone : postgres : pas prêt après ${POSTGRES_ATTENTE}s : kubectl --context $CTX -n $NS describe pod postgres-0" >&2
123
+ echo "devzone : postgres : not ready after ${POSTGRES_ATTENTE}s: kubectl --context $CTX -n $NS describe pod postgres-0" >&2
124
124
  return 1
125
125
  fi
126
- relais_arreter postgres
127
- relais_lancer postgres "$CTX" "$NS" svc/postgres "$POSTGRES_PORT:5432"
128
- echo "✔ PostgreSQL prêt : 127.0.0.1:$POSTGRES_PORT dans le conteneur"
129
- echo " Base d'un projet : devzone postgres create <projet>"
130
- regenerer_identifiants
126
+ relay_stop postgres
127
+ relay_start postgres "$CTX" "$NS" svc/postgres "$POSTGRES_PORT:5432"
128
+ echo "✔ PostgreSQL ready: 127.0.0.1:$POSTGRES_PORT in the container"
129
+ echo " Database for a project: devzone postgres create <project>"
130
+ regenerate_credentials
131
131
  }
132
132
 
133
- desinstaller() {
134
- CTX="$(cluster_lu)"
135
- relais_arreter postgres
136
- # Désinstallation sur une machine neuve : le contexte devzone est reposé sur
137
- # le cluster choisi (sinon il vise l'ancien) ; sans lui, seulement le
138
- # nettoyage local a lieu
133
+ do_uninstall() {
134
+ CTX="$(cluster_saved)"
135
+ relay_stop postgres
136
+ # Uninstall on a new machine: the devzone context is reset to the chosen
137
+ # cluster (otherwise it points to the old one); without it, only the
138
+ # local cleanup takes place
139
139
  if [ -n "$CTX" ]; then
140
- contexte_devzone_poser "$CTX" ||
141
- echo "devzone : postgres : contexte devzone non posé sur $CTX ; nettoyage local seulement" >&2
140
+ devzone_context_set "$CTX" ||
141
+ echo "devzone : postgres : devzone context not set on $CTX; local cleanup only" >&2
142
142
  fi
143
- if [ -n "$CTX" ] && installe; then
144
- echo "▶ Suppression de PostgreSQL et de toutes ses bases sur ${CTX}…"
145
- # RoleBinding retiré puis namespace supprimé par l'administrateur (#430)
146
- compte_retirer "$CTX" "$NS" >/dev/null 2>&1 || true
147
- compte_admin "$CTX" delete namespace "$NS" --wait=true >/dev/null
148
- cluster_liberer "$CTX"
143
+ if [ -n "$CTX" ] && is_installed; then
144
+ echo "▶ Deleting PostgreSQL and all its databases on ${CTX}…"
145
+ # RoleBinding removed, then namespace deleted by the administrator (#430)
146
+ account_remove "$CTX" "$NS" >/dev/null 2>&1 || true
147
+ account_admin "$CTX" delete namespace "$NS" --wait=true >/dev/null
148
+ cluster_release "$CTX"
149
149
  fi
150
150
  rm -rf "$SECRETS"
151
- echo "✔ PostgreSQL désinstallé."
152
- regenerer_identifiants
151
+ echo "✔ PostgreSQL uninstalled."
152
+ regenerate_credentials
153
153
  }
154
154
 
155
- nombre_bases() {
155
+ count_databases() {
156
156
  psql_admin -At -c "SELECT count(*) FROM pg_database WHERE datname NOT IN ('postgres','template0','template1')" 2>/dev/null || echo "?"
157
157
  }
158
158
 
159
- etat() {
160
- CTX="$(cluster_lu)"
161
- if [ -z "$CTX" ] || ! installe; then
162
- echo "désactivé"
159
+ do_status() {
160
+ CTX="$(cluster_saved)"
161
+ if [ -z "$CTX" ] || ! is_installed; then
162
+ echo "disabled"
163
163
  return 0
164
164
  fi
165
165
  if [ "$(k get statefulset postgres -o jsonpath='{.status.readyReplicas}' 2>/dev/null || true)" != 1 ]; then
166
- echo "en échec sur $CTX : devzone apply"
167
- elif ! relais_actif postgres; then
168
- echo "prêt sur $CTX, relais arrêté : devzone apply"
166
+ echo "failed on $CTX: devzone apply"
167
+ elif ! relay_active postgres; then
168
+ echo "ready on $CTX, relay stopped: devzone apply"
169
169
  else
170
- echo "prêt sur $CTX : 127.0.0.1:$POSTGRES_PORT, $(nombre_bases) base(s)"
170
+ echo "ready on $CTX: 127.0.0.1:$POSTGRES_PORT, $(count_databases) database(s)"
171
171
  fi
172
172
  }
173
173
 
174
- creer() {
175
- local projet="${1:-}" nouveau="" fichier mdp arg
176
- valider_projet "$projet"
174
+ do_create() {
175
+ local project="${1:-}" renew="" file pw arg
176
+ validate_project "$project"
177
177
  for arg in "${@:2}"; do
178
178
  case "$arg" in
179
- --new-password) nouveau=1 ;;
180
- *) refuse "argument inconnu : $arg" ;;
179
+ --new-password) renew=1 ;;
180
+ *) refuse "unknown argument: $arg" ;;
181
181
  esac
182
182
  done
183
- CTX="$(contexte)"
184
- installe || refuse "module inactif : devzone enable postgres"
185
- fichier="$SECRETS/$projet.env"
186
- # Mot de passe gardé : une application déjà configurée continue de marcher
187
- mdp="$(sed -n 's/^DB_PASSWORD=//p' "$fichier" 2>/dev/null || true)"
188
- if [ -z "$mdp" ] || [ -n "$nouveau" ]; then
189
- mdp="$(mot_de_passe)"
183
+ CTX="$(module_context)"
184
+ is_installed || refuse "module disabled: devzone enable postgres"
185
+ file="$SECRETS/$project.env"
186
+ # Kept password: an application already configured keeps working
187
+ pw="$(sed -n 's/^DB_PASSWORD=//p' "$file" 2>/dev/null || true)"
188
+ if [ -z "$pw" ] || [ -n "$renew" ]; then
189
+ pw="$(new_password)"
190
190
  fi
191
- # REVOKE … FROM PUBLIC : un projet ne se connecte pas à la base d'un autre
191
+ # REVOKE ... FROM PUBLIC: a project does not connect to another project's database
192
192
  psql_admin <<SQL
193
- SELECT 'CREATE ROLE $projet LOGIN' WHERE NOT EXISTS (SELECT FROM pg_roles WHERE rolname = '$projet')\gexec
194
- ALTER ROLE $projet PASSWORD '$mdp';
195
- SELECT 'CREATE DATABASE $projet OWNER $projet' WHERE NOT EXISTS (SELECT FROM pg_database WHERE datname = '$projet')\gexec
196
- REVOKE CONNECT ON DATABASE $projet FROM PUBLIC;
197
- GRANT CONNECT ON DATABASE $projet TO $projet;
193
+ SELECT 'CREATE ROLE $project LOGIN' WHERE NOT EXISTS (SELECT FROM pg_roles WHERE rolname = '$project')\gexec
194
+ ALTER ROLE $project PASSWORD '$pw';
195
+ SELECT 'CREATE DATABASE $project OWNER $project' WHERE NOT EXISTS (SELECT FROM pg_database WHERE datname = '$project')\gexec
196
+ REVOKE CONNECT ON DATABASE $project FROM PUBLIC;
197
+ GRANT CONNECT ON DATABASE $project TO $project;
198
198
  SQL
199
199
  mkdir -p "$SECRETS"
200
200
  chmod 700 "$SECRETS"
201
201
  (
202
202
  umask 077
203
- cat >"$fichier" <<ENV
203
+ cat >"$file" <<ENV
204
204
  DB_HOST=127.0.0.1
205
205
  DB_PORT=$POSTGRES_PORT
206
- DB_NAME=$projet
207
- DB_USER=$projet
208
- DB_PASSWORD=$mdp
209
- DB_URL=jdbc:postgresql://127.0.0.1:$POSTGRES_PORT/$projet
206
+ DB_NAME=$project
207
+ DB_USER=$project
208
+ DB_PASSWORD=$pw
209
+ DB_URL=jdbc:postgresql://127.0.0.1:$POSTGRES_PORT/$project
210
210
  ENV
211
211
  )
212
- echo "✔ base $projet prête ; identifiants : $fichier"
213
- regenerer_identifiants
212
+ echo "✔ database $project ready; credentials: $file"
213
+ regenerate_credentials
214
214
  }
215
215
 
216
- liste() {
217
- CTX="$(contexte)"
218
- installe || refuse "module inactif : devzone enable postgres"
216
+ do_list() {
217
+ CTX="$(module_context)"
218
+ is_installed || refuse "module disabled: devzone enable postgres"
219
219
  psql_admin -At -F ' ' -c "SELECT datname, pg_get_userbyid(datdba) FROM pg_database WHERE datname NOT IN ('postgres','template0','template1') ORDER BY 1" |
220
- awk 'BEGIN { n = 0 } { printf " %-30s propriétaire %s\n", $1, $2; n++ } END { if (n == 0) print " (aucune base : devzone postgres create <projet>)" }'
220
+ awk 'BEGIN { n = 0 } { printf " %-30s owner %s\n", $1, $2; n++ } END { if (n == 0) print " (no database: devzone postgres create <project>)" }'
221
221
  }
222
222
 
223
- console() {
224
- local projet="${1:-}" tty=()
225
- CTX="$(contexte)"
226
- installe || refuse "module inactif : devzone enable postgres"
223
+ do_psql() {
224
+ local project="${1:-}" tty=()
225
+ CTX="$(module_context)"
226
+ is_installed || refuse "module disabled: devzone enable postgres"
227
227
  [ -t 0 ] && tty=(-t)
228
- if [ -n "$projet" ]; then
229
- valider_projet "$projet"
230
- k exec -i ${tty[@]+"${tty[@]}"} postgres-0 -c postgres -- psql -U "$projet" -d "$projet"
228
+ if [ -n "$project" ]; then
229
+ validate_project "$project"
230
+ k exec -i ${tty[@]+"${tty[@]}"} postgres-0 -c postgres -- psql -U "$project" -d "$project"
231
231
  else
232
232
  k exec -i ${tty[@]+"${tty[@]}"} postgres-0 -c postgres -- psql -U postgres
233
233
  fi
234
234
  }
235
235
 
236
- supprimer() {
237
- local projet="${1:-}" oui="" arg reponse
238
- valider_projet "$projet"
236
+ do_delete() {
237
+ local project="${1:-}" yes="" arg answer
238
+ validate_project "$project"
239
239
  for arg in "${@:2}"; do
240
240
  case "$arg" in
241
- --yes) oui=1 ;;
242
- *) refuse "argument inconnu : $arg" ;;
241
+ --yes) yes=1 ;;
242
+ *) refuse "unknown argument: $arg" ;;
243
243
  esac
244
244
  done
245
- CTX="$(contexte)"
246
- installe || refuse "module inactif : devzone enable postgres"
247
- if [ -z "$oui" ]; then
248
- cluster_interactif || refuse "confirmation impossible sans terminal : devzone postgres delete $projet --yes"
249
- printf 'Supprimer la base %s et toutes ses données ? [o/N] ' "$projet" >&2
250
- read -r reponse || reponse=""
251
- case "$reponse" in
252
- o | O | oui) ;;
253
- *) echo "Abandon : rien n'a été supprimé."; return 0 ;;
245
+ CTX="$(module_context)"
246
+ is_installed || refuse "module disabled: devzone enable postgres"
247
+ if [ -z "$yes" ]; then
248
+ cluster_interactive || refuse "cannot confirm without a terminal: devzone postgres delete $project --yes"
249
+ printf 'Delete database %s and all its data? [y/N] ' "$project" >&2
250
+ read -r answer || answer=""
251
+ case "$answer" in
252
+ y | Y | yes) ;;
253
+ *) echo "Abandon: nothing was deleted."; return 0 ;;
254
254
  esac
255
255
  fi
256
256
  psql_admin <<SQL
257
- DROP DATABASE IF EXISTS $projet WITH (FORCE);
258
- DROP ROLE IF EXISTS $projet;
257
+ DROP DATABASE IF EXISTS $project WITH (FORCE);
258
+ DROP ROLE IF EXISTS $project;
259
259
  SQL
260
- rm -f "$SECRETS/$projet.env"
261
- echo "✔ base $projet supprimée"
262
- regenerer_identifiants
260
+ rm -f "$SECRETS/$project.env"
261
+ echo "✔ database $project deleted"
262
+ regenerate_credentials
263
263
  }
264
264
 
265
- relais() {
266
- CTX="$(cluster_lu)"
267
- if [ -n "$CTX" ] && installe; then
268
- relais_lancer postgres "$CTX" "$NS" svc/postgres "$POSTGRES_PORT:5432"
265
+ do_relay_start() {
266
+ CTX="$(cluster_saved)"
267
+ if [ -n "$CTX" ] && is_installed; then
268
+ relay_start postgres "$CTX" "$NS" svc/postgres "$POSTGRES_PORT:5432"
269
269
  fi
270
270
  }
271
271
 
272
- autoriser() {
272
+ do_authorize() {
273
273
  local ns="${1:-}"
274
- [ -n "$ns" ] || { echo "devzone postgres : namespace manquant" >&2; return 2; }
275
- namespace_isoler "$ns"
276
- echo "devzone postgres : accès autorisé depuis $ns vers le service PostgreSQL"
274
+ [ -n "$ns" ] || { echo "devzone postgres: namespace missing" >&2; return 2; }
275
+ namespace_isolate "$ns"
276
+ echo "devzone postgres: access allowed from $ns to the PostgreSQL service"
277
277
  }
278
278
 
279
- interdire() {
280
- local ns="${1:-}" patch sortie
281
- [ -n "$ns" ] || { echo "devzone postgres : namespace manquant" >&2; return 2; }
282
- # JSON construit par jq, jamais assemblé à la main (le JSON invalide était
283
- # rejeté en silence) ; l'échec du patch est affiché et rend un code (#396)
279
+ do_forbid() {
280
+ local ns="${1:-}" patch out
281
+ [ -n "$ns" ] || { echo "devzone postgres: namespace missing" >&2; return 2; }
282
+ # JSON built by jq, never assembled by hand (invalid JSON was silently
283
+ # rejected); a failed patch is displayed and returns a code (#396)
284
284
  patch="$(jq -nc '{"spec":{"ingress":[{"from":[{"podSelector":{}}]}]}}')"
285
- if ! sortie="$(kubectl --context devzone -n "$NS" patch networkpolicy devzone-meme-namespace \
285
+ if ! out="$(kubectl --context devzone -n "$NS" patch networkpolicy devzone-meme-namespace \
286
286
  -p "$patch" 2>&1)"; then
287
- echo "devzone : postgres : impossible de retirer la règle d'accès de $ns : $sortie" >&2
287
+ echo "devzone : postgres : cannot remove the access rule of $ns: $out" >&2
288
288
  return 1
289
289
  fi
290
- echo "devzone postgres : accès interdit depuis $ns vers le service PostgreSQL"
290
+ echo "devzone postgres: access forbidden from $ns to the PostgreSQL service"
291
291
  }
292
292
 
293
293
  case "${1:-}" in
294
- install) installer ;;
295
- uninstall) desinstaller ;;
296
- status) etat ;;
297
- create) creer "${@:2}" ;;
298
- list) liste ;;
299
- psql) console "${@:2}" ;;
300
- delete) supprimer "${@:2}" ;;
301
- relay-start) relais ;;
302
- relay-stop) relais_arreter postgres ;;
303
- authorize) autoriser "${@:2}" ;;
304
- forbid) interdire "${@:2}" ;;
294
+ install) do_install ;;
295
+ uninstall) do_uninstall ;;
296
+ status) do_status ;;
297
+ create) do_create "${@:2}" ;;
298
+ list) do_list ;;
299
+ psql) do_psql "${@:2}" ;;
300
+ delete) do_delete "${@:2}" ;;
301
+ relay-start) do_relay_start ;;
302
+ relay-stop) relay_stop postgres ;;
303
+ authorize) do_authorize "${@:2}" ;;
304
+ forbid) do_forbid "${@:2}" ;;
305
305
  *)
306
- echo "devzone postgres : create <projet> [--new-password] | list | psql [<projet>] | delete <projet> [--yes]" >&2
306
+ echo "devzone postgres: create <project> [--new-password] | list | psql [<project>] | delete <project> [--yes]" >&2
307
307
  exit 1
308
308
  ;;
309
309
  esac
@@ -0,0 +1,103 @@
1
+ #!/usr/bin/env bash
2
+ # shellcheck shell=bash
3
+ # Renames the files and folders that devzone wrote under their former French
4
+ # names to their English names (#733, lot 3), and the state key plateforme= to
5
+ # platform= (lot 4). Called by the pod startup, by the workspace init, and on the
6
+ # workstation by devzone update and workspace update.
7
+ # Idempotent: a name is renamed only when the old one exists and the new one
8
+ # does not, so a second run does nothing. An existing new name is never
9
+ # overwritten. One line per rename on stdout, exit 0. No alias of the old names
10
+ # is kept after this migration. bash 3.2 (macOS).
11
+ # DEVZONE_ROOT devzone folder (default: the parent of this .devcontainer)
12
+ # DEVZONE_TMP_DIR temporary folder (default: /tmp), set by the tests
13
+
14
+ ROOT="${DEVZONE_ROOT:-$(cd "$(dirname "$0")/.." && pwd)}"
15
+ TMP_DIR="${DEVZONE_TMP_DIR:-/tmp}"
16
+
17
+ # rename_legacy OLD NEW: moves OLD to NEW when OLD exists and NEW does not.
18
+ # A conflict is reported on stderr and both names are left as they are.
19
+ rename_legacy() {
20
+ local old="$1" new="$2"
21
+ if [ ! -e "$old" ] && [ ! -L "$old" ]; then
22
+ return 0
23
+ fi
24
+ if [ -e "$new" ] || [ -L "$new" ]; then
25
+ echo "devzone : $old kept, $new already exists" >&2
26
+ return 0
27
+ fi
28
+ if mv -- "$old" "$new"; then
29
+ echo "devzone : $old renamed to $new"
30
+ else
31
+ echo "devzone : $old not renamed to $new" >&2
32
+ fi
33
+ return 0
34
+ }
35
+
36
+ # Failure markers of the modules: .devzone.modules-echec-<module> becomes
37
+ # .devzone.modules-failed-<module>, one rename per marker found
38
+ migrate_markers() {
39
+ local f base
40
+ for f in "$ROOT"/.devzone.modules-echec-*; do
41
+ if [ ! -e "$f" ] && [ ! -L "$f" ]; then
42
+ continue
43
+ fi
44
+ base="${f##*/}"
45
+ rename_legacy "$f" "$ROOT/.devzone.modules-failed-${base#.devzone.modules-echec-}"
46
+ done
47
+ }
48
+
49
+ # Folders and files of the devzone folder
50
+ migrate_root() {
51
+ rename_legacy "$ROOT/.devzone.paquets" "$ROOT/.devzone.packages"
52
+ rename_legacy "$ROOT/.devzone.sauvegarde" "$ROOT/.devzone.backup"
53
+ rename_legacy "$ROOT/.devzone.ports-workspace" "$ROOT/.devzone.workspace-ports"
54
+ rename_legacy "$ROOT/.devzone.etat" "$ROOT/.devzone.state"
55
+ rename_legacy "$ROOT/.devzone.catalogue-veilleur" "$ROOT/.devzone.catalog-watcher"
56
+ migrate_markers
57
+ }
58
+
59
+ # Fingerprint of the devzone skill, next to its SKILL.md in each assistant folder
60
+ migrate_skills() {
61
+ local d
62
+ [ -n "${HOME:-}" ] || return 0
63
+ for d in "$HOME/.claude/skills/devzone" "$HOME/.config/opencode/skills/devzone"; do
64
+ rename_legacy "$d/.devzone-empreinte" "$d/.devzone-fingerprint"
65
+ done
66
+ }
67
+
68
+ # Markers written in the temporary folder by the packages check
69
+ migrate_tmp() {
70
+ rename_legacy "$TMP_DIR/devzone-paquets.echec" "$TMP_DIR/devzone-packages.failed"
71
+ }
72
+
73
+ # Key of the state file (#733, lot 4): the line plateforme=<v> becomes
74
+ # platform=<v>. When a platform= line is already there, only the old line goes.
75
+ # The file is rewritten in a temporary file, then moved over it; the other
76
+ # lines are copied as they are. A file without the old key is left alone.
77
+ migrate_state_keys() {
78
+ local f="$ROOT/.devzone.modules" tmp="$ROOT/.devzone.modules.tmp.$$"
79
+ [ -f "$f" ] || return 0
80
+ grep -q '^plateforme=' "$f" || return 0
81
+ if grep -q '^platform=' "$f"; then
82
+ sed '/^plateforme=/d' "$f" >"$tmp"
83
+ else
84
+ sed 's/^plateforme=/platform=/' "$f" >"$tmp"
85
+ fi || {
86
+ rm -f "$tmp"
87
+ echo "devzone : plateforme= not renamed to platform=" >&2
88
+ return 0
89
+ }
90
+ if mv -- "$tmp" "$f"; then
91
+ echo "devzone : plateforme= renamed to platform="
92
+ else
93
+ rm -f "$tmp"
94
+ echo "devzone : plateforme= not renamed to platform=" >&2
95
+ fi
96
+ return 0
97
+ }
98
+
99
+ migrate_root
100
+ migrate_skills
101
+ migrate_tmp
102
+ migrate_state_keys
103
+ exit 0
@@ -11,7 +11,7 @@
11
11
  # two contexts on the cluster of the pod (API server kubernetes.default.svc,
12
12
  # CA of the pod): devzone-admin, the administrator the installers use through
13
13
  # the line cluster=devzone-admin of the state, and devzone, the context the
14
- # module scripts use (compte_jeton may replace it by the limited account).
14
+ # module scripts use (account_token may replace it by the limited account).
15
15
  # The cluster line of the state is put back afterwards, and the relays
16
16
  # started by the installer are stopped: in the pod the services are reached
17
17
  # by the cluster DNS, and a relay would keep the token in use.
@@ -21,8 +21,8 @@ HERE="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
21
21
  # The devzone command beside this script, not the one of the PATH: the copy
22
22
  # that runs the installers is the one of this folder (#591)
23
23
  DEVZONE_CMD="$HERE/devzone"
24
- RACINE="${DEVZONE_RACINE:-$(dirname "$HERE")}"
25
- ETAT="${DEVZONE_ETAT:-$RACINE/.devzone.modules}"
24
+ RACINE="${DEVZONE_ROOT:-$(dirname "$HERE")}"
25
+ ETAT="${DEVZONE_STATE:-$RACINE/.devzone.modules}"
26
26
  SA_DIR="${DEVZONE_SA_DIR:-/var/run/secrets/kubernetes.io/serviceaccount}"
27
27
  API_SERVER="${DEVZONE_API_SERVER:-https://kubernetes.default.svc}"
28
28
  ADMIN_CONTEXT=devzone-admin