-
Notifications
You must be signed in to change notification settings - Fork 122
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(seeding): Add seeding as a default initializer, update seeded po…
…d copy and guide, change seeded pod config to array
- Loading branch information
1 parent
27a7fe7
commit 2dd0603
Showing
20 changed files
with
138 additions
and
138 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
{ | ||
"@context": "https://linkedsoftwaredependencies.org/bundles/npm/@solid/community-server/^3.0.0/components/context.jsonld", | ||
"@graph": [ | ||
{ | ||
"comment": "Separate manager from the RegistrationHandler in case registration is disabled.", | ||
"@id": "urn:solid-server:default:SeededPodRegistrationManager", | ||
"@type": "RegistrationManager", | ||
"args_baseUrl": { "@id": "urn:solid-server:default:variable:baseUrl" }, | ||
"args_webIdSuffix": "/profile/card#me", | ||
"args_identifierGenerator": { "@id": "urn:solid-server:default:IdentifierGenerator" }, | ||
"args_ownershipValidator": { "@id": "urn:solid-server:auth:password:OwnershipValidator" }, | ||
"args_accountStore": { "@id": "urn:solid-server:auth:password:AccountStore" }, | ||
"args_podManager": { "@id": "urn:solid-server:default:PodManager" } | ||
}, | ||
{ | ||
"comment": "Initializer that instantiates all the seeded accounts and pods.", | ||
"@id": "urn:solid-server:default:SeededPodInitializer", | ||
"@type": "SeededPodInitializer", | ||
"registrationManager": { "@id": "urn:solid-server:default:SeededPodRegistrationManager" }, | ||
"configFilePath": { "@id": "urn:solid-server:default:variable:seededPodConfigJson" }, | ||
} | ||
] | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
# How to seed Accounts and Pods | ||
If you need to seed accounts and pods, set the `--seededPodConfigJson` option to a file such as `./seeded-pod-config.json` to set your desired accounts and pods. The contents of `./seeded-pod-config.json` (or whatever file name you choose) should be a JSON array whose entries are objects which include | ||
`podName`, `email`, and `password`. For example: | ||
```json | ||
[ | ||
{ | ||
"podName": "example", | ||
"email": "hello@example.com", | ||
"password": "abc123" | ||
} | ||
] | ||
``` | ||
|
||
You may optionally specify other parameters accepted by the `register` method of [RegistrationManager](https://github.com/solid/community-server/blob/3b353affb1f0919fdcb66172364234eb59c2e3f6/src/identity/interaction/email-password/util/RegistrationManager.ts#L173). For example: | ||
|
||
To use a pre-existing wedId: | ||
```json | ||
createWebId: false, | ||
webId: "https://pod.inrupt.com/example/profile/card#me" | ||
``` | ||
|
||
To use a specific pod template: | ||
```json | ||
template: "./templates/custom_pod_template" | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,55 +1,51 @@ | ||
import { promises as fsPromises } from 'fs'; | ||
import type { RegistrationManager } from '../identity/interaction/email-password/util/RegistrationManager'; | ||
import { getLoggerFor } from '../logging/LogUtil'; | ||
import type { KeyValueStorage } from '../storage/keyvalue/KeyValueStorage'; | ||
import { Initializer } from './Initializer'; | ||
|
||
export interface SeederPodInitializerArgs { | ||
/** | ||
* Used for registering seeded pods. | ||
*/ | ||
registrationManager: RegistrationManager; | ||
/** | ||
* Settings that the seeded Pods should be created with. | ||
*/ | ||
configStorage: KeyValueStorage<string, unknown>; | ||
} | ||
|
||
/** | ||
* Uses a {@link RegistrationManager} to initializes accounts and pods | ||
* 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 configStorage: KeyValueStorage<string, unknown>; | ||
private readonly configFilePath: string | null; | ||
|
||
public constructor(args: SeederPodInitializerArgs) { | ||
public constructor(registrationManager: RegistrationManager, configFilePath: string | null) { | ||
super(); | ||
this.registrationManager = args.registrationManager; | ||
this.configStorage = args.configStorage; | ||
this.registrationManager = registrationManager; | ||
this.configFilePath = configFilePath; | ||
} | ||
|
||
public async handle(): Promise<void> { | ||
let count = 0; | ||
for await (const [ , value ] of this.configStorage.entries()) { | ||
const config = value as NodeJS.Dict<unknown>; | ||
config.confirmPassword = config.password; | ||
config.createPod = true; | ||
config.createWebId = true; | ||
config.register = true; | ||
|
||
this.logger.info(`Initializing pod ${config.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 "${config.podName}".`); | ||
count += 1; | ||
if (this.configFilePath) { | ||
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.`); | ||
} | ||
this.logger.info(`Initialized ${count} seeded pods.`); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.