-
Notifications
You must be signed in to change notification settings - Fork 5
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add the identity init
command to the Connector CLI
#343
base: main
Are you sure you want to change the base?
Conversation
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll think about it. I like the idea to throw an error if the identity already exists..
Codecov ReportAttention: Patch coverage is
|
Readiness checklist