-
Notifications
You must be signed in to change notification settings - Fork 5
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
2 changed files
with
44 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
import { AccountController } from "@nmshd/transport"; | ||
import { CommandModule } from "yargs"; | ||
import { BaseCommand, ConfigFileOptions, configOptionBuilder } from "../../BaseCommand"; | ||
|
||
export const identityInitHandler = async ({ config }: ConfigFileOptions): Promise<void> => { | ||
await new IdentityInit().run(config); | ||
}; | ||
export const yargsIdentityInitCommand: CommandModule<{}, ConfigFileOptions> = { | ||
command: "init", | ||
describe: "initialize the identity", | ||
handler: identityInitHandler, | ||
builder: configOptionBuilder | ||
}; | ||
|
||
export default class IdentityInit extends BaseCommand { | ||
public async runInternal(): Promise<{ message: string }> { | ||
if (!this.transport || !this.connectorConfig) { | ||
throw new Error("Transport or connectorConfig not initialized"); | ||
} | ||
const db = await this.transport.createDatabase(`${this.connectorConfig.database.dbNamePrefix}${this.connectorConfig.database.dbName}`); | ||
const identityCollection = await db.getMap("AccountInfo"); | ||
const identity = await identityCollection.get("identity"); | ||
if (identity) { | ||
this.log.log("Identity already created!"); | ||
return { message: "Identity already created!" }; | ||
} | ||
const accountController = new AccountController(this.transport, db, this.transport.config); | ||
await accountController.init(); | ||
|
||
this.log.log("Identity created successfully!"); | ||
return { message: "Identity created successfully!" }; | ||
} | ||
} |
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