budibase/packages/server/src/integrations/s3.js

61 lines
1.2 KiB
JavaScript
Raw Normal View History

const AWS = require("aws-sdk")
2021-01-11 18:18:22 +01:00
const SCHEMA = {
2021-01-15 18:29:46 +01:00
docs: "https://docs.aws.amazon.com/AWSJavaScriptSDK/latest/AWS/S3.html",
description:
"Amazon Simple Storage Service (Amazon S3) is an object storage service that offers industry-leading scalability, data availability, security, and performance.",
friendlyName: "Amazon S3",
2021-01-11 18:18:22 +01:00
datasource: {
region: {
type: "string",
required: true,
default: "us-east-1",
},
accessKeyId: {
2021-01-13 17:39:47 +01:00
type: "password",
2021-01-11 18:18:22 +01:00
required: true,
},
secretAccessKey: {
2021-01-13 17:39:47 +01:00
type: "password",
2021-01-11 18:18:22 +01:00
required: true,
},
},
2021-01-13 17:39:47 +01:00
query: {
read: {
type: "fields",
fields: {
bucket: {
type: "string",
required: true,
2021-01-13 17:39:47 +01:00
},
},
},
},
}
class S3Integration {
constructor(config) {
this.config = config
this.connect()
this.client = new AWS.S3()
}
async connect() {
AWS.config.update(this.config)
}
2021-01-13 17:39:47 +01:00
async read(query) {
const response = await this.client
.listObjects({
2021-01-13 17:39:47 +01:00
Bucket: query.bucket,
})
.promise()
return response.Contents
}
}
module.exports = {
2021-01-11 18:18:22 +01:00
schema: SCHEMA,
integration: S3Integration,
}