devzone 1.1.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.
- package/.devcontainer/Dockerfile +4 -4
- package/.devcontainer/{agent-erreurs.sh → agent-errors.sh} +6 -6
- package/.devcontainer/agent-local.sh +2 -2
- package/.devcontainer/{agent-modele.messages → agent-model.messages} +1 -1
- package/.devcontainer/{agent-modele.sh → agent-model.sh} +5 -5
- package/.devcontainer/agent-pod-manifest.sh +4 -4
- package/.devcontainer/{agent-droits.sh → agent-rights.sh} +2 -2
- package/.devcontainer/agent-session.sh +3 -3
- package/.devcontainer/{agent-etat-json.sh → agent-state-json.sh} +6 -6
- package/.devcontainer/agent-workspace.sh +1 -1
- package/.devcontainer/agent.sh +14 -14
- package/.devcontainer/{ia/docker-garde.sh → ai/docker-guard.sh} +1 -1
- package/.devcontainer/{ia → ai}/host-models.sh +2 -2
- package/.devcontainer/{ia/plugins/devzone-garde-v2.js → ai/plugins/devzone-guard-v2.js} +7 -7
- package/.devcontainer/{ia/plugins/devzone-garde.js → ai/plugins/devzone-guard.js} +6 -6
- package/.devcontainer/argocd/argocd.sh +94 -93
- package/.devcontainer/argocd/{catalogue-argocd.sh → catalog-argocd.sh} +3 -3
- package/.devcontainer/argocd/services-hook.sh +8 -8
- package/.devcontainer/argocd/services.sh +1 -1
- package/.devcontainer/catalog/app.sh +209 -0
- package/.devcontainer/catalog/catalog-watcher.sh +130 -0
- package/.devcontainer/{catalogue → catalog}/mysql/app.conf +1 -1
- package/.devcontainer/catalog/mysql/install.sh +87 -0
- package/.devcontainer/catalog/mysql/mysql.sh +262 -0
- package/.devcontainer/catalog/mysql/volume.sh +71 -0
- package/.devcontainer/catalog.sh +231 -0
- package/.devcontainer/chart-direct.sh +1 -1
- package/.devcontainer/cluster.sh +222 -224
- package/.devcontainer/clusters.sh +41 -41
- package/.devcontainer/devcontainer.json +1 -1
- package/.devcontainer/devzone +103 -1506
- package/.devcontainer/devzone-ai-guard.sh +76 -0
- package/.devcontainer/devzone-ai.sh +201 -0
- package/.devcontainer/devzone-cluster.sh +210 -0
- package/.devcontainer/devzone-modules.sh +126 -0
- package/.devcontainer/devzone-platform.sh +189 -0
- package/.devcontainer/devzone-repair.sh +94 -0
- package/.devcontainer/devzone-services.sh +241 -0
- package/.devcontainer/devzone-skill.sh +97 -0
- package/.devcontainer/devzone-status.sh +140 -0
- package/.devcontainer/devzone-version.sh +78 -0
- package/.devcontainer/git-identity.sh +28 -0
- package/.devcontainer/gitlab/argocd.sh +2 -2
- package/.devcontainer/gitlab/chart.sh +2 -2
- package/.devcontainer/gitlab/gitlab.sh +83 -84
- package/.devcontainer/gitlab/installation.sh +111 -111
- package/.devcontainer/gitlab/secrets.sh +47 -47
- package/.devcontainer/gitlab/seed.sh +77 -77
- package/.devcontainer/gitlab/test-gitlab.sh +242 -243
- package/.devcontainer/help.sh +1 -1
- package/.devcontainer/isolation.sh +65 -0
- package/.devcontainer/kind-wrapper.sh +45 -0
- package/.devcontainer/kube-account.sh +199 -0
- package/.devcontainer/kube-config.sh +45 -46
- package/.devcontainer/{invite-kube.sh → kube-prompt.sh} +6 -6
- package/.devcontainer/kube-reachable.sh +64 -0
- package/.devcontainer/{memoire.sh → memory.sh} +1 -1
- package/.devcontainer/metrics-server.sh +2 -2
- package/.devcontainer/opencode.jsonc +2 -2
- package/.devcontainer/packages.sh +228 -0
- package/.devcontainer/password.sh +1 -1
- package/.devcontainer/ports-auto.sh +152 -153
- package/.devcontainer/ports-json.sh +16 -15
- package/.devcontainer/ports.sh +127 -123
- package/.devcontainer/post-create.sh +52 -52
- package/.devcontainer/postgres/postgres.sh +176 -176
- package/.devcontainer/rename-legacy-files.sh +103 -0
- package/.devcontainer/services-admin.sh +5 -5
- package/.devcontainer/skills/devzone/SKILL.md +40 -41
- package/.devcontainer/startup.sh +65 -0
- package/.devcontainer/{etat-gitops.sh → state-gitops.sh} +1 -1
- package/.devcontainer/{etat-json.sh → state-json.sh} +39 -65
- package/.devcontainer/{etat-verrou.sh → state-lock.sh} +1 -1
- package/.devcontainer/{etat.sh → state.sh} +4 -4
- package/.devcontainer/workspace-init.sh +17 -3
- package/Makefile +8 -8
- package/README.md +195 -194
- package/charts/devzone-workspace/templates/statefulset.yaml +1 -1
- package/manage/devzone +8 -10
- package/manage/scripts/argocd-workspace.sh +1 -1
- package/manage/scripts/check-go-layout.sh +40 -0
- package/manage/scripts/check-names.sh +61 -0
- package/manage/scripts/create-cluster.sh +1 -1
- package/manage/scripts/create-mode.sh +2 -2
- package/manage/scripts/devzone-create.sh +5 -5
- package/manage/scripts/devzone-manifest.sh +3 -3
- package/manage/scripts/devzone-update.sh +12 -8
- package/manage/scripts/docker-workstation.sh +2 -2
- package/manage/scripts/docker.sh +2 -2
- package/manage/scripts/{lancer.sh → launch.sh} +10 -51
- package/manage/scripts/{migrer-retour.sh → migrate-revert.sh} +4 -4
- package/manage/scripts/{migrer.sh → migrate.sh} +8 -14
- package/manage/scripts/ports-apps.sh +1 -1
- package/manage/scripts/ports-workspace.sh +7 -7
- package/manage/scripts/{desinstaller.sh → uninstall.sh} +8 -8
- package/manage/scripts/workspace-egress.sh +2 -2
- package/manage/scripts/workspace-update.sh +5 -2
- package/manage/scripts/workspace-wait.sh +2 -2
- package/manage/workspace.sh +4 -4
- package/package.json +1 -1
- package/.devcontainer/catalogue/app.sh +0 -211
- package/.devcontainer/catalogue/catalogue-veilleur.sh +0 -130
- package/.devcontainer/catalogue/mysql/installer.sh +0 -87
- package/.devcontainer/catalogue/mysql/mysql.sh +0 -262
- package/.devcontainer/catalogue/mysql/volume.sh +0 -71
- package/.devcontainer/catalogue.sh +0 -231
- package/.devcontainer/demarrage.sh +0 -66
- package/.devcontainer/docker-relais.sh +0 -149
- package/.devcontainer/docker-sans-hote.sh +0 -12
- package/.devcontainer/git-identite.sh +0 -28
- package/.devcontainer/isolement.sh +0 -65
- package/.devcontainer/kind-enveloppe.sh +0 -45
- package/.devcontainer/kube-compte.sh +0 -200
- package/.devcontainer/kube-joignable.sh +0 -64
- package/.devcontainer/paquets.sh +0 -227
- /package/.devcontainer/{ia/docker-garde.message → ai/docker-guard.message} +0 -0
- /package/.devcontainer/{ia → ai}/host-check.message +0 -0
- /package/.devcontainer/{ia → ai}/host-check.sh +0 -0
|
@@ -1,18 +1,18 @@
|
|
|
1
1
|
#!/usr/bin/env bash
|
|
2
|
-
# Module postgres (#280)
|
|
3
|
-
#
|
|
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 <
|
|
6
|
-
# postgres.sh list
|
|
7
|
-
# postgres.sh psql [<
|
|
8
|
-
# postgres.sh delete <
|
|
9
|
-
# Secrets
|
|
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="${
|
|
14
|
-
# shellcheck disable=SC2034 #
|
|
15
|
-
ETAT="${
|
|
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
|
-
#
|
|
25
|
-
# shellcheck source=SCRIPTDIR/../
|
|
24
|
+
# Network isolation: namespace_isolate, which provides the NetworkPolicies
|
|
25
|
+
# shellcheck source=SCRIPTDIR/../isolation.sh
|
|
26
26
|
# shellcheck disable=SC1091
|
|
27
|
-
. "$ICI/../
|
|
27
|
+
. "$ICI/../isolation.sh"
|
|
28
28
|
|
|
29
29
|
NS=devzone-postgres
|
|
30
30
|
SECRETS="$RACINE/workspace/.postgres"
|
|
31
|
-
#
|
|
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
|
-
#
|
|
39
|
-
|
|
38
|
+
# Grouped credentials view: a failure never blocks the operation
|
|
39
|
+
regenerate_credentials() {
|
|
40
40
|
password_regenerate ||
|
|
41
|
-
echo "devzone : postgres :
|
|
41
|
+
echo "devzone : postgres : grouped credentials not updated (devzone passwords)" >&2
|
|
42
42
|
}
|
|
43
43
|
|
|
44
|
-
#
|
|
45
|
-
#
|
|
46
|
-
|
|
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="$(
|
|
49
|
-
[ -n "$c" ] || refuse "
|
|
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
|
|
58
|
-
#
|
|
59
|
-
|
|
60
|
-
|
|
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
|
|
64
|
-
#
|
|
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
|
-
#
|
|
70
|
-
#
|
|
71
|
-
|
|
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 "
|
|
74
|
-
[[ "$p" =~ ^[a-z][a-z0-9_]{0,62}$ ]] || refuse "
|
|
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 "
|
|
76
|
+
postgres | template0 | template1) refuse "reserved name: $p" ;;
|
|
77
77
|
esac
|
|
78
78
|
}
|
|
79
79
|
|
|
80
|
-
|
|
80
|
+
new_password() {
|
|
81
81
|
openssl rand -hex 24
|
|
82
82
|
}
|
|
83
83
|
|
|
84
|
-
#
|
|
85
|
-
# cluster (
|
|
86
|
-
#
|
|
87
|
-
|
|
88
|
-
local
|
|
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
|
-
|
|
93
|
-
(umask 077 && printf '%s' "$
|
|
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 "$
|
|
97
|
-
(umask 077 &&
|
|
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="$
|
|
99
|
+
k create secret generic postgres-admin --from-file=password="$file" >/dev/null
|
|
100
100
|
}
|
|
101
101
|
|
|
102
|
-
|
|
103
|
-
CTX="$(
|
|
104
|
-
|
|
105
|
-
#
|
|
106
|
-
#
|
|
107
|
-
if !
|
|
108
|
-
echo "devzone : postgres :
|
|
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
|
|
112
|
-
# Namespace
|
|
113
|
-
#
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
#
|
|
118
|
-
|
|
119
|
-
|
|
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 "▶
|
|
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 :
|
|
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
|
-
|
|
127
|
-
|
|
128
|
-
echo "✔ PostgreSQL
|
|
129
|
-
echo "
|
|
130
|
-
|
|
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
|
-
|
|
134
|
-
CTX="$(
|
|
135
|
-
|
|
136
|
-
#
|
|
137
|
-
#
|
|
138
|
-
#
|
|
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
|
-
|
|
141
|
-
echo "devzone : postgres :
|
|
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" ] &&
|
|
144
|
-
echo "▶
|
|
145
|
-
# RoleBinding
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
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
|
|
152
|
-
|
|
151
|
+
echo "✔ PostgreSQL uninstalled."
|
|
152
|
+
regenerate_credentials
|
|
153
153
|
}
|
|
154
154
|
|
|
155
|
-
|
|
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
|
-
|
|
160
|
-
CTX="$(
|
|
161
|
-
if [ -z "$CTX" ] || !
|
|
162
|
-
echo "
|
|
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 "
|
|
167
|
-
elif !
|
|
168
|
-
echo "
|
|
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 "
|
|
170
|
+
echo "ready on $CTX: 127.0.0.1:$POSTGRES_PORT, $(count_databases) database(s)"
|
|
171
171
|
fi
|
|
172
172
|
}
|
|
173
173
|
|
|
174
|
-
|
|
175
|
-
local
|
|
176
|
-
|
|
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)
|
|
180
|
-
*) refuse "argument
|
|
179
|
+
--new-password) renew=1 ;;
|
|
180
|
+
*) refuse "unknown argument: $arg" ;;
|
|
181
181
|
esac
|
|
182
182
|
done
|
|
183
|
-
CTX="$(
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
#
|
|
187
|
-
|
|
188
|
-
if [ -z "$
|
|
189
|
-
|
|
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
|
|
191
|
+
# REVOKE ... FROM PUBLIC: a project does not connect to another project's database
|
|
192
192
|
psql_admin <<SQL
|
|
193
|
-
SELECT 'CREATE ROLE $
|
|
194
|
-
ALTER ROLE $
|
|
195
|
-
SELECT 'CREATE DATABASE $
|
|
196
|
-
REVOKE CONNECT ON DATABASE $
|
|
197
|
-
GRANT CONNECT ON DATABASE $
|
|
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 >"$
|
|
203
|
+
cat >"$file" <<ENV
|
|
204
204
|
DB_HOST=127.0.0.1
|
|
205
205
|
DB_PORT=$POSTGRES_PORT
|
|
206
|
-
DB_NAME=$
|
|
207
|
-
DB_USER=$
|
|
208
|
-
DB_PASSWORD=$
|
|
209
|
-
DB_URL=jdbc:postgresql://127.0.0.1:$POSTGRES_PORT/$
|
|
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 "✔
|
|
213
|
-
|
|
212
|
+
echo "✔ database $project ready; credentials: $file"
|
|
213
|
+
regenerate_credentials
|
|
214
214
|
}
|
|
215
215
|
|
|
216
|
-
|
|
217
|
-
CTX="$(
|
|
218
|
-
|
|
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
|
|
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
|
-
|
|
224
|
-
local
|
|
225
|
-
CTX="$(
|
|
226
|
-
|
|
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 "$
|
|
229
|
-
|
|
230
|
-
k exec -i ${tty[@]+"${tty[@]}"} postgres-0 -c postgres -- psql -U "$
|
|
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
|
-
|
|
237
|
-
local
|
|
238
|
-
|
|
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)
|
|
242
|
-
*) refuse "argument
|
|
241
|
+
--yes) yes=1 ;;
|
|
242
|
+
*) refuse "unknown argument: $arg" ;;
|
|
243
243
|
esac
|
|
244
244
|
done
|
|
245
|
-
CTX="$(
|
|
246
|
-
|
|
247
|
-
if [ -z "$
|
|
248
|
-
|
|
249
|
-
printf '
|
|
250
|
-
read -r
|
|
251
|
-
case "$
|
|
252
|
-
|
|
253
|
-
*) echo "Abandon
|
|
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 $
|
|
258
|
-
DROP ROLE IF EXISTS $
|
|
257
|
+
DROP DATABASE IF EXISTS $project WITH (FORCE);
|
|
258
|
+
DROP ROLE IF EXISTS $project;
|
|
259
259
|
SQL
|
|
260
|
-
rm -f "$SECRETS/$
|
|
261
|
-
echo "✔
|
|
262
|
-
|
|
260
|
+
rm -f "$SECRETS/$project.env"
|
|
261
|
+
echo "✔ database $project deleted"
|
|
262
|
+
regenerate_credentials
|
|
263
263
|
}
|
|
264
264
|
|
|
265
|
-
|
|
266
|
-
CTX="$(
|
|
267
|
-
if [ -n "$CTX" ] &&
|
|
268
|
-
|
|
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
|
-
|
|
272
|
+
do_authorize() {
|
|
273
273
|
local ns="${1:-}"
|
|
274
|
-
[ -n "$ns" ] || { echo "devzone postgres
|
|
275
|
-
|
|
276
|
-
echo "devzone postgres
|
|
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
|
-
|
|
280
|
-
local ns="${1:-}" patch
|
|
281
|
-
[ -n "$ns" ] || { echo "devzone postgres
|
|
282
|
-
# JSON
|
|
283
|
-
#
|
|
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 !
|
|
285
|
+
if ! out="$(kubectl --context devzone -n "$NS" patch networkpolicy devzone-meme-namespace \
|
|
286
286
|
-p "$patch" 2>&1)"; then
|
|
287
|
-
echo "devzone : postgres :
|
|
287
|
+
echo "devzone : postgres : cannot remove the access rule of $ns: $out" >&2
|
|
288
288
|
return 1
|
|
289
289
|
fi
|
|
290
|
-
echo "devzone postgres
|
|
290
|
+
echo "devzone postgres: access forbidden from $ns to the PostgreSQL service"
|
|
291
291
|
}
|
|
292
292
|
|
|
293
293
|
case "${1:-}" in
|
|
294
|
-
install)
|
|
295
|
-
uninstall)
|
|
296
|
-
status)
|
|
297
|
-
create)
|
|
298
|
-
list)
|
|
299
|
-
psql)
|
|
300
|
-
delete)
|
|
301
|
-
relay-start)
|
|
302
|
-
relay-stop)
|
|
303
|
-
authorize)
|
|
304
|
-
forbid)
|
|
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
|
|
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 (
|
|
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="${
|
|
25
|
-
ETAT="${
|
|
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
|
|
@@ -34,9 +34,9 @@ refuse() {
|
|
|
34
34
|
exit 2
|
|
35
35
|
}
|
|
36
36
|
|
|
37
|
-
# shellcheck source=SCRIPTDIR/
|
|
37
|
+
# shellcheck source=SCRIPTDIR/state.sh
|
|
38
38
|
# shellcheck disable=SC1091
|
|
39
|
-
. "$HERE/
|
|
39
|
+
. "$HERE/state.sh"
|
|
40
40
|
|
|
41
41
|
action="${1:-}"
|
|
42
42
|
service="${2:-}"
|