forked from tsai/budibase
4 changed files with 24 additions and 13 deletions
@ -1,22 +1,23 @@ |
|||
const { apiKeyTable } = require("../../db/dynamoClient") |
|||
const env = require("../../environment") |
|||
const { getSelfHostInfo } = require("../../selfhost") |
|||
const { getSelfHostAPIKey } = require("../../selfhost") |
|||
|
|||
/** |
|||
* This file purely exists so that we can centralise all logic pertaining to API keys, as their usage differs |
|||
* in our Cloud environment versus self hosted. |
|||
*/ |
|||
|
|||
exports.getAPIKey = async apiKeyId => { |
|||
exports.isAPIKeyValid = async apiKeyId => { |
|||
if (env.CLOUD && !env.SELF_HOSTED) { |
|||
return apiKeyTable.get({ |
|||
let apiKeyInfo = await apiKeyTable.get({ |
|||
primary: apiKeyId, |
|||
}) |
|||
return apiKeyInfo != null |
|||
} |
|||
if (env.SELF_HOSTED) { |
|||
const selfHostInfo = await getSelfHostInfo() |
|||
const selfHostKey = await getSelfHostAPIKey() |
|||
// if the api key supplied is correct then return structure similar
|
|||
return apiKeyId === selfHostInfo.apiKeyId ? { pk: apiKeyId } : null |
|||
return apiKeyId === selfHostKey ? { pk: apiKeyId } : null |
|||
} |
|||
return null |
|||
return false |
|||
} |
|||
|
|||
Loading…
Reference in new issue