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

add env vars to auth variables section in rest config

This commit is contained in:
Peter Clement 2023-01-27 16:35:14 +00:00
parent 6bef0e64d5
commit 602570e834
2 changed files with 63 additions and 6 deletions

View file

@ -16,6 +16,7 @@
runtimeToReadableMap,
} from "builderStore/dataBinding"
import { cloneDeep } from "lodash/fp"
import { getEnvironmentBindings } from "builderStore/dataBinding"
export let datasource
export let queries
@ -93,6 +94,7 @@
headings
bind:object={datasource.config.staticVariables}
on:change
bindings={getEnvironmentBindings()}
/>
</Layout>
<div />

View file

@ -1,9 +1,22 @@
<script>
import { onMount } from "svelte"
import { ModalContent, Layout, Select, Body, Input } from "@budibase/bbui"
import {
ModalContent,
Layout,
Select,
Body,
Input,
EnvDropdown,
Modal,
} from "@budibase/bbui"
import { AUTH_TYPE_LABELS, AUTH_TYPES } from "./authTypes"
import BindableCombobox from "components/common/bindings/BindableCombobox.svelte"
import { getAuthBindings } from "builderStore/dataBinding"
import {
getAuthBindings,
getEnvironmentBindings,
} from "builderStore/dataBinding"
import { environment, licensing, auth } from "stores/portal"
import CreateEditVariableModal from "components/portal/environment/CreateEditVariableModal.svelte"
export let configs
export let currentConfig
@ -28,7 +41,16 @@
let hasErrors = false
let hasChanged = false
onMount(() => {
let createVariableModal
let formFieldkey
onMount(async () => {
await environment.loadVariables()
if ($auth.user) {
await licensing.init()
}
if (currentConfig) {
deconstructConfig()
}
@ -146,6 +168,12 @@
}
}
const save = data => {
environment.createVariable(data)
form.basic[formFieldkey] = `{{ env.${data.name} }}`
createVariableModal.hide()
}
const onFieldChange = () => {
checkErrors()
checkChanged()
@ -154,6 +182,16 @@
const onConfirmInternal = () => {
onConfirm(constructConfig())
}
async function handleUpgradePanel() {
await environment.upgradePanelOpened()
$licensing.goToUpgradePage()
}
function showModal(key) {
formFieldkey = key
createVariableModal.show()
}
</script>
<ModalContent
@ -189,26 +227,39 @@
error={blurred.type ? errors.type : null}
/>
{#if form.type === AUTH_TYPES.BASIC}
<Input
<EnvDropdown
label="Username"
bind:value={form.basic.username}
on:change={onFieldChange}
on:blur={() => (blurred.basic.username = true)}
error={blurred.basic.username ? errors.basic.username : null}
showModal={() => showModal("configKey")}
variables={$environment.variables}
environmentVariablesEnabled={$licensing.environmentVariablesEnabled}
{handleUpgradePanel}
/>
<Input
<EnvDropdown
label="Password"
bind:value={form.basic.password}
on:change={onFieldChange}
on:blur={() => (blurred.basic.password = true)}
error={blurred.basic.password ? errors.basic.password : null}
showModal={() => showModal("configKey")}
variables={$environment.variables}
environmentVariablesEnabled={$licensing.environmentVariablesEnabled}
{handleUpgradePanel}
/>
{/if}
{#if form.type === AUTH_TYPES.BEARER}
<BindableCombobox
label="Token"
value={form.bearer.token}
bindings={getAuthBindings()}
bindings={[
...getAuthBindings(),
...($licensing.environmentVariablesEnabled
? getEnvironmentBindings()
: []),
]}
on:change={e => {
form.bearer.token = e.detail
onFieldChange()
@ -226,3 +277,7 @@
{/if}
</Layout>
</ModalContent>
<Modal bind:this={createVariableModal}>
<CreateEditVariableModal {save} />
</Modal>