1
0
Fork 0
mirror of synced 2024-06-28 11:00:55 +12:00
budibase/packages/server/src/api/controllers/apikeys.js

37 lines
948 B
JavaScript
Raw Normal View History

2020-07-03 06:31:26 +12:00
const fs = require("fs")
const ENV_FILE_PATH = ".budibase/.env"
2020-07-03 03:53:09 +12:00
exports.fetch = async function (ctx) {
ctx.status = 200
ctx.body = {
2020-07-03 07:25:25 +12:00
budibase: process.env.BUDIBASE_API_KEY,
sendgrid: process.env.SENDGRID_API_KEY
2020-07-03 03:53:09 +12:00
}
}
exports.update = async function (ctx) {
2020-07-03 07:01:34 +12:00
// Set process.env
const envKeyName = `${ctx.params.key.toUpperCase()}_API_KEY`
process.env[envKeyName] = ctx.request.body.value
// Write to file
// TODO
2020-07-03 03:53:09 +12:00
ctx.status = 200
ctx.message = `Updated ${ctx.params.key} API key succesfully.`
ctx.body = { [ctx.params.key]: ctx.request.body.value }
2020-07-03 03:53:09 +12:00
}
2020-07-03 06:31:26 +12:00
async function getEnvironmentVariables() {
const home = require('os').homedir();
const filePath = `${home}/${ENV_FILE_PATH}`
return data = fs.readFileSync(filePath, 'utf8');
2020-07-03 03:53:09 +12:00
}
2020-07-03 06:31:26 +12:00
2020-07-03 07:01:34 +12:00
async function extractKeys(content) {
const lines = content.split(/\r?\n/)
2020-07-03 07:25:25 +12:00
console.log(lines)
2020-07-03 06:31:26 +12:00
// Extract keys here
2020-07-03 07:25:25 +12:00
return lines
2020-07-03 06:31:26 +12:00
}