From 9cbe03fd66f8b3260c1bf705951e5e07aa2e7738 Mon Sep 17 00:00:00 2001 From: Rory Powell Date: Tue, 7 Dec 2021 22:33:26 +0000 Subject: [PATCH 01/11] Add backend for query / datasource auth --- packages/server/src/integrations/rest.ts | 43 +++++++++++++- .../src/integrations/tests/rest.spec.js | 56 +++++++++++++++++++ 2 files changed, 98 insertions(+), 1 deletion(-) diff --git a/packages/server/src/integrations/rest.ts b/packages/server/src/integrations/rest.ts index 57bd11ef9a..48ae5af0eb 100644 --- a/packages/server/src/integrations/rest.ts +++ b/packages/server/src/integrations/rest.ts @@ -13,6 +13,25 @@ const BodyTypes = { TEXT: "text", } +enum AuthType { + BASIC = "basic", + BEARER = "bearer" +} + +interface AuthConfig { + id: string + type: AuthType + config: BasicAuthConfig | BearerAuthConfig +} +interface BasicAuthConfig { + username: string, + password: string, +} + +interface BearerAuthConfig { + token: string, +} + const coreFields = { path: { type: DatasourceFieldTypes.STRING, @@ -46,6 +65,7 @@ module RestModule { defaultHeaders: { [key: string]: any } + authConfigs: AuthConfig[] } interface Request { @@ -149,12 +169,32 @@ module RestModule { } } - async _req({ path = "", queryString = "", headers = {}, json = {}, method = "GET" }) { + processAuth(authConfigId: string) { + if (!this.config.authConfigs) { + return + } + const authConfig = this.config.authConfigs.filter(authConfig => authConfig.id === authConfigId)[0] + let config + switch (authConfig.type) { + case AuthType.BASIC: + config = authConfig.config as BasicAuthConfig + this.headers.Authorization = `Basic ${Buffer.from(`${config.username}:${config.password}`).toString("base64")}` + break + case AuthType.BEARER: + config = authConfig.config as BearerAuthConfig + this.headers.Authorization = `Bearer ${config.token}` + break + } + } + + async _req({ path = "", queryString = "", headers = {}, json = {}, method = "GET", authConfigId = "" }) { this.headers = { ...this.config.defaultHeaders, ...headers, } + this.processAuth(authConfigId) + const input: any = { method, headers: this.headers } if (json && typeof json === "object" && Object.keys(json).length > 0) { input.body = JSON.stringify(json) @@ -189,5 +229,6 @@ module RestModule { module.exports = { schema: SCHEMA, integration: RestIntegration, + AuthType } } diff --git a/packages/server/src/integrations/tests/rest.spec.js b/packages/server/src/integrations/tests/rest.spec.js index 7b128a6d14..610054ccfc 100644 --- a/packages/server/src/integrations/tests/rest.spec.js +++ b/packages/server/src/integrations/tests/rest.spec.js @@ -9,6 +9,7 @@ jest.mock("node-fetch", () => ) const fetch = require("node-fetch") const RestIntegration = require("../rest") +const { AuthType } = require("../rest") class TestConfiguration { constructor(config = {}) { @@ -26,6 +27,10 @@ describe("REST Integration", () => { }) }) + // afterEach(() => { + // jest.clearAllMocks() + // }) + it("calls the create method with the correct params", async () => { const query = { path: "api", @@ -103,4 +108,55 @@ describe("REST Integration", () => { }, }) }) + + describe("authentication", () => { + const basicAuth = { + id: "basic-1", + type : AuthType.BASIC, + config : { + username: "user", + password: "password" + } + } + const bearerAuth = { + id: "bearer-1", + type : AuthType.BEARER, + config : { + "token": "mytoken" + } + } + + beforeEach(() => { + config = new TestConfiguration({ + url: BASE_URL, + authConfigs : [basicAuth, bearerAuth] + }) + }) + + it("adds basic auth", async () => { + const query = { + authConfigId: "basic-1" + } + await config.integration.read(query) + expect(fetch).toHaveBeenCalledWith(`${BASE_URL}/?`, { + method: "GET", + headers: { + Authorization: "Basic dXNlcjpwYXNzd29yZA==" + }, + }) + }) + + it("adds bearer auth", async () => { + const query = { + authConfigId: "bearer-1" + } + await config.integration.read(query) + expect(fetch).toHaveBeenCalledWith(`${BASE_URL}/?`, { + method: "GET", + headers: { + Authorization: "Bearer mytoken" + }, + }) + }) + }) }) From a237d314244a2d4054b34d9baca7cdb9222f5e48 Mon Sep 17 00:00:00 2001 From: Rory Powell Date: Wed, 8 Dec 2021 10:52:08 +0000 Subject: [PATCH 02/11] Tidy --- packages/server/src/integrations/rest.ts | 3 ++- packages/server/src/integrations/tests/rest.spec.js | 4 ---- 2 files changed, 2 insertions(+), 5 deletions(-) diff --git a/packages/server/src/integrations/rest.ts b/packages/server/src/integrations/rest.ts index 48ae5af0eb..693a361fc8 100644 --- a/packages/server/src/integrations/rest.ts +++ b/packages/server/src/integrations/rest.ts @@ -23,6 +23,7 @@ interface AuthConfig { type: AuthType config: BasicAuthConfig | BearerAuthConfig } + interface BasicAuthConfig { username: string, password: string, @@ -170,7 +171,7 @@ module RestModule { } processAuth(authConfigId: string) { - if (!this.config.authConfigs) { + if (!this.config.authConfigs || !authConfigId) { return } const authConfig = this.config.authConfigs.filter(authConfig => authConfig.id === authConfigId)[0] diff --git a/packages/server/src/integrations/tests/rest.spec.js b/packages/server/src/integrations/tests/rest.spec.js index 610054ccfc..74e81448ba 100644 --- a/packages/server/src/integrations/tests/rest.spec.js +++ b/packages/server/src/integrations/tests/rest.spec.js @@ -27,10 +27,6 @@ describe("REST Integration", () => { }) }) - // afterEach(() => { - // jest.clearAllMocks() - // }) - it("calls the create method with the correct params", async () => { const query = { path: "api", From 720b828bee939e197eeb7174d25ac6ed2dabcaa8 Mon Sep 17 00:00:00 2001 From: Rory Powell Date: Wed, 8 Dec 2021 15:27:58 +0000 Subject: [PATCH 03/11] Render table of auth configs and linting --- .../PlusConfigForm.svelte | 2 +- .../RestAuthenticationBuilder.svelte | 29 +++++++++++++++ .../RestExtraConfigForm.svelte | 20 +++++++++-- .../{ => renderers}/ArrayRenderer.svelte | 0 .../renderers/CapitaliseRenderer.svelte} | 0 .../[selectedDatasource]/index.svelte | 6 ++-- .../src/api/controllers/query/import/index.ts | 2 +- .../query/import/sources/base/index.ts | 1 - .../controllers/query/import/sources/curl.ts | 2 +- .../src/integrations/base/IntegrationBase.ts | 8 ++--- packages/server/src/integrations/rest.ts | 35 ++++++++++++------- .../src/integrations/tests/rest.spec.js | 9 ++--- 12 files changed, 86 insertions(+), 28 deletions(-) create mode 100644 packages/builder/src/components/backend/DatasourceNavigator/TableIntegrationMenu/RestAuthenticationBuilder.svelte rename packages/builder/src/components/common/{ => renderers}/ArrayRenderer.svelte (100%) rename packages/builder/src/{pages/builder/app/[application]/data/datasource/[selectedDatasource]/_components/VerbRenderer.svelte => components/common/renderers/CapitaliseRenderer.svelte} (100%) diff --git a/packages/builder/src/components/backend/DatasourceNavigator/TableIntegrationMenu/PlusConfigForm.svelte b/packages/builder/src/components/backend/DatasourceNavigator/TableIntegrationMenu/PlusConfigForm.svelte index 01ba071a3f..f736d29bee 100644 --- a/packages/builder/src/components/backend/DatasourceNavigator/TableIntegrationMenu/PlusConfigForm.svelte +++ b/packages/builder/src/components/backend/DatasourceNavigator/TableIntegrationMenu/PlusConfigForm.svelte @@ -12,7 +12,7 @@ import { datasources, integrations, tables } from "stores/backend" import CreateEditRelationship from "components/backend/Datasources/CreateEditRelationship.svelte" import CreateExternalTableModal from "./CreateExternalTableModal.svelte" - import ArrayRenderer from "components/common/ArrayRenderer.svelte" + import ArrayRenderer from "components/common/renderers/ArrayRenderer.svelte" import ConfirmDialog from "components/common/ConfirmDialog.svelte" import { goto } from "@roxi/routify" diff --git a/packages/builder/src/components/backend/DatasourceNavigator/TableIntegrationMenu/RestAuthenticationBuilder.svelte b/packages/builder/src/components/backend/DatasourceNavigator/TableIntegrationMenu/RestAuthenticationBuilder.svelte new file mode 100644 index 0000000000..129acad852 --- /dev/null +++ b/packages/builder/src/components/backend/DatasourceNavigator/TableIntegrationMenu/RestAuthenticationBuilder.svelte @@ -0,0 +1,29 @@ + + +
+ {#if authConfigs && authConfigs.length > 0} +
+ + + {/if} + + + diff --git a/packages/builder/src/components/backend/DatasourceNavigator/TableIntegrationMenu/RestExtraConfigForm.svelte b/packages/builder/src/components/backend/DatasourceNavigator/TableIntegrationMenu/RestExtraConfigForm.svelte index ce3881d82c..c63872a1ef 100644 --- a/packages/builder/src/components/backend/DatasourceNavigator/TableIntegrationMenu/RestExtraConfigForm.svelte +++ b/packages/builder/src/components/backend/DatasourceNavigator/TableIntegrationMenu/RestExtraConfigForm.svelte @@ -1,6 +1,7 @@ -
+
Headers Optional @@ -30,8 +31,23 @@
+ +
+
+ Authentication + Optional +
+
+ + Create an authentication config that can be shared with queries. + + +
+ Add authentication +
+ diff --git a/packages/builder/src/components/backend/DatasourceNavigator/TableIntegrationMenu/RestExtraConfigForm.svelte b/packages/builder/src/components/backend/DatasourceNavigator/TableIntegrationMenu/rest/RestExtraConfigForm.svelte similarity index 89% rename from packages/builder/src/components/backend/DatasourceNavigator/TableIntegrationMenu/RestExtraConfigForm.svelte rename to packages/builder/src/components/backend/DatasourceNavigator/TableIntegrationMenu/rest/RestExtraConfigForm.svelte index c63872a1ef..c77f2900b0 100644 --- a/packages/builder/src/components/backend/DatasourceNavigator/TableIntegrationMenu/RestExtraConfigForm.svelte +++ b/packages/builder/src/components/backend/DatasourceNavigator/TableIntegrationMenu/rest/RestExtraConfigForm.svelte @@ -1,7 +1,7 @@ + +{renderAuthType()} diff --git a/packages/builder/src/components/backend/DatasourceNavigator/TableIntegrationMenu/rest/auth/RestAuthenticationBuilder.svelte b/packages/builder/src/components/backend/DatasourceNavigator/TableIntegrationMenu/rest/auth/RestAuthenticationBuilder.svelte new file mode 100644 index 0000000000..4d932869e7 --- /dev/null +++ b/packages/builder/src/components/backend/DatasourceNavigator/TableIntegrationMenu/rest/auth/RestAuthenticationBuilder.svelte @@ -0,0 +1,108 @@ + + + + + + + The authorization header will be automatically generated when you + sendthe request. + + + + {/if} + {#if currentConfig.type === AUTH_TYPES.BEARER} + + {/if} + + + + + + {#if authConfigs && authConfigs.length > 0} +
openConfigModal(detail)} + {schema} + data={authConfigs} + allowEditColumns={false} + allowEditRows={false} + allowSelectRows={false} + customRenderers={[{ column: "type", component: AuthTypeRenderer }]} + /> + {/if} +
+ openConfigModal()} con="Add" + >Add authentication +
+ + + diff --git a/packages/builder/src/components/backend/DatasourceNavigator/TableIntegrationMenu/rest/auth/authTypes.js b/packages/builder/src/components/backend/DatasourceNavigator/TableIntegrationMenu/rest/auth/authTypes.js new file mode 100644 index 0000000000..854391d6ce --- /dev/null +++ b/packages/builder/src/components/backend/DatasourceNavigator/TableIntegrationMenu/rest/auth/authTypes.js @@ -0,0 +1,15 @@ +export const AUTH_TYPES = { + BEARER: "bearer", + BASIC: "basic", +} + +export const AUTH_TYPE_LABELS = [ + { + label: "Bearer Token", + value: AUTH_TYPES.BEARER, + }, + { + label: "Basic Auth", + value: AUTH_TYPES.BASIC, + }, +] diff --git a/packages/builder/src/pages/builder/app/[application]/data/datasource/[selectedDatasource]/index.svelte b/packages/builder/src/pages/builder/app/[application]/data/datasource/[selectedDatasource]/index.svelte index 0e046e26f7..87ff9691f8 100644 --- a/packages/builder/src/pages/builder/app/[application]/data/datasource/[selectedDatasource]/index.svelte +++ b/packages/builder/src/pages/builder/app/[application]/data/datasource/[selectedDatasource]/index.svelte @@ -12,7 +12,7 @@ } from "@budibase/bbui" import { datasources, integrations, queries, tables } from "stores/backend" import IntegrationConfigForm from "components/backend/DatasourceNavigator/TableIntegrationMenu/IntegrationConfigForm.svelte" - import RestExtraConfigForm from "components/backend/DatasourceNavigator/TableIntegrationMenu/RestExtraConfigForm.svelte" + import RestExtraConfigForm from "components/backend/DatasourceNavigator/TableIntegrationMenu/rest/RestExtraConfigForm.svelte" import PlusConfigForm from "components/backend/DatasourceNavigator/TableIntegrationMenu/PlusConfigForm.svelte" import ICONS from "components/backend/DatasourceNavigator/icons" import CapitaliseRenderer from "components/common/renderers/CapitaliseRenderer.svelte" From 77d17e143d3d4fdbe8198e52ec65f13f076b6e58 Mon Sep 17 00:00:00 2001 From: Rory Powell Date: Sat, 11 Dec 2021 09:59:09 +0000 Subject: [PATCH 05/11] Auth config forms --- packages/bbui/src/Modal/ModalContent.svelte | 8 +- .../rest/RestExtraConfigForm.svelte | 2 +- .../rest/auth/AuthTypeRenderer.svelte | 4 +- .../auth/RestAuthenticationBuilder.svelte | 86 ++----- .../rest/auth/RestAuthenticationModal.svelte | 215 ++++++++++++++++++ 5 files changed, 246 insertions(+), 69 deletions(-) create mode 100644 packages/builder/src/components/backend/DatasourceNavigator/TableIntegrationMenu/rest/auth/RestAuthenticationModal.svelte diff --git a/packages/bbui/src/Modal/ModalContent.svelte b/packages/bbui/src/Modal/ModalContent.svelte index 7f2d7fbdb9..c18be1e4e1 100644 --- a/packages/bbui/src/Modal/ModalContent.svelte +++ b/packages/bbui/src/Modal/ModalContent.svelte @@ -21,6 +21,7 @@ export let showSecondaryButton = false export let secondaryButtonText = undefined export let secondaryAction = undefined + export let secondaryButtonWarning = false const { hide, cancel } = getContext(Context.Modal) let loading = false @@ -88,8 +89,11 @@ {#if showSecondaryButton && secondaryButtonText && secondaryAction}
- {secondaryButtonText}
{/if} diff --git a/packages/builder/src/components/backend/DatasourceNavigator/TableIntegrationMenu/rest/RestExtraConfigForm.svelte b/packages/builder/src/components/backend/DatasourceNavigator/TableIntegrationMenu/rest/RestExtraConfigForm.svelte index c77f2900b0..0272463d92 100644 --- a/packages/builder/src/components/backend/DatasourceNavigator/TableIntegrationMenu/rest/RestExtraConfigForm.svelte +++ b/packages/builder/src/components/backend/DatasourceNavigator/TableIntegrationMenu/rest/RestExtraConfigForm.svelte @@ -41,7 +41,7 @@ Create an authentication config that can be shared with queries. - + diff --git a/packages/builder/src/components/backend/DatasourceNavigator/TableIntegrationMenu/rest/auth/RestAuthenticationModal.svelte b/packages/builder/src/components/backend/DatasourceNavigator/TableIntegrationMenu/rest/auth/RestAuthenticationModal.svelte new file mode 100644 index 0000000000..79dc19f439 --- /dev/null +++ b/packages/builder/src/components/backend/DatasourceNavigator/TableIntegrationMenu/rest/auth/RestAuthenticationModal.svelte @@ -0,0 +1,215 @@ + + + + + + The authorization header will be automatically generated when you send the + request. + + (blurred.name = true)} + error={blurred.name ? errors.name : null} + /> + (blurred.basic.username = true)} + error={blurred.basic.username ? errors.basic.username : null} + /> + (blurred.basic.password = true)} + error={blurred.basic.password ? errors.basic.password : null} + /> + {/if} + {#if form.type === AUTH_TYPES.BEARER} + (blurred.bearer.token = true)} + error={blurred.bearer.token ? errors.bearer.token : null} + /> + {/if} + + + + From 9a0af5ba0a935b63cd1c2a6ec905f5e6e8b3b11a Mon Sep 17 00:00:00 2001 From: Rory Powell Date: Sat, 11 Dec 2021 10:40:57 +0000 Subject: [PATCH 06/11] Add _id field --- .../rest/auth/RestAuthenticationBuilder.svelte | 11 +++++------ .../rest/auth/RestAuthenticationModal.svelte | 1 - .../TableIntegrationMenu/rest/auth/authTypes.js | 10 +++++----- packages/server/src/integrations/rest.ts | 11 ++++++----- packages/server/src/integrations/tests/rest.spec.js | 6 ++++-- 5 files changed, 20 insertions(+), 19 deletions(-) diff --git a/packages/builder/src/components/backend/DatasourceNavigator/TableIntegrationMenu/rest/auth/RestAuthenticationBuilder.svelte b/packages/builder/src/components/backend/DatasourceNavigator/TableIntegrationMenu/rest/auth/RestAuthenticationBuilder.svelte index 4b32d53fb9..3f23b03a3d 100644 --- a/packages/builder/src/components/backend/DatasourceNavigator/TableIntegrationMenu/rest/auth/RestAuthenticationBuilder.svelte +++ b/packages/builder/src/components/backend/DatasourceNavigator/TableIntegrationMenu/rest/auth/RestAuthenticationBuilder.svelte @@ -2,6 +2,7 @@ import { Table, Modal, Layout, ActionButton } from "@budibase/bbui" import AuthTypeRenderer from "./AuthTypeRenderer.svelte" import RestAuthenticationModal from "./RestAuthenticationModal.svelte" + import { uuid } from "builderStore/uuid" export let configs = [] @@ -20,24 +21,22 @@ const onConfirm = config => { if (currentConfig) { - // TODO: Update with _id configs = configs.map(c => { // replace the current config with the new one - if (c.name === currentConfig.name) { + if (c._id === currentConfig._id) { return config } return c }) } else { - configs.push(config) - configs = [...configs] + config._id = uuid() + configs = [...configs, config] } } const onDelete = () => { - // TODO: Update with _id configs = configs.filter(c => { - return c.name !== currentConfig.name + return c._id !== currentConfig._id }) } diff --git a/packages/builder/src/components/backend/DatasourceNavigator/TableIntegrationMenu/rest/auth/RestAuthenticationModal.svelte b/packages/builder/src/components/backend/DatasourceNavigator/TableIntegrationMenu/rest/auth/RestAuthenticationModal.svelte index 79dc19f439..611e752a32 100644 --- a/packages/builder/src/components/backend/DatasourceNavigator/TableIntegrationMenu/rest/auth/RestAuthenticationModal.svelte +++ b/packages/builder/src/components/backend/DatasourceNavigator/TableIntegrationMenu/rest/auth/RestAuthenticationModal.svelte @@ -156,7 +156,6 @@ confirmText={currentConfig ? "Update" : "Add"} disabled={hasErrors || !hasChanged} cancelText={"Cancel"} - warning={true} size="M" showSecondaryButton={!!currentConfig} secondaryButtonText={"Delete"} diff --git a/packages/builder/src/components/backend/DatasourceNavigator/TableIntegrationMenu/rest/auth/authTypes.js b/packages/builder/src/components/backend/DatasourceNavigator/TableIntegrationMenu/rest/auth/authTypes.js index 854391d6ce..1e2b65dad9 100644 --- a/packages/builder/src/components/backend/DatasourceNavigator/TableIntegrationMenu/rest/auth/authTypes.js +++ b/packages/builder/src/components/backend/DatasourceNavigator/TableIntegrationMenu/rest/auth/authTypes.js @@ -1,15 +1,15 @@ export const AUTH_TYPES = { - BEARER: "bearer", BASIC: "basic", + BEARER: "bearer", } export const AUTH_TYPE_LABELS = [ - { - label: "Bearer Token", - value: AUTH_TYPES.BEARER, - }, { label: "Basic Auth", value: AUTH_TYPES.BASIC, }, + { + label: "Bearer Token", + value: AUTH_TYPES.BEARER, + }, ] diff --git a/packages/server/src/integrations/rest.ts b/packages/server/src/integrations/rest.ts index dd3a14c3d3..51310eef3b 100644 --- a/packages/server/src/integrations/rest.ts +++ b/packages/server/src/integrations/rest.ts @@ -19,6 +19,7 @@ enum AuthType { } interface AuthConfig { + _id: string name: string type: AuthType config: BasicAuthConfig | BearerAuthConfig @@ -170,12 +171,12 @@ module RestModule { } } - processAuth(authConfigName: string) { - if (!this.config.authConfigs || !authConfigName) { + processAuth(authConfigId: string) { + if (!this.config.authConfigs || !authConfigId) { return } const authConfig = this.config.authConfigs.filter( - authConfig => authConfig.name === authConfigName + c => c._id === authConfigId )[0] let config switch (authConfig.type) { @@ -198,14 +199,14 @@ module RestModule { headers = {}, json = {}, method = "GET", - authConfigName = "", + authConfigId = "", }) { this.headers = { ...this.config.defaultHeaders, ...headers, } - this.processAuth(authConfigName) + this.processAuth(authConfigId) const input: any = { method, headers: this.headers } if (json && typeof json === "object" && Object.keys(json).length > 0) { diff --git a/packages/server/src/integrations/tests/rest.spec.js b/packages/server/src/integrations/tests/rest.spec.js index 85b5ac473b..0523115ad8 100644 --- a/packages/server/src/integrations/tests/rest.spec.js +++ b/packages/server/src/integrations/tests/rest.spec.js @@ -107,6 +107,7 @@ describe("REST Integration", () => { describe("authentication", () => { const basicAuth = { + _id: "c59c14bd1898a43baa08da68959b24686", name: "basic-1", type : AuthType.BASIC, config : { @@ -116,6 +117,7 @@ describe("REST Integration", () => { } const bearerAuth = { + _id: "0d91d732f34e4befabeff50b392a8ff3", name: "bearer-1", type : AuthType.BEARER, config : { @@ -132,7 +134,7 @@ describe("REST Integration", () => { it("adds basic auth", async () => { const query = { - authConfigName: "basic-1" + authConfigId: "c59c14bd1898a43baa08da68959b24686" } await config.integration.read(query) expect(fetch).toHaveBeenCalledWith(`${BASE_URL}/?`, { @@ -145,7 +147,7 @@ describe("REST Integration", () => { it("adds bearer auth", async () => { const query = { - authConfigName: "bearer-1" + authConfigId: "0d91d732f34e4befabeff50b392a8ff3" } await config.integration.read(query) expect(fetch).toHaveBeenCalledWith(`${BASE_URL}/?`, { From 077c9ef43417ac5e752999bb81212e0724e39378 Mon Sep 17 00:00:00 2001 From: Rory Powell Date: Sat, 11 Dec 2021 23:34:30 +0000 Subject: [PATCH 07/11] Integrate query with datasource auth --- .../auth/RestAuthenticationBuilder.svelte | 4 +- .../rest/auth/RestAuthenticationModal.svelte | 10 ++-- .../rest/[query]/index.svelte | 51 +++++++++++++++++++ packages/server/src/integrations/rest.ts | 31 ++++++----- 4 files changed, 78 insertions(+), 18 deletions(-) diff --git a/packages/builder/src/components/backend/DatasourceNavigator/TableIntegrationMenu/rest/auth/RestAuthenticationBuilder.svelte b/packages/builder/src/components/backend/DatasourceNavigator/TableIntegrationMenu/rest/auth/RestAuthenticationBuilder.svelte index 3f23b03a3d..6c68e055e4 100644 --- a/packages/builder/src/components/backend/DatasourceNavigator/TableIntegrationMenu/rest/auth/RestAuthenticationBuilder.svelte +++ b/packages/builder/src/components/backend/DatasourceNavigator/TableIntegrationMenu/rest/auth/RestAuthenticationBuilder.svelte @@ -34,7 +34,7 @@ } } - const onDelete = () => { + const onRemove = () => { configs = configs.filter(c => { return c._id !== currentConfig._id }) @@ -42,7 +42,7 @@ - + diff --git a/packages/builder/src/components/backend/DatasourceNavigator/TableIntegrationMenu/rest/auth/RestAuthenticationModal.svelte b/packages/builder/src/components/backend/DatasourceNavigator/TableIntegrationMenu/rest/auth/RestAuthenticationModal.svelte index 611e752a32..091e3e7ce6 100644 --- a/packages/builder/src/components/backend/DatasourceNavigator/TableIntegrationMenu/rest/auth/RestAuthenticationModal.svelte +++ b/packages/builder/src/components/backend/DatasourceNavigator/TableIntegrationMenu/rest/auth/RestAuthenticationModal.svelte @@ -6,7 +6,7 @@ export let configs export let currentConfig export let onConfirm - export let onDelete + export let onRemove let form = { basic: {}, @@ -59,6 +59,10 @@ type: form.type, } + if (currentConfig) { + newConfig._id = currentConfig._id + } + if (form.type === AUTH_TYPES.BASIC) { newConfig.config = { ...form.basic, @@ -158,8 +162,8 @@ cancelText={"Cancel"} size="M" showSecondaryButton={!!currentConfig} - secondaryButtonText={"Delete"} - secondaryAction={onDelete} + secondaryButtonText={"Remove"} + secondaryAction={onRemove} secondaryButtonWarning={true} > diff --git a/packages/builder/src/pages/builder/app/[application]/data/datasource/[selectedDatasource]/rest/[query]/index.svelte b/packages/builder/src/pages/builder/app/[application]/data/datasource/[selectedDatasource]/rest/[query]/index.svelte index 64572280ca..56b51e5158 100644 --- a/packages/builder/src/pages/builder/app/[application]/data/datasource/[selectedDatasource]/rest/[query]/index.svelte +++ b/packages/builder/src/pages/builder/app/[application]/data/datasource/[selectedDatasource]/rest/[query]/index.svelte @@ -50,6 +50,7 @@ let saveId let response, schema, isGet let datasourceType, integrationInfo, queryConfig, responseSuccess + let authConfigId $: datasource = $datasources.list.find(ds => ds._id === query?.datasourceId) $: datasourceType = datasource?.source @@ -60,6 +61,7 @@ $: isGet = query?.queryVerb === "read" $: responseSuccess = response?.info?.code >= 200 && response?.info?.code <= 206 + $: authConfigs = buildAuthConfigs(datasource) function getSelectedQuery() { return cloneDeep( @@ -91,6 +93,16 @@ return qs.length > 0 ? `${newUrl}?${qs}` : newUrl } + const buildAuthConfigs = datasource => { + if (datasource?.config?.authConfigs) { + return datasource.config.authConfigs.map(c => ({ + label: c.name, + value: c._id, + })) + } + return [] + } + function learnMoreBanner() { window.open("https://docs.budibase.com/building-apps/data/transformers") } @@ -100,6 +112,7 @@ const queryString = buildQueryString(breakQs) newQuery.fields.path = url.split("?")[0] newQuery.fields.queryString = queryString + newQuery.fields.authConfigId = authConfigId newQuery.schema = fieldsToSchema(schema) newQuery.parameters = keyValueToQueryParameters(bindings) return newQuery @@ -132,6 +145,22 @@ } } + const getAuthConfigId = () => { + let id = query.fields.authConfigId + if (id) { + // find the matching config on the datasource + const matchedConfig = datasource?.config?.authConfigs?.filter( + c => c._id === authConfigId + )[0] + // clear the id if the config is not found (deleted) + // i.e. just show 'None' in the dropdown + if (!matchedConfig) { + id = undefined + } + } + return id + } + onMount(() => { query = getSelectedQuery() const qs = query?.fields.queryString @@ -139,6 +168,7 @@ url = buildUrl(query.fields.path, breakQs) schema = schemaToFields(query.schema) bindings = queryParametersToKeyValue(query.parameters) + authConfigId = getAuthConfigId() if (query && !query.transformer) { query.transformer = "return data" } @@ -238,6 +268,19 @@ /> +
+
+ +
+