-
Notifications
You must be signed in to change notification settings - Fork 125
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
21 changed files
with
206 additions
and
8 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 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,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 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 |
---|---|---|
@@ -0,0 +1,51 @@ | ||
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) { | ||
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 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
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,46 @@ | ||
import fs from 'fs'; | ||
import type { RegistrationManager } from '../../../src/identity/interaction/email-password/util/RegistrationManager'; | ||
import { SeededPodInitializer } from '../../../src/init/SeededPodInitializer'; | ||
|
||
jest.mock('fs'); | ||
const mockFs = fs as jest.Mocked<typeof fs>; | ||
|
||
describe('A SeededPodInitializer', (): void => { | ||
const dummyConfig = JSON.stringify([ | ||
{ | ||
podName: 'example', | ||
email: 'hello@example.com', | ||
password: 'abc123', | ||
}, | ||
{ | ||
podName: 'example2', | ||
email: 'hello2@example.com', | ||
password: '123abc', | ||
}, | ||
]); | ||
let registrationManager: RegistrationManager; | ||
let configFilePath: string | null; | ||
|
||
beforeEach(async(): Promise<void> => { | ||
configFilePath = './seeded-pod-config.json'; | ||
registrationManager = { | ||
validateInput: jest.fn((input): any => input), | ||
register: jest.fn(), | ||
} as any; | ||
|
||
(mockFs.promises as unknown) = { readFile: jest.fn().mockResolvedValue(dummyConfig) }; | ||
}); | ||
|
||
it('does not generate any accounts or pods if no config file is specified.', async(): Promise<void> => { | ||
configFilePath = null; | ||
await new SeededPodInitializer(registrationManager, configFilePath).handle(); | ||
expect(registrationManager.validateInput).not.toHaveBeenCalled(); | ||
expect(registrationManager.register).not.toHaveBeenCalled(); | ||
}); | ||
|
||
it('generates an account and a pod for every entry in the seeded pod configuration.', async(): Promise<void> => { | ||
await new SeededPodInitializer(registrationManager, configFilePath).handle(); | ||
expect(registrationManager.validateInput).toHaveBeenCalledTimes(2); | ||
expect(registrationManager.register).toHaveBeenCalledTimes(2); | ||
}); | ||
}); |
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