Merge pull request #12550 from Budibase/budi-7664-sqs-self-host-ui-for-detecting-lack-of-sqs-support
Add `isSqsAvailable` key to the environment endpoint.
This commit is contained in:
commit
a828881f87
|
@ -107,6 +107,7 @@ const environment = {
|
||||||
ENCRYPTION_KEY: process.env.ENCRYPTION_KEY,
|
ENCRYPTION_KEY: process.env.ENCRYPTION_KEY,
|
||||||
API_ENCRYPTION_KEY: getAPIEncryptionKey(),
|
API_ENCRYPTION_KEY: getAPIEncryptionKey(),
|
||||||
COUCH_DB_URL: process.env.COUCH_DB_URL || "http://localhost:4005",
|
COUCH_DB_URL: process.env.COUCH_DB_URL || "http://localhost:4005",
|
||||||
|
COUCH_DB_SQL_URL: process.env.COUCH_DB_SQL_URL || "http://localhost:4984",
|
||||||
COUCH_DB_USERNAME: process.env.COUCH_DB_USER,
|
COUCH_DB_USERNAME: process.env.COUCH_DB_USER,
|
||||||
COUCH_DB_PASSWORD: process.env.COUCH_DB_PASSWORD,
|
COUCH_DB_PASSWORD: process.env.COUCH_DB_PASSWORD,
|
||||||
GOOGLE_CLIENT_ID: process.env.GOOGLE_CLIENT_ID,
|
GOOGLE_CLIENT_ID: process.env.GOOGLE_CLIENT_ID,
|
||||||
|
|
|
@ -17,7 +17,6 @@ import {
|
||||||
basicWebhook,
|
basicWebhook,
|
||||||
} from "./structures"
|
} from "./structures"
|
||||||
import {
|
import {
|
||||||
auth,
|
|
||||||
cache,
|
cache,
|
||||||
constants,
|
constants,
|
||||||
context,
|
context,
|
||||||
|
|
|
@ -1,6 +1,25 @@
|
||||||
import { Ctx } from "@budibase/types"
|
import { Ctx } from "@budibase/types"
|
||||||
import env from "../../../environment"
|
import env from "../../../environment"
|
||||||
import { env as coreEnv } from "@budibase/backend-core"
|
import { env as coreEnv } from "@budibase/backend-core"
|
||||||
|
import nodeFetch from "node-fetch"
|
||||||
|
|
||||||
|
let sqsAvailable: boolean
|
||||||
|
async function isSqsAvailable() {
|
||||||
|
if (sqsAvailable !== undefined) {
|
||||||
|
return sqsAvailable
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
await nodeFetch(coreEnv.COUCH_DB_SQL_URL, {
|
||||||
|
timeout: 1000,
|
||||||
|
})
|
||||||
|
sqsAvailable = true
|
||||||
|
return true
|
||||||
|
} catch (e) {
|
||||||
|
sqsAvailable = false
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
export const fetch = async (ctx: Ctx) => {
|
export const fetch = async (ctx: Ctx) => {
|
||||||
ctx.body = {
|
ctx.body = {
|
||||||
|
@ -12,4 +31,10 @@ export const fetch = async (ctx: Ctx) => {
|
||||||
baseUrl: env.PLATFORM_URL,
|
baseUrl: env.PLATFORM_URL,
|
||||||
isDev: env.isDev() && !env.isTest(),
|
isDev: env.isDev() && !env.isTest(),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (env.SELF_HOSTED) {
|
||||||
|
ctx.body.infrastructure = {
|
||||||
|
sqs: await isSqsAvailable(),
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,7 @@
|
||||||
import { TestConfiguration } from "../../../../tests"
|
import { TestConfiguration } from "../../../../tests"
|
||||||
|
|
||||||
|
jest.unmock("node-fetch")
|
||||||
|
|
||||||
describe("/api/system/environment", () => {
|
describe("/api/system/environment", () => {
|
||||||
const config = new TestConfiguration()
|
const config = new TestConfiguration()
|
||||||
|
|
||||||
|
@ -27,5 +29,22 @@ describe("/api/system/environment", () => {
|
||||||
offlineMode: false,
|
offlineMode: false,
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
|
it("returns the expected environment for self hosters", async () => {
|
||||||
|
await config.withEnv({ SELF_HOSTED: true }, async () => {
|
||||||
|
const env = await config.api.environment.getEnvironment()
|
||||||
|
expect(env.body).toEqual({
|
||||||
|
cloud: false,
|
||||||
|
disableAccountPortal: 0,
|
||||||
|
isDev: false,
|
||||||
|
multiTenancy: true,
|
||||||
|
baseUrl: "http://localhost:10000",
|
||||||
|
offlineMode: false,
|
||||||
|
infrastructure: {
|
||||||
|
sqs: false,
|
||||||
|
},
|
||||||
|
})
|
||||||
|
})
|
||||||
|
})
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
|
@ -36,6 +36,7 @@ import {
|
||||||
} from "@budibase/types"
|
} from "@budibase/types"
|
||||||
import API from "./api"
|
import API from "./api"
|
||||||
import jwt, { Secret } from "jsonwebtoken"
|
import jwt, { Secret } from "jsonwebtoken"
|
||||||
|
import cloneDeep from "lodash/fp/cloneDeep"
|
||||||
|
|
||||||
class TestConfiguration {
|
class TestConfiguration {
|
||||||
server: any
|
server: any
|
||||||
|
@ -240,6 +241,34 @@ class TestConfiguration {
|
||||||
return { message: "Admin user only endpoint.", status: 403 }
|
return { message: "Admin user only endpoint.", status: 403 }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async withEnv(newEnvVars: Partial<typeof env>, f: () => Promise<void>) {
|
||||||
|
let cleanup = this.setEnv(newEnvVars)
|
||||||
|
try {
|
||||||
|
await f()
|
||||||
|
} finally {
|
||||||
|
cleanup()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Sets the environment variables to the given values and returns a function
|
||||||
|
* that can be called to reset the environment variables to their original values.
|
||||||
|
*/
|
||||||
|
setEnv(newEnvVars: Partial<typeof env>): () => void {
|
||||||
|
const oldEnv = cloneDeep(env)
|
||||||
|
|
||||||
|
let key: keyof typeof newEnvVars
|
||||||
|
for (key in newEnvVars) {
|
||||||
|
env._set(key, newEnvVars[key])
|
||||||
|
}
|
||||||
|
|
||||||
|
return () => {
|
||||||
|
for (const [key, value] of Object.entries(oldEnv)) {
|
||||||
|
env._set(key, value)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// USERS
|
// USERS
|
||||||
|
|
||||||
async createDefaultUser() {
|
async createDefaultUser() {
|
||||||
|
|
Loading…
Reference in New Issue