export { }; import { DBSQLClient } from "@databricks/sql"; import { IDataBricksConnectionConfig } from './interfaces' const mstime = require('mstime'); const aws_secret_manager = require("../aws-secret-manager/aws-secret-manager"); import { DATABRICKS_WAREHOUSEID } from "./config"; const { v4: uuidv4 } = require('uuid'); /** * Function to be consumed internally for building the connection * @internal * @stable * @async * @param config * @param wareHouseId */ export const createDatabricksConnection = async (config: IDataBricksConnectionConfig, wareHouseId: string | null = null) => { let id = uuidv4(); mstime.start(id); try{ let secretData = await aws_secret_manager.secretPromise("",config.awsSecretKey); const serverHostname = secretData[config.dataBricksConfig.hostname]; const warehouseId = wareHouseId == null ? secretData[config.dataBricksConfig.warehouseId] : wareHouseId; const token = secretData[config.dataBricksConfig.token]; const httpPath = DATABRICKS_WAREHOUSEID + warehouseId; const client: DBSQLClient = new DBSQLClient(); const connectOptions = { token: token, host: serverHostname, path: httpPath }; const connection = await client.connect(connectOptions) let result = mstime.end(id); console.log(`Successfully connected to Databricks, 🕒 Time taken: ${result.last} ms`); return connection; } catch(err) { console.error("Error connecting to databricks : " + err); throw err; } }