From fc3a4087ecfacaebce56590db4686797039de096 Mon Sep 17 00:00:00 2001 From: Pranav C Date: Sun, 6 Oct 2024 07:21:33 +0000 Subject: [PATCH] refactor: corrections --- packages/nc-secret-cli/src/core/NcConfig.ts | 18 +++++++++++------- packages/nc-secret-cli/src/index.ts | 21 +++++++++++---------- packages/nocodb/src/cli.ts | 2 +- 3 files changed, 23 insertions(+), 18 deletions(-) diff --git a/packages/nc-secret-cli/src/core/NcConfig.ts b/packages/nc-secret-cli/src/core/NcConfig.ts index 7bb184b410..fa69fee6da 100644 --- a/packages/nc-secret-cli/src/core/NcConfig.ts +++ b/packages/nc-secret-cli/src/core/NcConfig.ts @@ -79,14 +79,18 @@ export class NcConfig { } } -export const getNocoConfig = () =>{ +export const getNocoConfig = (options: { + ncDb?: string; + ncDbJson?: string; + ncDbJsonFile?: string; + databaseUrl?: string; + databaseUrlFile?: string; +} ={}) =>{ return NcConfig.create({ meta: { - metaUrl: process.env.NC_DB, - metaJson: process.env.NC_DB_JSON, - metaJsonFile: process.env.NC_DB_JSON_FILE, - }, - secret: process.env.NC_AUTH_JWT_SECRET, - credentialSecret: process.env.NC_KEY_CREDENTIAL_ENCRYPT, + metaUrl: process.env.NC_DB || options.ncDb, + metaJson: process.env.NC_DB_JSON || options.ncDbJson, + metaJsonFile: process.env.NC_DB_JSON_FILE || options.ncDbJsonFile, + } }); } diff --git a/packages/nc-secret-cli/src/index.ts b/packages/nc-secret-cli/src/index.ts index 76866d190c..f2b763aef9 100644 --- a/packages/nc-secret-cli/src/index.ts +++ b/packages/nc-secret-cli/src/index.ts @@ -13,18 +13,19 @@ program .version('1.0.0') .description('NocoDB Secret CLI') .arguments(' ') - .option('--nc-db ', 'NocoDB connection database url, equivalent to NC_DB env variable') - .option('--nc-db-json ', 'NocoDB connection database json, equivalent to NC_DB_JSON env variable') - .option('--nc-db-json-file ', 'NocoDB connection database json file path, equivalent to NC_DB_JSON_FILE env variable') - .option('--database-url ', 'JDBC database url, equivalent to DATABASE_URL env variable') - .option('--database-url-file ', 'JDBC database url file path, equivalent to DATABASE_URL_FILE env variable') - .option('-o, --old-secret ', 'old secret string to decrypt sources and integrations') - .option('-n, --new-secret ', 'new secret string to encrypt sources and integrations') - .action(async (key, value, ...rest) => { + .option('--nc-db ', 'NocoDB connection database url, equivalent to NC_DB env variable') + .option('--nc-db-json ', 'NocoDB connection database json, equivalent to NC_DB_JSON env variable') + .option('--nc-db-json-file ', 'NocoDB connection database json file path, equivalent to NC_DB_JSON_FILE env variable') + .option('--database-url ', 'JDBC database url, equivalent to DATABASE_URL env variable') + .option('--database-url-file ', 'JDBC database url file path, equivalent to DATABASE_URL_FILE env variable') + .option('-o, --old-secret ', 'old secret string to decrypt sources and integrations') + .option('-n, --new-secret ', 'new secret string to encrypt sources and integrations') + .action(async (key, value) => { try { - - const config = await getNocoConfig(); + // extract options + const options = program.opts(); + const config = await getNocoConfig(options); if (!key || !value) { console.error('Error: Both key and value are required.'); diff --git a/packages/nocodb/src/cli.ts b/packages/nocodb/src/cli.ts index f682a579d4..9a3098a9f7 100644 --- a/packages/nocodb/src/cli.ts +++ b/packages/nocodb/src/cli.ts @@ -1,5 +1,5 @@ export { SqlClientFactory } from '~/db/sql-client/lib/SqlClientFactory'; export { MetaTable } from '~/utils/globals'; export * from '~/utils/encryptDecrypt'; -export { getToolDir, metaUrlToDbConfig } from '~/utils/nc-config/helpers'; +export { getToolDir, metaUrlToDbConfig, prepareEnv } from '~/utils/nc-config/helpers'; export { DriverClient } from '~/utils/nc-config/constants';