Skip to content

Commit

Permalink
Merge pull request #15323 from Budibase/revert-15215-chore/aws-v2-to-v3
Browse files Browse the repository at this point in the history
Revert "Update AWS SDK to V3"
  • Loading branch information
mike12345567 authored Jan 8, 2025
2 parents 377e764 + 8eed6de commit a10bd26
Show file tree
Hide file tree
Showing 31 changed files with 364 additions and 1,537 deletions.
28 changes: 0 additions & 28 deletions packages/backend-core/__mocks__/@aws-sdk/client-s3.ts

This file was deleted.

This file was deleted.

19 changes: 19 additions & 0 deletions packages/backend-core/__mocks__/aws-sdk.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
const mockS3 = {
headBucket: jest.fn().mockReturnThis(),
deleteObject: jest.fn().mockReturnThis(),
deleteObjects: jest.fn().mockReturnThis(),
createBucket: jest.fn().mockReturnThis(),
getObject: jest.fn().mockReturnThis(),
listObject: jest.fn().mockReturnThis(),
getSignedUrl: jest.fn((operation: string, params: any) => {
return `http://s3.example.com/${params.Bucket}/${params.Key}`
}),
promise: jest.fn().mockReturnThis(),
catch: jest.fn(),
}

const AWS = {
S3: jest.fn(() => mockS3),
}

export default AWS
6 changes: 1 addition & 5 deletions packages/backend-core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,6 @@
"test:watch": "jest --watchAll"
},
"dependencies": {
"@aws-sdk/client-s3": "3.709.0",
"@aws-sdk/lib-storage": "3.709.0",
"@aws-sdk/s3-request-presigner": "3.709.0",
"@budibase/nano": "10.1.5",
"@budibase/pouchdb-replication-stream": "1.2.11",
"@budibase/shared-core": "*",
Expand Down Expand Up @@ -74,20 +71,19 @@
"devDependencies": {
"@jest/types": "^29.6.3",
"@shopify/jest-koa-mocks": "5.1.1",
"@smithy/types": "4.0.0",
"@swc/core": "1.3.71",
"@swc/jest": "0.2.27",
"@types/chance": "1.1.3",
"@types/cookies": "0.7.8",
"@types/jest": "29.5.5",
"@types/koa": "2.13.4",
"@types/lodash": "4.14.200",
"@types/node-fetch": "2.6.4",
"@types/pouchdb": "6.4.2",
"@types/redlock": "4.0.7",
"@types/semver": "7.3.7",
"@types/tar-fs": "2.0.1",
"@types/uuid": "8.3.4",
"@types/koa": "2.13.4",
"chance": "1.1.8",
"ioredis-mock": "8.9.0",
"jest": "29.7.0",
Expand Down
2 changes: 1 addition & 1 deletion packages/backend-core/src/environment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ const environment = {
MINIO_ACCESS_KEY: process.env.MINIO_ACCESS_KEY,
MINIO_SECRET_KEY: process.env.MINIO_SECRET_KEY,
AWS_SESSION_TOKEN: process.env.AWS_SESSION_TOKEN,
AWS_REGION: process.env.AWS_REGION || "eu-west-1",
AWS_REGION: process.env.AWS_REGION,
MINIO_URL: process.env.MINIO_URL,
MINIO_ENABLED: process.env.MINIO_ENABLED || 1,
INTERNAL_API_KEY: process.env.INTERNAL_API_KEY,
Expand Down
8 changes: 4 additions & 4 deletions packages/backend-core/src/objectStore/buckets/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export function clientLibraryPath(appId: string) {
* due to issues with the domain we were unable to continue doing this - keeping
* incase we are able to switch back to CDN path again in future.
*/
export async function clientLibraryCDNUrl(appId: string, version: string) {
export function clientLibraryCDNUrl(appId: string, version: string) {
let file = clientLibraryPath(appId)
if (env.CLOUDFRONT_CDN) {
// append app version to bust the cache
Expand All @@ -24,7 +24,7 @@ export async function clientLibraryCDNUrl(appId: string, version: string) {
// file is public
return cloudfront.getUrl(file)
} else {
return await objectStore.getPresignedUrl(env.APPS_BUCKET_NAME, file)
return objectStore.getPresignedUrl(env.APPS_BUCKET_NAME, file)
}
}

Expand All @@ -44,10 +44,10 @@ export function clientLibraryUrl(appId: string, version: string) {
return `/api/assets/client?${qs.encode(qsParams)}`
}

export async function getAppFileUrl(s3Key: string) {
export function getAppFileUrl(s3Key: string) {
if (env.CLOUDFRONT_CDN) {
return cloudfront.getPresignedUrl(s3Key)
} else {
return await objectStore.getPresignedUrl(env.APPS_BUCKET_NAME, s3Key)
return objectStore.getPresignedUrl(env.APPS_BUCKET_NAME, s3Key)
}
}
8 changes: 2 additions & 6 deletions packages/backend-core/src/objectStore/buckets/global.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,15 @@ import * as cloudfront from "../cloudfront"

// URLs

export const getGlobalFileUrl = async (
type: string,
name: string,
etag?: string
) => {
export const getGlobalFileUrl = (type: string, name: string, etag?: string) => {
let file = getGlobalFileS3Key(type, name)
if (env.CLOUDFRONT_CDN) {
if (etag) {
file = `${file}?etag=${etag}`
}
return cloudfront.getPresignedUrl(file)
} else {
return await objectStore.getPresignedUrl(env.GLOBAL_BUCKET_NAME, file)
return objectStore.getPresignedUrl(env.GLOBAL_BUCKET_NAME, file)
}
}

Expand Down
22 changes: 10 additions & 12 deletions packages/backend-core/src/objectStore/buckets/plugins.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,37 +6,35 @@ import { Plugin } from "@budibase/types"

// URLS

export async function enrichPluginURLs(plugins?: Plugin[]): Promise<Plugin[]> {
export function enrichPluginURLs(plugins?: Plugin[]): Plugin[] {
if (!plugins || !plugins.length) {
return []
}
return await Promise.all(
plugins.map(async plugin => {
const jsUrl = await getPluginJSUrl(plugin)
const iconUrl = await getPluginIconUrl(plugin)
return { ...plugin, jsUrl, iconUrl }
})
)
return plugins.map(plugin => {
const jsUrl = getPluginJSUrl(plugin)
const iconUrl = getPluginIconUrl(plugin)
return { ...plugin, jsUrl, iconUrl }
})
}

async function getPluginJSUrl(plugin: Plugin) {
function getPluginJSUrl(plugin: Plugin) {
const s3Key = getPluginJSKey(plugin)
return getPluginUrl(s3Key)
}

async function getPluginIconUrl(plugin: Plugin) {
function getPluginIconUrl(plugin: Plugin): string | undefined {
const s3Key = getPluginIconKey(plugin)
if (!s3Key) {
return
}
return getPluginUrl(s3Key)
}

async function getPluginUrl(s3Key: string) {
function getPluginUrl(s3Key: string) {
if (env.CLOUDFRONT_CDN) {
return cloudfront.getPresignedUrl(s3Key)
} else {
return await objectStore.getPresignedUrl(env.PLUGIN_BUCKET_NAME, s3Key)
return objectStore.getPresignedUrl(env.PLUGIN_BUCKET_NAME, s3Key)
}
}

Expand Down
24 changes: 12 additions & 12 deletions packages/backend-core/src/objectStore/buckets/tests/app.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,25 +93,25 @@ describe("app", () => {
testEnv.multiTenant()
})

it("gets url with embedded minio", async () => {
it("gets url with embedded minio", () => {
testEnv.withMinio()
const url = await getAppFileUrl()
const url = getAppFileUrl()
expect(url).toBe(
"/files/signed/prod-budi-app-assets/app_123/attachments/image.jpeg"
)
})

it("gets url with custom S3", async () => {
it("gets url with custom S3", () => {
testEnv.withS3()
const url = await getAppFileUrl()
const url = getAppFileUrl()
expect(url).toBe(
"http://s3.example.com/prod-budi-app-assets/app_123/attachments/image.jpeg"
)
})

it("gets url with cloudfront + s3", async () => {
it("gets url with cloudfront + s3", () => {
testEnv.withCloudfront()
const url = await getAppFileUrl()
const url = getAppFileUrl()
// omit rest of signed params
expect(
url.includes("http://cf.example.com/app_123/attachments/image.jpeg?")
Expand All @@ -126,8 +126,8 @@ describe("app", () => {

it("gets url with embedded minio", async () => {
testEnv.withMinio()
await testEnv.withTenant(async () => {
const url = await getAppFileUrl()
await testEnv.withTenant(() => {
const url = getAppFileUrl()
expect(url).toBe(
"/files/signed/prod-budi-app-assets/app_123/attachments/image.jpeg"
)
Expand All @@ -136,8 +136,8 @@ describe("app", () => {

it("gets url with custom S3", async () => {
testEnv.withS3()
await testEnv.withTenant(async () => {
const url = await getAppFileUrl()
await testEnv.withTenant(() => {
const url = getAppFileUrl()
expect(url).toBe(
"http://s3.example.com/prod-budi-app-assets/app_123/attachments/image.jpeg"
)
Expand All @@ -146,8 +146,8 @@ describe("app", () => {

it("gets url with cloudfront + s3", async () => {
testEnv.withCloudfront()
await testEnv.withTenant(async () => {
const url = await getAppFileUrl()
await testEnv.withTenant(() => {
const url = getAppFileUrl()
// omit rest of signed params
expect(
url.includes(
Expand Down
26 changes: 13 additions & 13 deletions packages/backend-core/src/objectStore/buckets/tests/global.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { testEnv } from "../../../../tests/extra"

describe("global", () => {
describe("getGlobalFileUrl", () => {
async function getGlobalFileUrl() {
function getGlobalFileUrl() {
return global.getGlobalFileUrl("settings", "logoUrl", "etag")
}

Expand All @@ -12,21 +12,21 @@ describe("global", () => {
testEnv.singleTenant()
})

it("gets url with embedded minio", async () => {
it("gets url with embedded minio", () => {
testEnv.withMinio()
const url = await getGlobalFileUrl()
const url = getGlobalFileUrl()
expect(url).toBe("/files/signed/global/settings/logoUrl")
})

it("gets url with custom S3", async () => {
it("gets url with custom S3", () => {
testEnv.withS3()
const url = await getGlobalFileUrl()
const url = getGlobalFileUrl()
expect(url).toBe("http://s3.example.com/global/settings/logoUrl")
})

it("gets url with cloudfront + s3", async () => {
it("gets url with cloudfront + s3", () => {
testEnv.withCloudfront()
const url = await getGlobalFileUrl()
const url = getGlobalFileUrl()
// omit rest of signed params
expect(
url.includes("http://cf.example.com/settings/logoUrl?etag=etag&")
Expand All @@ -41,16 +41,16 @@ describe("global", () => {

it("gets url with embedded minio", async () => {
testEnv.withMinio()
await testEnv.withTenant(async tenantId => {
const url = await getGlobalFileUrl()
await testEnv.withTenant(tenantId => {
const url = getGlobalFileUrl()
expect(url).toBe(`/files/signed/global/${tenantId}/settings/logoUrl`)
})
})

it("gets url with custom S3", async () => {
testEnv.withS3()
await testEnv.withTenant(async tenantId => {
const url = await getGlobalFileUrl()
await testEnv.withTenant(tenantId => {
const url = getGlobalFileUrl()
expect(url).toBe(
`http://s3.example.com/global/${tenantId}/settings/logoUrl`
)
Expand All @@ -59,8 +59,8 @@ describe("global", () => {

it("gets url with cloudfront + s3", async () => {
testEnv.withCloudfront()
await testEnv.withTenant(async tenantId => {
const url = await getGlobalFileUrl()
await testEnv.withTenant(tenantId => {
const url = getGlobalFileUrl()
// omit rest of signed params
expect(
url.includes(
Expand Down
Loading

0 comments on commit a10bd26

Please sign in to comment.