adds getEnvironmentVariables function

This commit is contained in:
kevmodrome 2020-07-02 20:31:26 +02:00
parent f6f2dfb8e4
commit 7a7ad75e12
No known key found for this signature in database
GPG Key ID: E8F9CD141E63BF38
1 changed files with 20 additions and 21 deletions

View File

@ -1,13 +1,15 @@
const CouchDB = require("../../db") const fs = require("fs")
const clientDb = require("../../db/clientDb")
const bcrypt = require("../../utilities/bcrypt") const ENV_FILE_PATH = ".budibase/.env"
const getUserId = userName => `user_${userName}`
const {
POWERUSER_LEVEL_ID,
ADMIN_LEVEL_ID,
} = require("../../utilities/accessLevels")
exports.fetch = async function (ctx) { exports.fetch = async function (ctx) {
// Check if structure of call makes sense, if not, return error
// Read File
const fileContent = await getEnvironmentVariables()
const keys = await extractKeys(fileContent)
// Temporary while "real" infrastructure to store keys is created // Temporary while "real" infrastructure to store keys is created
ctx.status = 200 ctx.status = 200
ctx.message = "API Keys" ctx.message = "API Keys"
@ -24,17 +26,14 @@ exports.update = async function (ctx) {
ctx.body = { [ctx.params.key]: ctx.request.body.value } ctx.body = { [ctx.params.key]: ctx.request.body.value }
} }
const checkAccessLevel = async (db, accessLevelId) => { async function getEnvironmentVariables() {
if (!accessLevelId) return const home = require('os').homedir();
if ( const filePath = `${home}/${ENV_FILE_PATH}`
accessLevelId === POWERUSER_LEVEL_ID ||
accessLevelId === ADMIN_LEVEL_ID return data = fs.readFileSync(filePath, 'utf8');
) { }
return {
_id: accessLevelId, async function extractKeys() {
name: accessLevelId, // Extract keys here
permissions: [], return []
}
}
return await db.get(accessLevelId)
} }