1
0
Fork 0
mirror of synced 2024-07-11 09:15:48 +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(
ctx: UserCtx<VerifyDatasourceRequest, VerifyDatasourceResponse>
) {
const datasource = ctx.request.body.datasource
const connector = (await getConnector(datasource)) as IntegrationBase
const { datasource } = ctx.request.body
const existingDatasource = await sdk.datasources.get(datasource._id!)
const enrichedDatasource = sdk.datasources.mergeConfigs(
datasource,
existingDatasource
)
const connector = await getConnector(enrichedDatasource)
if (!connector.testConnection) {
ctx.throw(400, "Connection information verification not supported")
}

View file

@ -1,5 +1,5 @@
import {
DatasourceFeature,
ConnectionInfo,
DatasourceFieldType,
DatasourcePlus,
FieldType,
@ -141,6 +141,19 @@ class GoogleSheetsIntegration implements DatasourcePlus {
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() {
return ""
}

View file

@ -1,4 +1,5 @@
import {
ConnectionInfo,
DatasourceFeature,
Integration,
QueryType,
@ -71,6 +72,18 @@ class SnowflakeIntegration {
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) {
await this.client.connect()
try {

View file

@ -13,6 +13,7 @@ import {
import { cloneDeep } from "lodash/fp"
import { getEnvironmentVariables } from "../../utils"
import { getDefinitions, getDefinition } from "../../../integrations"
import _ from "lodash"
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
for (let [key, value] of Object.entries(update.config)) {
if (value !== PASSWORD_REPLACEMENT) {