completed sync script update keycloak
This commit is contained in:
parent
a487b73c3b
commit
625885973e
13 changed files with 1867 additions and 466 deletions
93
scripts/sync-all.ts
Normal file
93
scripts/sync-all.ts
Normal file
|
|
@ -0,0 +1,93 @@
|
|||
import "dotenv/config";
|
||||
import { AppDataSource } from "../src/database/data-source";
|
||||
import { KeycloakAttributeService } from "../src/services/KeycloakAttributeService";
|
||||
import * as keycloak from "../src/keycloak/index";
|
||||
|
||||
/**
|
||||
* Main function
|
||||
*/
|
||||
async function main() {
|
||||
const args = process.argv.slice(2);
|
||||
const dryRun = args.includes("--dry-run");
|
||||
const limitArg = args.find((arg) => arg.startsWith("--limit="));
|
||||
const limit = limitArg ? parseInt(limitArg.split("=")[1], 10) : undefined;
|
||||
const concurrencyArg = args.find((arg) => arg.startsWith("--concurrency="));
|
||||
const concurrency = concurrencyArg ? parseInt(concurrencyArg.split("=")[1], 10) : undefined;
|
||||
|
||||
console.log("=".repeat(60));
|
||||
console.log("Sync All Attributes to Keycloak Script");
|
||||
console.log("=".repeat(60));
|
||||
console.log(`Mode: ${dryRun ? "DRY-RUN (no changes)" : "LIVE"}`);
|
||||
if (limit !== undefined) {
|
||||
console.log(`Limit: ${limit} profiles per table (for testing)`);
|
||||
}
|
||||
if (concurrency !== undefined) {
|
||||
console.log(`Concurrency: ${concurrency}`);
|
||||
}
|
||||
console.log("");
|
||||
|
||||
console.log("Attributes to sync:");
|
||||
console.log(" - profileId");
|
||||
console.log(" - orgRootDnaId");
|
||||
console.log(" - orgChild1DnaId");
|
||||
console.log(" - orgChild2DnaId");
|
||||
console.log(" - orgChild3DnaId");
|
||||
console.log(" - orgChild4DnaId");
|
||||
console.log(" - empType");
|
||||
console.log(" - prefix");
|
||||
console.log("");
|
||||
|
||||
// Initialize database
|
||||
try {
|
||||
await AppDataSource.initialize();
|
||||
console.log("Database connected");
|
||||
} catch (error) {
|
||||
console.error("Failed to connect to database:", error);
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
// Validate Keycloak connection
|
||||
try {
|
||||
await keycloak.getToken();
|
||||
console.log("Keycloak connected");
|
||||
} catch (error) {
|
||||
console.error("Failed to connect to Keycloak:", error);
|
||||
await AppDataSource.destroy();
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
console.log("");
|
||||
|
||||
// Run the sync operation
|
||||
const service = new KeycloakAttributeService();
|
||||
console.log("Syncing attributes for all profiles with Keycloak IDs...");
|
||||
console.log("");
|
||||
|
||||
const result = await service.batchSyncUsers({ limit, concurrency });
|
||||
|
||||
// Summary
|
||||
console.log("");
|
||||
console.log("=".repeat(60));
|
||||
console.log("Summary:");
|
||||
console.log(` Total profiles: ${result.total}`);
|
||||
console.log(` Success: ${result.success}`);
|
||||
console.log(` Failed: ${result.failed}`);
|
||||
console.log("=".repeat(60));
|
||||
|
||||
if (result.failed > 0) {
|
||||
console.log("");
|
||||
console.log("Failed Details:");
|
||||
for (const detail of result.details.filter(
|
||||
(d) => d.status === "failed" || d.status === "error",
|
||||
)) {
|
||||
console.log(
|
||||
` ${detail.profileId} (${detail.keycloakUserId}): ${detail.error || "Sync failed"}`,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
// Cleanup
|
||||
await AppDataSource.destroy();
|
||||
}
|
||||
|
||||
main().catch(console.error);
|
||||
Loading…
Add table
Add a link
Reference in a new issue