mirror of
https://github.com/elastic/kibana.git
synced 2025-04-24 01:38:56 -04:00
Fixes issue with Keystore's stdin option (#15221)
Fixes issue preventing stdin option from being used Using create to overwrite should reset keystore
This commit is contained in:
parent
efcf8737e7
commit
7df8dce8d8
8 changed files with 33 additions and 11 deletions
|
@ -60,7 +60,7 @@ through stdin, use the `--stdin` flag:
|
|||
|
||||
[source,sh]
|
||||
----------------------------------------------------------------
|
||||
cat /file/containing/setting/value | bin/kibana-keystore add --stdin the.setting.name.to.set
|
||||
cat /file/containing/setting/value | bin/kibana-keystore add the.setting.name.to.set --stdin
|
||||
----------------------------------------------------------------
|
||||
|
||||
[float]
|
||||
|
|
|
@ -126,7 +126,7 @@ describe('Kibana keystore', () => {
|
|||
stdin.end();
|
||||
});
|
||||
|
||||
await add(keystore, 'foo', { stdin });
|
||||
await add(keystore, 'foo', { stdin: true, stdinStream: stdin });
|
||||
|
||||
expect(keystore.data.foo).to.eql('kibana');
|
||||
});
|
||||
|
|
|
@ -41,8 +41,8 @@ describe('Kibana keystore', () => {
|
|||
const keystore = new Keystore('/data/nonexistent.keystore');
|
||||
list(keystore);
|
||||
|
||||
sinon.assert.calledOnce(Logger.prototype.log);
|
||||
sinon.assert.calledWith(Logger.prototype.log, '');
|
||||
sinon.assert.calledOnce(Logger.prototype.error);
|
||||
sinon.assert.calledWith(Logger.prototype.error, 'ERROR: Kibana keystore not found. Use \'create\' command to create one.');
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
|
@ -7,7 +7,8 @@ import { createPromiseFromStreams, createConcatStream } from '../utils';
|
|||
* @param {String} key
|
||||
* @param {Object|null} options
|
||||
* @property {Boolean} options.force - if true, will overwrite without prompting
|
||||
* @property {Stream|Boolean} options.stdin - if true, uses process.stdin
|
||||
* @property {Stream} options.stdinStream - defaults to process.stdin
|
||||
* @property {Boolean} options.stdin - if true, uses options.stdin to read value
|
||||
*/
|
||||
|
||||
export async function add(keystore, key, options = {}) {
|
||||
|
@ -19,16 +20,20 @@ export async function add(keystore, key, options = {}) {
|
|||
}
|
||||
|
||||
if (!options.force && keystore.has(key)) {
|
||||
const overwrite = await confirm(`Setting ${key} already exists. Overwrite?`);
|
||||
if (options.stdin) {
|
||||
return logger.log(`Setting ${key} already exists, exiting without modifying keystore.`);
|
||||
} else {
|
||||
const overwrite = await confirm(`Setting ${key} already exists. Overwrite?`);
|
||||
|
||||
if (!overwrite) {
|
||||
return logger.log('Exiting without modifying keystore.');
|
||||
if (!overwrite) {
|
||||
return logger.log('Exiting without modifying keystore.');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (options.stdin) {
|
||||
value = await createPromiseFromStreams([
|
||||
options.stdin || process.stdin,
|
||||
options.stdinStream || process.stdin,
|
||||
createConcatStream('')
|
||||
]);
|
||||
} else {
|
||||
|
|
|
@ -12,6 +12,7 @@ export async function create(keystore, command, options) {
|
|||
}
|
||||
}
|
||||
|
||||
keystore.reset();
|
||||
keystore.save();
|
||||
|
||||
logger.log(`Created Kibana keystore in ${keystore.path}`);
|
||||
|
|
|
@ -2,8 +2,12 @@ import Logger from '../cli_plugin/lib/logger';
|
|||
|
||||
export function list(keystore, command, options = {}) {
|
||||
const logger = new Logger(options);
|
||||
const keys = keystore.keys();
|
||||
|
||||
if (!keystore.exists()) {
|
||||
return logger.error('ERROR: Kibana keystore not found. Use \'create\' command to create one.');
|
||||
}
|
||||
|
||||
const keys = keystore.keys();
|
||||
logger.log(keys.join('\n'));
|
||||
}
|
||||
|
||||
|
|
|
@ -91,6 +91,14 @@ describe('Keystore', () => {
|
|||
});
|
||||
});
|
||||
|
||||
describe('reset', () => {
|
||||
it('clears the data', () => {
|
||||
const keystore = new Keystore('/data/protected.keystore', 'changeme');
|
||||
keystore.reset();
|
||||
expect(keystore.data).to.eql([]);
|
||||
});
|
||||
});
|
||||
|
||||
describe('keys', () => {
|
||||
it('lists object keys', () => {
|
||||
const keystore = new Keystore('/data/unprotected.keystore');
|
||||
|
|
|
@ -9,9 +9,9 @@ const ITERATIONS = 10000;
|
|||
export class Keystore {
|
||||
constructor(path, password = '') {
|
||||
this.path = path;
|
||||
this.data = {};
|
||||
this.password = password;
|
||||
|
||||
this.reset();
|
||||
this.load();
|
||||
}
|
||||
|
||||
|
@ -81,6 +81,10 @@ export class Keystore {
|
|||
}
|
||||
}
|
||||
|
||||
reset() {
|
||||
this.data = {};
|
||||
}
|
||||
|
||||
exists() {
|
||||
return existsSync(this.path);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue