1
0
Fork 0
mirror of synced 2024-07-30 10:36:28 +12:00

Merge pull request #10601 from Budibase/budi-6932/verify_google_sheets

Verify google sheets connection
This commit is contained in:
Adria Navarro 2023-05-16 13:33:08 +02:00 committed by GitHub
commit d285c2aeb2
4 changed files with 42 additions and 3 deletions

View file

@ -126,8 +126,15 @@ export async function fetch(ctx: UserCtx) {
export async function verify( export async function verify(
ctx: UserCtx<VerifyDatasourceRequest, VerifyDatasourceResponse> ctx: UserCtx<VerifyDatasourceRequest, VerifyDatasourceResponse>
) { ) {
const datasource = ctx.request.body.datasource const { datasource } = ctx.request.body
const connector = (await getConnector(datasource)) as IntegrationBase const existingDatasource = await sdk.datasources.get(datasource._id!)
const enrichedDatasource = sdk.datasources.mergeConfigs(
datasource,
existingDatasource
)
const connector = await getConnector(enrichedDatasource)
if (!connector.testConnection) { if (!connector.testConnection) {
ctx.throw(400, "Connection information verification not supported") ctx.throw(400, "Connection information verification not supported")
} }

View file

@ -1,5 +1,5 @@
import { import {
DatasourceFeature, ConnectionInfo,
DatasourceFieldType, DatasourceFieldType,
DatasourcePlus, DatasourcePlus,
FieldType, FieldType,
@ -141,6 +141,19 @@ class GoogleSheetsIntegration implements DatasourcePlus {
this.client = new GoogleSpreadsheet(spreadsheetId) this.client = new GoogleSpreadsheet(spreadsheetId)
} }
async testConnection(): Promise<ConnectionInfo> {
try {
await this.connect()
await this.client.loadInfo()
return { connected: true }
} catch (e: any) {
return {
connected: false,
error: e.message as string,
}
}
}
getBindingIdentifier() { getBindingIdentifier() {
return "" return ""
} }

View file

@ -1,4 +1,5 @@
import { import {
ConnectionInfo,
DatasourceFeature, DatasourceFeature,
Integration, Integration,
QueryType, QueryType,
@ -71,6 +72,18 @@ class SnowflakeIntegration {
this.client = new Snowflake(config) this.client = new Snowflake(config)
} }
async testConnection(): Promise<ConnectionInfo> {
try {
await this.client.connect()
return { connected: true }
} catch (e: any) {
return {
connected: false,
error: e.message as string,
}
}
}
async internalQuery(query: SqlQuery) { async internalQuery(query: SqlQuery) {
await this.client.connect() await this.client.connect()
try { try {

View file

@ -13,6 +13,7 @@ import {
import { cloneDeep } from "lodash/fp" import { cloneDeep } from "lodash/fp"
import { getEnvironmentVariables } from "../../utils" import { getEnvironmentVariables } from "../../utils"
import { getDefinitions, getDefinition } from "../../../integrations" import { getDefinitions, getDefinition } from "../../../integrations"
import _ from "lodash"
const ENV_VAR_PREFIX = "env." const ENV_VAR_PREFIX = "env."
@ -147,6 +148,11 @@ export function mergeConfigs(update: Datasource, old: Datasource) {
} }
} }
} }
if (old.config?.auth) {
update.config = _.merge(old.config, update.config)
}
// update back to actual passwords for everything else // update back to actual passwords for everything else
for (let [key, value] of Object.entries(update.config)) { for (let [key, value] of Object.entries(update.config)) {
if (value !== PASSWORD_REPLACEMENT) { if (value !== PASSWORD_REPLACEMENT) {