Merge pull request #10590 from Budibase/feature/datasource-testConnection-resp
Refactor datasource testConnection to use a simple type.
This commit is contained in:
commit
bc21484223
17 changed files with 80 additions and 40 deletions
|
@ -140,7 +140,7 @@ export async function verify(
|
||||||
} else {
|
} else {
|
||||||
ctx.body = {
|
ctx.body = {
|
||||||
connected: false,
|
connected: false,
|
||||||
error: response.error
|
error: response.error,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -19,7 +19,7 @@ const SCHEMA: Integration = {
|
||||||
"Airtable is a spreadsheet-database hybrid, with the features of a database but applied to a spreadsheet.",
|
"Airtable is a spreadsheet-database hybrid, with the features of a database but applied to a spreadsheet.",
|
||||||
friendlyName: "Airtable",
|
friendlyName: "Airtable",
|
||||||
type: "Spreadsheet",
|
type: "Spreadsheet",
|
||||||
features: [DatasourceFeature.CONNECTION_CHECKING],
|
features: [],
|
||||||
datasource: {
|
datasource: {
|
||||||
apiKey: {
|
apiKey: {
|
||||||
type: DatasourceFieldType.PASSWORD,
|
type: DatasourceFieldType.PASSWORD,
|
||||||
|
|
|
@ -4,6 +4,7 @@ import {
|
||||||
QueryType,
|
QueryType,
|
||||||
IntegrationBase,
|
IntegrationBase,
|
||||||
DatasourceFeature,
|
DatasourceFeature,
|
||||||
|
ConnectionInfo,
|
||||||
} from "@budibase/types"
|
} from "@budibase/types"
|
||||||
|
|
||||||
import { Database, aql } from "arangojs"
|
import { Database, aql } from "arangojs"
|
||||||
|
@ -77,12 +78,16 @@ class ArangoDBIntegration implements IntegrationBase {
|
||||||
}
|
}
|
||||||
|
|
||||||
async testConnection() {
|
async testConnection() {
|
||||||
|
const response: ConnectionInfo = {
|
||||||
|
connected: false,
|
||||||
|
}
|
||||||
try {
|
try {
|
||||||
await this.client.get()
|
await this.client.get()
|
||||||
return true
|
response.connected = true
|
||||||
} catch (e: any) {
|
} catch (e: any) {
|
||||||
return { error: e.message as string }
|
response.error = e.message as string
|
||||||
}
|
}
|
||||||
|
return response
|
||||||
}
|
}
|
||||||
|
|
||||||
async read(query: { sql: any }) {
|
async read(query: { sql: any }) {
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
import {
|
import {
|
||||||
|
ConnectionInfo,
|
||||||
DatasourceFeature,
|
DatasourceFeature,
|
||||||
DatasourceFieldType,
|
DatasourceFieldType,
|
||||||
Document,
|
Document,
|
||||||
|
@ -70,12 +71,16 @@ class CouchDBIntegration implements IntegrationBase {
|
||||||
}
|
}
|
||||||
|
|
||||||
async testConnection() {
|
async testConnection() {
|
||||||
|
const response: ConnectionInfo = {
|
||||||
|
connected: false,
|
||||||
|
}
|
||||||
try {
|
try {
|
||||||
const result = await this.query("exists", "validation error", {})
|
const result = await this.query("exists", "validation error", {})
|
||||||
return result === true
|
response.connected = result === true
|
||||||
} catch (e: any) {
|
} catch (e: any) {
|
||||||
return { error: e.message as string }
|
response.error = e.message as string
|
||||||
}
|
}
|
||||||
|
return response
|
||||||
}
|
}
|
||||||
|
|
||||||
async query(
|
async query(
|
||||||
|
|
|
@ -4,6 +4,7 @@ import {
|
||||||
QueryType,
|
QueryType,
|
||||||
IntegrationBase,
|
IntegrationBase,
|
||||||
DatasourceFeature,
|
DatasourceFeature,
|
||||||
|
ConnectionInfo,
|
||||||
} from "@budibase/types"
|
} from "@budibase/types"
|
||||||
|
|
||||||
import AWS from "aws-sdk"
|
import AWS from "aws-sdk"
|
||||||
|
@ -152,12 +153,16 @@ class DynamoDBIntegration implements IntegrationBase {
|
||||||
}
|
}
|
||||||
|
|
||||||
async testConnection() {
|
async testConnection() {
|
||||||
|
const response: ConnectionInfo = {
|
||||||
|
connected: false,
|
||||||
|
}
|
||||||
try {
|
try {
|
||||||
const scanRes = await new AWS.DynamoDB(this.config).listTables().promise()
|
const scanRes = await new AWS.DynamoDB(this.config).listTables().promise()
|
||||||
return !!scanRes.$response
|
response.connected = !!scanRes.$response
|
||||||
} catch (e: any) {
|
} catch (e: any) {
|
||||||
return { error: e.message as string }
|
response.error = e.message as string
|
||||||
}
|
}
|
||||||
|
return response
|
||||||
}
|
}
|
||||||
|
|
||||||
async create(query: {
|
async create(query: {
|
||||||
|
|
|
@ -21,7 +21,7 @@ const SCHEMA: Integration = {
|
||||||
"Elasticsearch is a search engine based on the Lucene library. It provides a distributed, multitenant-capable full-text search engine with an HTTP web interface and schema-free JSON documents.",
|
"Elasticsearch is a search engine based on the Lucene library. It provides a distributed, multitenant-capable full-text search engine with an HTTP web interface and schema-free JSON documents.",
|
||||||
friendlyName: "ElasticSearch",
|
friendlyName: "ElasticSearch",
|
||||||
type: "Non-relational",
|
type: "Non-relational",
|
||||||
features: [DatasourceFeature.CONNECTION_CHECKING],
|
features: [],
|
||||||
datasource: {
|
datasource: {
|
||||||
url: {
|
url: {
|
||||||
type: DatasourceFieldType.STRING,
|
type: DatasourceFieldType.STRING,
|
||||||
|
|
|
@ -19,7 +19,7 @@ const SCHEMA: Integration = {
|
||||||
type: "Non-relational",
|
type: "Non-relational",
|
||||||
description:
|
description:
|
||||||
"Cloud Firestore is a flexible, scalable database for mobile, web, and server development from Firebase and Google Cloud.",
|
"Cloud Firestore is a flexible, scalable database for mobile, web, and server development from Firebase and Google Cloud.",
|
||||||
features: [DatasourceFeature.CONNECTION_CHECKING],
|
features: [],
|
||||||
datasource: {
|
datasource: {
|
||||||
email: {
|
email: {
|
||||||
type: DatasourceFieldType.STRING,
|
type: DatasourceFieldType.STRING,
|
||||||
|
|
|
@ -65,7 +65,7 @@ const SCHEMA: Integration = {
|
||||||
"Create and collaborate on online spreadsheets in real-time and from any device. ",
|
"Create and collaborate on online spreadsheets in real-time and from any device. ",
|
||||||
friendlyName: "Google Sheets",
|
friendlyName: "Google Sheets",
|
||||||
type: "Spreadsheet",
|
type: "Spreadsheet",
|
||||||
features: [DatasourceFeature.CONNECTION_CHECKING],
|
features: [],
|
||||||
datasource: {
|
datasource: {
|
||||||
spreadsheetId: {
|
spreadsheetId: {
|
||||||
display: "Google Sheet URL",
|
display: "Google Sheet URL",
|
||||||
|
|
|
@ -9,6 +9,7 @@ import {
|
||||||
SqlQuery,
|
SqlQuery,
|
||||||
DatasourcePlus,
|
DatasourcePlus,
|
||||||
DatasourceFeature,
|
DatasourceFeature,
|
||||||
|
ConnectionInfo,
|
||||||
} from "@budibase/types"
|
} from "@budibase/types"
|
||||||
import {
|
import {
|
||||||
getSqlQuery,
|
getSqlQuery,
|
||||||
|
@ -124,12 +125,16 @@ class SqlServerIntegration extends Sql implements DatasourcePlus {
|
||||||
}
|
}
|
||||||
|
|
||||||
async testConnection() {
|
async testConnection() {
|
||||||
|
const response: ConnectionInfo = {
|
||||||
|
connected: false,
|
||||||
|
}
|
||||||
try {
|
try {
|
||||||
await this.connect()
|
await this.connect()
|
||||||
return true
|
response.connected = true
|
||||||
} catch (e: any) {
|
} catch (e: any) {
|
||||||
return { error: e.message as string }
|
response.error = e.message as string
|
||||||
}
|
}
|
||||||
|
return response
|
||||||
}
|
}
|
||||||
|
|
||||||
getBindingIdentifier(): string {
|
getBindingIdentifier(): string {
|
||||||
|
|
|
@ -4,6 +4,7 @@ import {
|
||||||
QueryType,
|
QueryType,
|
||||||
IntegrationBase,
|
IntegrationBase,
|
||||||
DatasourceFeature,
|
DatasourceFeature,
|
||||||
|
ConnectionInfo,
|
||||||
} from "@budibase/types"
|
} from "@budibase/types"
|
||||||
import {
|
import {
|
||||||
MongoClient,
|
MongoClient,
|
||||||
|
@ -361,12 +362,16 @@ class MongoIntegration implements IntegrationBase {
|
||||||
}
|
}
|
||||||
|
|
||||||
async testConnection() {
|
async testConnection() {
|
||||||
|
const response: ConnectionInfo = {
|
||||||
|
connected: false,
|
||||||
|
}
|
||||||
try {
|
try {
|
||||||
await this.connect()
|
await this.connect()
|
||||||
return true
|
response.connected = true
|
||||||
} catch (e: any) {
|
} catch (e: any) {
|
||||||
return { error: e.message as string }
|
response.error = e.message as string
|
||||||
}
|
}
|
||||||
|
return response
|
||||||
}
|
}
|
||||||
|
|
||||||
async connect() {
|
async connect() {
|
||||||
|
|
|
@ -8,6 +8,7 @@ import {
|
||||||
TableSchema,
|
TableSchema,
|
||||||
DatasourcePlus,
|
DatasourcePlus,
|
||||||
DatasourceFeature,
|
DatasourceFeature,
|
||||||
|
ConnectionInfo,
|
||||||
} from "@budibase/types"
|
} from "@budibase/types"
|
||||||
import {
|
import {
|
||||||
getSqlQuery,
|
getSqlQuery,
|
||||||
|
@ -155,15 +156,19 @@ class MySQLIntegration extends Sql implements DatasourcePlus {
|
||||||
}
|
}
|
||||||
|
|
||||||
async testConnection() {
|
async testConnection() {
|
||||||
|
const response: ConnectionInfo = {
|
||||||
|
connected: false,
|
||||||
|
}
|
||||||
try {
|
try {
|
||||||
const [result] = await this.internalQuery(
|
const [result] = await this.internalQuery(
|
||||||
{ sql: "SELECT 1+1 AS checkRes" },
|
{ sql: "SELECT 1+1 AS checkRes" },
|
||||||
{ connect: true }
|
{ connect: true }
|
||||||
)
|
)
|
||||||
return result?.checkRes == 2
|
response.connected = result?.checkRes == 2
|
||||||
} catch (e: any) {
|
} catch (e: any) {
|
||||||
return { error: e.message as string }
|
response.error = e.message as string
|
||||||
}
|
}
|
||||||
|
return response
|
||||||
}
|
}
|
||||||
|
|
||||||
getBindingIdentifier(): string {
|
getBindingIdentifier(): string {
|
||||||
|
|
|
@ -25,12 +25,7 @@ import {
|
||||||
ExecuteOptions,
|
ExecuteOptions,
|
||||||
Result,
|
Result,
|
||||||
} from "oracledb"
|
} from "oracledb"
|
||||||
import {
|
import { OracleTable, OracleColumn, OracleColumnsResponse } from "./base/types"
|
||||||
OracleTable,
|
|
||||||
OracleColumn,
|
|
||||||
OracleColumnsResponse,
|
|
||||||
OracleConstraint,
|
|
||||||
} from "./base/types"
|
|
||||||
let oracledb: any
|
let oracledb: any
|
||||||
try {
|
try {
|
||||||
oracledb = require("oracledb")
|
oracledb = require("oracledb")
|
||||||
|
@ -54,7 +49,7 @@ const SCHEMA: Integration = {
|
||||||
type: "Relational",
|
type: "Relational",
|
||||||
description:
|
description:
|
||||||
"Oracle Database is an object-relational database management system developed by Oracle Corporation",
|
"Oracle Database is an object-relational database management system developed by Oracle Corporation",
|
||||||
features: [DatasourceFeature.CONNECTION_CHECKING],
|
features: [],
|
||||||
datasource: {
|
datasource: {
|
||||||
host: {
|
host: {
|
||||||
type: DatasourceFieldType.STRING,
|
type: DatasourceFieldType.STRING,
|
||||||
|
|
|
@ -7,6 +7,7 @@ import {
|
||||||
Table,
|
Table,
|
||||||
DatasourcePlus,
|
DatasourcePlus,
|
||||||
DatasourceFeature,
|
DatasourceFeature,
|
||||||
|
ConnectionInfo,
|
||||||
} from "@budibase/types"
|
} from "@budibase/types"
|
||||||
import {
|
import {
|
||||||
getSqlQuery,
|
getSqlQuery,
|
||||||
|
@ -153,14 +154,18 @@ class PostgresIntegration extends Sql implements DatasourcePlus {
|
||||||
}
|
}
|
||||||
|
|
||||||
async testConnection() {
|
async testConnection() {
|
||||||
|
const response: ConnectionInfo = {
|
||||||
|
connected: false,
|
||||||
|
}
|
||||||
try {
|
try {
|
||||||
await this.openConnection()
|
await this.openConnection()
|
||||||
return true
|
response.connected = true
|
||||||
} catch (e: any) {
|
} catch (e: any) {
|
||||||
return { error: e.message as string }
|
response.error = e.message as string
|
||||||
} finally {
|
} finally {
|
||||||
await this.closeConnection()
|
await this.closeConnection()
|
||||||
}
|
}
|
||||||
|
return response
|
||||||
}
|
}
|
||||||
|
|
||||||
getBindingIdentifier(): string {
|
getBindingIdentifier(): string {
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
import {
|
import {
|
||||||
|
ConnectionInfo,
|
||||||
DatasourceFeature,
|
DatasourceFeature,
|
||||||
DatasourceFieldType,
|
DatasourceFieldType,
|
||||||
Integration,
|
Integration,
|
||||||
|
@ -107,14 +108,18 @@ class RedisIntegration {
|
||||||
}
|
}
|
||||||
|
|
||||||
async testConnection() {
|
async testConnection() {
|
||||||
|
const response: ConnectionInfo = {
|
||||||
|
connected: false,
|
||||||
|
}
|
||||||
try {
|
try {
|
||||||
await this.client.ping()
|
await this.client.ping()
|
||||||
return true
|
response.connected = true
|
||||||
} catch (e: any) {
|
} catch (e: any) {
|
||||||
return { error: e.message as string }
|
response.error = e.message as string
|
||||||
} finally {
|
} finally {
|
||||||
await this.disconnect()
|
await this.disconnect()
|
||||||
}
|
}
|
||||||
|
return response
|
||||||
}
|
}
|
||||||
|
|
||||||
async disconnect() {
|
async disconnect() {
|
||||||
|
|
|
@ -4,6 +4,7 @@ import {
|
||||||
IntegrationBase,
|
IntegrationBase,
|
||||||
DatasourceFieldType,
|
DatasourceFieldType,
|
||||||
DatasourceFeature,
|
DatasourceFeature,
|
||||||
|
ConnectionInfo,
|
||||||
} from "@budibase/types"
|
} from "@budibase/types"
|
||||||
|
|
||||||
import AWS from "aws-sdk"
|
import AWS from "aws-sdk"
|
||||||
|
@ -168,12 +169,16 @@ class S3Integration implements IntegrationBase {
|
||||||
}
|
}
|
||||||
|
|
||||||
async testConnection() {
|
async testConnection() {
|
||||||
try {
|
const response: ConnectionInfo = {
|
||||||
const buckets = await this.client.listBuckets().promise()
|
connected: false,
|
||||||
return true
|
|
||||||
} catch (e: any) {
|
|
||||||
return { error: e.message as string }
|
|
||||||
}
|
}
|
||||||
|
try {
|
||||||
|
await this.client.listBuckets().promise()
|
||||||
|
response.connected = true
|
||||||
|
} catch (e: any) {
|
||||||
|
response.error = e.message as string
|
||||||
|
}
|
||||||
|
return response
|
||||||
}
|
}
|
||||||
|
|
||||||
async create(query: {
|
async create(query: {
|
||||||
|
|
|
@ -21,7 +21,7 @@ const SCHEMA: Integration = {
|
||||||
"Snowflake is a solution for data warehousing, data lakes, data engineering, data science, data application development, and securely sharing and consuming shared data.",
|
"Snowflake is a solution for data warehousing, data lakes, data engineering, data science, data application development, and securely sharing and consuming shared data.",
|
||||||
friendlyName: "Snowflake",
|
friendlyName: "Snowflake",
|
||||||
type: "Relational",
|
type: "Relational",
|
||||||
features: [DatasourceFeature.CONNECTION_CHECKING],
|
features: [],
|
||||||
datasource: {
|
datasource: {
|
||||||
account: {
|
account: {
|
||||||
type: "string",
|
type: "string",
|
||||||
|
|
|
@ -128,17 +128,17 @@ export interface Integration {
|
||||||
extra?: ExtraQueryConfig
|
extra?: ExtraQueryConfig
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export type ConnectionInfo = {
|
||||||
|
connected: boolean
|
||||||
|
error?: string
|
||||||
|
}
|
||||||
|
|
||||||
export interface IntegrationBase {
|
export interface IntegrationBase {
|
||||||
create?(query: any): Promise<any[] | any>
|
create?(query: any): Promise<any[] | any>
|
||||||
read?(query: any): Promise<any[] | any>
|
read?(query: any): Promise<any[] | any>
|
||||||
update?(query: any): Promise<any[] | any>
|
update?(query: any): Promise<any[] | any>
|
||||||
delete?(query: any): Promise<any[] | any>
|
delete?(query: any): Promise<any[] | any>
|
||||||
testConnection?(): Promise<
|
testConnection?(): Promise<ConnectionInfo>
|
||||||
| boolean
|
|
||||||
| {
|
|
||||||
error: string
|
|
||||||
}
|
|
||||||
>
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface DatasourcePlus extends IntegrationBase {
|
export interface DatasourcePlus extends IntegrationBase {
|
||||||
|
|
Loading…
Reference in a new issue