adds getEnvironmentVariables function

This commit is contained in:
kevmodrome 2020-07-02 20:31:26 +02:00
parent a5d33854da
commit e3e5caaf97
1 changed files with 20 additions and 21 deletions

View File

@ -1,13 +1,15 @@
const CouchDB = require("../../db")
const clientDb = require("../../db/clientDb")
const bcrypt = require("../../utilities/bcrypt")
const getUserId = userName => `user_${userName}`
const {
POWERUSER_LEVEL_ID,
ADMIN_LEVEL_ID,
} = require("../../utilities/accessLevels")
const fs = require("fs")
const ENV_FILE_PATH = ".budibase/.env"
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
ctx.status = 200
ctx.message = "API Keys"
@ -24,17 +26,14 @@ exports.update = async function (ctx) {
ctx.body = { [ctx.params.key]: ctx.request.body.value }
}
const checkAccessLevel = async (db, accessLevelId) => {
if (!accessLevelId) return
if (
accessLevelId === POWERUSER_LEVEL_ID ||
accessLevelId === ADMIN_LEVEL_ID
) {
return {
_id: accessLevelId,
name: accessLevelId,
permissions: [],
}
}
return await db.get(accessLevelId)
async function getEnvironmentVariables() {
const home = require('os').homedir();
const filePath = `${home}/${ENV_FILE_PATH}`
return data = fs.readFileSync(filePath, 'utf8');
}
async function extractKeys() {
// Extract keys here
return []
}