Merge pull request #7461 from Budibase/fix/remove-global-aws-configs
fixing s3 outage errors and scoping AWS configuration to service level
This commit is contained in:
commit
7f0e38501d
|
@ -66,15 +66,13 @@ const PUBLIC_BUCKETS = [ObjectStoreBuckets.APPS, ObjectStoreBuckets.GLOBAL]
|
||||||
* @constructor
|
* @constructor
|
||||||
*/
|
*/
|
||||||
export const ObjectStore = (bucket: any) => {
|
export const ObjectStore = (bucket: any) => {
|
||||||
AWS.config.update({
|
|
||||||
accessKeyId: env.MINIO_ACCESS_KEY,
|
|
||||||
secretAccessKey: env.MINIO_SECRET_KEY,
|
|
||||||
region: env.AWS_REGION,
|
|
||||||
})
|
|
||||||
const config: any = {
|
const config: any = {
|
||||||
s3ForcePathStyle: true,
|
s3ForcePathStyle: true,
|
||||||
signatureVersion: "v4",
|
signatureVersion: "v4",
|
||||||
apiVersion: "2006-03-01",
|
apiVersion: "2006-03-01",
|
||||||
|
accessKeyId: env.MINIO_ACCESS_KEY,
|
||||||
|
secretAccessKey: env.MINIO_SECRET_KEY,
|
||||||
|
region: env.AWS_REGION,
|
||||||
}
|
}
|
||||||
if (bucket) {
|
if (bucket) {
|
||||||
config.params = {
|
config.params = {
|
||||||
|
|
|
@ -103,11 +103,9 @@ class Table {
|
||||||
|
|
||||||
exports.init = endpoint => {
|
exports.init = endpoint => {
|
||||||
let AWS = require("aws-sdk")
|
let AWS = require("aws-sdk")
|
||||||
AWS.config.update({
|
|
||||||
region: AWS_REGION,
|
|
||||||
})
|
|
||||||
let docClientParams = {
|
let docClientParams = {
|
||||||
correctClockSkew: true,
|
correctClockSkew: true,
|
||||||
|
region: AWS_REGION,
|
||||||
}
|
}
|
||||||
if (endpoint) {
|
if (endpoint) {
|
||||||
docClientParams.endpoint = endpoint
|
docClientParams.endpoint = endpoint
|
||||||
|
|
|
@ -13,7 +13,8 @@ module DynamoModule {
|
||||||
region: string
|
region: string
|
||||||
accessKeyId: string
|
accessKeyId: string
|
||||||
secretAccessKey: string
|
secretAccessKey: string
|
||||||
endpoint: string
|
endpoint?: string
|
||||||
|
currentClockSkew?: boolean
|
||||||
}
|
}
|
||||||
|
|
||||||
const SCHEMA: Integration = {
|
const SCHEMA: Integration = {
|
||||||
|
@ -132,31 +133,20 @@ module DynamoModule {
|
||||||
|
|
||||||
constructor(config: DynamoDBConfig) {
|
constructor(config: DynamoDBConfig) {
|
||||||
this.config = config
|
this.config = config
|
||||||
if (this.config.endpoint && !this.config.endpoint.includes("localhost")) {
|
|
||||||
this.connect()
|
// User is using a local dynamoDB endpoint, don't auth with remote
|
||||||
}
|
if (this.config?.endpoint?.includes("localhost")) {
|
||||||
let options = {
|
// @ts-ignore
|
||||||
correctClockSkew: true,
|
this.config = {}
|
||||||
region: this.config.region || AWS_REGION,
|
|
||||||
endpoint: config.endpoint ? config.endpoint : undefined,
|
|
||||||
}
|
|
||||||
this.client = new AWS.DynamoDB.DocumentClient(options)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
end() {
|
this.config = {
|
||||||
this.disconnect()
|
...this.config,
|
||||||
|
currentClockSkew: true,
|
||||||
|
region: config.region || AWS_REGION,
|
||||||
|
endpoint: config.endpoint || undefined,
|
||||||
}
|
}
|
||||||
|
this.client = new AWS.DynamoDB.DocumentClient(this.config)
|
||||||
connect() {
|
|
||||||
AWS.config.update(this.config)
|
|
||||||
}
|
|
||||||
|
|
||||||
disconnect() {
|
|
||||||
AWS.config.update({
|
|
||||||
secretAccessKey: undefined,
|
|
||||||
accessKeyId: undefined,
|
|
||||||
region: AWS_REGION,
|
|
||||||
})
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async create(query: { table: string; json: object }) {
|
async create(query: { table: string; json: object }) {
|
||||||
|
@ -197,7 +187,7 @@ module DynamoModule {
|
||||||
const params = {
|
const params = {
|
||||||
TableName: query.table,
|
TableName: query.table,
|
||||||
}
|
}
|
||||||
return new AWS.DynamoDB().describeTable(params).promise()
|
return new AWS.DynamoDB(this.config).describeTable(params).promise()
|
||||||
}
|
}
|
||||||
|
|
||||||
async get(query: { table: string; json: object }) {
|
async get(query: { table: string; json: object }) {
|
||||||
|
|
|
@ -100,4 +100,52 @@ describe("DynamoDB Integration", () => {
|
||||||
Name: "John"
|
Name: "John"
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
|
it("configures the dynamoDB constructor based on an empty endpoint parameter", async () => {
|
||||||
|
const config = {
|
||||||
|
region: "us-east-1",
|
||||||
|
accessKeyId: "test",
|
||||||
|
secretAccessKeyId: "test"
|
||||||
|
}
|
||||||
|
|
||||||
|
const integration = new DynamoDBIntegration.integration(config)
|
||||||
|
|
||||||
|
expect(integration.config).toEqual({
|
||||||
|
currentClockSkew: true,
|
||||||
|
...config
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
it("configures the dynamoDB constructor based on a localhost endpoint parameter", async () => {
|
||||||
|
const config = {
|
||||||
|
region: "us-east-1",
|
||||||
|
accessKeyId: "test",
|
||||||
|
secretAccessKeyId: "test",
|
||||||
|
endpoint: "localhost:8080"
|
||||||
|
}
|
||||||
|
|
||||||
|
const integration = new DynamoDBIntegration.integration(config)
|
||||||
|
|
||||||
|
expect(integration.config).toEqual({
|
||||||
|
region: "us-east-1",
|
||||||
|
currentClockSkew: true,
|
||||||
|
endpoint: "localhost:8080"
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
it("configures the dynamoDB constructor based on a remote endpoint parameter", async () => {
|
||||||
|
const config = {
|
||||||
|
region: "us-east-1",
|
||||||
|
accessKeyId: "test",
|
||||||
|
secretAccessKeyId: "test",
|
||||||
|
endpoint: "dynamodb.aws.foo.net"
|
||||||
|
}
|
||||||
|
|
||||||
|
const integration = new DynamoDBIntegration.integration(config)
|
||||||
|
|
||||||
|
expect(integration.config).toEqual({
|
||||||
|
currentClockSkew: true,
|
||||||
|
...config
|
||||||
|
})
|
||||||
|
})
|
||||||
})
|
})
|
Loading…
Reference in New Issue