Browse Source

feat: new api backend for converting connection url to config

Signed-off-by: mertmit <mertmit99@gmail.com>
pull/3306/head
mertmit 2 years ago
parent
commit
7a5c6c7371
  1. 16
      packages/nocodb-sdk/src/lib/Api.ts
  2. 14
      packages/nocodb/src/lib/meta/api/utilApis.ts
  3. 15
      packages/nocodb/src/lib/utils/NcConfigFactory.ts
  4. 18
      scripts/sdk/swagger.json

16
packages/nocodb-sdk/src/lib/Api.ts

@ -3210,6 +3210,22 @@ export class Api<
...params,
}),
/**
* No description
*
* @tags Utils
* @name UrlToConfig
* @request POST:/api/v1/url_to_config
*/
urlToConfig: (data: any, params: RequestParams = {}) =>
this.request<any, any>({
path: `/api/v1/url_to_config`,
method: 'POST',
body: data,
type: ContentType.Json,
...params,
}),
/**
* No description
*

14
packages/nocodb/src/lib/meta/api/utilApis.ts

@ -4,7 +4,7 @@ import { Request, Response } from 'express';
import { packageVersion } from 'nc-help';
import ncMetaAclMw from '../helpers/ncMetaAclMw';
import SqlMgrv2 from '../../db/sql-mgr/v2/SqlMgrv2';
import { defaultConnectionConfig } from '../../utils/NcConfigFactory';
import NcConfigFactory, { defaultConnectionConfig } from '../../utils/NcConfigFactory';
import User from '../../models/User';
import catchError from '../helpers/catchError';
import axios from 'axios';
@ -147,6 +147,17 @@ export async function axiosRequestMake(req: Request, res: Response) {
return await _axiosRequestMake(req, res);
}
export async function urlToDbConfig(req: Request, res: Response) {
const { url } = req.body;
try {
let connectionConfig;
connectionConfig = NcConfigFactory.extractXcUrlFromJdbc(url, true);
return res.json(connectionConfig);
} catch (error) {
return res.sendStatus(500)
}
}
export default (router) => {
router.post(
'/api/v1/db/meta/connection/test',
@ -157,4 +168,5 @@ export default (router) => {
router.get('/api/v1/version', catchError(versionInfo));
router.get('/api/v1/health', catchError(appHealth));
router.get('/api/v1/feedback_form', catchError(feedbackFormGet));
router.post('/api/v1/url_to_config', catchError(urlToDbConfig));
};

15
packages/nocodb/src/lib/utils/NcConfigFactory.ts

@ -636,7 +636,7 @@ export default class NcConfigFactory implements NcConfig {
}
}
public static extractXcUrlFromJdbc(url: string) {
public static extractXcUrlFromJdbc(url: string, rtConfig: boolean = false) {
// drop the jdbc prefix
if (url.startsWith('jdbc:')) {
url = url.substring(5);
@ -655,9 +655,20 @@ export default class NcConfigFactory implements NcConfig {
}
if (!parsedConfig?.port) parsedConfig.port = defaultClientPortMapping[parsedConfig.driver];
if (rtConfig) {
const { driver, ...connectionConfig } = parsedConfig;
return {
client: driverClientMapping[driver] || driver,
connection: {
...connectionConfig
}
} as any;
}
const { driver, host, port, database, user, password, ...extra } = parsedConfig;
const extraParams = [];
for (const [key, value] of Object.entries(extra)) {

18
scripts/sdk/swagger.json

@ -5204,6 +5204,24 @@
"description": ""
}
},
"/api/v1/url_to_config": {
"parameters": [],
"post": {
"summary": "",
"operationId": "utils-url-to-config",
"tags": [
"Utils"
],
"requestBody": {
"content": {
"application/json": {
"schema": {}
}
}
},
"description": ""
}
},
"/api/v1/db/meta/nocodb/info": {
"parameters": [],
"get": {

Loading…
Cancel
Save