Skip to content

Commit

Permalink
[keystore] use get_keystore in server cli (elastic#72954)
Browse files Browse the repository at this point in the history
* [keystore] use get_keystore in server cli

* temporily add docker build so this can be retested in original env

* Revert "temporily add docker build so this can be retested in original env"

This reverts commit 25f401a.
  • Loading branch information
jbudz committed Jul 23, 2020
1 parent 5d8eb61 commit b11297d
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 9 deletions.
7 changes: 3 additions & 4 deletions src/cli/serve/read_keystore.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,13 @@
* under the License.
*/

import path from 'path';
import { set } from '@elastic/safer-lodash-set';

import { Keystore } from '../../legacy/server/keystore';
import { getDataPath } from '../../core/server/path';
import { getKeystore } from '../../cli_keystore/get_keystore';

export function readKeystore(dataPath = getDataPath()) {
const keystore = new Keystore(path.join(dataPath, 'kibana.keystore'));
export function readKeystore(keystorePath = getKeystore()) {
const keystore = new Keystore(keystorePath);
keystore.load();

const keys = Object.keys(keystore.data);
Expand Down
16 changes: 11 additions & 5 deletions src/cli/serve/read_keystore.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,17 @@ describe('cli/serve/read_keystore', () => {
});
});

it('uses data path provided', () => {
const keystoreDir = '/foo/';
const keystorePath = path.join(keystoreDir, 'kibana.keystore');
it('uses data path if provided', () => {
const keystorePath = path.join('/foo/', 'kibana.keystore');

readKeystore(keystoreDir);
expect(Keystore.mock.calls[0][0]).toEqual(keystorePath);
readKeystore(keystorePath);
expect(Keystore.mock.calls[0][0]).toContain(keystorePath);
});

it('uses the getKeystore path if not', () => {
readKeystore();
// we test exact path scenarios in get_keystore.test.js - we use both
// deprecated and new to cover any older local environments
expect(Keystore.mock.calls[0][0]).toMatch(/data|config/);
});
});

0 comments on commit b11297d

Please sign in to comment.