1
0
Fork 0
mirror of synced 2024-08-15 18:11:40 +12:00

Merge branch 'feature/environment-variables' of github.com:Budibase/budibase into feature/environment-variables

This commit is contained in:
Peter Clement 2023-01-30 11:08:09 +00:00
commit 29a6bbbb90
22 changed files with 157 additions and 98 deletions

View file

@ -1,5 +1,5 @@
{
"version": "2.2.12-alpha.41",
"version": "2.2.12-alpha.43",
"npmClient": "yarn",
"packages": [
"packages/*"

View file

@ -1,6 +1,6 @@
{
"name": "@budibase/backend-core",
"version": "2.2.12-alpha.41",
"version": "2.2.12-alpha.43",
"description": "Budibase backend core libraries used in server and worker",
"main": "dist/src/index.js",
"types": "dist/src/index.d.ts",
@ -23,7 +23,7 @@
},
"dependencies": {
"@budibase/nano": "10.1.1",
"@budibase/types": "2.2.12-alpha.41",
"@budibase/types": "2.2.12-alpha.43",
"@shopify/jest-koa-mocks": "5.0.1",
"@techpass/passport-openidconnect": "0.3.2",
"aws-cloudfront-sign": "2.2.0",

View file

@ -1,7 +1,7 @@
{
"name": "@budibase/bbui",
"description": "A UI solution used in the different Budibase projects.",
"version": "2.2.12-alpha.41",
"version": "2.2.12-alpha.43",
"license": "MPL-2.0",
"svelte": "src/index.js",
"module": "dist/bbui.es.js",
@ -38,7 +38,7 @@
],
"dependencies": {
"@adobe/spectrum-css-workflow-icons": "1.2.1",
"@budibase/string-templates": "2.2.12-alpha.41",
"@budibase/string-templates": "2.2.12-alpha.43",
"@spectrum-css/accordion": "3.0.24",
"@spectrum-css/actionbutton": "1.0.1",
"@spectrum-css/actiongroup": "1.0.1",

View file

@ -1,4 +1,4 @@
const ignoredClasses = [".flatpickr-calendar"]
const ignoredClasses = [".flatpickr-calendar", ".spectrum-Popover"]
let clickHandlers = []
/**
@ -19,7 +19,7 @@ const handleClick = event => {
}
// Ignore clicks for modals, unless the handler is registered from a modal
const sourceInModal = handler.element.closest(".spectrum-Modal") != null
const sourceInModal = handler.anchor.closest(".spectrum-Modal") != null
const clickInModal = event.target.closest(".spectrum-Modal") != null
if (clickInModal && !sourceInModal) {
return
@ -33,10 +33,10 @@ document.documentElement.addEventListener("click", handleClick, true)
/**
* Adds or updates a click handler
*/
const updateHandler = (id, element, callback) => {
const updateHandler = (id, element, anchor, callback) => {
let existingHandler = clickHandlers.find(x => x.id === id)
if (!existingHandler) {
clickHandlers.push({ id, element, callback })
clickHandlers.push({ id, element, anchor, callback })
} else {
existingHandler.callback = callback
}
@ -51,12 +51,22 @@ const removeHandler = id => {
/**
* Svelte action to apply a click outside handler for a certain element
* opts.anchor is an optional param specifying the real root source of the
* component being observed. This is required for things like popovers, where
* the element using the clickoutside action is the popover, but the popover is
* rendered at the root of the DOM somewhere, whereas the popover anchor is the
* element we actually want to consider when determining the source component.
*/
export default (element, callback) => {
export default (element, opts) => {
const id = Math.random()
updateHandler(id, element, callback)
const update = newOpts => {
const callback = newOpts?.callback || newOpts
const anchor = newOpts?.anchor || element
updateHandler(id, element, anchor, callback)
}
update(opts)
return {
update: newCallback => updateHandler(id, element, newCallback),
update,
destroy: () => removeHandler(id),
}
}

View file

@ -14,6 +14,7 @@
<Icon name={icon} />
{/if}
{/if}
<slot name="icon" />
<div>
<slot />
</div>

View file

@ -68,7 +68,10 @@
<div
tabindex="0"
use:positionDropdown={{ anchor, align, maxWidth, useAnchorWidth }}
use:clickOutside={handleOutsideClick}
use:clickOutside={{
callback: handleOutsideClick,
anchor,
}}
on:keydown={handleEscape}
class={"spectrum-Popover is-open " + (tooltipClasses || "")}
role="presentation"

View file

@ -1,6 +1,6 @@
{
"name": "@budibase/builder",
"version": "2.2.12-alpha.41",
"version": "2.2.12-alpha.43",
"license": "GPL-3.0",
"private": true,
"scripts": {
@ -71,10 +71,10 @@
}
},
"dependencies": {
"@budibase/bbui": "2.2.12-alpha.41",
"@budibase/client": "2.2.12-alpha.41",
"@budibase/frontend-core": "2.2.12-alpha.41",
"@budibase/string-templates": "2.2.12-alpha.41",
"@budibase/bbui": "2.2.12-alpha.43",
"@budibase/client": "2.2.12-alpha.43",
"@budibase/frontend-core": "2.2.12-alpha.43",
"@budibase/string-templates": "2.2.12-alpha.43",
"@sentry/browser": "5.19.1",
"@spectrum-css/accordion": "^3.0.24",
"@spectrum-css/page": "^3.0.1",

View file

@ -20,7 +20,8 @@
$isActive,
$tables,
$queries,
$views
$views,
openDataSources
)
$: openDataSource = enrichedDataSources.find(x => x.open)
$: {
@ -36,7 +37,8 @@
isActive,
tables,
queries,
views
views,
openDataSources
) => {
if (!datasources?.list?.length) {
return []

View file

@ -1,6 +1,6 @@
{
"name": "@budibase/cli",
"version": "2.2.12-alpha.41",
"version": "2.2.12-alpha.43",
"description": "Budibase CLI, for developers, self hosting and migrations.",
"main": "src/index.js",
"bin": {
@ -26,9 +26,9 @@
"outputPath": "build"
},
"dependencies": {
"@budibase/backend-core": "2.2.12-alpha.41",
"@budibase/string-templates": "2.2.12-alpha.41",
"@budibase/types": "2.2.12-alpha.41",
"@budibase/backend-core": "2.2.12-alpha.43",
"@budibase/string-templates": "2.2.12-alpha.43",
"@budibase/types": "2.2.12-alpha.43",
"axios": "0.21.2",
"chalk": "4.1.0",
"cli-progress": "3.11.2",

View file

@ -1,6 +1,6 @@
{
"name": "@budibase/client",
"version": "2.2.12-alpha.41",
"version": "2.2.12-alpha.43",
"license": "MPL-2.0",
"module": "dist/budibase-client.js",
"main": "dist/budibase-client.js",
@ -19,9 +19,9 @@
"dev:builder": "rollup -cw"
},
"dependencies": {
"@budibase/bbui": "2.2.12-alpha.41",
"@budibase/frontend-core": "2.2.12-alpha.41",
"@budibase/string-templates": "2.2.12-alpha.41",
"@budibase/bbui": "2.2.12-alpha.43",
"@budibase/frontend-core": "2.2.12-alpha.43",
"@budibase/string-templates": "2.2.12-alpha.43",
"@spectrum-css/button": "^3.0.3",
"@spectrum-css/card": "^3.0.3",
"@spectrum-css/divider": "^1.0.3",

View file

@ -1,12 +1,12 @@
{
"name": "@budibase/frontend-core",
"version": "2.2.12-alpha.41",
"version": "2.2.12-alpha.43",
"description": "Budibase frontend core libraries used in builder and client",
"author": "Budibase",
"license": "MPL-2.0",
"svelte": "src/index.js",
"dependencies": {
"@budibase/bbui": "2.2.12-alpha.41",
"@budibase/bbui": "2.2.12-alpha.43",
"lodash": "^4.17.21",
"svelte": "^3.46.2"
}

View file

@ -1,6 +1,6 @@
{
"name": "@budibase/sdk",
"version": "2.2.12-alpha.41",
"version": "2.2.12-alpha.43",
"description": "Budibase Public API SDK",
"author": "Budibase",
"license": "MPL-2.0",

View file

@ -1,7 +1,7 @@
{
"name": "@budibase/server",
"email": "hi@budibase.com",
"version": "2.2.12-alpha.41",
"version": "2.2.12-alpha.43",
"description": "Budibase Web Server",
"main": "src/index.ts",
"repository": {
@ -43,11 +43,11 @@
"license": "GPL-3.0",
"dependencies": {
"@apidevtools/swagger-parser": "10.0.3",
"@budibase/backend-core": "2.2.12-alpha.41",
"@budibase/client": "2.2.12-alpha.41",
"@budibase/pro": "2.2.12-alpha.41",
"@budibase/string-templates": "2.2.12-alpha.41",
"@budibase/types": "2.2.12-alpha.41",
"@budibase/backend-core": "2.2.12-alpha.43",
"@budibase/client": "2.2.12-alpha.43",
"@budibase/pro": "2.2.12-alpha.43",
"@budibase/string-templates": "2.2.12-alpha.43",
"@budibase/types": "2.2.12-alpha.43",
"@bull-board/api": "3.7.0",
"@bull-board/koa": "3.9.4",
"@elastic/elasticsearch": "7.10.0",

View file

@ -14,6 +14,7 @@ import { invalidateDynamicVariables } from "../../threads/utils"
import { db as dbCore, context, events } from "@budibase/backend-core"
import { UserCtx, Datasource, Row } from "@budibase/types"
import sdk from "../../sdk"
import { mergeConfigs } from "../../sdk/app/datasources/datasources"
export async function fetch(ctx: UserCtx) {
// Get internal tables
@ -152,17 +153,16 @@ export async function update(ctx: UserCtx) {
const auth = datasource.config?.auth
await invalidateVariables(datasource, ctx.request.body)
if (!sdk.datasources.isValid(datasource)) {
ctx.throw(400, "Environment variables binding format incorrect")
}
const isBudibaseSource = datasource.type === dbCore.BUDIBASE_DATASOURCE_TYPE
const dataSourceBody = isBudibaseSource
? { name: ctx.request.body?.name }
: ctx.request.body
datasource = { ...datasource, ...dataSourceBody }
datasource = {
...datasource,
...sdk.datasources.mergeConfigs(dataSourceBody, datasource),
}
if (auth && !ctx.request.body.auth) {
// don't strip auth config from DB
datasource.config!.auth = auth
@ -198,10 +198,6 @@ export async function save(ctx: UserCtx) {
...ctx.request.body.datasource,
}
if (!sdk.datasources.isValid(datasource)) {
ctx.throw(400, "Environment variables binding format incorrect")
}
let schemaError = null
if (fetchSchema) {
const { tables, error } = await buildSchemaHelper(datasource)

View file

@ -2,7 +2,8 @@ jest.mock("pg")
import * as setup from "./utilities"
import { checkBuilderEndpoint } from "./utilities/TestFunctions"
import { checkCacheForDynamicVariable } from "../../../threads/utils"
import { events } from "@budibase/backend-core"
import { context, events } from "@budibase/backend-core"
import sdk from "../../../sdk"
let { basicDatasource } = setup.structures
const pg = require("pg")
@ -184,4 +185,37 @@ describe("/datasources", () => {
})
})
})
describe("check secret replacement", () => {
async function makeDatasource() {
datasource = basicDatasource()
datasource.datasource.config.password = "testing"
const res = await request
.post(`/api/datasources`)
.send(datasource)
.set(config.defaultHeaders())
.expect("Content-Type", /json/)
.expect(200)
return res.body.datasource
}
it("should save a datasource with password", async () => {
const datasource = await makeDatasource()
expect(datasource.config.password).toBe("--secret-value--")
})
it("should not the password on update with the --secret-value--", async () => {
const datasource = await makeDatasource()
await request
.put(`/api/datasources/${datasource._id}`)
.send(datasource)
.set(config.defaultHeaders())
.expect("Content-Type", /json/)
.expect(200)
await context.doInAppContext(config.getAppId(), async () => {
const dbDatasource: any = await sdk.datasources.get(datasource._id)
expect(dbDatasource.config.password).toBe("testing")
})
})
})
})

View file

@ -2,7 +2,7 @@ import TestConfig from "../../../../tests/utilities/TestConfiguration"
import * as syncRows from "../syncRows"
import { quotas } from "@budibase/pro"
import { QuotaUsageType, StaticQuotaName } from "@budibase/types"
const { db: dbCore } = require("@budibase/backend-core")
import { db as dbCore, context } from "@budibase/backend-core"
describe("syncRows", () => {
let config = new TestConfig(false)
@ -24,13 +24,17 @@ describe("syncRows", () => {
// app 1
const app1 = config.app
await config.createTable()
await config.createRow()
await context.doInAppContext(app1.appId, async () => {
await config.createTable()
await config.createRow()
})
// app 2
const app2 = await config.createApp("second-app")
await config.createTable()
await config.createRow()
await config.createRow()
await context.doInAppContext(app2.appId, async () => {
await config.createTable()
await config.createRow()
await config.createRow()
})
// migrate
await syncRows.run()

View file

@ -47,14 +47,6 @@ export async function getWithEnvVars(datasourceId: string) {
return enrichDatasourceWithValues(datasource)
}
export function isValid(datasource: Datasource) {
const blocks = findHBSBlocks(JSON.stringify(datasource))
const validList = blocks.filter(
block => block.includes(ENV_VAR_PREFIX) || block.includes(USER_PREFIX)
)
return blocks.length === validList.length
}
export async function removeSecrets(datasources: Datasource[]) {
const definitions = await getDefinitions()
for (let datasource of datasources) {
@ -87,3 +79,20 @@ export async function removeSecrets(datasources: Datasource[]) {
export async function removeSecretSingle(datasource: Datasource) {
return (await removeSecrets([datasource]))[0]
}
export function mergeConfigs(update: Datasource, old: Datasource) {
if (!update.config) {
return update
}
for (let [key, value] of Object.entries(update.config)) {
if (value !== PASSWORD_REPLACEMENT) {
continue
}
if (old.config?.[key]) {
update.config[key] = old.config?.[key]
} else {
delete update.config[key]
}
}
return update
}

View file

@ -1273,13 +1273,13 @@
resolved "https://registry.yarnpkg.com/@bcoe/v8-coverage/-/v8-coverage-0.2.3.tgz#75a2e8b51cb758a7553d6804a5932d7aace75c39"
integrity sha512-0hYQ8SB4Db5zvZB4axdMHGwEaQjkZzFjQiN9LVYvIFB2nSUHW9tYpxWriPrWDASIxiaXax83REcLxuSdnGPZtw==
"@budibase/backend-core@2.2.12-alpha.41":
version "2.2.12-alpha.41"
resolved "https://registry.yarnpkg.com/@budibase/backend-core/-/backend-core-2.2.12-alpha.41.tgz#9fa210c3c94481c38af5aad71ac246451dda6e43"
integrity sha512-vYb8x6JgncYdT8VqVi/WfScg4Ng0O1wtt9SspNPKnOX2CR7rA8VH6PW1QMRa5uUYvBFupg6UbY9jFqu2XXtujg==
"@budibase/backend-core@2.2.12-alpha.43":
version "2.2.12-alpha.43"
resolved "https://registry.yarnpkg.com/@budibase/backend-core/-/backend-core-2.2.12-alpha.43.tgz#c7d64564730a9ea443e9351eff79218163e510f3"
integrity sha512-0oRoXK0SL14fzl38zoX+8j4jFWvl3LGjBvTTvOzsbvLifyCT76bAGaZdTLOgaAIKR2NfwpglS+qKiM5sQmvcQA==
dependencies:
"@budibase/nano" "10.1.1"
"@budibase/types" "2.2.12-alpha.41"
"@budibase/types" "2.2.12-alpha.43"
"@shopify/jest-koa-mocks" "5.0.1"
"@techpass/passport-openidconnect" "0.3.2"
aws-cloudfront-sign "2.2.0"
@ -1374,13 +1374,13 @@
qs "^6.11.0"
tough-cookie "^4.1.2"
"@budibase/pro@2.2.12-alpha.41":
version "2.2.12-alpha.41"
resolved "https://registry.yarnpkg.com/@budibase/pro/-/pro-2.2.12-alpha.41.tgz#c1923d52d7cd2ace665e44b196c91578b1b50bbe"
integrity sha512-J1yN74Gixa8UzkD44Ydzj2iR+5WRbJtjZzn7NFI3VB1A2sTLxmilSBRyCALzhF3UMpueaBRjwWBovbF/De106A==
"@budibase/pro@2.2.12-alpha.43":
version "2.2.12-alpha.43"
resolved "https://registry.yarnpkg.com/@budibase/pro/-/pro-2.2.12-alpha.43.tgz#11e3a138f33b67ac0866bb760a14925ddf9d08cf"
integrity sha512-U2QjEqCEKO7l9FZZcU2TAK0I+M3dHDzMm9HEzGvjcCK72LlMlRy0ca8sYjxhzqhpSxLrQuI22hfyf6wDzgHo5g==
dependencies:
"@budibase/backend-core" "2.2.12-alpha.41"
"@budibase/types" "2.2.12-alpha.41"
"@budibase/backend-core" "2.2.12-alpha.43"
"@budibase/types" "2.2.12-alpha.43"
"@koa/router" "8.0.8"
bull "4.10.1"
joi "17.6.0"
@ -1405,10 +1405,10 @@
svelte-apexcharts "^1.0.2"
svelte-flatpickr "^3.1.0"
"@budibase/types@2.2.12-alpha.41":
version "2.2.12-alpha.41"
resolved "https://registry.yarnpkg.com/@budibase/types/-/types-2.2.12-alpha.41.tgz#662115c5ba09f3c2057a96321e233c819cfae84b"
integrity sha512-+uzr668cuvDTMqy7roWiG/qQzOzQO7uWYtysaHPsQQG5PxA0ZuwixJOvvX1qOr1rgv9Is54p9J7dvzvtKW/wAw==
"@budibase/types@2.2.12-alpha.43":
version "2.2.12-alpha.43"
resolved "https://registry.yarnpkg.com/@budibase/types/-/types-2.2.12-alpha.43.tgz#2ddbbc2c3f3e9dedcba57eacd5648e012faba46d"
integrity sha512-u/i25rO7pSqzbs5YrO47KVQp65jhD71udnFmUbwNgs1XBIeivilqbFdxk5DCKbBrTA04McuOZ3nxI9JNZG6qMw==
"@bull-board/api@3.7.0":
version "3.7.0"

View file

@ -1,6 +1,6 @@
{
"name": "@budibase/string-templates",
"version": "2.2.12-alpha.41",
"version": "2.2.12-alpha.43",
"description": "Handlebars wrapper for Budibase templating.",
"main": "src/index.cjs",
"module": "dist/bundle.mjs",

View file

@ -1,6 +1,6 @@
{
"name": "@budibase/types",
"version": "2.2.12-alpha.41",
"version": "2.2.12-alpha.43",
"description": "Budibase types",
"main": "dist/index.js",
"types": "dist/index.d.ts",

View file

@ -1,7 +1,7 @@
{
"name": "@budibase/worker",
"email": "hi@budibase.com",
"version": "2.2.12-alpha.41",
"version": "2.2.12-alpha.43",
"description": "Budibase background service",
"main": "src/index.ts",
"repository": {
@ -36,10 +36,10 @@
"author": "Budibase",
"license": "GPL-3.0",
"dependencies": {
"@budibase/backend-core": "2.2.12-alpha.41",
"@budibase/pro": "2.2.12-alpha.41",
"@budibase/string-templates": "2.2.12-alpha.41",
"@budibase/types": "2.2.12-alpha.41",
"@budibase/backend-core": "2.2.12-alpha.43",
"@budibase/pro": "2.2.12-alpha.43",
"@budibase/string-templates": "2.2.12-alpha.43",
"@budibase/types": "2.2.12-alpha.43",
"@koa/router": "8.0.8",
"@sentry/node": "6.17.7",
"@techpass/passport-openidconnect": "0.3.2",

View file

@ -470,13 +470,13 @@
resolved "https://registry.yarnpkg.com/@bcoe/v8-coverage/-/v8-coverage-0.2.3.tgz#75a2e8b51cb758a7553d6804a5932d7aace75c39"
integrity sha512-0hYQ8SB4Db5zvZB4axdMHGwEaQjkZzFjQiN9LVYvIFB2nSUHW9tYpxWriPrWDASIxiaXax83REcLxuSdnGPZtw==
"@budibase/backend-core@2.2.12-alpha.41":
version "2.2.12-alpha.41"
resolved "https://registry.yarnpkg.com/@budibase/backend-core/-/backend-core-2.2.12-alpha.41.tgz#9fa210c3c94481c38af5aad71ac246451dda6e43"
integrity sha512-vYb8x6JgncYdT8VqVi/WfScg4Ng0O1wtt9SspNPKnOX2CR7rA8VH6PW1QMRa5uUYvBFupg6UbY9jFqu2XXtujg==
"@budibase/backend-core@2.2.12-alpha.43":
version "2.2.12-alpha.43"
resolved "https://registry.yarnpkg.com/@budibase/backend-core/-/backend-core-2.2.12-alpha.43.tgz#c7d64564730a9ea443e9351eff79218163e510f3"
integrity sha512-0oRoXK0SL14fzl38zoX+8j4jFWvl3LGjBvTTvOzsbvLifyCT76bAGaZdTLOgaAIKR2NfwpglS+qKiM5sQmvcQA==
dependencies:
"@budibase/nano" "10.1.1"
"@budibase/types" "2.2.12-alpha.41"
"@budibase/types" "2.2.12-alpha.43"
"@shopify/jest-koa-mocks" "5.0.1"
"@techpass/passport-openidconnect" "0.3.2"
aws-cloudfront-sign "2.2.0"
@ -521,23 +521,23 @@
qs "^6.11.0"
tough-cookie "^4.1.2"
"@budibase/pro@2.2.12-alpha.41":
version "2.2.12-alpha.41"
resolved "https://registry.yarnpkg.com/@budibase/pro/-/pro-2.2.12-alpha.41.tgz#c1923d52d7cd2ace665e44b196c91578b1b50bbe"
integrity sha512-J1yN74Gixa8UzkD44Ydzj2iR+5WRbJtjZzn7NFI3VB1A2sTLxmilSBRyCALzhF3UMpueaBRjwWBovbF/De106A==
"@budibase/pro@2.2.12-alpha.43":
version "2.2.12-alpha.43"
resolved "https://registry.yarnpkg.com/@budibase/pro/-/pro-2.2.12-alpha.43.tgz#11e3a138f33b67ac0866bb760a14925ddf9d08cf"
integrity sha512-U2QjEqCEKO7l9FZZcU2TAK0I+M3dHDzMm9HEzGvjcCK72LlMlRy0ca8sYjxhzqhpSxLrQuI22hfyf6wDzgHo5g==
dependencies:
"@budibase/backend-core" "2.2.12-alpha.41"
"@budibase/types" "2.2.12-alpha.41"
"@budibase/backend-core" "2.2.12-alpha.43"
"@budibase/types" "2.2.12-alpha.43"
"@koa/router" "8.0.8"
bull "4.10.1"
joi "17.6.0"
jsonwebtoken "8.5.1"
node-fetch "^2.6.1"
"@budibase/types@2.2.12-alpha.41":
version "2.2.12-alpha.41"
resolved "https://registry.yarnpkg.com/@budibase/types/-/types-2.2.12-alpha.41.tgz#662115c5ba09f3c2057a96321e233c819cfae84b"
integrity sha512-+uzr668cuvDTMqy7roWiG/qQzOzQO7uWYtysaHPsQQG5PxA0ZuwixJOvvX1qOr1rgv9Is54p9J7dvzvtKW/wAw==
"@budibase/types@2.2.12-alpha.43":
version "2.2.12-alpha.43"
resolved "https://registry.yarnpkg.com/@budibase/types/-/types-2.2.12-alpha.43.tgz#2ddbbc2c3f3e9dedcba57eacd5648e012faba46d"
integrity sha512-u/i25rO7pSqzbs5YrO47KVQp65jhD71udnFmUbwNgs1XBIeivilqbFdxk5DCKbBrTA04McuOZ3nxI9JNZG6qMw==
"@cspotcode/source-map-support@^0.8.0":
version "0.8.1"