mirror of
https://github.com/CommunitySolidServer/CommunitySolidServer.git
synced 2024-10-03 14:55:10 +00:00
feat: Support seeding pods and accounts
* feat(seeding): seed accounts and pods with seeded-pod-config.json * feat(seeding): dry up SeededPodInitializer by using RegistrationManager directly and make compatible with version/3.0.0 * feat(seeding): update seed config files to version 3.0.0 context * feat(seeding): simplify seeded-root config by importing pre-existing prefilled-root config * feat(seeding): Add seeding as a default initializer, update seeded pod copy and guide, change seeded pod config to array * feat(seeding): remove template info from seeded pod guide, use mockFs, code style nit, fix redlock test * feat(seeding): remove old config file
This commit is contained in:
52
src/init/SeededPodInitializer.ts
Normal file
52
src/init/SeededPodInitializer.ts
Normal file
@@ -0,0 +1,52 @@
|
||||
import { promises as fsPromises } from 'fs';
|
||||
import type { RegistrationManager } from '../identity/interaction/email-password/util/RegistrationManager';
|
||||
import { getLoggerFor } from '../logging/LogUtil';
|
||||
import { Initializer } from './Initializer';
|
||||
|
||||
/**
|
||||
* Uses a {@link RegistrationManager} to initialize accounts and pods
|
||||
* for all seeded pods. Reads the pod settings from seededPodConfigJson.
|
||||
*/
|
||||
export class SeededPodInitializer extends Initializer {
|
||||
protected readonly logger = getLoggerFor(this);
|
||||
|
||||
private readonly registrationManager: RegistrationManager;
|
||||
private readonly configFilePath: string | null;
|
||||
|
||||
public constructor(registrationManager: RegistrationManager, configFilePath: string | null) {
|
||||
super();
|
||||
this.registrationManager = registrationManager;
|
||||
this.configFilePath = configFilePath;
|
||||
}
|
||||
|
||||
public async handle(): Promise<void> {
|
||||
if (!this.configFilePath) {
|
||||
return;
|
||||
}
|
||||
const configText = await fsPromises.readFile(this.configFilePath, 'utf8');
|
||||
const configuration: NodeJS.Dict<unknown>[] = JSON.parse(configText);
|
||||
|
||||
let count = 0;
|
||||
for await (const input of configuration) {
|
||||
const config = {
|
||||
confirmPassword: input.password,
|
||||
createPod: true,
|
||||
createWebId: true,
|
||||
register: true,
|
||||
...input,
|
||||
};
|
||||
|
||||
this.logger.info(`Initializing pod ${input.podName}`);
|
||||
|
||||
// Validate the input JSON
|
||||
const validated = this.registrationManager.validateInput(config, true);
|
||||
this.logger.debug(`Validated input: ${JSON.stringify(validated)}`);
|
||||
|
||||
// Register and/or create a pod as requested. Potentially does nothing if all booleans are false.
|
||||
await this.registrationManager.register(validated, true);
|
||||
this.logger.info(`Initialized seeded pod and account for "${input.podName}".`);
|
||||
count += 1;
|
||||
}
|
||||
this.logger.info(`Initialized ${count} seeded pods.`);
|
||||
}
|
||||
}
|
||||
@@ -18,9 +18,14 @@ export class AssetPathExtractor extends SettingsExtractor {
|
||||
|
||||
public async handle(args: Settings): Promise<unknown> {
|
||||
const path = args[this.key] ?? this.defaultPath;
|
||||
if (typeof path !== 'string') {
|
||||
throw new Error(`Invalid ${this.key} argument`);
|
||||
if (path) {
|
||||
if (typeof path !== 'string') {
|
||||
throw new Error(`Invalid ${this.key} argument`);
|
||||
}
|
||||
|
||||
return resolveAssetPath(path);
|
||||
}
|
||||
return resolveAssetPath(path);
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user