diff --git a/packages/nocodb/src/helpers/initDataSourceEncryption.ts b/packages/nocodb/src/helpers/initDataSourceEncryption.ts index c1dbce00dc..53ffbd18ad 100644 --- a/packages/nocodb/src/helpers/initDataSourceEncryption.ts +++ b/packages/nocodb/src/helpers/initDataSourceEncryption.ts @@ -1,6 +1,6 @@ import process from 'process'; import Noco from '~/Noco'; -import { MetaTable } from '~/utils/globals'; +import { MetaTable, RootScopes } from '~/utils/globals'; import { encryptPropIfRequired } from '~/utils'; export default async function initDataSourceEncryption(_ncMeta = Noco.ncMeta) { @@ -28,13 +28,11 @@ export default async function initDataSourceEncryption(_ncMeta = Noco.ncMeta) { qb.where('is_local', false).orWhereNull('is_local'); }); - const isAtleastOneSourceEncrypted = false; - for (const source of sources) { // encrypt the data source await ncMeta.metaUpdate( source.fk_workspace_id, - source.id, + source.base_id, MetaTable.SOURCES, { config: encryptPropIfRequired({ @@ -43,6 +41,7 @@ export default async function initDataSourceEncryption(_ncMeta = Noco.ncMeta) { }), is_encrypted: true, }, + source.id, ); } @@ -55,8 +54,8 @@ export default async function initDataSourceEncryption(_ncMeta = Noco.ncMeta) { for (const integration of integrations) { // encrypt the data source await ncMeta.metaUpdate( - integration.fk_workspace_id, - integration.id, + RootScopes.WORKSPACE, + RootScopes.WORKSPACE, MetaTable.INTEGRATIONS, { config: encryptPropIfRequired({ @@ -65,9 +64,9 @@ export default async function initDataSourceEncryption(_ncMeta = Noco.ncMeta) { }), is_encrypted: true, }, + integration.id, ); } - await ncMeta.commit(); } catch (e) { await ncMeta.rollback(); diff --git a/packages/nocodb/src/models/Integration.spec.ts b/packages/nocodb/src/models/Integration.spec.ts index 59e74c68d3..d2c13bafe9 100644 --- a/packages/nocodb/src/models/Integration.spec.ts +++ b/packages/nocodb/src/models/Integration.spec.ts @@ -2,7 +2,7 @@ import { IntegrationsType } from 'nocodb-sdk'; import { Integration } from '~/models'; import { MetaTable } from '~/utils/globals'; import Noco from '~/Noco'; -import { decryptPropIfRequired, encryptPropIfRequired } from '~/utils'; +import { decryptPropIfRequired } from '~/utils'; // Mock dependencies jest.mock('~/helpers/catchError'); @@ -147,6 +147,8 @@ describe('Integration Model', () => { fk_workspace_id: 'workspace-1', workspaceId: undefined, id: undefined, + config: JSON.stringify(newIntegration.config), + is_encrypted: false, }, ); }); diff --git a/packages/nocodb/src/models/Source.ts b/packages/nocodb/src/models/Source.ts index 88439a2cf4..f4bd970cdd 100644 --- a/packages/nocodb/src/models/Source.ts +++ b/packages/nocodb/src/models/Source.ts @@ -343,11 +343,9 @@ export default class Source implements SourceType { return config; } - const config = JSON.parse( - decryptPropIfRequired({ - data: this, - }), - ); + const config = decryptPropIfRequired({ + data: this, + }); if (skipIntegrationConfig) { return config; @@ -357,12 +355,10 @@ export default class Source implements SourceType { return config; } - const integrationConfig = JSON.parse( - decryptPropIfRequired({ - data: this, - prop: 'integration_config', - }), - ); + const integrationConfig = decryptPropIfRequired({ + data: this, + prop: 'integration_config', + }); // merge integration config with source config // override integration config with source config if exists // only override database and searchPath diff --git a/packages/nocodb/src/providers/init-meta-service.provider.ts b/packages/nocodb/src/providers/init-meta-service.provider.ts index dc9df73c5e..ca5b00b11c 100644 --- a/packages/nocodb/src/providers/init-meta-service.provider.ts +++ b/packages/nocodb/src/providers/init-meta-service.provider.ts @@ -31,7 +31,7 @@ export const InitMetaServiceProvider: FactoryProvider = { const config = await NcConfig.createByEnv(); // set version - process.env.NC_VERSION = '0111005'; + process.env.NC_VERSION = '0225002'; // set migration jobs version process.env.NC_MIGRATION_JOBS_VERSION = '2'; diff --git a/packages/nocodb/src/utils/encryptDecrypt.ts b/packages/nocodb/src/utils/encryptDecrypt.ts index f1ba59ae7f..d36b9d543b 100644 --- a/packages/nocodb/src/utils/encryptDecrypt.ts +++ b/packages/nocodb/src/utils/encryptDecrypt.ts @@ -39,11 +39,13 @@ export const decryptPropIfRequired = ({ } if (!secret) { - return data[prop]; + return typeof data[prop] === 'string' ? JSON.parse(data[prop]) : data[prop]; } try { - CryptoJS.AES.decrypt(data[prop], secret).toString(CryptoJS.enc.Utf8); + return JSON.parse( + CryptoJS.AES.decrypt(data[prop], secret).toString(CryptoJS.enc.Utf8), + ); } catch { return data[prop]; } diff --git a/packages/nocodb/src/utils/nc-config/helpers.ts b/packages/nocodb/src/utils/nc-config/helpers.ts index 57abff9703..b41ca3f8e3 100644 --- a/packages/nocodb/src/utils/nc-config/helpers.ts +++ b/packages/nocodb/src/utils/nc-config/helpers.ts @@ -14,19 +14,15 @@ import { DriverClient } from './interfaces'; import type { Connection, DbConfig } from './interfaces'; export async function prepareEnv({ -databaseUrlFile = process.env.NC_DATABASE_URL_FILE || process.env.DATABASE_URL_FILE, -databaseUrl = process.env.NC_DATABASE_URL || process.env.DATABASE_URL, - } = {}) { + databaseUrlFile = process.env.NC_DATABASE_URL_FILE || + process.env.DATABASE_URL_FILE, + databaseUrl = process.env.NC_DATABASE_URL || process.env.DATABASE_URL, +} = {}) { if (databaseUrlFile) { - const database_url = await promisify(fs.readFile)( - databaseUrlFile, - 'utf-8', - ); + const database_url = await promisify(fs.readFile)(databaseUrlFile, 'utf-8'); process.env.NC_DB = jdbcToXcUrl(database_url); } else if (databaseUrl) { - process.env.NC_DB = jdbcToXcUrl( - databaseUrl, - ); + process.env.NC_DB = jdbcToXcUrl(databaseUrl); } } diff --git a/packages/nocodb/src/version-upgrader/upgraders/0225002_ncDatasourceDecrypt.ts b/packages/nocodb/src/version-upgrader/upgraders/0225002_ncDatasourceDecrypt.ts index 76828ee687..50c8f067ce 100644 --- a/packages/nocodb/src/version-upgrader/upgraders/0225002_ncDatasourceDecrypt.ts +++ b/packages/nocodb/src/version-upgrader/upgraders/0225002_ncDatasourceDecrypt.ts @@ -36,26 +36,7 @@ export default async function ({ ncMeta }: NcUpgraderCtx) { } // get all external sources - const sources = await ncMeta.knexConnection(MetaTable.SOURCES).condition({ - _not: { - _or: [ - { - is_meta: { - eq: 1, - }, - }, - ...(Noco.isEE() - ? [ - { - is_local: { - eq: 1, - }, - }, - ] - : []), - ], - }, - }); + const sources = await ncMeta.knexConnection(MetaTable.SOURCES); const passed = [];