kourou 0.20.7 → 0.22.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (61) hide show
  1. package/README.md +92 -10
  2. package/lib/commands/app/scaffold.d.ts +3 -3
  3. package/lib/commands/app/scaffold.js +16 -69
  4. package/lib/commands/app/start-services.js +6 -4
  5. package/lib/commands/collection/export.d.ts +1 -0
  6. package/lib/commands/collection/export.js +3 -2
  7. package/lib/commands/collection/import.d.ts +1 -0
  8. package/lib/commands/collection/import.js +3 -2
  9. package/lib/commands/config/diff.js +3 -3
  10. package/lib/commands/es/migrate.d.ts +5 -2
  11. package/lib/commands/es/migrate.js +51 -30
  12. package/lib/commands/file/decrypt.js +2 -2
  13. package/lib/commands/file/encrypt.js +2 -2
  14. package/lib/commands/file/test.js +2 -2
  15. package/lib/commands/import.d.ts +1 -0
  16. package/lib/commands/import.js +3 -2
  17. package/lib/commands/index/export.d.ts +1 -0
  18. package/lib/commands/index/export.js +4 -3
  19. package/lib/commands/index/import.d.ts +1 -0
  20. package/lib/commands/index/import.js +3 -2
  21. package/lib/commands/instance/kill.js +7 -5
  22. package/lib/commands/instance/logs.js +1 -1
  23. package/lib/commands/instance/spawn.js +8 -7
  24. package/lib/commands/paas/deploy.d.ts +18 -0
  25. package/lib/commands/paas/deploy.js +66 -0
  26. package/lib/commands/paas/init.d.ts +14 -0
  27. package/lib/commands/paas/init.js +31 -0
  28. package/lib/commands/paas/login.d.ts +15 -0
  29. package/lib/commands/paas/login.js +64 -0
  30. package/lib/commands/paas/logs.d.ts +17 -0
  31. package/lib/commands/paas/logs.js +54 -0
  32. package/lib/commands/profile/export.js +2 -2
  33. package/lib/commands/profile/import.js +1 -1
  34. package/lib/commands/realtime/subscribe.js +1 -1
  35. package/lib/commands/role/export.js +2 -2
  36. package/lib/commands/role/import.js +1 -1
  37. package/lib/commands/sdk/query.js +1 -1
  38. package/lib/commands/user/export-mappings.js +2 -2
  39. package/lib/commands/user/export.js +4 -4
  40. package/lib/commands/user/import-mappings.js +1 -1
  41. package/lib/commands/user/import.js +1 -1
  42. package/lib/commands/vault/add.js +2 -2
  43. package/lib/commands/vault/decrypt.js +2 -2
  44. package/lib/commands/vault/encrypt.js +2 -2
  45. package/lib/commands/vault/show.js +3 -3
  46. package/lib/commands/vault/test.js +1 -1
  47. package/lib/common.d.ts +6 -1
  48. package/lib/common.js +32 -15
  49. package/lib/hooks/command_not_found/api-action.js +10 -6
  50. package/lib/support/PaasKommand.d.ts +22 -0
  51. package/lib/support/PaasKommand.js +58 -0
  52. package/lib/support/dump-collection.js +4 -4
  53. package/lib/support/editor.js +2 -2
  54. package/lib/support/kuzzle.d.ts +3 -1
  55. package/lib/support/kuzzle.js +14 -10
  56. package/lib/support/restore-collection.js +3 -3
  57. package/lib/support/restore-securities.js +2 -2
  58. package/package.json +10 -11
  59. package/oclif.manifest.json +0 -1
  60. package/scripts/postinstall.sh +0 -10
  61. package/templates.tgz +0 -0
package/README.md CHANGED
@@ -13,7 +13,7 @@ The CLI that helps you manage your Kuzzle instances.
13
13
  * [Commands](#commands)
14
14
  * [Where does this weird name come from?](#where-does-this-weird-name-come-from)
15
15
  * [Have fun with a quine](#have-fun-with-a-quine)
16
- * [Analytics](#analytics)
16
+ * [Telemetry](#telemetry)
17
17
  <!-- tocstop -->
18
18
 
19
19
  :warning: This project is currently in beta and breaking changes may occur until the 1.0.0
@@ -26,7 +26,7 @@ $ npm install -g kourou
26
26
  $ kourou COMMAND
27
27
  running command...
28
28
  $ kourou (-v|--version|version)
29
- kourou/0.20.7 linux-x64 node-v12.22.12
29
+ kourou/0.22.0 linux-x64 node-v16.15.0
30
30
  $ kourou --help [COMMAND]
31
31
  USAGE
32
32
  $ kourou COMMAND
@@ -129,7 +129,7 @@ All other arguments and options will be passed as-is to the `sdk:query` method.
129
129
  * [`kourou api-key:create USER`](#kourou-api-keycreate-user)
130
130
  * [`kourou api-key:delete USER ID`](#kourou-api-keydelete-user-id)
131
131
  * [`kourou api-key:search USER`](#kourou-api-keysearch-user)
132
- * [`kourou app:scaffold NAME`](#kourou-appscaffold-name)
132
+ * [`kourou app:scaffold DESTINATION`](#kourou-appscaffold-destination)
133
133
  * [`kourou app:start-services`](#kourou-appstart-services)
134
134
  * [`kourou autocomplete [SHELL]`](#kourou-autocomplete-shell)
135
135
  * [`kourou collection:create INDEX COLLECTION [BODY]`](#kourou-collectioncreate-index-collection-body)
@@ -155,6 +155,10 @@ All other arguments and options will be passed as-is to the `sdk:query` method.
155
155
  * [`kourou instance:list`](#kourou-instancelist)
156
156
  * [`kourou instance:logs`](#kourou-instancelogs)
157
157
  * [`kourou instance:spawn`](#kourou-instancespawn)
158
+ * [`kourou paas:deploy ENVIRONMENT IMAGE`](#kourou-paasdeploy-environment-image)
159
+ * [`kourou paas:init PROJECT`](#kourou-paasinit-project)
160
+ * [`kourou paas:login`](#kourou-paaslogin)
161
+ * [`kourou paas:logs ENVIRONMENT APPLICATION`](#kourou-paaslogs-environment-application)
158
162
  * [`kourou profile:export`](#kourou-profileexport)
159
163
  * [`kourou profile:import PATH`](#kourou-profileimport-path)
160
164
  * [`kourou realtime:subscribe INDEX COLLECTION [FILTERS]`](#kourou-realtimesubscribe-index-collection-filters)
@@ -284,19 +288,20 @@ OPTIONS
284
288
 
285
289
  _See code: [src/commands/api-key/search.ts](src/commands/api-key/search.ts)_
286
290
 
287
- ## `kourou app:scaffold NAME`
291
+ ## `kourou app:scaffold DESTINATION`
288
292
 
289
293
  Scaffolds a new Kuzzle application
290
294
 
291
295
  ```
292
296
  USAGE
293
- $ kourou app:scaffold NAME
297
+ $ kourou app:scaffold DESTINATION
294
298
 
295
299
  ARGUMENTS
296
- NAME Application name
300
+ DESTINATION Directory to scaffold the app
297
301
 
298
302
  OPTIONS
299
- --help show CLI help
303
+ --flavor=flavor [default: generic] Template flavor ("generic", "iot-platform")
304
+ --help show CLI help
300
305
  ```
301
306
 
302
307
  _See code: [src/commands/app/scaffold.ts](src/commands/app/scaffold.ts)_
@@ -337,7 +342,7 @@ EXAMPLES
337
342
  $ kourou autocomplete --refresh-cache
338
343
  ```
339
344
 
340
- _See code: [@oclif/plugin-autocomplete](https://github.com/oclif/plugin-autocomplete/blob/v0.3.0/src/commands/autocomplete/index.ts)_
345
+ _See code: [@oclif/plugin-autocomplete](https://github.com/oclif/plugin-autocomplete/blob/v1.2.0/src/commands/autocomplete/index.ts)_
341
346
 
342
347
  ## `kourou collection:create INDEX COLLECTION [BODY]`
343
348
 
@@ -598,9 +603,12 @@ USAGE
598
603
  OPTIONS
599
604
  --batch-size=batch-size [default: 1000] How many documents to move in batch per operation
600
605
  --dest=dest (required) Destination Elasticsearch server URL
606
+ --dry-run Print witch collections will be migrated
601
607
  --help show CLI help
602
608
  --no-interactive Skip confirmation interactive prompts (perfect for scripting)
609
+ --pattern=pattern Pattern to match indices to migrate
603
610
  --reset Reset destination Elasticsearch server
611
+ --scroll=scroll [default: 30s] Scroll duration for Elasticsearch scrolling
604
612
  --src=src (required) Source Elasticsearch server URL
605
613
 
606
614
  EXAMPLES
@@ -911,6 +919,78 @@ OPTIONS
911
919
 
912
920
  _See code: [src/commands/instance/spawn.ts](src/commands/instance/spawn.ts)_
913
921
 
922
+ ## `kourou paas:deploy ENVIRONMENT IMAGE`
923
+
924
+ Deploy a new version of the application in the PaaS
925
+
926
+ ```
927
+ USAGE
928
+ $ kourou paas:deploy ENVIRONMENT IMAGE
929
+
930
+ ARGUMENTS
931
+ ENVIRONMENT Project environment name
932
+ IMAGE Image name and hash as myimage:mytag
933
+
934
+ OPTIONS
935
+ --help show CLI help
936
+ --project=project Current PaaS project
937
+ --token=token Authentication token
938
+ ```
939
+
940
+ _See code: [src/commands/paas/deploy.ts](src/commands/paas/deploy.ts)_
941
+
942
+ ## `kourou paas:init PROJECT`
943
+
944
+ Initialize a PaaS project in current directory
945
+
946
+ ```
947
+ USAGE
948
+ $ kourou paas:init PROJECT
949
+
950
+ ARGUMENTS
951
+ PROJECT Kuzzle PaaS project name
952
+
953
+ OPTIONS
954
+ --help show CLI help
955
+ ```
956
+
957
+ _See code: [src/commands/paas/init.ts](src/commands/paas/init.ts)_
958
+
959
+ ## `kourou paas:login`
960
+
961
+ Login for a PaaS project
962
+
963
+ ```
964
+ USAGE
965
+ $ kourou paas:login
966
+
967
+ OPTIONS
968
+ --help show CLI help
969
+ --project=project Current PaaS project
970
+ --username=username PaaS username
971
+ ```
972
+
973
+ _See code: [src/commands/paas/login.ts](src/commands/paas/login.ts)_
974
+
975
+ ## `kourou paas:logs ENVIRONMENT APPLICATION`
976
+
977
+ Show logs of the targeted application
978
+
979
+ ```
980
+ USAGE
981
+ $ kourou paas:logs ENVIRONMENT APPLICATION
982
+
983
+ ARGUMENTS
984
+ ENVIRONMENT Kuzzle PaaS environment
985
+ APPLICATION Kuzzle PaaS application
986
+
987
+ OPTIONS
988
+ --help show CLI help
989
+ --project=project Current PaaS project
990
+ ```
991
+
992
+ _See code: [src/commands/paas/logs.ts](src/commands/paas/logs.ts)_
993
+
914
994
  ## `kourou profile:export`
915
995
 
916
996
  Exports profiles
@@ -1555,8 +1635,10 @@ $ kourou sdk:execute --print-raw '(
1555
1635
 
1556
1636
  (Kuzzle must be accessible and running in local)
1557
1637
 
1558
- # Analytics
1638
+ # Telemetry
1639
+
1640
+ We use a custom Open Source analytics backend (you can check the code [here](https://gihtub.com/kuzzleio/kepler)) to record the use of Kourou by users.
1559
1641
 
1560
- We use a custom Open Source analytics backend (you can check the code [here](https://gihtub.com/kuzzleio/kepler)) to record the use of Kourou by users.
1561
1642
  Collected metrics will allow us to study the use of our products in order to improve them. We do not collect any personal data about users.
1643
+
1562
1644
  You can disable usage metrics collection by setting the `KOUROU_USAGE` environment variable to `false`.
@@ -1,17 +1,17 @@
1
+ import { flags } from '@oclif/command';
1
2
  import { Kommand } from '../../common';
2
3
  export default class AppScaffold extends Kommand {
3
4
  static initSdk: boolean;
4
5
  static description: string;
5
6
  static flags: {
6
7
  help: import("@oclif/parser/lib/flags").IBooleanFlag<void>;
8
+ flavor: flags.IOptionFlag<string>;
7
9
  };
8
10
  static args: {
9
11
  name: string;
10
12
  description: string;
11
13
  required: boolean;
12
14
  }[];
13
- checkKebabCase(name: string): boolean;
14
- convertToKebabCase(name: string): string;
15
15
  runSafe(): Promise<void>;
16
- renderTemplates(directory: string, templatePath: string): Promise<void>;
16
+ cloneTemplate(flavor: string, destination: string): Promise<void>;
17
17
  }
@@ -1,86 +1,29 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  const tslib_1 = require("tslib");
4
- const path_1 = (0, tslib_1.__importDefault)(require("path"));
5
- const fs_1 = (0, tslib_1.__importDefault)(require("fs"));
6
4
  const command_1 = require("@oclif/command");
7
- const lodash_1 = (0, tslib_1.__importDefault)(require("lodash"));
8
- const chalk_1 = (0, tslib_1.__importDefault)(require("chalk"));
9
- const listr_1 = (0, tslib_1.__importDefault)(require("listr"));
10
- const inquirer_1 = (0, tslib_1.__importDefault)(require("inquirer"));
5
+ const chalk_1 = tslib_1.__importDefault(require("chalk"));
6
+ const listr_1 = tslib_1.__importDefault(require("listr"));
11
7
  const common_1 = require("../../common");
12
8
  const execute_1 = require("../../support/execute");
13
- const templatesDir = path_1.default.join(__dirname, '..', '..', '..', 'templates');
14
- const TEMPLATED_ENTRIES = [
15
- 'package.json',
16
- 'app.ts',
17
- 'README.md'
18
- ];
19
- const KEBAB_CASE_REGEX = /^[a-z-\d]+$/;
20
9
  class AppScaffold extends common_1.Kommand {
21
- checkKebabCase(name) {
22
- return KEBAB_CASE_REGEX.test(name);
23
- }
24
- convertToKebabCase(name) {
25
- return name.replace(/([a-z])([A-Z])/g, '$1-$2').toLowerCase();
26
- }
27
10
  async runSafe() {
28
- if (!this.checkKebabCase(this.args.name)) {
29
- this.logKo(`The application name must be in kebab-case`);
30
- const kebabCasedName = this.convertToKebabCase(this.args.name);
31
- const response = await inquirer_1.default.prompt([
32
- {
33
- name: 'kebabCaseConversion',
34
- type: 'confirm',
35
- message: `Would you like to convert "${this.args.name}" to "${kebabCasedName}"`
36
- }
37
- ]);
38
- if (!response.kebabCaseConversion) {
39
- process.exit(0);
40
- }
41
- this.args.name = kebabCasedName;
42
- }
43
- const templatePath = path_1.default.join(templatesDir, 'app-scaffold', 'ts');
11
+ const destination = this.args.destination;
12
+ const flavor = this.flags.flavor;
44
13
  const tasks = new listr_1.default([
45
- {
46
- title: `Creating directory: ${chalk_1.default.gray(this.args.name + path_1.default.sep)}`,
47
- task: () => (0, execute_1.execute)('mkdir', this.args.name)
48
- },
49
14
  {
50
15
  title: 'Creating and rendering application files',
51
- task: () => this.renderTemplates(templatePath, templatePath)
52
- },
53
- {
54
- title: 'Installing dependencies (this can take some time)',
55
- task: () => (0, execute_1.execute)('npm', 'run', 'install:docker', { cwd: this.args.name })
16
+ task: async () => this.cloneTemplate(flavor, destination)
56
17
  },
57
18
  ]);
58
19
  await tasks.run();
59
- this.logOk(`Scaffolding complete! Use "${chalk_1.default.grey('cd ' + this.args.name + ' && npm run dev:docker')}" to run your application`);
20
+ this.log('');
21
+ this.logOk(`Scaffolding complete! Use ${chalk_1.default.grey(`cd ${destination} && npm run docker npm install`)} install dependencies and then ${chalk_1.default.grey(`npm run docker:dev`)} to run your application!`);
60
22
  }
61
- async renderTemplates(directory, templatePath) {
62
- const entries = fs_1.default.readdirSync(directory);
63
- for (const entry of entries) {
64
- const entryPath = path_1.default.join(directory, entry);
65
- const entryDir = path_1.default.dirname(path_1.default.join(this.args.name, entryPath));
66
- const entryInfo = fs_1.default.statSync(entryPath);
67
- if (entryInfo.isDirectory()) {
68
- fs_1.default.mkdirSync(entryDir.replace(templatePath, ''), { recursive: true });
69
- await this.renderTemplates(entryPath, templatePath);
70
- }
71
- else if (entryInfo.isFile() || entryInfo.isSymbolicLink()) {
72
- const content = fs_1.default.readFileSync(entryPath, 'utf8');
73
- // Only render a whitelist a files who need it
74
- const rendered = TEMPLATED_ENTRIES.includes(entry)
75
- ? lodash_1.default.template(content)({ appName: this.args.name })
76
- : content;
77
- fs_1.default.mkdirSync(entryDir.replace(templatePath, ''), { recursive: true });
78
- fs_1.default.writeFileSync(path_1.default.join(this.args.name, entryPath.replace(templatePath, '')), rendered);
79
- }
80
- else {
81
- this.logInfo(`Skipped ${entryPath} because it's not a regular file`);
82
- }
83
- }
23
+ async cloneTemplate(flavor, destination) {
24
+ await (0, execute_1.execute)('git', 'clone', '--depth=1', 'https://github.com/kuzzleio/project-templates', '--branch', flavor, '--single-branch');
25
+ await (0, execute_1.execute)('mv', `project-templates/${flavor}`, `${destination}/`);
26
+ await (0, execute_1.execute)('rm', '-rf', 'project-templates/');
84
27
  }
85
28
  }
86
29
  exports.default = AppScaffold;
@@ -88,7 +31,11 @@ AppScaffold.initSdk = false;
88
31
  AppScaffold.description = 'Scaffolds a new Kuzzle application';
89
32
  AppScaffold.flags = {
90
33
  help: command_1.flags.help(),
34
+ flavor: command_1.flags.string({
35
+ default: 'generic',
36
+ description: 'Template flavor ("generic", "iot-platform")'
37
+ })
91
38
  };
92
39
  AppScaffold.args = [
93
- { name: 'name', description: 'Application name', required: true },
40
+ { name: 'destination', description: 'Directory to scaffold the app', required: true },
94
41
  ];
@@ -2,10 +2,11 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  const tslib_1 = require("tslib");
4
4
  const fs_1 = require("fs");
5
+ const path_1 = tslib_1.__importDefault(require("path"));
5
6
  const command_1 = require("@oclif/command");
6
- const chalk_1 = (0, tslib_1.__importDefault)(require("chalk"));
7
- const listr_1 = (0, tslib_1.__importDefault)(require("listr"));
8
- const node_emoji_1 = (0, tslib_1.__importDefault)(require("node-emoji"));
7
+ const chalk_1 = tslib_1.__importDefault(require("chalk"));
8
+ const listr_1 = tslib_1.__importDefault(require("listr"));
9
+ const node_emoji_1 = tslib_1.__importDefault(require("node-emoji"));
9
10
  const common_1 = require("../../common");
10
11
  const execute_1 = require("../../support/execute");
11
12
  const MIN_DOCO_VERSION = '1.12.0';
@@ -27,7 +28,8 @@ services:
27
28
  `;
28
29
  class AppStartServices extends common_1.Kommand {
29
30
  async runSafe() {
30
- const docoFilename = '/tmp/kuzzle-services.yml';
31
+ this.createKourouDir();
32
+ const docoFilename = path_1.default.join(this.kourouDir, 'kuzzle-services.yml');
31
33
  const successfullCheck = this.flags.check ?
32
34
  await this.checkPrerequisites() :
33
35
  true;
@@ -1,6 +1,7 @@
1
1
  import { flags } from '@oclif/command';
2
2
  import { Kommand } from '../../common';
3
3
  export default class CollectionExport extends Kommand {
4
+ static keepAuth: boolean;
4
5
  static description: string;
5
6
  static flags: {
6
7
  protocol: flags.IOptionFlag<string>;
@@ -2,8 +2,8 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  const tslib_1 = require("tslib");
4
4
  const command_1 = require("@oclif/command");
5
- const fs_1 = (0, tslib_1.__importDefault)(require("fs"));
6
- const path_1 = (0, tslib_1.__importDefault)(require("path"));
5
+ const fs_1 = tslib_1.__importDefault(require("fs"));
6
+ const path_1 = tslib_1.__importDefault(require("path"));
7
7
  const common_1 = require("../../common");
8
8
  const kuzzle_1 = require("../../support/kuzzle");
9
9
  const dump_collection_1 = require("../../support/dump-collection");
@@ -32,6 +32,7 @@ class CollectionExport extends common_1.Kommand {
32
32
  }
33
33
  }
34
34
  exports.default = CollectionExport;
35
+ CollectionExport.keepAuth = true;
35
36
  CollectionExport.description = 'Exports a collection (JSONL format)';
36
37
  CollectionExport.flags = Object.assign(Object.assign({ help: command_1.flags.help({}), path: command_1.flags.string({
37
38
  description: 'Dump root directory',
@@ -1,6 +1,7 @@
1
1
  import { flags } from '@oclif/command';
2
2
  import { Kommand } from '../../common';
3
3
  export default class CollectionImport extends Kommand {
4
+ static keepAuth: boolean;
4
5
  static description: string;
5
6
  static flags: {
6
7
  protocol: flags.IOptionFlag<string>;
@@ -1,8 +1,8 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  const tslib_1 = require("tslib");
4
- const path_1 = (0, tslib_1.__importDefault)(require("path"));
5
- const fs_1 = (0, tslib_1.__importDefault)(require("fs"));
4
+ const path_1 = tslib_1.__importDefault(require("path"));
5
+ const fs_1 = tslib_1.__importDefault(require("fs"));
6
6
  const command_1 = require("@oclif/command");
7
7
  const common_1 = require("../../common");
8
8
  const kuzzle_1 = require("../../support/kuzzle");
@@ -20,6 +20,7 @@ class CollectionImport extends common_1.Kommand {
20
20
  }
21
21
  }
22
22
  exports.default = CollectionImport;
23
+ CollectionImport.keepAuth = true;
23
24
  CollectionImport.description = 'Imports a collection';
24
25
  CollectionImport.flags = Object.assign(Object.assign({ help: command_1.flags.help({}), 'batch-size': command_1.flags.string({
25
26
  description: 'Maximum batch size (see limits.documentsWriteCount config)',
@@ -3,9 +3,9 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.ConfigKeyDiff = void 0;
4
4
  const tslib_1 = require("tslib");
5
5
  const command_1 = require("@oclif/command");
6
- const lodash_1 = (0, tslib_1.__importDefault)(require("lodash"));
7
- const fs_1 = (0, tslib_1.__importDefault)(require("fs"));
8
- const strip_json_comments_1 = (0, tslib_1.__importDefault)(require("strip-json-comments"));
6
+ const lodash_1 = tslib_1.__importDefault(require("lodash"));
7
+ const fs_1 = tslib_1.__importDefault(require("fs"));
8
+ const strip_json_comments_1 = tslib_1.__importDefault(require("strip-json-comments"));
9
9
  const common_1 = require("../../common");
10
10
  class ConfigKeyDiff extends common_1.Kommand {
11
11
  async runSafe() {
@@ -1,4 +1,5 @@
1
1
  import { flags } from '@oclif/command';
2
+ import { Client } from '@elastic/elasticsearch';
2
3
  import { Kommand } from '../../common';
3
4
  export default class EsMigrate extends Kommand {
4
5
  static initSdk: boolean;
@@ -10,11 +11,13 @@ export default class EsMigrate extends Kommand {
10
11
  reset: import("@oclif/parser/lib/flags").IBooleanFlag<boolean>;
11
12
  'batch-size': import("@oclif/parser/lib/flags").IOptionFlag<number>;
12
13
  'no-interactive': import("@oclif/parser/lib/flags").IBooleanFlag<boolean>;
14
+ 'dry-run': import("@oclif/parser/lib/flags").IBooleanFlag<boolean>;
15
+ pattern: flags.IOptionFlag<string | undefined>;
16
+ scroll: flags.IOptionFlag<string>;
13
17
  };
14
18
  static examples: string[];
15
- private src;
16
- private dest;
17
19
  private migrateMappings;
18
20
  private migrateData;
21
+ runMigrate(index: string, src: Client, dest: Client): Promise<void>;
19
22
  runSafe(): Promise<void>;
20
23
  }
@@ -3,21 +3,21 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  const tslib_1 = require("tslib");
4
4
  const command_1 = require("@oclif/command");
5
5
  const elasticsearch_1 = require("@elastic/elasticsearch");
6
- const cli_ux_1 = (0, tslib_1.__importDefault)(require("cli-ux"));
7
- const chalk_1 = (0, tslib_1.__importDefault)(require("chalk"));
8
- const node_emoji_1 = (0, tslib_1.__importDefault)(require("node-emoji"));
6
+ const cli_ux_1 = tslib_1.__importDefault(require("cli-ux"));
7
+ const chalk_1 = tslib_1.__importDefault(require("chalk"));
8
+ const node_emoji_1 = tslib_1.__importDefault(require("node-emoji"));
9
9
  const common_1 = require("../../common");
10
10
  class EsMigrate extends common_1.Kommand {
11
- async migrateMappings(index) {
12
- const { body } = await this.src.indices.getMapping({ index, format: 'json' });
11
+ async migrateMappings(index, src, dest) {
12
+ const { body } = await src.indices.getMapping({ index });
13
13
  const mappings = body[index];
14
- await this.dest.indices.create({ index, body: mappings });
14
+ await dest.indices.create({ index, body: { mappings: mappings.mappings } });
15
15
  }
16
- async migrateData(index, batch_size) {
16
+ async migrateData(index, batch_size, src, dest) {
17
17
  const queue = [];
18
- const { body } = await this.src.search({
18
+ const { body } = await src.search({
19
19
  index,
20
- scroll: '20s',
20
+ scroll: this.flags.scroll,
21
21
  size: batch_size,
22
22
  body: {
23
23
  query: {
@@ -42,42 +42,52 @@ class EsMigrate extends common_1.Kommand {
42
42
  bulk.push(doc._source);
43
43
  count++;
44
44
  }
45
- await this.dest.bulk({ body: bulk });
45
+ await dest.bulk({ body: bulk });
46
46
  progressBar.update(count);
47
- const { body: { hits } } = await this.src.scroll({
48
- scrollId,
49
- scroll: '20s'
47
+ const { body: { hits } } = await src.scroll({
48
+ scroll_id: scrollId,
49
+ scroll: this.flags.scroll
50
50
  });
51
51
  queue.push(hits);
52
52
  }
53
53
  progressBar.stop();
54
54
  return total;
55
55
  }
56
+ async runMigrate(index, src, dest) {
57
+ this.logInfo(`Importing ${chalk_1.default.bold(index)} to ${chalk_1.default.bold(this.flags.dest)}`);
58
+ await this.migrateMappings(index, src, dest);
59
+ this.logOk('Mappings successfully imported!');
60
+ const count = await this.migrateData(index, this.flags['batch-size'], src, dest);
61
+ if (count === 0) {
62
+ this.logInfo('No documents to import\n');
63
+ }
64
+ else {
65
+ this.logOk(`${chalk_1.default.bold(count)} document(s) imported!\n`);
66
+ }
67
+ }
56
68
  async runSafe() {
57
- this.src = new elasticsearch_1.Client({ node: this.flags.src });
58
- this.dest = new elasticsearch_1.Client({ node: this.flags.dest });
69
+ const src = new elasticsearch_1.Client({ node: this.flags.src });
70
+ const dest = new elasticsearch_1.Client({ node: this.flags.dest });
59
71
  if (this.flags.reset && !this.flags['no-interactive']) {
60
72
  this.log(chalk_1.default.red(`${node_emoji_1.default.get('fire')} Are you sure you want to reset ${chalk_1.default.bold(this.flags.dest)}?`));
61
73
  await cli_ux_1.default.confirm(chalk_1.default.redBright(` ${node_emoji_1.default.get('fire')} You will lose all the data stored in it (Type "yes" to confirm)`));
62
- await this.dest.indices.delete({ index: '_all' });
74
+ await dest.indices.delete({ index: '_all' });
63
75
  }
64
76
  this.logInfo(`Fetching indices list from ${chalk_1.default.bold(this.flags.src)}`);
65
- const { body } = await this.src.cat.indices({ format: 'json' });
66
- const indices = body
77
+ const srcBody = await src.cat.indices({ format: 'json' });
78
+ const srcIndices = srcBody.body
67
79
  .map(({ index }) => index)
80
+ .filter((index) => index.match(this.flags.pattern))
68
81
  .sort();
69
- this.logOk(`Found ${chalk_1.default.bold(indices.length)} indices in the source Elasticsearch server\n`);
70
- this.logInfo(`Starting indices migration from ${chalk_1.default.bold(this.flags.src)} to ${chalk_1.default.bold(this.flags.dest)}`);
71
- for (const index of indices) {
72
- this.logInfo(`Importing ${chalk_1.default.bold(index)} to ${chalk_1.default.bold(this.flags.dest)}`);
73
- await this.migrateMappings(index);
74
- this.logOk('Mappings successfully imported!');
75
- const count = await this.migrateData(index, this.flags['batch-size']);
76
- if (count === 0) {
77
- this.logInfo('No documents to import\n');
78
- }
79
- else {
80
- this.logOk(`${chalk_1.default.bold(count)} document(s) imported!\n`);
82
+ this.logOk(`Found ${chalk_1.default.bold(srcIndices.length)} indices in the source Elasticsearch server\n`);
83
+ if (this.flags['dry-run']) {
84
+ this.log(`${chalk_1.default.bold(srcIndices)}`);
85
+ this.logInfo(`${chalk_1.default.bold(srcIndices.length)} indices will be migrated`);
86
+ }
87
+ else {
88
+ this.logInfo(`Starting indices migration from ${chalk_1.default.bold(this.flags.src)} to ${chalk_1.default.bold(this.flags.dest)}`);
89
+ for (const index of srcIndices) {
90
+ await this.runMigrate(index, src, dest);
81
91
  }
82
92
  }
83
93
  }
@@ -109,6 +119,17 @@ EsMigrate.flags = {
109
119
  description: 'Skip confirmation interactive prompts (perfect for scripting)',
110
120
  default: false,
111
121
  }),
122
+ 'dry-run': command_1.flags.boolean({
123
+ description: 'Print witch collections will be migrated',
124
+ default: false,
125
+ }),
126
+ 'pattern': command_1.flags.string({
127
+ description: 'Pattern to match indices to migrate'
128
+ }),
129
+ 'scroll': command_1.flags.string({
130
+ description: 'Scroll duration for Elasticsearch scrolling',
131
+ default: '30s'
132
+ }),
112
133
  };
113
134
  EsMigrate.examples = [
114
135
  'kourou es:migrate --src http://elasticsearch:9200 --dest http://otherElasticsearch:9200 --reset --batch-size 2000',
@@ -2,8 +2,8 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.FileDecrypt = void 0;
4
4
  const tslib_1 = require("tslib");
5
- const fs_1 = (0, tslib_1.__importDefault)(require("fs"));
6
- const lodash_1 = (0, tslib_1.__importDefault)(require("lodash"));
5
+ const fs_1 = tslib_1.__importDefault(require("fs"));
6
+ const lodash_1 = tslib_1.__importDefault(require("lodash"));
7
7
  const command_1 = require("@oclif/command");
8
8
  const kuzzle_vault_1 = require("kuzzle-vault");
9
9
  const common_1 = require("../../common");
@@ -2,8 +2,8 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.VaultEncrypt = void 0;
4
4
  const tslib_1 = require("tslib");
5
- const fs_1 = (0, tslib_1.__importDefault)(require("fs"));
6
- const lodash_1 = (0, tslib_1.__importDefault)(require("lodash"));
5
+ const fs_1 = tslib_1.__importDefault(require("fs"));
6
+ const lodash_1 = tslib_1.__importDefault(require("lodash"));
7
7
  const command_1 = require("@oclif/command");
8
8
  const kuzzle_vault_1 = require("kuzzle-vault");
9
9
  const common_1 = require("../../common");
@@ -2,8 +2,8 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.FileTest = void 0;
4
4
  const tslib_1 = require("tslib");
5
- const fs_1 = (0, tslib_1.__importDefault)(require("fs"));
6
- const lodash_1 = (0, tslib_1.__importDefault)(require("lodash"));
5
+ const fs_1 = tslib_1.__importDefault(require("fs"));
6
+ const lodash_1 = tslib_1.__importDefault(require("lodash"));
7
7
  const command_1 = require("@oclif/command");
8
8
  const kuzzle_vault_1 = require("kuzzle-vault");
9
9
  const common_1 = require("../../common");
@@ -1,6 +1,7 @@
1
1
  import { flags } from '@oclif/command';
2
2
  import { Kommand } from '../common';
3
3
  export default class Import extends Kommand {
4
+ static keepAuth: boolean;
4
5
  static description: string;
5
6
  static flags: {
6
7
  protocol: flags.IOptionFlag<string>;
@@ -2,8 +2,8 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  const tslib_1 = require("tslib");
4
4
  const command_1 = require("@oclif/command");
5
- const fs_1 = (0, tslib_1.__importDefault)(require("fs"));
6
- const path_1 = (0, tslib_1.__importDefault)(require("path"));
5
+ const fs_1 = tslib_1.__importDefault(require("fs"));
6
+ const path_1 = tslib_1.__importDefault(require("path"));
7
7
  const common_1 = require("../common");
8
8
  const kuzzle_1 = require("../support/kuzzle");
9
9
  const restore_collection_1 = require("../support/restore-collection");
@@ -116,6 +116,7 @@ class Import extends common_1.Kommand {
116
116
  }
117
117
  }
118
118
  exports.default = Import;
119
+ Import.keepAuth = true;
119
120
  Import.description = 'Recursively imports dump files from a root directory';
120
121
  Import.flags = Object.assign(Object.assign({ 'preserve-anonymous': command_1.flags.boolean({
121
122
  description: 'Preserve anonymous rights',
@@ -1,6 +1,7 @@
1
1
  import { flags } from '@oclif/command';
2
2
  import { Kommand } from '../../common';
3
3
  export default class IndexExport extends Kommand {
4
+ static keepAuth: boolean;
4
5
  static description: string;
5
6
  static flags: {
6
7
  protocol: flags.IOptionFlag<string>;
@@ -2,9 +2,9 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  const tslib_1 = require("tslib");
4
4
  const command_1 = require("@oclif/command");
5
- const fs_1 = (0, tslib_1.__importDefault)(require("fs"));
6
- const cli_ux_1 = (0, tslib_1.__importDefault)(require("cli-ux"));
7
- const path_1 = (0, tslib_1.__importDefault)(require("path"));
5
+ const fs_1 = tslib_1.__importDefault(require("fs"));
6
+ const cli_ux_1 = tslib_1.__importDefault(require("cli-ux"));
7
+ const path_1 = tslib_1.__importDefault(require("path"));
8
8
  const common_1 = require("../../common");
9
9
  const kuzzle_1 = require("../../support/kuzzle");
10
10
  const dump_collection_1 = require("../../support/dump-collection");
@@ -33,6 +33,7 @@ class IndexExport extends common_1.Kommand {
33
33
  }
34
34
  }
35
35
  exports.default = IndexExport;
36
+ IndexExport.keepAuth = true;
36
37
  IndexExport.description = 'Exports an index (JSONL or Kuzzle format)';
37
38
  IndexExport.flags = Object.assign(Object.assign({ help: command_1.flags.help({}), path: command_1.flags.string({
38
39
  description: 'Dump root directory',
@@ -1,6 +1,7 @@
1
1
  import { flags } from '@oclif/command';
2
2
  import { Kommand } from '../../common';
3
3
  export default class IndexImport extends Kommand {
4
+ static keepAuth: boolean;
4
5
  static description: string;
5
6
  static examples: string[];
6
7
  static flags: {