2021-06-27 00:09:46 +02:00
import { Integration , QueryTypes } from "../definitions/datasource"
2021-11-10 20:35:09 +01:00
import { IntegrationBase } from "./base/IntegrationBase"
2021-06-24 19:16:48 +02:00
module S3Module {
const AWS = require ( "aws-sdk" )
interface S3Config {
2021-06-24 19:17:26 +02:00
region : string
accessKeyId : string
secretAccessKey : string
2021-12-31 17:15:49 +01:00
s3ForcePathStyle : boolean
endpoint? : string
2021-06-24 19:16:48 +02:00
}
const SCHEMA : Integration = {
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" ,
datasource : {
region : {
type : "string" ,
2021-12-31 17:15:49 +01:00
required : false ,
2021-06-24 19:16:48 +02:00
default : "us-east-1" ,
} ,
accessKeyId : {
type : "password" ,
required : true ,
} ,
secretAccessKey : {
type : "password" ,
required : true ,
} ,
2021-12-30 18:44:27 +01:00
endpoint : {
type : "string" ,
required : false ,
} ,
signatureVersion : {
type : "string" ,
required : false ,
2022-01-13 18:24:52 +01:00
default : "v4" ,
2021-12-30 18:44:27 +01:00
} ,
2021-06-24 19:16:48 +02:00
} ,
query : {
read : {
type : QueryTypes . FIELDS ,
fields : {
bucket : {
type : "string" ,
required : true ,
} ,
} ,
} ,
} ,
}
2021-11-10 20:35:09 +01:00
class S3Integration implements IntegrationBase {
2021-06-24 19:16:48 +02:00
private readonly config : S3Config
private client : any
constructor ( config : S3Config ) {
this . config = config
2021-12-31 17:15:49 +01:00
if ( this . config . endpoint ) {
this . config . s3ForcePathStyle = true
} else {
delete this . config . endpoint
}
2021-06-24 19:16:48 +02:00
2021-12-31 17:15:49 +01:00
this . client = new AWS . S3 ( this . config )
2021-06-24 19:16:48 +02:00
}
async read ( query : { bucket : string } ) {
const response = await this . client
. listObjects ( {
Bucket : query.bucket ,
} )
. promise ( )
return response . Contents
}
}
module .exports = {
schema : SCHEMA ,
integration : S3Integration ,
}
}