Updating so that datasources always have correct types after environment variable enrichment.
This commit is contained in:
parent
f8ef06c849
commit
4acfae6af6
|
@ -67,6 +67,15 @@ if (
|
||||||
INTEGRATIONS[SourceName.ORACLE] = oracle.integration
|
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() {
|
export async function getDefinitions() {
|
||||||
const pluginSchemas: { [key: string]: Integration } = {}
|
const pluginSchemas: { [key: string]: Integration } = {}
|
||||||
if (env.SELF_HOSTED) {
|
if (env.SELF_HOSTED) {
|
||||||
|
|
|
@ -108,9 +108,6 @@ class SqlServerIntegration extends Sql implements DatasourcePlus {
|
||||||
constructor(config: MSSQLConfig) {
|
constructor(config: MSSQLConfig) {
|
||||||
super(SqlClient.MS_SQL)
|
super(SqlClient.MS_SQL)
|
||||||
this.config = config
|
this.config = config
|
||||||
if (typeof this.config?.port === "string") {
|
|
||||||
this.config.port = parseInt(this.config.port)
|
|
||||||
}
|
|
||||||
const clientCfg = {
|
const clientCfg = {
|
||||||
...this.config,
|
...this.config,
|
||||||
options: {
|
options: {
|
||||||
|
|
|
@ -3,6 +3,7 @@ import { findHBSBlocks, processObjectSync } from "@budibase/string-templates"
|
||||||
import {
|
import {
|
||||||
Datasource,
|
Datasource,
|
||||||
DatasourceFieldType,
|
DatasourceFieldType,
|
||||||
|
Integration,
|
||||||
PASSWORD_REPLACEMENT,
|
PASSWORD_REPLACEMENT,
|
||||||
RestAuthConfig,
|
RestAuthConfig,
|
||||||
RestAuthType,
|
RestAuthType,
|
||||||
|
@ -11,16 +12,38 @@ import {
|
||||||
} from "@budibase/types"
|
} from "@budibase/types"
|
||||||
import { cloneDeep } from "lodash/fp"
|
import { cloneDeep } from "lodash/fp"
|
||||||
import { getEnvironmentVariables } from "../../utils"
|
import { getEnvironmentVariables } from "../../utils"
|
||||||
import { getDefinitions } from "../../../integrations"
|
import { getDefinitions, getDefinition } from "../../../integrations"
|
||||||
|
|
||||||
const ENV_VAR_PREFIX = "env."
|
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) {
|
async function enrichDatasourceWithValues(datasource: Datasource) {
|
||||||
const cloned = cloneDeep(datasource)
|
const cloned = cloneDeep(datasource)
|
||||||
const env = await getEnvironmentVariables()
|
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 {
|
return {
|
||||||
datasource: processed as Datasource,
|
datasource: processed,
|
||||||
envVars: env as Record<string, string>,
|
envVars: env as Record<string, string>,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue