joplin/CliClient/app/command-encrypt-config.js

40 lines
977 B
JavaScript
Raw Normal View History

2017-12-12 18:17:30 +00:00
const { BaseCommand } = require('./base-command.js');
const { _ } = require('lib/locale.js');
const { cliUtils } = require('./cli-utils.js');
2017-12-12 21:58:57 +00:00
const EncryptionService = require('lib/services/EncryptionService');
const MasterKey = require('lib/models/MasterKey');
const { Setting } = require('lib/models/setting.js');
2017-12-12 18:17:30 +00:00
class Command extends BaseCommand {
usage() {
return 'encrypt-config <command>';
}
description() {
return _('Manages encryption configuration.');
}
async action(args) {
// init
// change-password
if (args.command === 'init') {
const password = await this.prompt(_('Enter master password:'), { type: 'string', secure: true });
2017-12-12 21:58:57 +00:00
if (!password) {
this.stdout(_('Operation cancelled'));
return;
}
const service = new EncryptionService();
const masterKey = await service.generateMasterKey(password);
await MasterKey.save(masterKey);
Setting.setValue('encryption.enabled', true);
2017-12-12 18:17:30 +00:00
}
}
}
module.exports = Command;