changed crypto setting initilization
MODIFY
src/integration/billing/stripe/StripeBillingIntegration.ts
src/integration/billing/stripe/StripeBillingIntegration.ts
@@ -38,7 +38,7 @@ export default class StripeBillingIntegration extends BillingIntegration<StripeB
}
public async checkConnection(): Promise<void> {
- // Check Stripe
+ // Initialize Stripe
await this.initializeStripe();
// Check Key
if (!this.settings.secretKey) {

MODIFY
src/server/rest/v1/service/TenantService.ts
src/server/rest/v1/service/TenantService.ts
import { Action, Entity } from '../../../../types/Authorization';
+import { CryptoSettingsType, KeySetting, SettingDB, SettingDBContent } from '../../../../types/Setting';
import { HTTPAuthError, HTTPError } from '../../../../types/HTTPError';
import { NextFunction, Request, Response } from 'express';
-import { SettingDB, SettingDBContent } from '../../../../types/Setting';
import Tenant, { TenantLogo } from '../../../../types/Tenant';
import User, { UserRole } from '../../../../types/User';
@@ -17,6 +17,7 @@ import { ServerAction } from '../../../../types/Server';
import SettingStorage from '../../../../storage/mongodb/SettingStorage';
import SiteAreaStorage from '../../../../storage/mongodb/SiteAreaStorage';
import { StatusCodes } from 'http-status-codes';
+import TenantComponents from '../../../../types/TenantComponents';
import TenantStorage from '../../../../storage/mongodb/TenantStorage';
import TenantValidator from '../validator/TenantValidation';
import UserStorage from '../../../../storage/mongodb/UserStorage';
@@ -163,6 +164,28 @@ export default class TenantService {
next();
}
+ public static async createInitialSettingsForTenant(tenantID: string): Promise<void> {
+ await this.createInitialCryptoSetting(tenantID);
+ }
+
+ public static async createInitialCryptoSetting(tenantID: string): Promise<void> {
+ // Check for settings in db
+ const keySettings = await SettingStorage.getCryptoSettings(tenantID);
+ // Generate Crypto Key Settings
+ if (!keySettings) {
+ const keySettingToSave = {
+ identifier: TenantComponents.CRYPTO,
+ type: CryptoSettingsType.CRYPTO,
+ crypto: {
+ key: Utils.generateKey(),
+ keyProperties: Utils.getDefaultKeyProperties()
+ }
+ } as KeySetting;
+ // Save Crypto Key Settings
+ await SettingStorage.saveCryptoSettings(tenantID, keySettingToSave);
+ }
+ }
+
public static async handleCreateTenant(action: ServerAction, req: Request, res: Response, next: NextFunction): Promise<void> {
// Validate
const filteredRequest = TenantValidator.getInstance().validateTenantCreateRequestSuperAdmin(req.body);
@@ -212,6 +235,8 @@ export default class TenantService {
if (await LockingManager.acquire(createDatabaseLock)) {
try {
await TenantStorage.createTenantDB(filteredRequest.id);
+ // Create initial settings for tenant
+ await TenantService.createInitialSettingsForTenant(filteredRequest.id);
} finally {
// Release the database creation Lock
await LockingManager.release(createDatabaseLock);

MODIFY
src/storage/mongodb/MongoDBStorage.ts
src/storage/mongodb/MongoDBStorage.ts
import { ChangeStream, ChangeStreamOptions, ClientSession, Collection, Db, GridFSBucket, MongoClient } from 'mongodb';
-import { CryptoSettingsType, KeySetting } from '../../types/Setting';
import BackendError from '../../exception/BackendError';
import Configuration from '../../utils/Configuration';
@@ -10,9 +9,7 @@ import LockingManager from '../../locking/LockingManager';
import Logging from '../../utils/Logging';
import MigrationConfiguration from '../../types/configuration/MigrationConfiguration';
import { ServerAction } from '../../types/Server';
-import SettingStorage from './SettingStorage';
import StorageCfg from '../../types/configuration/StorageConfiguration';
-import TenantComponents from '../../types/TenantComponents';
import Utils from '../../utils/Utils';
import cluster from 'cluster';
import mongoUriBuilder from 'mongo-uri-builder';
@@ -165,28 +162,6 @@ export default class MongoDBStorage {
});
}
- public async createInitialSettingsForTenant(tenantID: string): Promise<void> {
- await this.createInitialCryptoSetting(tenantID);
- }
-
- public async createInitialCryptoSetting(tenantID: string): Promise<void> {
- // Check for settings in db
- const keySettings = await SettingStorage.getCryptoSettings(tenantID);
- // Generate Crypto Key Settings
- if (!keySettings) {
- const keySettingToSave = {
- identifier: TenantComponents.CRYPTO,
- type: CryptoSettingsType.CRYPTO,
- crypto: {
- key: Utils.generateKey(),
- keyProperties: Utils.getDefaultKeyProperties()
- }
- } as KeySetting;
- // Save Crypto Key Settings
- await SettingStorage.saveCryptoSettings(tenantID, keySettingToSave);
- }
- }
-
public async deleteTenantDatabase(tenantID: string): Promise<void> {
// Not the Default tenant
if (tenantID !== Constants.DEFAULT_TENANT) {

MODIFY
src/storage/mongodb/TenantStorage.ts
src/storage/mongodb/TenantStorage.ts
@@ -121,8 +121,6 @@ export default class TenantStorage {
const uniqueTimerID = Logging.traceStart(tenantID, MODULE_NAME, 'createTenantDB');
// Create tenant collections
await global.database.checkAndCreateTenantDatabase(tenantID);
- // Create initial settings for tenant
- await global.database.createInitialSettingsForTenant(tenantID);
// Debug
Logging.traceEnd(tenantID, MODULE_NAME, 'createTenantDB', uniqueTimerID, { tenantID });
}

MODIFY
src/utils/Cypher.ts
src/utils/Cypher.ts
@@ -2,6 +2,7 @@ import BackendError from '../exception/BackendError';
import Constants from './Constants';
import { CryptoSetting } from '../types/Setting';
import SettingStorage from '../storage/mongodb/SettingStorage';
+import TenantStorage from '../storage/mongodb/TenantStorage';
import Utils from './Utils';
import _ from 'lodash';
import crypto from 'crypto';
@@ -136,11 +137,12 @@ export default class Cypher {
private static async getCryptoSetting(tenantID: string): Promise<CryptoSetting> {
const cryptoSettings = (await SettingStorage.getCryptoSettings(tenantID)).crypto;
if (!cryptoSettings) {
+ const tenantName = (await TenantStorage.getTenant(tenantID)).name;
throw new BackendError({
source: Constants.CENTRAL_SERVER,
module: MODULE_NAME,
method: 'getCryptoSetting',
- message: `Tenant with ID: ${tenantID} does not have crypto settings.`
+ message: `Tenant with ID: ${tenantName} does not have crypto settings.`
});
}
return cryptoSettings;

changed crypto setting initilization