1
0
Fork 0
mirror of synced 2024-07-07 07:15:43 +12:00

adds getEnvironmentVariables function

This commit is contained in:
kevmodrome 2020-07-02 20:31:26 +02:00
parent a5d33854da
commit e3e5caaf97

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,
name: accessLevelId,
permissions: [],
}
}
return await db.get(accessLevelId)
} }
async function extractKeys() {
// Extract keys here
return []
}