-
Notifications
You must be signed in to change notification settings - Fork 8.3k
/
Copy pathgenerate.js
48 lines (45 loc) · 1.89 KB
/
generate.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0 and the Server Side Public License, v 1; you may not use this file except
* in compliance with, at your election, the Elastic License 2.0 or the Server
* Side Public License, v 1.
*/
import { safeDump } from 'js-yaml';
import { isEmpty } from 'lodash';
import { interactive } from './interactive';
import { Logger } from '../cli/logger';
export async function generate(encryptionConfig, command) {
const logger = new Logger();
const keys = encryptionConfig.generate({ force: command.force });
if (isEmpty(keys)) {
logger.log('No keys to write. Use the --force flag to generate new keys.');
} else {
if (!command.quiet) {
logger.log('## Kibana Encryption Key Generation Utility\n');
logger.log(
`The 'generate' command guides you through the process of setting encryption keys for:\n`
);
logger.log(encryptionConfig.docs());
logger.log(
'Already defined settings are ignored and can be regenerated using the --force flag. Check the documentation links for instructions on how to rotate encryption keys.'
);
logger.log('Definitions should be set in the kibana.yml used configure Kibana.\n');
}
if (command.interactive) {
await interactive(keys, encryptionConfig.docs({ comment: true }), logger);
} else {
if (!command.quiet) logger.log('Settings:');
logger.log(safeDump(keys));
}
}
}
export function generateCli(program, encryptionConfig) {
program
.command('generate')
.description('Generates encryption keys')
.option('-i, --interactive', 'interactive output')
.option('-q, --quiet', 'do not include instructions')
.option('-f, --force', 'generate new keys for all settings')
.action(generate.bind(null, encryptionConfig));
}