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 { datasources, integrations, tables } from "stores/backend"
|
||||||
import CreateEditRelationship from "components/backend/Datasources/CreateEditRelationship.svelte"
|
import CreateEditRelationship from "components/backend/Datasources/CreateEditRelationship.svelte"
|
||||||
import CreateExternalTableModal from "./CreateExternalTableModal.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 ConfirmDialog from "components/common/ConfirmDialog.svelte"
|
||||||
import { goto } from "@roxi/routify"
|
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>
|
<script>
|
||||||
import { Divider, Heading, ActionButton, Badge, Body } from "@budibase/bbui"
|
import { Divider, Heading, ActionButton, Badge, Body } from "@budibase/bbui"
|
||||||
import KeyValueBuilder from "components/integration/KeyValueBuilder.svelte"
|
import KeyValueBuilder from "components/integration/KeyValueBuilder.svelte"
|
||||||
|
import RestAuthenticationBuilder from "./RestAuthenticationBuilder.svelte"
|
||||||
|
|
||||||
export let datasource
|
export let datasource
|
||||||
|
|
||||||
|
@ -8,7 +9,7 @@
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<Divider size="S" />
|
<Divider size="S" />
|
||||||
<div class="query-header">
|
<div class="section-header">
|
||||||
<div class="badge">
|
<div class="badge">
|
||||||
<Heading size="S">Headers</Heading>
|
<Heading size="S">Headers</Heading>
|
||||||
<Badge quiet grey>Optional</Badge>
|
<Badge quiet grey>Optional</Badge>
|
||||||
|
@ -30,8 +31,23 @@
|
||||||
</ActionButton>
|
</ActionButton>
|
||||||
</div>
|
</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>
|
<style>
|
||||||
.query-header {
|
.section-header {
|
||||||
display: flex;
|
display: flex;
|
||||||
flex-direction: row;
|
flex-direction: row;
|
||||||
justify-content: space-between;
|
justify-content: space-between;
|
||||||
|
|
|
@ -15,7 +15,7 @@
|
||||||
import RestExtraConfigForm from "components/backend/DatasourceNavigator/TableIntegrationMenu/RestExtraConfigForm.svelte"
|
import RestExtraConfigForm from "components/backend/DatasourceNavigator/TableIntegrationMenu/RestExtraConfigForm.svelte"
|
||||||
import PlusConfigForm from "components/backend/DatasourceNavigator/TableIntegrationMenu/PlusConfigForm.svelte"
|
import PlusConfigForm from "components/backend/DatasourceNavigator/TableIntegrationMenu/PlusConfigForm.svelte"
|
||||||
import ICONS from "components/backend/DatasourceNavigator/icons"
|
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 { IntegrationTypes } from "constants/backend"
|
||||||
import { isEqual } from "lodash"
|
import { isEqual } from "lodash"
|
||||||
import { cloneDeep } from "lodash/fp"
|
import { cloneDeep } from "lodash/fp"
|
||||||
|
@ -135,7 +135,9 @@
|
||||||
allowEditColumns={false}
|
allowEditColumns={false}
|
||||||
allowEditRows={false}
|
allowEditRows={false}
|
||||||
allowSelectRows={false}
|
allowSelectRows={false}
|
||||||
customRenderers={[{ column: "queryVerb", component: VerbRenderer }]}
|
customRenderers={[
|
||||||
|
{ column: "queryVerb", component: CapitaliseRenderer },
|
||||||
|
]}
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
{/if}
|
{/if}
|
||||||
|
|
|
@ -3,7 +3,7 @@ import { queryValidation } from "../validation"
|
||||||
import { generateQueryID } from "../../../../db/utils"
|
import { generateQueryID } from "../../../../db/utils"
|
||||||
import { ImportInfo, ImportSource } from "./sources/base"
|
import { ImportInfo, ImportSource } from "./sources/base"
|
||||||
import { OpenAPI2 } from "./sources/openapi2"
|
import { OpenAPI2 } from "./sources/openapi2"
|
||||||
import { Query } from './../../../../definitions/common';
|
import { Query } from "./../../../../definitions/common"
|
||||||
import { Curl } from "./sources/curl"
|
import { Curl } from "./sources/curl"
|
||||||
interface ImportResult {
|
interface ImportResult {
|
||||||
errorQueries: Query[]
|
errorQueries: Query[]
|
||||||
|
|
|
@ -1,4 +1,3 @@
|
||||||
|
|
||||||
import { Query, QueryParameter } from "../../../../../../definitions/common"
|
import { Query, QueryParameter } from "../../../../../../definitions/common"
|
||||||
|
|
||||||
export interface ImportInfo {
|
export interface ImportInfo {
|
||||||
|
|
|
@ -29,7 +29,7 @@ const parseBody = (curl: any) => {
|
||||||
}
|
}
|
||||||
|
|
||||||
const parseCookie = (curl: any) => {
|
const parseCookie = (curl: any) => {
|
||||||
if (curl.cookies){
|
if (curl.cookies) {
|
||||||
return Object.entries(curl.cookies).reduce((acc, entry) => {
|
return Object.entries(curl.cookies).reduce((acc, entry) => {
|
||||||
const [key, value] = entry
|
const [key, value] = entry
|
||||||
return acc + `${key}=${value}; `
|
return acc + `${key}=${value}; `
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
export interface IntegrationBase {
|
export interface IntegrationBase {
|
||||||
create?(query: any): Promise<any[]|any>
|
create?(query: any): Promise<any[] | any>
|
||||||
read?(query: any): Promise<any[]|any>
|
read?(query: any): Promise<any[] | any>
|
||||||
update?(query: any): Promise<any[]|any>
|
update?(query: any): Promise<any[] | any>
|
||||||
delete?(query: any): Promise<any[]|any>
|
delete?(query: any): Promise<any[] | any>
|
||||||
}
|
}
|
||||||
|
|
|
@ -15,22 +15,22 @@ const BodyTypes = {
|
||||||
|
|
||||||
enum AuthType {
|
enum AuthType {
|
||||||
BASIC = "basic",
|
BASIC = "basic",
|
||||||
BEARER = "bearer"
|
BEARER = "bearer",
|
||||||
}
|
}
|
||||||
|
|
||||||
interface AuthConfig {
|
interface AuthConfig {
|
||||||
id: string
|
name: string
|
||||||
type: AuthType
|
type: AuthType
|
||||||
config: BasicAuthConfig | BearerAuthConfig
|
config: BasicAuthConfig | BearerAuthConfig
|
||||||
}
|
}
|
||||||
|
|
||||||
interface BasicAuthConfig {
|
interface BasicAuthConfig {
|
||||||
username: string,
|
username: string
|
||||||
password: string,
|
password: string
|
||||||
}
|
}
|
||||||
|
|
||||||
interface BearerAuthConfig {
|
interface BearerAuthConfig {
|
||||||
token: string,
|
token: string
|
||||||
}
|
}
|
||||||
|
|
||||||
const coreFields = {
|
const coreFields = {
|
||||||
|
@ -170,16 +170,20 @@ module RestModule {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
processAuth(authConfigId: string) {
|
processAuth(authConfigName: string) {
|
||||||
if (!this.config.authConfigs || !authConfigId) {
|
if (!this.config.authConfigs || !authConfigName) {
|
||||||
return
|
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
|
let config
|
||||||
switch (authConfig.type) {
|
switch (authConfig.type) {
|
||||||
case AuthType.BASIC:
|
case AuthType.BASIC:
|
||||||
config = authConfig.config as BasicAuthConfig
|
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
|
break
|
||||||
case AuthType.BEARER:
|
case AuthType.BEARER:
|
||||||
config = authConfig.config as BearerAuthConfig
|
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.headers = {
|
||||||
...this.config.defaultHeaders,
|
...this.config.defaultHeaders,
|
||||||
...headers,
|
...headers,
|
||||||
}
|
}
|
||||||
|
|
||||||
this.processAuth(authConfigId)
|
this.processAuth(authConfigName)
|
||||||
|
|
||||||
const input: any = { method, headers: this.headers }
|
const input: any = { method, headers: this.headers }
|
||||||
if (json && typeof json === "object" && Object.keys(json).length > 0) {
|
if (json && typeof json === "object" && Object.keys(json).length > 0) {
|
||||||
|
@ -230,6 +241,6 @@ module RestModule {
|
||||||
module.exports = {
|
module.exports = {
|
||||||
schema: SCHEMA,
|
schema: SCHEMA,
|
||||||
integration: RestIntegration,
|
integration: RestIntegration,
|
||||||
AuthType
|
AuthType,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -107,15 +107,16 @@ describe("REST Integration", () => {
|
||||||
|
|
||||||
describe("authentication", () => {
|
describe("authentication", () => {
|
||||||
const basicAuth = {
|
const basicAuth = {
|
||||||
id: "basic-1",
|
name: "basic-1",
|
||||||
type : AuthType.BASIC,
|
type : AuthType.BASIC,
|
||||||
config : {
|
config : {
|
||||||
username: "user",
|
username: "user",
|
||||||
password: "password"
|
password: "password"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const bearerAuth = {
|
const bearerAuth = {
|
||||||
id: "bearer-1",
|
name: "bearer-1",
|
||||||
type : AuthType.BEARER,
|
type : AuthType.BEARER,
|
||||||
config : {
|
config : {
|
||||||
"token": "mytoken"
|
"token": "mytoken"
|
||||||
|
@ -131,7 +132,7 @@ describe("REST Integration", () => {
|
||||||
|
|
||||||
it("adds basic auth", async () => {
|
it("adds basic auth", async () => {
|
||||||
const query = {
|
const query = {
|
||||||
authConfigId: "basic-1"
|
authConfigName: "basic-1"
|
||||||
}
|
}
|
||||||
await config.integration.read(query)
|
await config.integration.read(query)
|
||||||
expect(fetch).toHaveBeenCalledWith(`${BASE_URL}/?`, {
|
expect(fetch).toHaveBeenCalledWith(`${BASE_URL}/?`, {
|
||||||
|
@ -144,7 +145,7 @@ describe("REST Integration", () => {
|
||||||
|
|
||||||
it("adds bearer auth", async () => {
|
it("adds bearer auth", async () => {
|
||||||
const query = {
|
const query = {
|
||||||
authConfigId: "bearer-1"
|
authConfigName: "bearer-1"
|
||||||
}
|
}
|
||||||
await config.integration.read(query)
|
await config.integration.read(query)
|
||||||
expect(fetch).toHaveBeenCalledWith(`${BASE_URL}/?`, {
|
expect(fetch).toHaveBeenCalledWith(`${BASE_URL}/?`, {
|
||||||
|
|
Loading…
Reference in New Issue