Add the identity init command to the Connector CLI#343
Add the identity init command to the Connector CLI#343
identity init command to the Connector CLI#343Conversation
src/cli/BaseCommand.ts
Outdated
| protected async createTransport(): Promise<void> { | ||
| if (this.transport) { | ||
| return; | ||
| } | ||
| if (!this.connectorConfig) throw new Error("Connector config not initialized"); | ||
| const eventBus = new EventEmitter2EventBus(() => { | ||
| // ignore errors | ||
| }); | ||
| const logger = new NodeLoggerFactory(this.connectorConfig.logging); | ||
| this.databaseConnection = await BaseCommand.createDBConnection(this.connectorConfig); | ||
|
|
||
| this.transport = new Transport(this.databaseConnection, { ...this.connectorConfig.transportLibrary, supportedIdentityVersion: 1 }, eventBus, logger); | ||
| await this.transport.init(); | ||
| } | ||
|
|
||
| public static async createDBConnection(runtimeConfig: ConnectorRuntimeConfig): Promise<IDatabaseConnection> { | ||
| if (runtimeConfig.database.driver === "lokijs") { | ||
| if (!runtimeConfig.debug) throw new Error("LokiJS is only available in debug mode."); | ||
|
|
||
| const folder = runtimeConfig.database.folder; | ||
| if (!folder) throw new Error("No folder provided for LokiJS database."); | ||
|
|
||
| return new LokiJsConnection(folder, undefined, { autoload: true, autosave: true, persistenceMethod: "fs" }); | ||
| } | ||
|
|
||
| if (!runtimeConfig.database.connectionString) { | ||
| throw new Error(`No database connection string provided. See ${DocumentationLink.operate__configuration("database")} on how to configure the database connection.`); | ||
| } | ||
|
|
||
| const mongodbConnection = new MongoDbConnection(runtimeConfig.database.connectionString); | ||
|
|
||
| try { | ||
| await mongodbConnection.connect(); | ||
| } catch (e) { | ||
| throw new Error(`Could not connect to the configured database. Try to check the connection string and the database status. Root error: ${e}`); | ||
| } | ||
| return mongodbConnection; | ||
| } |
There was a problem hiding this comment.
@jkoenig134 I currently don't like this as it duplicates the DB creation code from the ConnectorRuntime.
Best would be to export the DB creation out of the ConnectorRuntime, but don't know where it fits best
There was a problem hiding this comment.
WTB just starting the runtime with allowIdentityCreation set to true in this command? Then the runtime does the rest.
There was a problem hiding this comment.
Yea, but we then could not distinguish if the identity already existed or if it was just created. Don't know if we need that, but yea, that would make it way easier.
There was a problem hiding this comment.
I'll think about it. I like the idea to throw an error if the identity already exists..
There was a problem hiding this comment.
I now build it so that the already thrown exception is used.
I don't think that throwing an exception when the identity already exists is a good idea because we would need an exception for our test, or rewrite all that "reuse" an existing identity
Codecov ReportAttention: Patch coverage is
|
|
I put this back to draft as it will not land in v7 |
Readiness checklist