Skip to content

Commit

Permalink
chore: add cli to create identity
Browse files Browse the repository at this point in the history
  • Loading branch information
sebbi08 committed Oct 17, 2024
1 parent 7ac5965 commit 34e7560
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 0 deletions.
33 changes: 33 additions & 0 deletions src/cli/commands/identity/init.ts
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!" };
}
}
11 changes: 11 additions & 0 deletions src/cli/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,20 @@

import yargs from "yargs";
import { configOptionBuilder } from "./BaseCommand";
import { yargsIdentityInitCommand } from "./commands/identity/init";
import { startConnectorHandler } from "./commands/start";

const argv = yargs(process.argv.slice(2))
.command({
command: "identity [command]",
describe: "identity related commands ",
builder: (yargs) => {
return yargs.command(yargsIdentityInitCommand);
},
handler: () => {
yargs.showHelp();
}
})
.command({
command: "start",
describe: "start the connector",
Expand Down

0 comments on commit 34e7560

Please sign in to comment.