handle migration in progress
MODIFY
src/server/rest/v1/service/SettingService.ts
src/server/rest/v1/service/SettingService.ts
@@ -206,11 +206,23 @@ export default class SettingService {
setting.lastChangedBy = { 'id': req.user.id };
setting.lastChangedOn = new Date();
if (settingUpdate.identifier === TenantComponents.CRYPTO) {
+ if (setting.content.crypto.migrationToBeDone) {
+ // If migration in progress, throw error
+ throw new AppError({
+ source: Constants.CENTRAL_SERVER,
+ errorCode: HTTPError.MIGRATION_IN_PROGRESS,
+ message: 'Sensitive Data Migration is in progress',
+ module: MODULE_NAME,
+ method: 'handleUpdateSetting',
+ user: req.user
+ });
+ } else {
if (Cypher.hash(settingUpdate.content.crypto.key) !== Cypher.hash(setting.content.crypto.key)) {
settingUpdate.content.crypto.migrationToBeDone = true;
}
settingUpdate.content.crypto.formerKey = setting.content.crypto.key;
}
+ }
// Update Setting
settingUpdate.id = await SettingStorage.saveSettings(req.user.tenantID, settingUpdate);
// Crypto Setting handling

MODIFY
src/types/HTTPError.ts
src/types/HTTPError.ts
@@ -57,6 +57,7 @@ export enum HTTPError {
THREE_PHASE_CHARGER_ON_SINGLE_PHASE_SITE_AREA = 539,
CANNOT_ACQUIRE_LOCK = 510,
+ MIGRATION_IN_PROGRESS = 511
}
export enum HTTPAuthError {

MODIFY
src/utils/Cypher.ts
src/utils/Cypher.ts
@@ -143,7 +143,6 @@ export default class Cypher {
// This method will be reused in a Scheduler task that resumes migation
public static async handleCryptoSettingsChange(tenantID: string): Promise<void> {
const createDatabaseLock = LockingManager.createExclusiveLock(tenantID, LockEntity.DATABASE, 'migrate-settings-sensitive-data');
- try {
if (await LockingManager.acquire(createDatabaseLock)) {
try {
await Cypher.migrate(tenantID);
@@ -162,13 +161,12 @@ export default class Cypher {
// Release the database Lock
await LockingManager.release(createDatabaseLock);
}
- }
- } catch (err) {
+ } else {
throw new BackendError({
source: Constants.CENTRAL_SERVER,
module: MODULE_NAME,
method: 'handleCryptoSettingsChange',
- message: `Sensitive Data migration in progress for tenant with ID: ${tenantID}.`
+ message: `Sensitive Data migration is in progress for tenant with ID: ${tenantID}.`
});
}
}

handle migration in progress