Implement s3 checks
This commit is contained in:
parent
cb398dad02
commit
1e505791c0
|
@ -5,8 +5,8 @@ import {
|
|||
DatasourceFieldType,
|
||||
} from "@budibase/types"
|
||||
|
||||
const AWS = require("aws-sdk")
|
||||
const csv = require("csvtojson")
|
||||
import AWS from "aws-sdk"
|
||||
import csv from "csvtojson"
|
||||
|
||||
interface S3Config {
|
||||
region: string
|
||||
|
@ -152,7 +152,7 @@ const SCHEMA: Integration = {
|
|||
|
||||
class S3Integration implements IntegrationBase {
|
||||
private readonly config: S3Config
|
||||
private client: any
|
||||
private client
|
||||
|
||||
constructor(config: S3Config) {
|
||||
this.config = config
|
||||
|
@ -165,6 +165,15 @@ class S3Integration implements IntegrationBase {
|
|||
this.client = new AWS.S3(this.config)
|
||||
}
|
||||
|
||||
async testConnection() {
|
||||
try {
|
||||
const buckets = await this.client.listBuckets().promise()
|
||||
return true
|
||||
} catch (e: any) {
|
||||
return { error: e.message as string }
|
||||
}
|
||||
}
|
||||
|
||||
async create(query: {
|
||||
bucket: string
|
||||
location: string
|
||||
|
|
|
@ -0,0 +1,37 @@
|
|||
import s3 from "../../../../packages/server/src/integrations/s3"
|
||||
import { GenericContainer } from "testcontainers"
|
||||
import { generator } from "../../shared"
|
||||
|
||||
jest.unmock("aws-sdk")
|
||||
|
||||
describe("datasource validators", () => {
|
||||
describe("s3", () => {
|
||||
let host: string
|
||||
let port: number
|
||||
|
||||
beforeAll(async () => {
|
||||
const container = await new GenericContainer("localstack/localstack")
|
||||
.withExposedPorts(4566)
|
||||
.withEnv("SERVICES", "s3")
|
||||
.withEnv("DEFAULT_REGION", "eu-west-1")
|
||||
.withEnv("AWS_ACCESS_KEY_ID", "testkey")
|
||||
.withEnv("AWS_SECRET_ACCESS_KEY", "testsecret")
|
||||
.start()
|
||||
|
||||
host = container.getContainerIpAddress()
|
||||
port = container.getMappedPort(4566)
|
||||
})
|
||||
|
||||
it("test valid connection", async () => {
|
||||
const integration = new s3.integration({
|
||||
region: "eu-west-1",
|
||||
accessKeyId: "testkey",
|
||||
secretAccessKey: "testsecret",
|
||||
s3ForcePathStyle: false,
|
||||
endpoint: `http://${host}:${port}`,
|
||||
})
|
||||
const result = await integration.testConnection()
|
||||
expect(result).toBe(true)
|
||||
})
|
||||
})
|
||||
})
|
|
@ -1,3 +1,3 @@
|
|||
const Chance = require("chance")
|
||||
import Chance from "chance"
|
||||
|
||||
export default new Chance()
|
||||
|
|
Loading…
Reference in New Issue