support for external webhooks
This commit is contained in:
parent
25a91b62f0
commit
1f92c9cd14
|
@ -1,6 +1,7 @@
|
||||||
<script>
|
<script>
|
||||||
import { Input } from "@budibase/bbui"
|
import { Input, Label } from "@budibase/bbui"
|
||||||
import api from "builderStore/api"
|
import api from "builderStore/api"
|
||||||
|
import { backendUiStore } from "builderStore"
|
||||||
import analytics from "analytics"
|
import analytics from "analytics"
|
||||||
|
|
||||||
let keys = { budibase: "" }
|
let keys = { budibase: "" }
|
||||||
|
@ -38,6 +39,10 @@
|
||||||
edit
|
edit
|
||||||
value={keys.budibase}
|
value={keys.budibase}
|
||||||
label="Budibase API Key" />
|
label="Budibase API Key" />
|
||||||
|
<div>
|
||||||
|
<Label extraSmall grey>Instance ID (Webhooks)</Label>
|
||||||
|
<span>{$backendUiStore.selectedDatabase._id}</span>
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<style>
|
<style>
|
||||||
|
@ -45,4 +50,9 @@
|
||||||
display: grid;
|
display: grid;
|
||||||
grid-gap: var(--spacing-xl);
|
grid-gap: var(--spacing-xl);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
span {
|
||||||
|
font-size: var(--font-size-xs);
|
||||||
|
font-weight: 500;
|
||||||
|
}
|
||||||
</style>
|
</style>
|
||||||
|
|
|
@ -5,8 +5,33 @@ const {
|
||||||
BUILDER_LEVEL_ID,
|
BUILDER_LEVEL_ID,
|
||||||
BUILDER,
|
BUILDER,
|
||||||
} = require("../utilities/accessLevels")
|
} = require("../utilities/accessLevels")
|
||||||
|
const environment = require("../environment")
|
||||||
|
const { apiKeyTable } = require("../db/dynamoClient")
|
||||||
|
|
||||||
module.exports = (permName, getItemId) => async (ctx, next) => {
|
module.exports = (permName, getItemId) => async (ctx, next) => {
|
||||||
|
if (
|
||||||
|
environment.CLOUD &&
|
||||||
|
ctx.headers["x-api-key"] &&
|
||||||
|
ctx.headers["x-instanceid"]
|
||||||
|
) {
|
||||||
|
// api key header passed by external webhook
|
||||||
|
const apiKeyInfo = await apiKeyTable.get({
|
||||||
|
primary: ctx.headers["x-api-key"],
|
||||||
|
})
|
||||||
|
|
||||||
|
if (apiKeyInfo) {
|
||||||
|
ctx.isAuthenticated = true
|
||||||
|
ctx.externalWebhook = true
|
||||||
|
ctx.apiKey = ctx.headers["x-api-key"]
|
||||||
|
ctx.user = {
|
||||||
|
instanceId: ctx.headers["x-instanceid"],
|
||||||
|
}
|
||||||
|
return next()
|
||||||
|
}
|
||||||
|
|
||||||
|
ctx.throw(403, "API key invalid")
|
||||||
|
}
|
||||||
|
|
||||||
if (!ctx.isAuthenticated) {
|
if (!ctx.isAuthenticated) {
|
||||||
ctx.throw(403, "Session not authenticated")
|
ctx.throw(403, "Session not authenticated")
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue