Change structure
This commit is contained in:
parent
92b505dd56
commit
8d59fe7b67
File diff suppressed because it is too large
Load Diff
123
src/bin/start-keycloak/realmConfig/ParsedRealmJson.ts
Normal file
123
src/bin/start-keycloak/realmConfig/ParsedRealmJson.ts
Normal file
@ -0,0 +1,123 @@
|
|||||||
|
import { z } from "zod";
|
||||||
|
import { assert, type Equals } from "tsafe/assert";
|
||||||
|
import { is } from "tsafe/is";
|
||||||
|
import { id } from "tsafe/id";
|
||||||
|
import * as fs from "fs";
|
||||||
|
import { join as pathJoin } from "path";
|
||||||
|
import { getThisCodebaseRootDirPath } from "../../tools/getThisCodebaseRootDirPath";
|
||||||
|
|
||||||
|
export type ParsedRealmJson = {
|
||||||
|
name: string;
|
||||||
|
users: {
|
||||||
|
id: string;
|
||||||
|
email: string;
|
||||||
|
username: string;
|
||||||
|
attributes: Record<string, unknown>;
|
||||||
|
credentials: {
|
||||||
|
type: string /* "password" or something else */;
|
||||||
|
}[];
|
||||||
|
clientRoles: Record<string, string[]>;
|
||||||
|
}[];
|
||||||
|
roles: {
|
||||||
|
client: {
|
||||||
|
name: string;
|
||||||
|
containerId: string; // client id
|
||||||
|
}[];
|
||||||
|
};
|
||||||
|
clients: {
|
||||||
|
id: string;
|
||||||
|
clientId: string; // example: realm-management
|
||||||
|
baseUrl?: string;
|
||||||
|
redirectUris?: string[];
|
||||||
|
webOrigins?: string[];
|
||||||
|
attributes?: {
|
||||||
|
"post.logout.redirect.uris"?: string;
|
||||||
|
};
|
||||||
|
protocol?: string;
|
||||||
|
protocolMappers?: unknown[];
|
||||||
|
}[];
|
||||||
|
};
|
||||||
|
|
||||||
|
export function readRealmJsonFile(params: {
|
||||||
|
realmJsonFilePath: string;
|
||||||
|
}): ParsedRealmJson {
|
||||||
|
const { realmJsonFilePath } = params;
|
||||||
|
|
||||||
|
const parsedRealmJson = JSON.parse(
|
||||||
|
fs.readFileSync(realmJsonFilePath).toString("utf8")
|
||||||
|
) as unknown;
|
||||||
|
|
||||||
|
const zParsedRealmJson = (() => {
|
||||||
|
type TargetType = ParsedRealmJson;
|
||||||
|
|
||||||
|
const zTargetType = z.object({
|
||||||
|
name: z.string(),
|
||||||
|
users: z.array(
|
||||||
|
z.object({
|
||||||
|
id: z.string(),
|
||||||
|
email: z.string(),
|
||||||
|
username: z.string(),
|
||||||
|
attributes: z.record(z.unknown()),
|
||||||
|
credentials: z.array(
|
||||||
|
z.object({
|
||||||
|
type: z.string()
|
||||||
|
})
|
||||||
|
),
|
||||||
|
clientRoles: z.record(z.array(z.string()))
|
||||||
|
})
|
||||||
|
),
|
||||||
|
roles: z.object({
|
||||||
|
client: z.array(
|
||||||
|
z.object({
|
||||||
|
name: z.string(),
|
||||||
|
containerId: z.string()
|
||||||
|
})
|
||||||
|
)
|
||||||
|
}),
|
||||||
|
clients: z.array(
|
||||||
|
z.object({
|
||||||
|
id: z.string(),
|
||||||
|
clientId: z.string(),
|
||||||
|
baseUrl: z.string().optional(),
|
||||||
|
redirectUris: z.array(z.string()).optional(),
|
||||||
|
webOrigins: z.array(z.string()).optional(),
|
||||||
|
attributes: z
|
||||||
|
.object({
|
||||||
|
"post.logout.redirect.uris": z.string().optional()
|
||||||
|
})
|
||||||
|
.optional(),
|
||||||
|
protocol: z.string().optional(),
|
||||||
|
protocolMappers: z.array(z.unknown()).optional()
|
||||||
|
})
|
||||||
|
)
|
||||||
|
});
|
||||||
|
|
||||||
|
type InferredType = z.infer<typeof zTargetType>;
|
||||||
|
|
||||||
|
assert<Equals<TargetType, InferredType>>;
|
||||||
|
|
||||||
|
return id<z.ZodType<TargetType>>(zTargetType);
|
||||||
|
})();
|
||||||
|
|
||||||
|
zParsedRealmJson.parse(parsedRealmJson);
|
||||||
|
|
||||||
|
assert(is<ParsedRealmJson>(parsedRealmJson));
|
||||||
|
|
||||||
|
return parsedRealmJson;
|
||||||
|
}
|
||||||
|
|
||||||
|
export function getDefaultConfig(params: {
|
||||||
|
keycloakMajorVersionNumber: number;
|
||||||
|
}): ParsedRealmJson {
|
||||||
|
const { keycloakMajorVersionNumber } = params;
|
||||||
|
|
||||||
|
const realmJsonFilePath = pathJoin(
|
||||||
|
getThisCodebaseRootDirPath(),
|
||||||
|
"src",
|
||||||
|
"bin",
|
||||||
|
"start-keycloak",
|
||||||
|
`myrealm-realm-${keycloakMajorVersionNumber}.json`
|
||||||
|
);
|
||||||
|
|
||||||
|
return readRealmJsonFile({ realmJsonFilePath });
|
||||||
|
}
|
@ -1,11 +1,11 @@
|
|||||||
import { runPrettier, getIsPrettierAvailable } from "../tools/runPrettier";
|
import { runPrettier, getIsPrettierAvailable } from "../../tools/runPrettier";
|
||||||
import { CONTAINER_NAME } from "../shared/constants";
|
import { CONTAINER_NAME } from "../../shared/constants";
|
||||||
import child_process from "child_process";
|
import child_process from "child_process";
|
||||||
import { join as pathJoin } from "path";
|
import { join as pathJoin } from "path";
|
||||||
import chalk from "chalk";
|
import chalk from "chalk";
|
||||||
import { Deferred } from "evt/tools/Deferred";
|
import { Deferred } from "evt/tools/Deferred";
|
||||||
import { assert, is } from "tsafe/assert";
|
import { assert, is } from "tsafe/assert";
|
||||||
import type { BuildContext } from "../shared/buildContext";
|
import type { BuildContext } from "../../shared/buildContext";
|
||||||
import * as fs from "fs/promises";
|
import * as fs from "fs/promises";
|
||||||
|
|
||||||
export type BuildContextLike = {
|
export type BuildContextLike = {
|
||||||
@ -14,7 +14,7 @@ export type BuildContextLike = {
|
|||||||
|
|
||||||
assert<BuildContext extends BuildContextLike ? true : false>();
|
assert<BuildContext extends BuildContextLike ? true : false>();
|
||||||
|
|
||||||
export async function dumpRealmConfig(params: {
|
export async function dumpContainerConfig(params: {
|
||||||
realmName: string;
|
realmName: string;
|
||||||
keycloakMajorVersionNumber: number;
|
keycloakMajorVersionNumber: number;
|
||||||
targetRealmConfigJsonFilePath: string;
|
targetRealmConfigJsonFilePath: string;
|
@ -1,6 +1,35 @@
|
|||||||
import { assert } from "tsafe/assert";
|
import { assert } from "tsafe/assert";
|
||||||
import { getDefaultConfig, type ParsedRealmJson } from "./ParsedRealmJson";
|
import { getDefaultConfig, type ParsedRealmJson } from "./ParsedRealmJson";
|
||||||
|
|
||||||
|
export function prepareRealmConfig(params: {
|
||||||
|
parsedRealmJson: ParsedRealmJson;
|
||||||
|
keycloakMajorVersionNumber: number;
|
||||||
|
}): {
|
||||||
|
realmName: string;
|
||||||
|
clientName: string;
|
||||||
|
username: string;
|
||||||
|
} {
|
||||||
|
const { parsedRealmJson, keycloakMajorVersionNumber } = params;
|
||||||
|
|
||||||
|
const { username } = addOrEditTestUser({
|
||||||
|
parsedRealmJson,
|
||||||
|
keycloakMajorVersionNumber
|
||||||
|
});
|
||||||
|
|
||||||
|
const { clientId } = addOrEditClient({
|
||||||
|
parsedRealmJson,
|
||||||
|
keycloakMajorVersionNumber
|
||||||
|
});
|
||||||
|
|
||||||
|
editAccountConsoleAndSecurityAdminConsole({ parsedRealmJson });
|
||||||
|
|
||||||
|
return {
|
||||||
|
realmName: parsedRealmJson.name,
|
||||||
|
clientName: clientId,
|
||||||
|
username
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
function addOrEditTestUser(params: {
|
function addOrEditTestUser(params: {
|
||||||
parsedRealmJson: ParsedRealmJson;
|
parsedRealmJson: ParsedRealmJson;
|
||||||
keycloakMajorVersionNumber: number;
|
keycloakMajorVersionNumber: number;
|
||||||
@ -240,32 +269,3 @@ function editAccountConsoleAndSecurityAdminConsole(params: {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export function makeRealmConfigTestable(params: {
|
|
||||||
parsedRealmJson: ParsedRealmJson;
|
|
||||||
keycloakMajorVersionNumber: number;
|
|
||||||
}): {
|
|
||||||
realmName: string;
|
|
||||||
clientName: string;
|
|
||||||
username: string;
|
|
||||||
} {
|
|
||||||
const { parsedRealmJson, keycloakMajorVersionNumber } = params;
|
|
||||||
|
|
||||||
const { username } = addOrEditTestUser({
|
|
||||||
parsedRealmJson,
|
|
||||||
keycloakMajorVersionNumber
|
|
||||||
});
|
|
||||||
|
|
||||||
const { clientId } = addOrEditClient({
|
|
||||||
parsedRealmJson,
|
|
||||||
keycloakMajorVersionNumber
|
|
||||||
});
|
|
||||||
|
|
||||||
editAccountConsoleAndSecurityAdminConsole({ parsedRealmJson });
|
|
||||||
|
|
||||||
return {
|
|
||||||
realmName: parsedRealmJson.name,
|
|
||||||
clientName: clientId,
|
|
||||||
username
|
|
||||||
};
|
|
||||||
}
|
|
2548
src/bin/start-keycloak/realmConfig/realm-kc-26.json
Normal file
2548
src/bin/start-keycloak/realmConfig/realm-kc-26.json
Normal file
File diff suppressed because it is too large
Load Diff
Loading…
x
Reference in New Issue
Block a user