Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Verify google sheets connection #10601

Merged
merged 12 commits into from
May 16, 2023
11 changes: 9 additions & 2 deletions packages/server/src/api/controllers/datasource.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}
Expand Down
15 changes: 14 additions & 1 deletion packages/server/src/integrations/googlesheets.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import {
DatasourceFeature,
ConnectionInfo,
DatasourceFieldType,
DatasourcePlus,
FieldType,
Expand Down Expand Up @@ -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 ""
}
Expand Down
13 changes: 13 additions & 0 deletions packages/server/src/integrations/snowflake.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import {
ConnectionInfo,
DatasourceFeature,
Integration,
QueryType,
Expand Down Expand Up @@ -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 {
Expand Down
6 changes: 6 additions & 0 deletions packages/server/src/sdk/app/datasources/datasources.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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."

Expand Down Expand Up @@ -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) {
Expand Down