Updating so that datasources always have correct types after environment variable enrichment.

This commit is contained in:
mike12345567 2023-02-10 12:47:23 +00:00
parent f8ef06c849
commit 4acfae6af6
3 changed files with 35 additions and 6 deletions

View File

@ -67,6 +67,15 @@ if (
INTEGRATIONS[SourceName.ORACLE] = oracle.integration
}
export async function getDefinition(source: SourceName): Promise<Integration> {
// check if its integrated, faster
if (DEFINITIONS[source]) {
return DEFINITIONS[source]
}
const allDefinitions = await getDefinitions()
return allDefinitions[source]
}
export async function getDefinitions() {
const pluginSchemas: { [key: string]: Integration } = {}
if (env.SELF_HOSTED) {

View File

@ -108,9 +108,6 @@ class SqlServerIntegration extends Sql implements DatasourcePlus {
constructor(config: MSSQLConfig) {
super(SqlClient.MS_SQL)
this.config = config
if (typeof this.config?.port === "string") {
this.config.port = parseInt(this.config.port)
}
const clientCfg = {
...this.config,
options: {

View File

@ -3,6 +3,7 @@ import { findHBSBlocks, processObjectSync } from "@budibase/string-templates"
import {
Datasource,
DatasourceFieldType,
Integration,
PASSWORD_REPLACEMENT,
RestAuthConfig,
RestAuthType,
@ -11,16 +12,38 @@ import {
} from "@budibase/types"
import { cloneDeep } from "lodash/fp"
import { getEnvironmentVariables } from "../../utils"
import { getDefinitions } from "../../../integrations"
import { getDefinitions, getDefinition } from "../../../integrations"
const ENV_VAR_PREFIX = "env."
export function checkDatasourceTypes(schema: Integration, config: any) {
for (let key of Object.keys(config)) {
if (!schema.datasource[key]) {
continue
}
const type = schema.datasource[key].type
if (
type === DatasourceFieldType.NUMBER &&
typeof config[key] === "string"
) {
config[key] = parseFloat(config[key])
}
}
return config
}
async function enrichDatasourceWithValues(datasource: Datasource) {
const cloned = cloneDeep(datasource)
const env = await getEnvironmentVariables()
const processed = processObjectSync(cloned, { env }, { onlyFound: true })
const processed = processObjectSync(
cloned,
{ env },
{ onlyFound: true }
) as Datasource
const definition = await getDefinition(processed.source)
processed.config = checkDatasourceTypes(definition, processed.config)
return {
datasource: processed as Datasource,
datasource: processed,
envVars: env as Record<string, string>,
}
}