Render table of auth configs and linting
This commit is contained in:
parent
2256b366ef
commit
720b828bee
|
@ -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"
|
||||
|
||||
|
|
|
@ -0,0 +1,29 @@
|
|||
<script>
|
||||
import { Table } from "@budibase/bbui"
|
||||
import CapitaliseRenderer from "components/common/renderers/CapitaliseRenderer.svelte"
|
||||
|
||||
export let authConfigs = []
|
||||
|
||||
const schema = {
|
||||
name: "",
|
||||
type: "",
|
||||
}
|
||||
</script>
|
||||
|
||||
<div>
|
||||
{#if authConfigs && authConfigs.length > 0}
|
||||
<div class="query-list">
|
||||
<Table
|
||||
{schema}
|
||||
data={authConfigs}
|
||||
allowEditColumns={false}
|
||||
allowEditRows={false}
|
||||
allowSelectRows={false}
|
||||
customRenderers={[{ column: "type", component: CapitaliseRenderer }]}
|
||||
/>
|
||||
</div>
|
||||
{/if}
|
||||
</div>
|
||||
|
||||
<style>
|
||||
</style>
|
|
@ -1,6 +1,7 @@
|
|||
<script>
|
||||
import { Divider, Heading, ActionButton, Badge, Body } from "@budibase/bbui"
|
||||
import KeyValueBuilder from "components/integration/KeyValueBuilder.svelte"
|
||||
import RestAuthenticationBuilder from "./RestAuthenticationBuilder.svelte"
|
||||
|
||||
export let datasource
|
||||
|
||||
|
@ -8,7 +9,7 @@
|
|||
</script>
|
||||
|
||||
<Divider size="S" />
|
||||
<div class="query-header">
|
||||
<div class="section-header">
|
||||
<div class="badge">
|
||||
<Heading size="S">Headers</Heading>
|
||||
<Badge quiet grey>Optional</Badge>
|
||||
|
@ -30,8 +31,23 @@
|
|||
</ActionButton>
|
||||
</div>
|
||||
|
||||
<Divider size="S" />
|
||||
<div class="section-header">
|
||||
<div class="badge">
|
||||
<Heading size="S">Authentication</Heading>
|
||||
<Badge quiet grey>Optional</Badge>
|
||||
</div>
|
||||
</div>
|
||||
<Body size="S">
|
||||
Create an authentication config that can be shared with queries.
|
||||
</Body>
|
||||
<RestAuthenticationBuilder bind:authConfigs={datasource.config.authConfigs} />
|
||||
<div>
|
||||
<ActionButton icon="Add">Add authentication</ActionButton>
|
||||
</div>
|
||||
|
||||
<style>
|
||||
.query-header {
|
||||
.section-header {
|
||||
display: flex;
|
||||
flex-direction: row;
|
||||
justify-content: space-between;
|
||||
|
|
|
@ -15,7 +15,7 @@
|
|||
import RestExtraConfigForm from "components/backend/DatasourceNavigator/TableIntegrationMenu/RestExtraConfigForm.svelte"
|
||||
import PlusConfigForm from "components/backend/DatasourceNavigator/TableIntegrationMenu/PlusConfigForm.svelte"
|
||||
import ICONS from "components/backend/DatasourceNavigator/icons"
|
||||
import VerbRenderer from "./_components/VerbRenderer.svelte"
|
||||
import CapitaliseRenderer from "components/common/renderers/CapitaliseRenderer.svelte"
|
||||
import { IntegrationTypes } from "constants/backend"
|
||||
import { isEqual } from "lodash"
|
||||
import { cloneDeep } from "lodash/fp"
|
||||
|
@ -135,7 +135,9 @@
|
|||
allowEditColumns={false}
|
||||
allowEditRows={false}
|
||||
allowSelectRows={false}
|
||||
customRenderers={[{ column: "queryVerb", component: VerbRenderer }]}
|
||||
customRenderers={[
|
||||
{ column: "queryVerb", component: CapitaliseRenderer },
|
||||
]}
|
||||
/>
|
||||
</div>
|
||||
{/if}
|
||||
|
|
|
@ -3,7 +3,7 @@ import { queryValidation } from "../validation"
|
|||
import { generateQueryID } from "../../../../db/utils"
|
||||
import { ImportInfo, ImportSource } from "./sources/base"
|
||||
import { OpenAPI2 } from "./sources/openapi2"
|
||||
import { Query } from './../../../../definitions/common';
|
||||
import { Query } from "./../../../../definitions/common"
|
||||
import { Curl } from "./sources/curl"
|
||||
interface ImportResult {
|
||||
errorQueries: Query[]
|
||||
|
|
|
@ -1,4 +1,3 @@
|
|||
|
||||
import { Query, QueryParameter } from "../../../../../../definitions/common"
|
||||
|
||||
export interface ImportInfo {
|
||||
|
|
|
@ -29,7 +29,7 @@ const parseBody = (curl: any) => {
|
|||
}
|
||||
|
||||
const parseCookie = (curl: any) => {
|
||||
if (curl.cookies){
|
||||
if (curl.cookies) {
|
||||
return Object.entries(curl.cookies).reduce((acc, entry) => {
|
||||
const [key, value] = entry
|
||||
return acc + `${key}=${value}; `
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
export interface IntegrationBase {
|
||||
create?(query: any): Promise<any[]|any>
|
||||
read?(query: any): Promise<any[]|any>
|
||||
update?(query: any): Promise<any[]|any>
|
||||
delete?(query: any): Promise<any[]|any>
|
||||
create?(query: any): Promise<any[] | any>
|
||||
read?(query: any): Promise<any[] | any>
|
||||
update?(query: any): Promise<any[] | any>
|
||||
delete?(query: any): Promise<any[] | any>
|
||||
}
|
||||
|
|
|
@ -15,22 +15,22 @@ const BodyTypes = {
|
|||
|
||||
enum AuthType {
|
||||
BASIC = "basic",
|
||||
BEARER = "bearer"
|
||||
BEARER = "bearer",
|
||||
}
|
||||
|
||||
interface AuthConfig {
|
||||
id: string
|
||||
name: string
|
||||
type: AuthType
|
||||
config: BasicAuthConfig | BearerAuthConfig
|
||||
}
|
||||
|
||||
interface BasicAuthConfig {
|
||||
username: string,
|
||||
password: string,
|
||||
username: string
|
||||
password: string
|
||||
}
|
||||
|
||||
interface BearerAuthConfig {
|
||||
token: string,
|
||||
token: string
|
||||
}
|
||||
|
||||
const coreFields = {
|
||||
|
@ -170,16 +170,20 @@ module RestModule {
|
|||
}
|
||||
}
|
||||
|
||||
processAuth(authConfigId: string) {
|
||||
if (!this.config.authConfigs || !authConfigId) {
|
||||
processAuth(authConfigName: string) {
|
||||
if (!this.config.authConfigs || !authConfigName) {
|
||||
return
|
||||
}
|
||||
const authConfig = this.config.authConfigs.filter(authConfig => authConfig.id === authConfigId)[0]
|
||||
const authConfig = this.config.authConfigs.filter(
|
||||
authConfig => authConfig.name === authConfigName
|
||||
)[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")}`
|
||||
this.headers.Authorization = `Basic ${Buffer.from(
|
||||
`${config.username}:${config.password}`
|
||||
).toString("base64")}`
|
||||
break
|
||||
case AuthType.BEARER:
|
||||
config = authConfig.config as BearerAuthConfig
|
||||
|
@ -188,13 +192,20 @@ module RestModule {
|
|||
}
|
||||
}
|
||||
|
||||
async _req({ path = "", queryString = "", headers = {}, json = {}, method = "GET", authConfigId = "" }) {
|
||||
async _req({
|
||||
path = "",
|
||||
queryString = "",
|
||||
headers = {},
|
||||
json = {},
|
||||
method = "GET",
|
||||
authConfigName = "",
|
||||
}) {
|
||||
this.headers = {
|
||||
...this.config.defaultHeaders,
|
||||
...headers,
|
||||
}
|
||||
|
||||
this.processAuth(authConfigId)
|
||||
this.processAuth(authConfigName)
|
||||
|
||||
const input: any = { method, headers: this.headers }
|
||||
if (json && typeof json === "object" && Object.keys(json).length > 0) {
|
||||
|
@ -230,6 +241,6 @@ module RestModule {
|
|||
module.exports = {
|
||||
schema: SCHEMA,
|
||||
integration: RestIntegration,
|
||||
AuthType
|
||||
AuthType,
|
||||
}
|
||||
}
|
||||
|
|
|
@ -107,15 +107,16 @@ describe("REST Integration", () => {
|
|||
|
||||
describe("authentication", () => {
|
||||
const basicAuth = {
|
||||
id: "basic-1",
|
||||
name: "basic-1",
|
||||
type : AuthType.BASIC,
|
||||
config : {
|
||||
username: "user",
|
||||
password: "password"
|
||||
}
|
||||
}
|
||||
|
||||
const bearerAuth = {
|
||||
id: "bearer-1",
|
||||
name: "bearer-1",
|
||||
type : AuthType.BEARER,
|
||||
config : {
|
||||
"token": "mytoken"
|
||||
|
@ -131,7 +132,7 @@ describe("REST Integration", () => {
|
|||
|
||||
it("adds basic auth", async () => {
|
||||
const query = {
|
||||
authConfigId: "basic-1"
|
||||
authConfigName: "basic-1"
|
||||
}
|
||||
await config.integration.read(query)
|
||||
expect(fetch).toHaveBeenCalledWith(`${BASE_URL}/?`, {
|
||||
|
@ -144,7 +145,7 @@ describe("REST Integration", () => {
|
|||
|
||||
it("adds bearer auth", async () => {
|
||||
const query = {
|
||||
authConfigId: "bearer-1"
|
||||
authConfigName: "bearer-1"
|
||||
}
|
||||
await config.integration.read(query)
|
||||
expect(fetch).toHaveBeenCalledWith(`${BASE_URL}/?`, {
|
||||
|
|
Loading…
Reference in New Issue