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) {
|
|
|
|
ctx.status = 200
|
|
|
|
ctx.body = {
|
2020-07-02 21:25:25 +02:00
|
|
|
budibase: process.env.BUDIBASE_API_KEY,
|
|
|
|
sendgrid: process.env.SENDGRID_API_KEY
|
2020-07-02 17:53:09 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
exports.update = async function (ctx) {
|
2020-07-02 21:01:34 +02: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-02 17:53:09 +02:00
|
|
|
ctx.status = 200
|
2020-07-02 18:38:00 +02:00
|
|
|
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
|
|
|
|
2020-07-02 21:01:34 +02:00
|
|
|
async function extractKeys(content) {
|
|
|
|
const lines = content.split(/\r?\n/)
|
2020-07-02 21:25:25 +02:00
|
|
|
console.log(lines)
|
2020-07-02 20:31:26 +02:00
|
|
|
// Extract keys here
|
2020-07-02 21:25:25 +02:00
|
|
|
return lines
|
2020-07-02 20:31:26 +02:00
|
|
|
}
|