Skip to content

Commit df44cf9

Browse files
committed
add tests and fix docs a bit
1 parent f75729a commit df44cf9

File tree

1 file changed

+87
-0
lines changed

1 file changed

+87
-0
lines changed

http/keycloak.http

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,3 +20,90 @@ Authorization: openid password env
2020
Content-Type: application/json
2121

2222
###
23+
24+
###
25+
# @name GET all users
26+
GET {{keycloakUrl}}/admin/realms/{{realm}}/users
27+
Authorization: openid password env
28+
Content-Type: application/json
29+
30+
###
31+
32+
### Benutzer holen, Fortschritt loggen, Liste am Ende ausgeben
33+
GET {{keycloakUrl}}/admin/realms/{{realm}}/users?max=3
34+
Authorization: openid password env
35+
Accept: application/json
36+
37+
###
38+
39+
@targetOu = 4AHIF
40+
@max = 3000
41+
### Benutzer abrufen mit Fortschrittsausgabe + reiner Namensliste
42+
GET {{keycloakUrl}}/admin/realms/{{realm}}/users?max={{max}}
43+
Authorization: openid password env
44+
Accept: application/json
45+
46+
> {%
47+
console.log("==> Starte Abruf der Benutzer...");
48+
const t0 = Date.now();
49+
50+
// Body ggf. parsen (abhängig von HTTP Yac-Version)
51+
let users;
52+
if (Array.isArray(response.body)) {
53+
users = response.body;
54+
} else if (typeof response.body === "string") {
55+
try {
56+
users = JSON.parse(response.body);
57+
} catch (e) {
58+
console.error("⚠️ Antwort ist kein gültiges JSON!");
59+
console.log(response.body);
60+
throw e;
61+
}
62+
} else {
63+
console.error("⚠️ Unerwarteter Typ von response.body:", typeof response.body);
64+
users = [];
65+
}
66+
67+
console.log(`==> Abruf fertig: ${users.length} Benutzer (${((Date.now()-t0)/1000).toFixed(1)} s)`);
68+
69+
const wantOu = "4AHIF";
70+
function inTargetOu(u) {
71+
if (!wantOu) return true;
72+
const dn = u.attributes?.LDAP_ENTRY_DN?.[0] || "";
73+
return dn.includes(`,OU=${wantOu},`);
74+
}
75+
76+
const total = users.length;
77+
const chunkSize = 100;
78+
console.log(`==> Verarbeite Benutzer in Blöcken von ${chunkSize}...`);
79+
let processed = 0;
80+
const lines = [];
81+
82+
for (let i = 0; i < total; i += chunkSize) {
83+
const chunk = users.slice(i, i + chunkSize);
84+
for (const u of chunk) {
85+
if (inTargetOu(u)) {
86+
const first = (u.firstName ?? "").trim();
87+
const last = (u.lastName ?? "").trim();
88+
const line = `${first} ${last}`.trim();
89+
if (line) lines.push(line);
90+
}
91+
}
92+
processed = Math.min(i + chunkSize, total);
93+
console.log(` ... verarbeitet: ${processed}/${total}`);
94+
}
95+
96+
console.log(`==> Fertig. Gefiltert: ${lines.length} Zeilen.`);
97+
if (wantOu) console.log(`==> OU-Filter aktiv: ${wantOu}`);
98+
99+
lines.sort((a,b) => a.localeCompare(b, "de", { sensitivity: "base" }));
100+
101+
console.log("\n=== KOPIERBARE LISTE ===");
102+
for (const line of lines) {
103+
console.log("@@@" + line);
104+
console.log("");
105+
console.log("@@@");
106+
}
107+
%}
108+
109+
###

0 commit comments

Comments
 (0)