budibase/packages/server/src/api/controllers/apikeys.js

39 lines
1.0 KiB
JavaScript
Raw Normal View History

2020-07-02 20:31:26 +02:00
const fs = require("fs")
const ENV_FILE_PATH = ".budibase/.env"
2020-07-02 17:53:09 +02:00
exports.fetch = async function (ctx) {
2020-07-02 20:31:26 +02:00
// Check if structure of call makes sense, if not, return error
// Read File
const fileContent = await getEnvironmentVariables()
const keys = await extractKeys(fileContent)
2020-07-02 17:53:09 +02:00
// Temporary while "real" infrastructure to store keys is created
ctx.status = 200
ctx.message = "API Keys"
ctx.body = {
budibase: 'testFromBackEnd',
sendgrid: 'testFromBackEnd'
}
}
exports.update = async function (ctx) {
// Do something with ctx.request.body: <{ value: value }>
2020-07-02 17:53:09 +02:00
ctx.status = 200
ctx.message = `Updated ${ctx.params.key} API key succesfully.`
ctx.body = { [ctx.params.key]: ctx.request.body.value }
2020-07-02 17:53:09 +02:00
}
2020-07-02 20:31:26 +02:00
async function getEnvironmentVariables() {
const home = require('os').homedir();
const filePath = `${home}/${ENV_FILE_PATH}`
return data = fs.readFileSync(filePath, 'utf8');
2020-07-02 17:53:09 +02:00
}
2020-07-02 20:31:26 +02:00
async function extractKeys() {
// Extract keys here
return []
}