Merge pull request #10601 from Budibase/budi-6932/verify_google_sheets
Verify google sheets connection
This commit is contained in:
commit
d285c2aeb2
|
@ -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")
|
||||
}
|
||||
|
|
|
@ -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 ""
|
||||
}
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -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) {
|
||||
|
|
Loading…
Reference in New Issue