poad 2.10.0 → 2.10.2
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/package.json +1 -1
- package/project/info.js +5 -1
- package/utils/keycloak.js +27 -4
- package/utils/services.js +30 -5
package/package.json
CHANGED
package/project/info.js
CHANGED
|
@@ -49,7 +49,11 @@ module.exports = async () => {
|
|
|
49
49
|
const label = chalk.bold(s.label.padEnd(width));
|
|
50
50
|
if (running) {
|
|
51
51
|
console.log(`${chalk.greenBright('●')} ${label} ${chalk.greenBright('running')}`);
|
|
52
|
-
for (const [k, v] of Object.entries(s.info(config)))
|
|
52
|
+
for (const [k, v] of Object.entries(s.info(config, root))) {
|
|
53
|
+
// Une liste (comptes de test) : une ligne par entrée, alignées
|
|
54
|
+
const lines = Array.isArray(v) ? v : [v];
|
|
55
|
+
lines.forEach((l, i) => console.log(` ${chalk.grey((i ? '' : k).padEnd(16))} ${l}`));
|
|
56
|
+
}
|
|
53
57
|
} else if (configured) {
|
|
54
58
|
const how = s.optional ? `poad run ${s.cmd}` : 'poad stop && poad start';
|
|
55
59
|
console.log(`${chalk.yellowBright('○')} ${label} ${chalk.yellowBright('stopped')} ${chalk.grey(`(${how})`)}`);
|
package/utils/keycloak.js
CHANGED
|
@@ -30,6 +30,15 @@ const containerName = (config) => `${config.project_uuid}-keycloak`;
|
|
|
30
30
|
const dataDir = (root) => path.join(path.dirname(root), 'data', 'keycloak');
|
|
31
31
|
const random = (n) => crypto.randomBytes(n).toString('base64url');
|
|
32
32
|
|
|
33
|
+
/**
|
|
34
|
+
* Mot de passe à recopier : lettres et chiffres seulement. Un « - » ou un
|
|
35
|
+
* « _ » coupe la sélection au double-clic dans un terminal, et le mot de
|
|
36
|
+
* passe collé est alors tronqué.
|
|
37
|
+
*/
|
|
38
|
+
const ALNUM = 'ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz23456789';
|
|
39
|
+
const typeable = (n) => Array.from({ length: n }, () => ALNUM[crypto.randomInt(ALNUM.length)]).join('');
|
|
40
|
+
const isTypeable = (p) => typeof p === 'string' && /^[A-Za-z0-9]+$/.test(p);
|
|
41
|
+
|
|
33
42
|
/** Le drapeau désigne-t-il Keycloak ? ({ kc: true }, { keycloak: true }) */
|
|
34
43
|
const wanted = (args = {}) => NAMES.some((n) => args[n]);
|
|
35
44
|
|
|
@@ -69,19 +78,33 @@ const loadSecrets = (dir) => {
|
|
|
69
78
|
const file = path.join(dir, 'users.json');
|
|
70
79
|
if (fs.existsSync(file)) {
|
|
71
80
|
const secrets = JSON.parse(fs.readFileSync(file, 'utf-8'));
|
|
81
|
+
let changed = false;
|
|
72
82
|
if (!secrets.signing_key) {
|
|
73
83
|
secrets.signing_key = rsaKey();
|
|
74
|
-
|
|
84
|
+
changed = true;
|
|
85
|
+
}
|
|
86
|
+
// Anciens mots de passe (base64url, avec « - » ou « _ ») : remplacés. Sans
|
|
87
|
+
// risque ici : Keycloak est recréé et son realm réimporté juste après.
|
|
88
|
+
if (!isTypeable(secrets.admin_password)) {
|
|
89
|
+
secrets.admin_password = typeable(16);
|
|
90
|
+
changed = true;
|
|
91
|
+
}
|
|
92
|
+
for (const u of secrets.users || []) {
|
|
93
|
+
if (!isTypeable(u.password)) {
|
|
94
|
+
u.password = typeable(12);
|
|
95
|
+
changed = true;
|
|
96
|
+
}
|
|
75
97
|
}
|
|
98
|
+
if (changed) fs.writeFileSync(file, JSON.stringify(secrets, null, 2) + '\n', { mode: 0o600 });
|
|
76
99
|
return { file, secrets };
|
|
77
100
|
}
|
|
78
101
|
const secrets = {
|
|
79
102
|
signing_key: rsaKey(),
|
|
80
103
|
client_secret: random(24),
|
|
81
|
-
admin_password:
|
|
104
|
+
admin_password: typeable(16),
|
|
82
105
|
users: [
|
|
83
|
-
{ username: 'alice', email: 'alice@poad.test', password:
|
|
84
|
-
{ username: 'bob', email: 'bob@poad.test', password:
|
|
106
|
+
{ username: 'alice', email: 'alice@poad.test', password: typeable(12), emailVerified: true },
|
|
107
|
+
{ username: 'bob', email: 'bob@poad.test', password: typeable(12), emailVerified: false },
|
|
85
108
|
],
|
|
86
109
|
};
|
|
87
110
|
fs.mkdirSync(dir, { recursive: true });
|
package/utils/services.js
CHANGED
|
@@ -8,6 +8,17 @@
|
|
|
8
8
|
const kc = require('./keycloak');
|
|
9
9
|
const valkey = require('./valkey');
|
|
10
10
|
const mail = require('./mail');
|
|
11
|
+
const fs = require('fs');
|
|
12
|
+
const path = require('path');
|
|
13
|
+
|
|
14
|
+
const readKeycloakUsers = (root) => {
|
|
15
|
+
if (!root) return null;
|
|
16
|
+
try {
|
|
17
|
+
return JSON.parse(fs.readFileSync(path.join(kc.dataDir(root), 'users.json'), 'utf-8'));
|
|
18
|
+
} catch {
|
|
19
|
+
return null;
|
|
20
|
+
}
|
|
21
|
+
};
|
|
11
22
|
|
|
12
23
|
const SERVICES = [
|
|
13
24
|
{
|
|
@@ -26,11 +37,25 @@ const SERVICES = [
|
|
|
26
37
|
cmd: 'kc',
|
|
27
38
|
container: (config) => kc.containerName(config),
|
|
28
39
|
configured: (config) => Boolean(config.keycloak && config.keycloak.port),
|
|
29
|
-
info: (config) =>
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
40
|
+
info: (config, root) => {
|
|
41
|
+
const out = {
|
|
42
|
+
URL: `http://localhost:${config.keycloak.port}`,
|
|
43
|
+
Issuer: `http://localhost:${config.keycloak.port}/realms/${kc.REALM}`,
|
|
44
|
+
Provider: `"${kc.PROVIDER}"`,
|
|
45
|
+
};
|
|
46
|
+
// Comptes de test du realm (poad/data/keycloak/users.json) : locaux, faits pour être affichés
|
|
47
|
+
const users = readKeycloakUsers(root);
|
|
48
|
+
if (users) {
|
|
49
|
+
const base = `http://localhost:${config.keycloak.port}`;
|
|
50
|
+
// Deux realms, deux usages : ne pas essayer alice sur la console d'admin
|
|
51
|
+
out['Admin console'] = [`${base}/admin`, `admin ${users.admin_password}`];
|
|
52
|
+
out['Test users'] = [
|
|
53
|
+
`realm "${kc.REALM}" : "Continuer avec Keycloak" in the app, or ${base}/realms/${kc.REALM}/account`,
|
|
54
|
+
...users.users.map((u) => `${u.username.padEnd(6)} ${u.password} ${u.email}${u.emailVerified ? '' : ' (email not verified)'}`),
|
|
55
|
+
];
|
|
56
|
+
}
|
|
57
|
+
return out;
|
|
58
|
+
},
|
|
34
59
|
},
|
|
35
60
|
{
|
|
36
61
|
id: 'valkey',
|