Skip to content

Commit 18a0a95

Browse files
authored
Refactor Dokuwiki configuration to use secrets.env (#44)
NethServer/dev#7514
1 parent c83ac05 commit 18a0a95

File tree

6 files changed

+32
-21
lines changed

6 files changed

+32
-21
lines changed

imageroot/actions/configure-module/20configure

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,6 @@ else:
5252
# Setup configuration from user input.
5353
agent.set_env("DOKUWIKI_WIKI_NAME", wiki_name)
5454
agent.set_env("DOKUWIKI_USERNAME", username)
55-
agent.set_env("DOKUWIKI_PASSWORD", password)
5655
agent.set_env("DOKUWIKI_EMAIL", email)
5756
agent.set_env("DOKUWIKI_FULL_NAME", full_name)
5857

@@ -63,3 +62,9 @@ agent.set_env("PHP_TIMEZONE", "UTC")
6362

6463
# Setup LDAP domain
6564
agent.set_env("LDAP_DOMAIN", ldap_domain)
65+
66+
# setup dokuwiki password
67+
secrets_env = {
68+
"DOKUWIKI_PASSWORD": password,
69+
}
70+
agent.write_envfile("secrets.env", secrets_env)

imageroot/actions/get-configuration/20read

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -35,15 +35,16 @@ config = {}
3535

3636
# Read current configuration from Redis
3737
env = f'module/{os.environ["MODULE_ID"]}/environment'
38-
rdb = agent.redis_connect()
39-
config["wiki_name"] = rdb.hget(env, "DOKUWIKI_WIKI_NAME")
40-
config["username"] = rdb.hget(env, "DOKUWIKI_USERNAME");
41-
config["password"] = rdb.hget(env, "DOKUWIKI_PASSWORD");
42-
config["email"] = rdb.hget(env, "DOKUWIKI_EMAIL");
43-
config["user_full_name"] = rdb.hget(env, "DOKUWIKI_FULL_NAME");
44-
config["host"] = rdb.hget(env, "TRAEFIK_HOST");
45-
config["http2https"] = rdb.hget(env, "TRAEFIK_HTTP2HTTPS") == "True";
46-
config["lets_encrypt"] = rdb.hget(env, "TRAEFIK_LETS_ENCRYPT") == "True";
38+
config["wiki_name"] = os.getenv("DOKUWIKI_WIKI_NAME")
39+
config["username"] = os.getenv("DOKUWIKI_USERNAME");
40+
41+
config["password"] = agent.read_envfile("secrets.env")["DOKUWIKI_PASSWORD"] if os.path.exists("secrets.env") else None
42+
43+
config["email"] = os.getenv("DOKUWIKI_EMAIL");
44+
config["user_full_name"] = os.getenv("DOKUWIKI_FULL_NAME");
45+
config["host"] = os.getenv("TRAEFIK_HOST");
46+
config["http2https"] = os.getenv("TRAEFIK_HTTP2HTTPS") == "True";
47+
config["lets_encrypt"] = os.getenv("TRAEFIK_LETS_ENCRYPT") == "True";
4748
# retrieve LDAP domains list
4849
lp = Ldapproxy()
4950
domains = []

imageroot/actions/restore-module/06copyenv

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@ for evar in [
3232
"DOKUWIKI_EMAIL",
3333
"DOKUWIKI_FULL_NAME",
3434
"DOKUWIKI_IMAGE",
35-
"DOKUWIKI_PASSWORD",
3635
"DOKUWIKI_USERNAME",
3736
"DOKUWIKI_WIKI_NAME",
3837
"PHP_ENABLE_OPCACHE",

imageroot/bin/push-configuration

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@
77

88
set -e
99

10+
# Load environment variables, if available and protect against shell special chars.
11+
DOKUWIKI_PASSWORD=$(grep '^DOKUWIKI_PASSWORD=' ./secrets.env) && export "${DOKUWIKI_PASSWORD?}"
12+
1013
if ! podman exec dokuwiki ls /storage/conf/local.php >/dev/null 2>&1; then
1114
echo "We init the first configuration of Dokuwiki by the install PHP script"
1215
curl -s -o /dev/null -X POST "http://127.0.0.1:${TCP_PORT}/install.php" \

imageroot/etc/state-include.conf

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,4 @@
44
# Restic --files-from: https://restic.readthedocs.io/en/stable/040_backup.html#including-files
55
#
66
volumes/dokuwiki-data
7+
state/secrets.env
Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,17 @@
1-
#!/bin/bash
1+
#!/usr/bin/env python3
22

33
#
4-
# Copyright (C) 2023 Nethesis S.r.l.
4+
# Copyright (C) 2025 Nethesis S.r.l.
55
# SPDX-License-Identifier: GPL-3.0-or-later
66
#
7+
import os
8+
import agent
79

8-
exec 1>&2
9-
10-
# we need to create a log folder for the upgrade to 20230404
11-
if [[ "$PREV_DOKUWIKI_IMAGE" == "docker.io/bitnami/dokuwiki:20200729.0.0-debian-10-r299" ]]; then
12-
/usr/bin/podman run -d --rm --name dokuwiki_upgrade -v dokuwiki-data:/bitnami/dokuwiki:z ${DOKUWIKI_IMAGE}
13-
/usr/bin/podman exec -ti dokuwiki_upgrade mkdir -vp /bitnami/dokuwiki/data/log
14-
/usr/bin/podman stop dokuwiki_upgrade
15-
fi
10+
# test if the secrets.env is not present
11+
if not os.path.exists("secrets.env"):
12+
# if not present, create it
13+
passwords = {
14+
"DOKUWIKI_PASSWORD": os.environ["DOKUWIKI_PASSWORD"],
15+
}
16+
agent.write_envfile("secrets.env", passwords)
17+
agent.unset_env("DOKUWIKI_PASSWORD")

0 commit comments

Comments
 (0)