Skip to content

Commit

Permalink
feat: copy yaml config with defaults
Browse files Browse the repository at this point in the history
  • Loading branch information
jakowenko committed Sep 21, 2021
1 parent d854dcf commit 052ab4b
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 10 deletions.
15 changes: 9 additions & 6 deletions api/src/controllers/config.controller.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,15 @@ const { STORAGE } = require('../constants');
module.exports.get = async (req, res) => {
const { format } = req.query;
const isLegacyPath = fs.existsSync('./config.yml');
const output =
format === 'yaml'
? fs.readFileSync(isLegacyPath ? './config.yml' : `${STORAGE.CONFIG.PATH}/config.yml`, 'utf8')
: req.query.redact === ''
? redact(config())
: config();
let output = {};
if (format === 'yaml')
output = fs.readFileSync(
isLegacyPath ? './config.yml' : `${STORAGE.CONFIG.PATH}/config.yml`,
'utf8'
);
else if (format === 'yaml-with-defaults') output = yaml.dump(config());
else if (req.query.redact === '') output = redact(config());
else output = config();
res.send(output);
};

Expand Down
7 changes: 6 additions & 1 deletion api/src/routes/config.routes.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,12 @@ const { query } = expressValidator;
const router = express.Router();

router
.get('/', validate([query('format').default('json').isIn(['json', 'yaml'])]), jwt, controller.get)
.get(
'/',
jwt,
validate([query('format').default('json').isIn(['json', 'yaml', 'yaml-with-defaults'])]),
controller.get
)
.patch('/', jwt, controller.patch);

module.exports = router;
21 changes: 18 additions & 3 deletions frontend/src/views/Config.vue
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,23 @@
</div>
</div>
<div class="p-d-flex">
<Button
icon="pi pi-copy"
class="p-button-sm p-button-secondary p-mr-1"
@click="copyYamlConfig"
v-tooltip.left="'Copy Config (YAML)'"
/>
<Button
icon="pi pi-copy"
class="p-button-sm p-button-secondary"
@click="copyConfig"
v-tooltip.left="'Copy Config'"
v-tooltip.left="'Copy Config (JSON)'"
/>
</div>
<div class="p-mr-3 buttons">
<Button
icon="pi pi-refresh"
class="p-button-sm p-button-success p-mb-2"
class="p-button-sm p-button-success p-mb-1"
@click="reload"
:disabled="loading"
v-tooltip.left="'Refresh Page'"
Expand Down Expand Up @@ -266,7 +272,16 @@ export default {
try {
const { data } = await ApiService.get('config?redact');
copy(JSON.stringify(data, null, '\t'));
this.emitter.emit('toast', { message: 'Config copied' });
this.emitter.emit('toast', { message: 'JSON config copied' });
} catch (error) {
this.emitter.emit('error', error);
}
},
async copyYamlConfig() {
try {
const { data } = await ApiService.get('config?format=yaml-with-defaults');
copy(data);
this.emitter.emit('toast', { message: 'YAML config copied' });
} catch (error) {
this.emitter.emit('error', error);
}
Expand Down

0 comments on commit 052ab4b

Please sign in to comment.