Browse Source

fix: corrections

pull/9499/head
Pranav C 2 months ago
parent
commit
11b63eb181
  1. 13
      packages/nocodb/src/helpers/initDataSourceEncryption.ts
  2. 4
      packages/nocodb/src/models/Integration.spec.ts
  3. 18
      packages/nocodb/src/models/Source.ts
  4. 2
      packages/nocodb/src/providers/init-meta-service.provider.ts
  5. 6
      packages/nocodb/src/utils/encryptDecrypt.ts
  6. 16
      packages/nocodb/src/utils/nc-config/helpers.ts
  7. 21
      packages/nocodb/src/version-upgrader/upgraders/0225002_ncDatasourceDecrypt.ts

13
packages/nocodb/src/helpers/initDataSourceEncryption.ts

@ -1,6 +1,6 @@
import process from 'process'; import process from 'process';
import Noco from '~/Noco'; import Noco from '~/Noco';
import { MetaTable } from '~/utils/globals'; import { MetaTable, RootScopes } from '~/utils/globals';
import { encryptPropIfRequired } from '~/utils'; import { encryptPropIfRequired } from '~/utils';
export default async function initDataSourceEncryption(_ncMeta = Noco.ncMeta) { 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'); qb.where('is_local', false).orWhereNull('is_local');
}); });
const isAtleastOneSourceEncrypted = false;
for (const source of sources) { for (const source of sources) {
// encrypt the data source // encrypt the data source
await ncMeta.metaUpdate( await ncMeta.metaUpdate(
source.fk_workspace_id, source.fk_workspace_id,
source.id, source.base_id,
MetaTable.SOURCES, MetaTable.SOURCES,
{ {
config: encryptPropIfRequired({ config: encryptPropIfRequired({
@ -43,6 +41,7 @@ export default async function initDataSourceEncryption(_ncMeta = Noco.ncMeta) {
}), }),
is_encrypted: true, is_encrypted: true,
}, },
source.id,
); );
} }
@ -55,8 +54,8 @@ export default async function initDataSourceEncryption(_ncMeta = Noco.ncMeta) {
for (const integration of integrations) { for (const integration of integrations) {
// encrypt the data source // encrypt the data source
await ncMeta.metaUpdate( await ncMeta.metaUpdate(
integration.fk_workspace_id, RootScopes.WORKSPACE,
integration.id, RootScopes.WORKSPACE,
MetaTable.INTEGRATIONS, MetaTable.INTEGRATIONS,
{ {
config: encryptPropIfRequired({ config: encryptPropIfRequired({
@ -65,9 +64,9 @@ export default async function initDataSourceEncryption(_ncMeta = Noco.ncMeta) {
}), }),
is_encrypted: true, is_encrypted: true,
}, },
integration.id,
); );
} }
await ncMeta.commit(); await ncMeta.commit();
} catch (e) { } catch (e) {
await ncMeta.rollback(); await ncMeta.rollback();

4
packages/nocodb/src/models/Integration.spec.ts

@ -2,7 +2,7 @@ import { IntegrationsType } from 'nocodb-sdk';
import { Integration } from '~/models'; import { Integration } from '~/models';
import { MetaTable } from '~/utils/globals'; import { MetaTable } from '~/utils/globals';
import Noco from '~/Noco'; import Noco from '~/Noco';
import { decryptPropIfRequired, encryptPropIfRequired } from '~/utils'; import { decryptPropIfRequired } from '~/utils';
// Mock dependencies // Mock dependencies
jest.mock('~/helpers/catchError'); jest.mock('~/helpers/catchError');
@ -147,6 +147,8 @@ describe('Integration Model', () => {
fk_workspace_id: 'workspace-1', fk_workspace_id: 'workspace-1',
workspaceId: undefined, workspaceId: undefined,
id: undefined, id: undefined,
config: JSON.stringify(newIntegration.config),
is_encrypted: false,
}, },
); );
}); });

18
packages/nocodb/src/models/Source.ts

@ -343,11 +343,9 @@ export default class Source implements SourceType {
return config; return config;
} }
const config = JSON.parse( const config = decryptPropIfRequired({
decryptPropIfRequired({ data: this,
data: this, });
}),
);
if (skipIntegrationConfig) { if (skipIntegrationConfig) {
return config; return config;
@ -357,12 +355,10 @@ export default class Source implements SourceType {
return config; return config;
} }
const integrationConfig = JSON.parse( const integrationConfig = decryptPropIfRequired({
decryptPropIfRequired({ data: this,
data: this, prop: 'integration_config',
prop: 'integration_config', });
}),
);
// merge integration config with source config // merge integration config with source config
// override integration config with source config if exists // override integration config with source config if exists
// only override database and searchPath // only override database and searchPath

2
packages/nocodb/src/providers/init-meta-service.provider.ts

@ -31,7 +31,7 @@ export const InitMetaServiceProvider: FactoryProvider = {
const config = await NcConfig.createByEnv(); const config = await NcConfig.createByEnv();
// set version // set version
process.env.NC_VERSION = '0111005'; process.env.NC_VERSION = '0225002';
// set migration jobs version // set migration jobs version
process.env.NC_MIGRATION_JOBS_VERSION = '2'; process.env.NC_MIGRATION_JOBS_VERSION = '2';

6
packages/nocodb/src/utils/encryptDecrypt.ts

@ -39,11 +39,13 @@ export const decryptPropIfRequired = ({
} }
if (!secret) { if (!secret) {
return data[prop]; return typeof data[prop] === 'string' ? JSON.parse(data[prop]) : data[prop];
} }
try { 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 { } catch {
return data[prop]; return data[prop];
} }

16
packages/nocodb/src/utils/nc-config/helpers.ts

@ -14,19 +14,15 @@ import { DriverClient } from './interfaces';
import type { Connection, DbConfig } from './interfaces'; import type { Connection, DbConfig } from './interfaces';
export async function prepareEnv({ export async function prepareEnv({
databaseUrlFile = process.env.NC_DATABASE_URL_FILE || process.env.DATABASE_URL_FILE, databaseUrlFile = process.env.NC_DATABASE_URL_FILE ||
databaseUrl = process.env.NC_DATABASE_URL || process.env.DATABASE_URL, process.env.DATABASE_URL_FILE,
} = {}) { databaseUrl = process.env.NC_DATABASE_URL || process.env.DATABASE_URL,
} = {}) {
if (databaseUrlFile) { if (databaseUrlFile) {
const database_url = await promisify(fs.readFile)( const database_url = await promisify(fs.readFile)(databaseUrlFile, 'utf-8');
databaseUrlFile,
'utf-8',
);
process.env.NC_DB = jdbcToXcUrl(database_url); process.env.NC_DB = jdbcToXcUrl(database_url);
} else if (databaseUrl) { } else if (databaseUrl) {
process.env.NC_DB = jdbcToXcUrl( process.env.NC_DB = jdbcToXcUrl(databaseUrl);
databaseUrl,
);
} }
} }

21
packages/nocodb/src/version-upgrader/upgraders/0225002_ncDatasourceDecrypt.ts

@ -36,26 +36,7 @@ export default async function ({ ncMeta }: NcUpgraderCtx) {
} }
// get all external sources // get all external sources
const sources = await ncMeta.knexConnection(MetaTable.SOURCES).condition({ const sources = await ncMeta.knexConnection(MetaTable.SOURCES);
_not: {
_or: [
{
is_meta: {
eq: 1,
},
},
...(Noco.isEE()
? [
{
is_local: {
eq: 1,
},
},
]
: []),
],
},
});
const passed = []; const passed = [];

Loading…
Cancel
Save