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. 12
      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. 12
      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 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();

4
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,
},
);
});

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

@ -343,11 +343,9 @@ export default class Source implements SourceType {
return config;
}
const config = JSON.parse(
decryptPropIfRequired({
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({
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

2
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';

6
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];
}

12
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,
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);
}
}

21
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 = [];

Loading…
Cancel
Save