1
0
Fork 0
mirror of synced 2024-10-02 10:08:09 +13:00

Implement s3 checks

This commit is contained in:
Adria Navarro 2023-05-15 17:37:28 +02:00
parent cb398dad02
commit 1e505791c0
3 changed files with 50 additions and 4 deletions

View file

@ -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

View file

@ -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)
})
})
})

View file

@ -1,3 +1,3 @@
const Chance = require("chance")
import Chance from "chance"
export default new Chance()