Removing unused code that was causing some issues with API key lookup and validation in self hosted setups.
This commit is contained in:
parent
c4b828416a
commit
60841d1b1f
|
@ -9,7 +9,6 @@ const env = require("./environment")
|
|||
const eventEmitter = require("./events")
|
||||
const automations = require("./automations/index")
|
||||
const Sentry = require("@sentry/node")
|
||||
const selfhost = require("./selfhost")
|
||||
|
||||
const app = new Koa()
|
||||
|
||||
|
@ -66,11 +65,8 @@ module.exports = server.listen(env.PORT || 0, async () => {
|
|||
console.log(`Budibase running on ${JSON.stringify(server.address())}`)
|
||||
env._set("PORT", server.address().port)
|
||||
eventEmitter.emitPort(env.PORT)
|
||||
automations.init()
|
||||
// only init the self hosting DB info in the Pouch, not needed in self hosting prod
|
||||
if (!env.CLOUD) {
|
||||
await selfhost.init()
|
||||
}
|
||||
|
||||
await automations.init()
|
||||
})
|
||||
|
||||
process.on("uncaughtException", err => {
|
||||
|
|
|
@ -1,7 +0,0 @@
|
|||
### Self hosting
|
||||
This directory contains utilities that are needed for self hosted platforms to operate.
|
||||
These will mostly be utilities, necessary to the operation of the server e.g. storing self
|
||||
hosting specific options and attributes to CouchDB.
|
||||
|
||||
All the internal operations should be exposed through the `index.js` so importing
|
||||
the self host directory should give you everything you need.
|
|
@ -1,44 +0,0 @@
|
|||
const CouchDB = require("../db")
|
||||
const env = require("../environment")
|
||||
const newid = require("../db/newid")
|
||||
|
||||
const SELF_HOST_DB = "self-host-db"
|
||||
const SELF_HOST_DOC = "self-host-info"
|
||||
|
||||
async function createSelfHostDB(db) {
|
||||
await db.put({
|
||||
_id: "_design/database",
|
||||
views: {},
|
||||
})
|
||||
const selfHostInfo = {
|
||||
_id: SELF_HOST_DOC,
|
||||
apiKeyId: newid(),
|
||||
}
|
||||
await db.put(selfHostInfo)
|
||||
return selfHostInfo
|
||||
}
|
||||
|
||||
exports.init = async () => {
|
||||
if (!env.SELF_HOSTED) {
|
||||
return
|
||||
}
|
||||
const db = new CouchDB(SELF_HOST_DB)
|
||||
try {
|
||||
await db.get(SELF_HOST_DOC)
|
||||
} catch (err) {
|
||||
// failed to retrieve
|
||||
if (err.status === 404) {
|
||||
await createSelfHostDB(db)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
exports.getSelfHostInfo = async () => {
|
||||
const db = new CouchDB(SELF_HOST_DB)
|
||||
return db.get(SELF_HOST_DOC)
|
||||
}
|
||||
|
||||
exports.getSelfHostAPIKey = async () => {
|
||||
const info = await exports.getSelfHostInfo()
|
||||
return info ? info.apiKeyId : null
|
||||
}
|
|
@ -1,6 +1,5 @@
|
|||
const { apiKeyTable } = require("../../db/dynamoClient")
|
||||
const env = require("../../environment")
|
||||
const { getSelfHostAPIKey } = require("../../selfhost")
|
||||
|
||||
/**
|
||||
* This file purely exists so that we can centralise all logic pertaining to API keys, as their usage differs
|
||||
|
@ -8,16 +7,13 @@ const { getSelfHostAPIKey } = require("../../selfhost")
|
|||
*/
|
||||
|
||||
exports.isAPIKeyValid = async apiKeyId => {
|
||||
if (env.CLOUD && !env.SELF_HOSTED) {
|
||||
if (!env.SELF_HOSTED) {
|
||||
let apiKeyInfo = await apiKeyTable.get({
|
||||
primary: apiKeyId,
|
||||
})
|
||||
return apiKeyInfo != null
|
||||
}
|
||||
if (env.SELF_HOSTED) {
|
||||
const selfHostKey = await getSelfHostAPIKey()
|
||||
} else {
|
||||
// if the api key supplied is correct then return structure similar
|
||||
return apiKeyId === selfHostKey ? { pk: apiKeyId } : null
|
||||
return apiKeyId === env.HOSTING_KEY
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue