2023-04-17 15:07:49 +02:00
|
|
|
import { existsSync, readFileSync } from "fs"
|
2023-07-28 17:08:33 +02:00
|
|
|
import { ServiceType } from "@budibase/types"
|
2023-04-17 15:07:49 +02:00
|
|
|
|
2021-05-05 18:49:34 +02:00
|
|
|
function isTest() {
|
2023-09-07 15:37:22 +02:00
|
|
|
return isJest()
|
2022-12-12 23:02:32 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
function isJest() {
|
2023-09-07 15:37:22 +02:00
|
|
|
return (
|
|
|
|
process.env.NODE_ENV === "jest" ||
|
|
|
|
(process.env.JEST_WORKER_ID != null &&
|
|
|
|
process.env.JEST_WORKER_ID !== "null")
|
|
|
|
)
|
2021-05-05 18:49:34 +02:00
|
|
|
}
|
|
|
|
|
2022-05-04 13:28:21 +02:00
|
|
|
function isDev() {
|
|
|
|
return process.env.NODE_ENV !== "production"
|
|
|
|
}
|
|
|
|
|
2022-05-17 18:44:40 +02:00
|
|
|
let LOADED = false
|
|
|
|
if (!LOADED && isDev() && !isTest()) {
|
|
|
|
require("dotenv").config()
|
|
|
|
LOADED = true
|
|
|
|
}
|
|
|
|
|
2022-09-23 17:30:45 +02:00
|
|
|
const DefaultBucketName = {
|
|
|
|
BACKUPS: "backups",
|
|
|
|
APPS: "prod-budi-app-assets",
|
|
|
|
TEMPLATES: "templates",
|
|
|
|
GLOBAL: "global",
|
|
|
|
PLUGINS: "plugins",
|
|
|
|
}
|
|
|
|
|
2023-02-27 14:42:51 +01:00
|
|
|
const selfHosted = !!parseInt(process.env.SELF_HOSTED || "")
|
|
|
|
|
2023-03-13 16:02:59 +01:00
|
|
|
function getAPIEncryptionKey() {
|
|
|
|
return process.env.API_ENCRYPTION_KEY
|
|
|
|
? process.env.API_ENCRYPTION_KEY
|
|
|
|
: process.env.JWT_SECRET // fallback to the JWT_SECRET used historically
|
|
|
|
}
|
|
|
|
|
2023-04-04 16:08:46 +02:00
|
|
|
function httpLogging() {
|
|
|
|
if (process.env.HTTP_LOGGING === undefined) {
|
|
|
|
// on by default unless otherwise specified
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
|
|
|
|
return process.env.HTTP_LOGGING
|
|
|
|
}
|
|
|
|
|
2023-07-05 10:27:13 +02:00
|
|
|
function getPackageJsonFields(): {
|
2023-10-23 12:23:44 +02:00
|
|
|
VERSION: string
|
2023-07-05 16:43:23 +02:00
|
|
|
SERVICE_NAME: string
|
2023-07-05 10:27:13 +02:00
|
|
|
} {
|
2023-04-17 15:07:49 +02:00
|
|
|
function findFileInAncestors(
|
|
|
|
fileName: string,
|
|
|
|
currentDir: string
|
|
|
|
): string | null {
|
|
|
|
const filePath = `${currentDir}/${fileName}`
|
|
|
|
if (existsSync(filePath)) {
|
|
|
|
return filePath
|
|
|
|
}
|
|
|
|
|
|
|
|
const parentDir = `${currentDir}/..`
|
|
|
|
if (parentDir === currentDir) {
|
|
|
|
// reached root directory
|
|
|
|
return null
|
|
|
|
}
|
|
|
|
|
|
|
|
return findFileInAncestors(fileName, parentDir)
|
|
|
|
}
|
|
|
|
|
|
|
|
try {
|
|
|
|
const packageJsonFile = findFileInAncestors("package.json", process.cwd())
|
|
|
|
const content = readFileSync(packageJsonFile!, "utf-8")
|
2023-07-05 10:27:13 +02:00
|
|
|
const parsedContent = JSON.parse(content)
|
|
|
|
return {
|
2023-10-23 13:55:58 +02:00
|
|
|
VERSION: process.env.BUDIBASE_VERSION || parsedContent.version,
|
2023-07-05 16:51:42 +02:00
|
|
|
SERVICE_NAME: parsedContent.name,
|
2023-07-05 10:27:13 +02:00
|
|
|
}
|
2023-04-17 15:07:49 +02:00
|
|
|
} catch {
|
2023-05-15 16:52:59 +02:00
|
|
|
// throwing an error here is confusing/causes backend-core to be hard to import
|
2023-10-23 13:55:58 +02:00
|
|
|
return { VERSION: process.env.BUDIBASE_VERSION || "", SERVICE_NAME: "" }
|
2023-04-17 15:07:49 +02:00
|
|
|
}
|
2023-04-17 14:53:00 +02:00
|
|
|
}
|
|
|
|
|
2023-07-28 16:39:59 +02:00
|
|
|
function isWorker() {
|
2023-07-28 17:50:44 +02:00
|
|
|
return environment.SERVICE_TYPE === ServiceType.WORKER
|
2023-07-28 16:39:59 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
function isApps() {
|
2023-07-28 17:50:44 +02:00
|
|
|
return environment.SERVICE_TYPE === ServiceType.APPS
|
2023-07-28 16:39:59 +02:00
|
|
|
}
|
|
|
|
|
2022-11-25 20:57:07 +01:00
|
|
|
const environment = {
|
2022-05-17 18:44:40 +02:00
|
|
|
isTest,
|
2022-12-12 23:02:32 +01:00
|
|
|
isJest,
|
2022-05-17 18:44:40 +02:00
|
|
|
isDev,
|
2023-07-28 16:39:59 +02:00
|
|
|
isWorker,
|
|
|
|
isApps,
|
2022-12-15 12:35:22 +01:00
|
|
|
isProd: () => {
|
|
|
|
return !isDev()
|
|
|
|
},
|
2022-09-13 19:00:10 +02:00
|
|
|
JS_BCRYPT: process.env.JS_BCRYPT,
|
2021-04-14 15:13:48 +02:00
|
|
|
JWT_SECRET: process.env.JWT_SECRET,
|
2023-03-13 16:02:59 +01:00
|
|
|
JWT_SECRET_FALLBACK: process.env.JWT_SECRET_FALLBACK,
|
2023-01-16 19:15:43 +01:00
|
|
|
ENCRYPTION_KEY: process.env.ENCRYPTION_KEY,
|
2023-03-13 16:02:59 +01:00
|
|
|
API_ENCRYPTION_KEY: getAPIEncryptionKey(),
|
2022-04-27 23:36:45 +02:00
|
|
|
COUCH_DB_URL: process.env.COUCH_DB_URL || "http://localhost:4005",
|
2023-12-11 16:22:02 +01:00
|
|
|
COUCH_DB_SQL_URL: process.env.COUCH_DB_SQL_URL || "http://localhost:4984",
|
2021-08-18 12:23:28 +02:00
|
|
|
COUCH_DB_USERNAME: process.env.COUCH_DB_USER,
|
2021-08-17 15:11:03 +02:00
|
|
|
COUCH_DB_PASSWORD: process.env.COUCH_DB_PASSWORD,
|
2022-02-10 10:28:46 +01:00
|
|
|
GOOGLE_CLIENT_ID: process.env.GOOGLE_CLIENT_ID,
|
|
|
|
GOOGLE_CLIENT_SECRET: process.env.GOOGLE_CLIENT_SECRET,
|
2021-04-14 15:13:48 +02:00
|
|
|
SALT_ROUNDS: process.env.SALT_ROUNDS,
|
2023-02-13 13:09:16 +01:00
|
|
|
REDIS_URL: process.env.REDIS_URL || "localhost:6379",
|
2023-05-08 16:59:12 +02:00
|
|
|
REDIS_PASSWORD: process.env.REDIS_PASSWORD,
|
2023-04-28 20:53:15 +02:00
|
|
|
REDIS_CLUSTERED: process.env.REDIS_CLUSTERED,
|
2021-05-06 20:27:24 +02:00
|
|
|
MINIO_ACCESS_KEY: process.env.MINIO_ACCESS_KEY,
|
|
|
|
MINIO_SECRET_KEY: process.env.MINIO_SECRET_KEY,
|
2021-09-21 12:49:32 +02:00
|
|
|
AWS_REGION: process.env.AWS_REGION,
|
2021-05-06 20:27:24 +02:00
|
|
|
MINIO_URL: process.env.MINIO_URL,
|
2022-12-15 12:35:22 +01:00
|
|
|
MINIO_ENABLED: process.env.MINIO_ENABLED || 1,
|
2021-05-11 16:23:03 +02:00
|
|
|
INTERNAL_API_KEY: process.env.INTERNAL_API_KEY,
|
2023-03-13 16:02:59 +01:00
|
|
|
INTERNAL_API_KEY_FALLBACK: process.env.INTERNAL_API_KEY_FALLBACK,
|
2021-08-05 10:59:08 +02:00
|
|
|
MULTI_TENANCY: process.env.MULTI_TENANCY,
|
2022-04-25 13:19:36 +02:00
|
|
|
ACCOUNT_PORTAL_URL:
|
|
|
|
process.env.ACCOUNT_PORTAL_URL || "https://account.budibase.app",
|
2022-09-12 11:43:26 +02:00
|
|
|
ACCOUNT_PORTAL_API_KEY: process.env.ACCOUNT_PORTAL_API_KEY || "",
|
2021-09-29 17:55:59 +02:00
|
|
|
DISABLE_ACCOUNT_PORTAL: process.env.DISABLE_ACCOUNT_PORTAL,
|
2023-02-27 14:42:51 +01:00
|
|
|
SELF_HOSTED: selfHosted,
|
2021-09-28 17:35:31 +02:00
|
|
|
COOKIE_DOMAIN: process.env.COOKIE_DOMAIN,
|
2022-07-08 11:52:23 +02:00
|
|
|
PLATFORM_URL: process.env.PLATFORM_URL || "",
|
2022-03-25 14:04:34 +01:00
|
|
|
POSTHOG_TOKEN: process.env.POSTHOG_TOKEN,
|
|
|
|
ENABLE_ANALYTICS: process.env.ENABLE_ANALYTICS,
|
2022-03-22 01:23:22 +01:00
|
|
|
TENANT_FEATURE_FLAGS: process.env.TENANT_FEATURE_FLAGS,
|
2022-12-15 12:35:22 +01:00
|
|
|
CLOUDFRONT_CDN: process.env.CLOUDFRONT_CDN,
|
|
|
|
CLOUDFRONT_PRIVATE_KEY_64: process.env.CLOUDFRONT_PRIVATE_KEY_64,
|
|
|
|
CLOUDFRONT_PUBLIC_KEY_ID: process.env.CLOUDFRONT_PUBLIC_KEY_ID,
|
2022-09-23 17:30:45 +02:00
|
|
|
BACKUPS_BUCKET_NAME:
|
|
|
|
process.env.BACKUPS_BUCKET_NAME || DefaultBucketName.BACKUPS,
|
|
|
|
APPS_BUCKET_NAME: process.env.APPS_BUCKET_NAME || DefaultBucketName.APPS,
|
|
|
|
TEMPLATES_BUCKET_NAME:
|
|
|
|
process.env.TEMPLATES_BUCKET_NAME || DefaultBucketName.TEMPLATES,
|
|
|
|
GLOBAL_BUCKET_NAME:
|
|
|
|
process.env.GLOBAL_BUCKET_NAME || DefaultBucketName.GLOBAL,
|
|
|
|
PLUGIN_BUCKET_NAME:
|
|
|
|
process.env.PLUGIN_BUCKET_NAME || DefaultBucketName.PLUGINS,
|
2022-04-26 18:13:45 +02:00
|
|
|
USE_COUCH: process.env.USE_COUCH || true,
|
2023-06-01 01:02:55 +02:00
|
|
|
MOCK_REDIS: process.env.MOCK_REDIS,
|
2022-05-24 10:12:39 +02:00
|
|
|
DEFAULT_LICENSE: process.env.DEFAULT_LICENSE,
|
2022-06-01 15:10:00 +02:00
|
|
|
SERVICE: process.env.SERVICE || "budibase",
|
2023-04-04 16:08:46 +02:00
|
|
|
LOG_LEVEL: process.env.LOG_LEVEL || "info",
|
2022-08-05 18:13:03 +02:00
|
|
|
SESSION_UPDATE_PERIOD: process.env.SESSION_UPDATE_PERIOD,
|
2022-06-01 15:10:00 +02:00
|
|
|
DEPLOYMENT_ENVIRONMENT:
|
|
|
|
process.env.DEPLOYMENT_ENVIRONMENT || "docker-compose",
|
2023-04-04 16:08:46 +02:00
|
|
|
HTTP_LOGGING: httpLogging(),
|
2023-02-27 12:42:52 +01:00
|
|
|
ENABLE_AUDIT_LOG_IP_ADDR: process.env.ENABLE_AUDIT_LOG_IP_ADDR,
|
2023-02-23 14:41:35 +01:00
|
|
|
// smtp
|
|
|
|
SMTP_FALLBACK_ENABLED: process.env.SMTP_FALLBACK_ENABLED,
|
|
|
|
SMTP_USER: process.env.SMTP_USER,
|
|
|
|
SMTP_PASSWORD: process.env.SMTP_PASSWORD,
|
|
|
|
SMTP_HOST: process.env.SMTP_HOST,
|
|
|
|
SMTP_PORT: parseInt(process.env.SMTP_PORT || ""),
|
|
|
|
SMTP_FROM_ADDRESS: process.env.SMTP_FROM_ADDRESS,
|
2023-03-03 11:03:33 +01:00
|
|
|
DISABLE_JWT_WARNING: process.env.DISABLE_JWT_WARNING,
|
2023-03-08 17:30:26 +01:00
|
|
|
BLACKLIST_IPS: process.env.BLACKLIST_IPS,
|
2023-07-28 16:39:59 +02:00
|
|
|
SERVICE_TYPE: "unknown",
|
2024-01-05 14:17:10 +01:00
|
|
|
PASSWORD_MIN_LENGTH: process.env.PASSWORD_MIN_LENGTH,
|
|
|
|
PASSWORD_MAX_LENGTH: process.env.PASSWORD_MAX_LENGTH,
|
2023-02-27 14:42:51 +01:00
|
|
|
/**
|
|
|
|
* Enable to allow an admin user to login using a password.
|
|
|
|
* This can be useful to prevent lockout when configuring SSO.
|
|
|
|
* However, this should be turned OFF by default for security purposes.
|
|
|
|
*/
|
|
|
|
ENABLE_SSO_MAINTENANCE_MODE: selfHosted
|
|
|
|
? process.env.ENABLE_SSO_MAINTENANCE_MODE
|
|
|
|
: false,
|
2023-07-05 10:27:13 +02:00
|
|
|
...getPackageJsonFields(),
|
2023-05-02 17:22:43 +02:00
|
|
|
DISABLE_PINO_LOGGER: process.env.DISABLE_PINO_LOGGER,
|
2023-07-06 21:44:48 +02:00
|
|
|
OFFLINE_MODE: process.env.OFFLINE_MODE,
|
2024-01-25 17:22:39 +01:00
|
|
|
SESSION_EXPIRY_SECONDS: process.env.SESSION_EXPIRY_SECONDS,
|
2022-05-03 23:58:19 +02:00
|
|
|
_set(key: any, value: any) {
|
2021-07-15 13:55:35 +02:00
|
|
|
process.env[key] = value
|
2022-11-28 18:54:04 +01:00
|
|
|
// @ts-ignore
|
|
|
|
environment[key] = value
|
2021-07-15 13:55:35 +02:00
|
|
|
},
|
2023-07-11 14:02:18 +02:00
|
|
|
ROLLING_LOG_MAX_SIZE: process.env.ROLLING_LOG_MAX_SIZE || "10M",
|
2024-03-01 13:09:42 +01:00
|
|
|
DISABLE_SCIM_CALLS: process.env.DISABLE_SCIM_CALLS,
|
2021-04-14 15:13:48 +02:00
|
|
|
}
|
2022-03-25 14:04:34 +01:00
|
|
|
|
|
|
|
// clean up any environment variable edge cases
|
2022-11-25 20:57:07 +01:00
|
|
|
for (let [key, value] of Object.entries(environment)) {
|
2022-03-25 14:04:34 +01:00
|
|
|
// handle the edge case of "0" to disable an environment variable
|
|
|
|
if (value === "0") {
|
2022-06-23 21:22:51 +02:00
|
|
|
// @ts-ignore
|
2022-11-28 20:12:23 +01:00
|
|
|
environment[key] = 0
|
2022-03-25 14:04:34 +01:00
|
|
|
}
|
2022-12-15 12:35:22 +01:00
|
|
|
// handle the edge case of "false" to disable an environment variable
|
|
|
|
if (value === "false") {
|
|
|
|
// @ts-ignore
|
|
|
|
environment[key] = 0
|
|
|
|
}
|
2022-03-25 14:04:34 +01:00
|
|
|
}
|
2022-05-23 23:14:44 +02:00
|
|
|
|
2023-01-11 10:37:37 +01:00
|
|
|
export default environment
|