kourou 0.25.1 → 0.26.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.
- package/README.md +123 -70
- package/lib/commands/app/debug-proxy.js +2 -0
- package/lib/commands/collection/export.d.ts +1 -0
- package/lib/commands/collection/export.js +12 -3
- package/lib/commands/index/export.d.ts +1 -0
- package/lib/commands/index/export.js +12 -2
- package/lib/commands/paas/deploy.d.ts +0 -1
- package/lib/commands/paas/deploy.js +0 -22
- package/lib/commands/paas/login.js +3 -2
- package/lib/commands/paas/logs.d.ts +0 -2
- package/lib/commands/paas/logs.js +19 -37
- package/lib/commands/paas/snapshots/cat.d.ts +17 -0
- package/lib/commands/paas/snapshots/cat.js +45 -0
- package/lib/commands/paas/snapshots/dump.d.ts +17 -0
- package/lib/commands/paas/snapshots/dump.js +45 -0
- package/lib/commands/paas/snapshots/restore.d.ts +17 -0
- package/lib/commands/paas/snapshots/restore.js +53 -0
- package/lib/support/PaasKommand.d.ts +1 -0
- package/lib/support/PaasKommand.js +10 -0
- package/lib/support/dump-collection.js +1 -0
- package/lib/support/kuzzle.js +1 -1
- package/lib/support/migrate/providers/elasticsearch.js +1 -0
- package/lib/support/restore-collection.js +6 -7
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
The CLI that helps you manage your Kuzzle instances.
|
|
4
4
|
|
|
5
|
+
|
|
5
6
|
[](https://oclif.io)
|
|
6
7
|
[](https://npmjs.org/package/kourou)
|
|
7
8
|
[](https://npmjs.org/package/kourou)
|
|
@@ -26,7 +27,7 @@ $ npm install -g kourou
|
|
|
26
27
|
$ kourou COMMAND
|
|
27
28
|
running command...
|
|
28
29
|
$ kourou (-v|--version|version)
|
|
29
|
-
kourou/0.
|
|
30
|
+
kourou/0.26.0 linux-x64 node-v14.21.2
|
|
30
31
|
$ kourou --help [COMMAND]
|
|
31
32
|
USAGE
|
|
32
33
|
$ kourou COMMAND
|
|
@@ -125,61 +126,72 @@ All other arguments and options will be passed as-is to the `sdk:query` method.
|
|
|
125
126
|
# Commands
|
|
126
127
|
|
|
127
128
|
<!-- commands -->
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
129
|
+
- [kourou](#kourou)
|
|
130
|
+
- [Usage](#usage)
|
|
131
|
+
- [Connect and authenticate to Kuzzle API](#connect-and-authenticate-to-kuzzle-api)
|
|
132
|
+
- [User impersonation](#user-impersonation)
|
|
133
|
+
- [Automatic command infering for API actions](#automatic-command-infering-for-api-actions)
|
|
134
|
+
- [Commands](#commands)
|
|
135
|
+
- [`kourou api-key:check TOKEN`](#kourou-api-keycheck-token)
|
|
136
|
+
- [`kourou api-key:create USER`](#kourou-api-keycreate-user)
|
|
137
|
+
- [`kourou api-key:delete USER ID`](#kourou-api-keydelete-user-id)
|
|
138
|
+
- [`kourou api-key:search USER`](#kourou-api-keysearch-user)
|
|
139
|
+
- [`kourou app:debug-proxy`](#kourou-appdebug-proxy)
|
|
140
|
+
- [`kourou app:doctor`](#kourou-appdoctor)
|
|
141
|
+
- [`kourou app:scaffold DESTINATION`](#kourou-appscaffold-destination)
|
|
142
|
+
- [`kourou app:start-services`](#kourou-appstart-services)
|
|
143
|
+
- [`kourou autocomplete [SHELL]`](#kourou-autocomplete-shell)
|
|
144
|
+
- [`kourou collection:create INDEX COLLECTION [BODY]`](#kourou-collectioncreate-index-collection-body)
|
|
145
|
+
- [`kourou collection:export INDEX COLLECTION`](#kourou-collectionexport-index-collection)
|
|
146
|
+
- [`kourou collection:import PATH`](#kourou-collectionimport-path)
|
|
147
|
+
- [`kourou collection:migrate SCRIPT PATH`](#kourou-collectionmigrate-script-path)
|
|
148
|
+
- [`kourou config:diff FIRST SECOND`](#kourou-configdiff-first-second)
|
|
149
|
+
- [`kourou document:search INDEX COLLECTION [QUERY]`](#kourou-documentsearch-index-collection-query)
|
|
150
|
+
- [`kourou es:aliases:cat`](#kourou-esaliasescat)
|
|
151
|
+
- [`kourou es:indices:cat`](#kourou-esindicescat)
|
|
152
|
+
- [`kourou es:indices:get INDEX ID`](#kourou-esindicesget-index-id)
|
|
153
|
+
- [`kourou es:indices:insert INDEX`](#kourou-esindicesinsert-index)
|
|
154
|
+
- [`kourou es:migrate`](#kourou-esmigrate)
|
|
155
|
+
- [`kourou es:snapshot:create REPOSITORY NAME`](#kourou-essnapshotcreate-repository-name)
|
|
156
|
+
- [`kourou es:snapshot:create-repository REPOSITORY LOCATION`](#kourou-essnapshotcreate-repository-repository-location)
|
|
157
|
+
- [`kourou es:snapshot:list REPOSITORY`](#kourou-essnapshotlist-repository)
|
|
158
|
+
- [`kourou file:decrypt FILE`](#kourou-filedecrypt-file)
|
|
159
|
+
- [`kourou file:encrypt FILE`](#kourou-fileencrypt-file)
|
|
160
|
+
- [`kourou file:test FILE`](#kourou-filetest-file)
|
|
161
|
+
- [`kourou help [COMMAND]`](#kourou-help-command)
|
|
162
|
+
- [`kourou import PATH`](#kourou-import-path)
|
|
163
|
+
- [`kourou index:export INDEX`](#kourou-indexexport-index)
|
|
164
|
+
- [`kourou index:import PATH`](#kourou-indeximport-path)
|
|
165
|
+
- [`kourou instance:kill`](#kourou-instancekill)
|
|
166
|
+
- [`kourou instance:list`](#kourou-instancelist)
|
|
167
|
+
- [`kourou instance:logs`](#kourou-instancelogs)
|
|
168
|
+
- [`kourou instance:spawn`](#kourou-instancespawn)
|
|
169
|
+
- [`kourou paas:deploy ENVIRONMENT APPLICATIONID IMAGE`](#kourou-paasdeploy-environment-applicationid-image)
|
|
170
|
+
- [`kourou paas:init PROJECT`](#kourou-paasinit-project)
|
|
171
|
+
- [`kourou paas:login`](#kourou-paaslogin)
|
|
172
|
+
- [`kourou paas:snapshots:cat ENVIRONMENT APPLICATIONID`](#kourou-paassnapshotscat-environment-applicationid)
|
|
173
|
+
- [`kourou paas:snapshots:dump ENVIRONMENT APPLICATIONID`](#kourou-paassnapshotsdump-environment-applicationid)
|
|
174
|
+
- [`kourou paas:snapshots:restore ENVIRONMENT APPLICATIONID SNAPSHOTID`](#kourou-paassnapshotsrestore-environment-applicationid-snapshotid)
|
|
175
|
+
- [`kourou profile:export`](#kourou-profileexport)
|
|
176
|
+
- [`kourou profile:import PATH`](#kourou-profileimport-path)
|
|
177
|
+
- [`kourou realtime:subscribe INDEX COLLECTION [FILTERS]`](#kourou-realtimesubscribe-index-collection-filters)
|
|
178
|
+
- [`kourou redis:list-keys [MATCH]`](#kourou-redislist-keys-match)
|
|
179
|
+
- [`kourou role:export`](#kourou-roleexport)
|
|
180
|
+
- [`kourou role:import PATH`](#kourou-roleimport-path)
|
|
181
|
+
- [`kourou sdk:execute [CODE]`](#kourou-sdkexecute-code)
|
|
182
|
+
- [`kourou sdk:query CONTROLLER:ACTION`](#kourou-sdkquery-controlleraction)
|
|
183
|
+
- [`kourou user:export`](#kourou-userexport)
|
|
184
|
+
- [`kourou user:export-mappings`](#kourou-userexport-mappings)
|
|
185
|
+
- [`kourou user:import PATH`](#kourou-userimport-path)
|
|
186
|
+
- [`kourou user:import-mappings PATH`](#kourou-userimport-mappings-path)
|
|
187
|
+
- [`kourou vault:add SECRETS-FILE KEY VALUE`](#kourou-vaultadd-secrets-file-key-value)
|
|
188
|
+
- [`kourou vault:decrypt FILE`](#kourou-vaultdecrypt-file)
|
|
189
|
+
- [`kourou vault:encrypt FILE`](#kourou-vaultencrypt-file)
|
|
190
|
+
- [`kourou vault:show SECRETS-FILE [KEY]`](#kourou-vaultshow-secrets-file-key)
|
|
191
|
+
- [`kourou vault:test SECRETS-FILE`](#kourou-vaulttest-secrets-file)
|
|
192
|
+
- [Where does this weird name come from?](#where-does-this-weird-name-come-from)
|
|
193
|
+
- [Have fun with a quine](#have-fun-with-a-quine)
|
|
194
|
+
- [Telemetry](#telemetry)
|
|
183
195
|
|
|
184
196
|
## `kourou api-key:check TOKEN`
|
|
185
197
|
|
|
@@ -409,7 +421,7 @@ EXAMPLES
|
|
|
409
421
|
$ kourou autocomplete --refresh-cache
|
|
410
422
|
```
|
|
411
423
|
|
|
412
|
-
_See code: [@oclif/plugin-autocomplete](https://github.com/oclif/plugin-autocomplete/blob/v1.3.
|
|
424
|
+
_See code: [@oclif/plugin-autocomplete](https://github.com/oclif/plugin-autocomplete/blob/v1.3.0/src/commands/autocomplete/index.ts)_
|
|
413
425
|
|
|
414
426
|
## `kourou collection:create INDEX COLLECTION [BODY]`
|
|
415
427
|
|
|
@@ -506,6 +518,9 @@ OPTIONS
|
|
|
506
518
|
--ssl
|
|
507
519
|
Use SSL to connect to Kuzzle
|
|
508
520
|
|
|
521
|
+
--type=type
|
|
522
|
+
[default: all] Type of the export: all, mappings, data
|
|
523
|
+
|
|
509
524
|
--username=username
|
|
510
525
|
[default: anonymous] Kuzzle username (local strategy)
|
|
511
526
|
|
|
@@ -870,7 +885,7 @@ OPTIONS
|
|
|
870
885
|
--all see all commands in CLI
|
|
871
886
|
```
|
|
872
887
|
|
|
873
|
-
_See code: [@oclif/plugin-help](https://github.com/oclif/plugin-help/blob/v3.2.
|
|
888
|
+
_See code: [@oclif/plugin-help](https://github.com/oclif/plugin-help/blob/v3.2.2/src/commands/help.ts)_
|
|
874
889
|
|
|
875
890
|
## `kourou import PATH`
|
|
876
891
|
|
|
@@ -938,6 +953,8 @@ OPTIONS
|
|
|
938
953
|
|
|
939
954
|
--ssl Use SSL to connect to Kuzzle
|
|
940
955
|
|
|
956
|
+
--type=type [default: all] Type of the export: all, mappings, data
|
|
957
|
+
|
|
941
958
|
--username=username [default: anonymous] Kuzzle username (local strategy)
|
|
942
959
|
|
|
943
960
|
EXAMPLES
|
|
@@ -1091,30 +1108,66 @@ OPTIONS
|
|
|
1091
1108
|
|
|
1092
1109
|
_See code: [src/commands/paas/login.ts](src/commands/paas/login.ts)_
|
|
1093
1110
|
|
|
1094
|
-
## `kourou paas:
|
|
1111
|
+
## `kourou paas:snapshots:cat ENVIRONMENT APPLICATIONID`
|
|
1112
|
+
|
|
1113
|
+
List all snapshots for a given kuzzle application in a environment
|
|
1114
|
+
|
|
1115
|
+
```
|
|
1116
|
+
USAGE
|
|
1117
|
+
$ kourou paas:snapshots:cat ENVIRONMENT APPLICATIONID
|
|
1118
|
+
|
|
1119
|
+
ARGUMENTS
|
|
1120
|
+
ENVIRONMENT Project environment name
|
|
1121
|
+
APPLICATIONID Application Identifier
|
|
1122
|
+
|
|
1123
|
+
OPTIONS
|
|
1124
|
+
--help show CLI help
|
|
1125
|
+
--project=project Current PaaS project
|
|
1126
|
+
--token=token Authentication token
|
|
1127
|
+
```
|
|
1128
|
+
|
|
1129
|
+
_See code: [src/commands/paas/snapshots/cat.ts](src/commands/paas/snapshots/cat.ts)_
|
|
1130
|
+
|
|
1131
|
+
## `kourou paas:snapshots:dump ENVIRONMENT APPLICATIONID`
|
|
1095
1132
|
|
|
1096
|
-
|
|
1133
|
+
List all snapshots for a given kuzzle application in a environment
|
|
1097
1134
|
|
|
1098
1135
|
```
|
|
1099
1136
|
USAGE
|
|
1100
|
-
$ kourou paas:
|
|
1137
|
+
$ kourou paas:snapshots:dump ENVIRONMENT APPLICATIONID
|
|
1101
1138
|
|
|
1102
1139
|
ARGUMENTS
|
|
1103
|
-
ENVIRONMENT
|
|
1104
|
-
|
|
1140
|
+
ENVIRONMENT Project environment name
|
|
1141
|
+
APPLICATIONID Application Identifier
|
|
1105
1142
|
|
|
1106
1143
|
OPTIONS
|
|
1107
|
-
-f, --follow Follow log output
|
|
1108
|
-
-n, --tail=tail Number of lines to show from the end of the logs
|
|
1109
|
-
-t, --timestamp Show timestamp
|
|
1110
1144
|
--help show CLI help
|
|
1111
|
-
--podName=podName Name of the pod to show logs from
|
|
1112
1145
|
--project=project Current PaaS project
|
|
1113
|
-
--
|
|
1114
|
-
|
|
1146
|
+
--token=token Authentication token
|
|
1147
|
+
```
|
|
1148
|
+
|
|
1149
|
+
_See code: [src/commands/paas/snapshots/dump.ts](src/commands/paas/snapshots/dump.ts)_
|
|
1150
|
+
|
|
1151
|
+
## `kourou paas:snapshots:restore ENVIRONMENT APPLICATIONID SNAPSHOTID`
|
|
1152
|
+
|
|
1153
|
+
List all snapshots for a given kuzzle application in a environment
|
|
1154
|
+
|
|
1155
|
+
```
|
|
1156
|
+
USAGE
|
|
1157
|
+
$ kourou paas:snapshots:restore ENVIRONMENT APPLICATIONID SNAPSHOTID
|
|
1158
|
+
|
|
1159
|
+
ARGUMENTS
|
|
1160
|
+
ENVIRONMENT Project environment name
|
|
1161
|
+
APPLICATIONID Application Identifier
|
|
1162
|
+
SNAPSHOTID Snapshot Identifier
|
|
1163
|
+
|
|
1164
|
+
OPTIONS
|
|
1165
|
+
--help show CLI help
|
|
1166
|
+
--project=project Current PaaS project
|
|
1167
|
+
--token=token Authentication token
|
|
1115
1168
|
```
|
|
1116
1169
|
|
|
1117
|
-
_See code: [src/commands/paas/
|
|
1170
|
+
_See code: [src/commands/paas/snapshots/restore.ts](src/commands/paas/snapshots/restore.ts)_
|
|
1118
1171
|
|
|
1119
1172
|
## `kourou profile:export`
|
|
1120
1173
|
|
|
@@ -17,6 +17,8 @@ function sendResponse(response, bodyObject) {
|
|
|
17
17
|
}
|
|
18
18
|
class DebugProxy extends common_1.Kommand {
|
|
19
19
|
async runSafe() {
|
|
20
|
+
// @ts-ignore Disable ping pong since when debugging Kuzzle might not be responding
|
|
21
|
+
clearInterval(this.sdk.sdk.protocol.pingIntervalId);
|
|
20
22
|
const nodeVersionResponse = (await this.sdk.query({
|
|
21
23
|
controller: "debug",
|
|
22
24
|
action: "nodeVersion",
|
|
@@ -22,10 +22,16 @@ class CollectionExport extends common_1.Kommand {
|
|
|
22
22
|
}
|
|
23
23
|
const countAll = await this.sdk.document.count(this.args.index, this.args.collection);
|
|
24
24
|
const count = await this.sdk.document.count(this.args.index, this.args.collection, { query });
|
|
25
|
-
this.logInfo(`Dumping
|
|
25
|
+
this.logInfo(`Dumping collection "${this.args.index}:${this.args.collection}" in ${exportPath} ...`);
|
|
26
26
|
fs_1.default.mkdirSync(exportPath, { recursive: true });
|
|
27
|
-
|
|
28
|
-
|
|
27
|
+
if (this.flags.type === "all" || this.flags.type === "mappings") {
|
|
28
|
+
this.logInfo(`Dumping collection mappings ...`);
|
|
29
|
+
await (0, dump_collection_1.dumpCollectionMappings)(this.sdk, this.args.index, this.args.collection, exportPath, this.flags.format);
|
|
30
|
+
}
|
|
31
|
+
if (this.flags.type === "all" || this.flags.type === "data") {
|
|
32
|
+
this.logInfo(`Dumping collection ${count} of ${countAll} documents ...`);
|
|
33
|
+
await (0, dump_collection_1.dumpCollectionData)(this.sdk, this.args.index, this.args.collection, Number(this.flags["batch-size"]), exportPath, query, this.flags.format, fields, this.flags.scrollTTL);
|
|
34
|
+
}
|
|
29
35
|
this.logOk(`Collection ${this.args.index}:${this.args.collection} dumped`);
|
|
30
36
|
}
|
|
31
37
|
}
|
|
@@ -60,6 +66,9 @@ exportable fields in the mapping will be exported.`,
|
|
|
60
66
|
description: `The scroll TTL option to pass to the dump operation (which performs a document.search under the hood),
|
|
61
67
|
expressed in ms format, e.g. '2s', '1m', '3h'.`,
|
|
62
68
|
default: "20s",
|
|
69
|
+
}), type: command_1.flags.string({
|
|
70
|
+
description: "Type of the export: all, mappings, data",
|
|
71
|
+
default: "all",
|
|
63
72
|
}) }, kuzzle_1.kuzzleFlags), { protocol: command_1.flags.string({
|
|
64
73
|
description: "Kuzzle protocol (http or websocket)",
|
|
65
74
|
default: "ws",
|
|
@@ -5,6 +5,7 @@ export default class IndexExport extends Kommand {
|
|
|
5
5
|
static description: string;
|
|
6
6
|
static flags: {
|
|
7
7
|
protocol: flags.IOptionFlag<string>;
|
|
8
|
+
type: flags.IOptionFlag<string>;
|
|
8
9
|
host: flags.IOptionFlag<string>;
|
|
9
10
|
port: flags.IOptionFlag<string>;
|
|
10
11
|
ssl: import("@oclif/parser/lib/flags").IBooleanFlag<boolean>;
|
|
@@ -19,11 +19,18 @@ class IndexExport extends common_1.Kommand {
|
|
|
19
19
|
const { collections } = await this.sdk.collection.list(this.args.index);
|
|
20
20
|
for (const collection of collections) {
|
|
21
21
|
try {
|
|
22
|
-
if (collection.type
|
|
22
|
+
if (collection.type === "realtime") {
|
|
23
|
+
continue;
|
|
24
|
+
}
|
|
25
|
+
if (this.flags.type === "all" || this.flags.type === "mappings") {
|
|
26
|
+
this.logInfo(`Dumping collection "${collection.name}" mappings ...`);
|
|
23
27
|
await (0, dump_collection_1.dumpCollectionMappings)(this.sdk, this.args.index, collection.name, exportPath, this.flags.format);
|
|
28
|
+
}
|
|
29
|
+
if (this.flags.type === "all" || this.flags.type === "data") {
|
|
30
|
+
this.logInfo(`Dumping collection "${collection.name}" documents ...`);
|
|
24
31
|
await (0, dump_collection_1.dumpCollectionData)(this.sdk, this.args.index, collection.name, Number(this.flags["batch-size"]), exportPath, query, this.flags.format, this.flags.scrollTTL);
|
|
25
|
-
cli_ux_1.default.action.stop();
|
|
26
32
|
}
|
|
33
|
+
cli_ux_1.default.action.stop();
|
|
27
34
|
}
|
|
28
35
|
catch (error) {
|
|
29
36
|
this.logKo(`Error when exporting collection "${collection.name}": ${error}`);
|
|
@@ -53,6 +60,9 @@ expressed in ms format, e.g. '2s', '1m', '3h'.`,
|
|
|
53
60
|
}) }, kuzzle_1.kuzzleFlags), { protocol: command_1.flags.string({
|
|
54
61
|
description: "Kuzzle protocol (http or websocket)",
|
|
55
62
|
default: "ws",
|
|
63
|
+
}), type: command_1.flags.string({
|
|
64
|
+
description: "Type of the export: all, mappings, data",
|
|
65
|
+
default: "all",
|
|
56
66
|
}) });
|
|
57
67
|
IndexExport.args = [{ name: "index", description: "Index name", required: true }];
|
|
58
68
|
IndexExport.examples = [
|
|
@@ -1,10 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const tslib_1 = require("tslib");
|
|
4
|
-
const fs_1 = (0, tslib_1.__importDefault)(require("fs"));
|
|
5
3
|
const command_1 = require("@oclif/command");
|
|
6
|
-
const cli_ux_1 = (0, tslib_1.__importDefault)(require("cli-ux"));
|
|
7
|
-
const login_1 = (0, tslib_1.__importDefault)(require("./login"));
|
|
8
4
|
const PaasKommand_1 = require("../../support/PaasKommand");
|
|
9
5
|
class PaasDeploy extends PaasKommand_1.PaasKommand {
|
|
10
6
|
async runSafe() {
|
|
@@ -29,24 +25,6 @@ class PaasDeploy extends PaasKommand_1.PaasKommand {
|
|
|
29
25
|
});
|
|
30
26
|
this.logOk("Deployment in progress");
|
|
31
27
|
}
|
|
32
|
-
async getCredentials() {
|
|
33
|
-
const project = this.getProject();
|
|
34
|
-
const projectFile = this.fileProjectCredentials(project);
|
|
35
|
-
if (!fs_1.default.existsSync(projectFile)) {
|
|
36
|
-
this.log("");
|
|
37
|
-
const nextStep = await cli_ux_1.default.prompt("Cannot find credentials for this project. Do you want to login first? [Y/N]", { type: "single" });
|
|
38
|
-
this.log("");
|
|
39
|
-
if (nextStep.toLowerCase().startsWith("y")) {
|
|
40
|
-
await login_1.default.run(["--project", project]);
|
|
41
|
-
}
|
|
42
|
-
else {
|
|
43
|
-
this.logKo("Aborting.");
|
|
44
|
-
process.exit(1);
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
const credentials = JSON.parse(fs_1.default.readFileSync(projectFile, "utf8"));
|
|
48
|
-
return credentials.apiKey;
|
|
49
|
-
}
|
|
50
28
|
}
|
|
51
29
|
PaasDeploy.description = "Deploy a new version of the application in the PaaS";
|
|
52
30
|
PaasDeploy.flags = {
|
|
@@ -21,9 +21,9 @@ class PaasLogin extends PaasKommand_1.PaasKommand {
|
|
|
21
21
|
return;
|
|
22
22
|
}
|
|
23
23
|
await this.initPaasClient({ username, password });
|
|
24
|
+
await this.authenticateNPM(username, password);
|
|
24
25
|
const apiKey = await this.paas.auth.createApiKey("Kourou PaaS API Key");
|
|
25
26
|
this.createProjectCredentials(apiKey);
|
|
26
|
-
await this.authenticateNPM(username, password);
|
|
27
27
|
this.logOk(`Successfully logged in as ${username}. Your Kuzzle Enterprise license is now enabled on this host.`);
|
|
28
28
|
}
|
|
29
29
|
createProjectCredentials(apiKey) {
|
|
@@ -49,7 +49,8 @@ class PaasLogin extends PaasKommand_1.PaasKommand {
|
|
|
49
49
|
password,
|
|
50
50
|
}),
|
|
51
51
|
};
|
|
52
|
-
const
|
|
52
|
+
const targetUrl = `https://${this.packagesHost}/-/user/org.couchdb.user:${username}`;
|
|
53
|
+
const response = await (0, node_fetch_1.default)(targetUrl, options);
|
|
53
54
|
const json = await response.json();
|
|
54
55
|
if (response.status !== 201) {
|
|
55
56
|
throw new Error(json.error);
|
|
@@ -32,8 +32,6 @@ declare class PaasLogs extends PaasKommand {
|
|
|
32
32
|
*/
|
|
33
33
|
private podsColor;
|
|
34
34
|
runSafe(): Promise<void>;
|
|
35
|
-
getCredentials(): Promise<any>;
|
|
36
|
-
getNumberOfSpaces(names: string[], currentName: string): number;
|
|
37
35
|
/**
|
|
38
36
|
* Returns the color to use for a pod name.
|
|
39
37
|
* @param podName Name of the pod.
|
|
@@ -1,13 +1,10 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
const tslib_1 = require("tslib");
|
|
4
|
-
const fs_1 = (0, tslib_1.__importDefault)(require("fs"));
|
|
5
4
|
const readline = (0, tslib_1.__importStar)(require("readline"));
|
|
6
5
|
const command_1 = require("@oclif/command");
|
|
7
6
|
const chalk_1 = (0, tslib_1.__importDefault)(require("chalk"));
|
|
8
7
|
const chrono = (0, tslib_1.__importStar)(require("chrono-node"));
|
|
9
|
-
const cli_ux_1 = require("cli-ux");
|
|
10
|
-
const login_1 = (0, tslib_1.__importDefault)(require("./login"));
|
|
11
8
|
const PaasKommand_1 = require("../../support/PaasKommand");
|
|
12
9
|
class PaasLogs extends PaasKommand_1.PaasKommand {
|
|
13
10
|
constructor() {
|
|
@@ -15,7 +12,15 @@ class PaasLogs extends PaasKommand_1.PaasKommand {
|
|
|
15
12
|
/**
|
|
16
13
|
* Allowed colors for pod names.
|
|
17
14
|
*/
|
|
18
|
-
this.allColors = [
|
|
15
|
+
this.allColors = [
|
|
16
|
+
chalk_1.default.red,
|
|
17
|
+
chalk_1.default.green,
|
|
18
|
+
chalk_1.default.yellow,
|
|
19
|
+
chalk_1.default.blue,
|
|
20
|
+
chalk_1.default.magenta,
|
|
21
|
+
chalk_1.default.cyan,
|
|
22
|
+
chalk_1.default.gray,
|
|
23
|
+
];
|
|
19
24
|
/**
|
|
20
25
|
* Available colors for pod names.
|
|
21
26
|
*/
|
|
@@ -34,8 +39,12 @@ class PaasLogs extends PaasKommand_1.PaasKommand {
|
|
|
34
39
|
this.logInfo(`Logged as "${user._id}" for project "${this.flags.project || this.getProject()}"`);
|
|
35
40
|
const separator = "\t";
|
|
36
41
|
// Parse the time arguments
|
|
37
|
-
const since = this.flags.since
|
|
38
|
-
|
|
42
|
+
const since = this.flags.since
|
|
43
|
+
? chrono.parseDate(this.flags.since).toISOString()
|
|
44
|
+
: undefined;
|
|
45
|
+
const until = this.flags.until
|
|
46
|
+
? chrono.parseDate(this.flags.until).toISOString()
|
|
47
|
+
: undefined;
|
|
39
48
|
// Perform the streamed request
|
|
40
49
|
const incomingMessage = await this.paas.queryHttpStream({
|
|
41
50
|
controller: "application",
|
|
@@ -63,18 +72,19 @@ class PaasLogs extends PaasKommand_1.PaasKommand {
|
|
|
63
72
|
const data = JSON.parse(line);
|
|
64
73
|
// Exclude logs that are empty or that are not from a pod
|
|
65
74
|
if (!data.content || !data.podName) {
|
|
66
|
-
this.logKo(line);
|
|
67
75
|
continue;
|
|
68
76
|
}
|
|
69
77
|
// Get the pod color
|
|
70
78
|
const podColor = this.getPodColor(data.podName);
|
|
71
79
|
// Display the log
|
|
72
|
-
const timestamp = this.flags.timestamp
|
|
80
|
+
const timestamp = this.flags.timestamp
|
|
81
|
+
? `[${new Date(data.timeStamp).toLocaleString()}] `
|
|
82
|
+
: "";
|
|
73
83
|
const name = podColor(`${data.podName}${separator}`);
|
|
74
84
|
this.log(`${timestamp}${name}| ${data.content}`);
|
|
75
85
|
}
|
|
76
86
|
catch (error) {
|
|
77
|
-
this.logKo(`
|
|
87
|
+
this.logKo(`Error while parsing log: ${error} (Received: "${line}")`);
|
|
78
88
|
}
|
|
79
89
|
}
|
|
80
90
|
}
|
|
@@ -86,34 +96,6 @@ class PaasLogs extends PaasKommand_1.PaasKommand {
|
|
|
86
96
|
finally { if (e_1) throw e_1.error; }
|
|
87
97
|
}
|
|
88
98
|
}
|
|
89
|
-
async getCredentials() {
|
|
90
|
-
const project = this.getProject();
|
|
91
|
-
const projectFile = this.fileProjectCredentials(project);
|
|
92
|
-
if (!fs_1.default.existsSync(projectFile)) {
|
|
93
|
-
this.log("");
|
|
94
|
-
const nextStep = await cli_ux_1.cli.prompt("Cannot find credentials for this project. Do you want to login first? [Y/N]", { type: "single" });
|
|
95
|
-
this.log("");
|
|
96
|
-
if (nextStep.toLowerCase().startsWith("y")) {
|
|
97
|
-
await login_1.default.run(["--project", project]);
|
|
98
|
-
}
|
|
99
|
-
else {
|
|
100
|
-
this.logKo("Aborting.");
|
|
101
|
-
process.exit(1);
|
|
102
|
-
}
|
|
103
|
-
}
|
|
104
|
-
const credentials = JSON.parse(fs_1.default.readFileSync(projectFile, "utf8"));
|
|
105
|
-
return credentials.apiKey;
|
|
106
|
-
}
|
|
107
|
-
getNumberOfSpaces(names, currentName) {
|
|
108
|
-
const end = 10;
|
|
109
|
-
let max = { name: '', length: 0 };
|
|
110
|
-
for (const name of names) {
|
|
111
|
-
if (max.length < name.length) {
|
|
112
|
-
max = { name: name, length: name.length };
|
|
113
|
-
}
|
|
114
|
-
}
|
|
115
|
-
return currentName === max.name ? end : end + (max.length - currentName.length);
|
|
116
|
-
}
|
|
117
99
|
/**
|
|
118
100
|
* Returns the color to use for a pod name.
|
|
119
101
|
* @param podName Name of the pod.
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { flags } from "@oclif/command";
|
|
2
|
+
import { PaasKommand } from "../../../support/PaasKommand";
|
|
3
|
+
declare class PaasSnapshotsCat extends PaasKommand {
|
|
4
|
+
static description: string;
|
|
5
|
+
static flags: {
|
|
6
|
+
help: import("@oclif/parser/lib/flags").IBooleanFlag<void>;
|
|
7
|
+
token: flags.IOptionFlag<string | undefined>;
|
|
8
|
+
project: flags.IOptionFlag<string | undefined>;
|
|
9
|
+
};
|
|
10
|
+
static args: {
|
|
11
|
+
name: string;
|
|
12
|
+
description: string;
|
|
13
|
+
required: boolean;
|
|
14
|
+
}[];
|
|
15
|
+
runSafe(): Promise<void>;
|
|
16
|
+
}
|
|
17
|
+
export default PaasSnapshotsCat;
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const command_1 = require("@oclif/command");
|
|
4
|
+
const PaasKommand_1 = require("../../../support/PaasKommand");
|
|
5
|
+
class PaasSnapshotsCat extends PaasKommand_1.PaasKommand {
|
|
6
|
+
async runSafe() {
|
|
7
|
+
const apiKey = await this.getCredentials();
|
|
8
|
+
await this.initPaasClient({ apiKey });
|
|
9
|
+
const user = await this.paas.auth.getCurrentUser();
|
|
10
|
+
this.logInfo(`Logged as "${user._id}" for project "${this.flags.project || this.getProject()}"`);
|
|
11
|
+
const { result } = await this.paas.query({
|
|
12
|
+
controller: "application",
|
|
13
|
+
action: "snapshots",
|
|
14
|
+
environmentId: this.args.environment,
|
|
15
|
+
projectId: this.flags.project || this.getProject(),
|
|
16
|
+
applicationId: this.args.applicationId,
|
|
17
|
+
body: {},
|
|
18
|
+
});
|
|
19
|
+
this.logInfo(JSON.stringify(result, null, 2));
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
PaasSnapshotsCat.description = "List all snapshots for a given kuzzle application in a environment";
|
|
23
|
+
PaasSnapshotsCat.flags = {
|
|
24
|
+
help: command_1.flags.help(),
|
|
25
|
+
token: command_1.flags.string({
|
|
26
|
+
default: process.env.KUZZLE_PAAS_TOKEN,
|
|
27
|
+
description: "Authentication token",
|
|
28
|
+
}),
|
|
29
|
+
project: command_1.flags.string({
|
|
30
|
+
description: "Current PaaS project",
|
|
31
|
+
}),
|
|
32
|
+
};
|
|
33
|
+
PaasSnapshotsCat.args = [
|
|
34
|
+
{
|
|
35
|
+
name: "environment",
|
|
36
|
+
description: "Project environment name",
|
|
37
|
+
required: true,
|
|
38
|
+
},
|
|
39
|
+
{
|
|
40
|
+
name: "applicationId",
|
|
41
|
+
description: "Application Identifier",
|
|
42
|
+
required: true,
|
|
43
|
+
}
|
|
44
|
+
];
|
|
45
|
+
exports.default = PaasSnapshotsCat;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { flags } from "@oclif/command";
|
|
2
|
+
import { PaasKommand } from "../../../support/PaasKommand";
|
|
3
|
+
declare class PaasSnapshotsDump extends PaasKommand {
|
|
4
|
+
static description: string;
|
|
5
|
+
static flags: {
|
|
6
|
+
help: import("@oclif/parser/lib/flags").IBooleanFlag<void>;
|
|
7
|
+
token: flags.IOptionFlag<string | undefined>;
|
|
8
|
+
project: flags.IOptionFlag<string | undefined>;
|
|
9
|
+
};
|
|
10
|
+
static args: {
|
|
11
|
+
name: string;
|
|
12
|
+
description: string;
|
|
13
|
+
required: boolean;
|
|
14
|
+
}[];
|
|
15
|
+
runSafe(): Promise<void>;
|
|
16
|
+
}
|
|
17
|
+
export default PaasSnapshotsDump;
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const command_1 = require("@oclif/command");
|
|
4
|
+
const PaasKommand_1 = require("../../../support/PaasKommand");
|
|
5
|
+
class PaasSnapshotsDump extends PaasKommand_1.PaasKommand {
|
|
6
|
+
async runSafe() {
|
|
7
|
+
const apiKey = await this.getCredentials();
|
|
8
|
+
await this.initPaasClient({ apiKey });
|
|
9
|
+
const user = await this.paas.auth.getCurrentUser();
|
|
10
|
+
this.logInfo(`Logged as "${user._id}" for project "${this.flags.project || this.getProject()}"`);
|
|
11
|
+
const { result } = await this.paas.query({
|
|
12
|
+
controller: "application",
|
|
13
|
+
action: "dump",
|
|
14
|
+
environmentId: this.args.environment,
|
|
15
|
+
projectId: this.flags.project || this.getProject(),
|
|
16
|
+
applicationId: this.args.applicationId,
|
|
17
|
+
body: {},
|
|
18
|
+
});
|
|
19
|
+
this.logOk(result.body);
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
PaasSnapshotsDump.description = "List all snapshots for a given kuzzle application in a environment";
|
|
23
|
+
PaasSnapshotsDump.flags = {
|
|
24
|
+
help: command_1.flags.help(),
|
|
25
|
+
token: command_1.flags.string({
|
|
26
|
+
default: process.env.KUZZLE_PAAS_TOKEN,
|
|
27
|
+
description: "Authentication token",
|
|
28
|
+
}),
|
|
29
|
+
project: command_1.flags.string({
|
|
30
|
+
description: "Current PaaS project",
|
|
31
|
+
}),
|
|
32
|
+
};
|
|
33
|
+
PaasSnapshotsDump.args = [
|
|
34
|
+
{
|
|
35
|
+
name: "environment",
|
|
36
|
+
description: "Project environment name",
|
|
37
|
+
required: true,
|
|
38
|
+
},
|
|
39
|
+
{
|
|
40
|
+
name: "applicationId",
|
|
41
|
+
description: "Application Identifier",
|
|
42
|
+
required: true,
|
|
43
|
+
}
|
|
44
|
+
];
|
|
45
|
+
exports.default = PaasSnapshotsDump;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { flags } from "@oclif/command";
|
|
2
|
+
import { PaasKommand } from "../../../support/PaasKommand";
|
|
3
|
+
declare class PaasSnapshotsRestore extends PaasKommand {
|
|
4
|
+
static description: string;
|
|
5
|
+
static flags: {
|
|
6
|
+
help: import("@oclif/parser/lib/flags").IBooleanFlag<void>;
|
|
7
|
+
token: flags.IOptionFlag<string | undefined>;
|
|
8
|
+
project: flags.IOptionFlag<string | undefined>;
|
|
9
|
+
};
|
|
10
|
+
static args: {
|
|
11
|
+
name: string;
|
|
12
|
+
description: string;
|
|
13
|
+
required: boolean;
|
|
14
|
+
}[];
|
|
15
|
+
runSafe(): Promise<void>;
|
|
16
|
+
}
|
|
17
|
+
export default PaasSnapshotsRestore;
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const command_1 = require("@oclif/command");
|
|
4
|
+
const PaasKommand_1 = require("../../../support/PaasKommand");
|
|
5
|
+
class PaasSnapshotsRestore extends PaasKommand_1.PaasKommand {
|
|
6
|
+
async runSafe() {
|
|
7
|
+
const apiKey = await this.getCredentials();
|
|
8
|
+
await this.initPaasClient({ apiKey });
|
|
9
|
+
const user = await this.paas.auth.getCurrentUser();
|
|
10
|
+
this.logInfo(`Logged as "${user._id}" for project "${this.flags.project || this.getProject()}"`);
|
|
11
|
+
await this.paas.query({
|
|
12
|
+
controller: "application",
|
|
13
|
+
action: "restore",
|
|
14
|
+
environmentId: this.args.environment,
|
|
15
|
+
projectId: this.flags.project || this.getProject(),
|
|
16
|
+
applicationId: this.args.applicationId,
|
|
17
|
+
body: {
|
|
18
|
+
repository: "automated",
|
|
19
|
+
snapshot: this.args.snapshotId,
|
|
20
|
+
},
|
|
21
|
+
});
|
|
22
|
+
this.logInfo("Ok");
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
PaasSnapshotsRestore.description = "List all snapshots for a given kuzzle application in a environment";
|
|
26
|
+
PaasSnapshotsRestore.flags = {
|
|
27
|
+
help: command_1.flags.help(),
|
|
28
|
+
token: command_1.flags.string({
|
|
29
|
+
default: process.env.KUZZLE_PAAS_TOKEN,
|
|
30
|
+
description: "Authentication token",
|
|
31
|
+
}),
|
|
32
|
+
project: command_1.flags.string({
|
|
33
|
+
description: "Current PaaS project",
|
|
34
|
+
}),
|
|
35
|
+
};
|
|
36
|
+
PaasSnapshotsRestore.args = [
|
|
37
|
+
{
|
|
38
|
+
name: "environment",
|
|
39
|
+
description: "Project environment name",
|
|
40
|
+
required: true,
|
|
41
|
+
},
|
|
42
|
+
{
|
|
43
|
+
name: "applicationId",
|
|
44
|
+
description: "Application Identifier",
|
|
45
|
+
required: true,
|
|
46
|
+
},
|
|
47
|
+
{
|
|
48
|
+
name: "snapshotId",
|
|
49
|
+
description: "Snapshot Identifier",
|
|
50
|
+
required: true,
|
|
51
|
+
}
|
|
52
|
+
];
|
|
53
|
+
exports.default = PaasSnapshotsRestore;
|
|
@@ -56,6 +56,16 @@ class PaasKommand extends common_1.Kommand {
|
|
|
56
56
|
}
|
|
57
57
|
return this.flags.project;
|
|
58
58
|
}
|
|
59
|
+
async getCredentials() {
|
|
60
|
+
const project = this.getProject();
|
|
61
|
+
const projectFile = this.fileProjectCredentials(project);
|
|
62
|
+
if (!fs_1.default.existsSync(projectFile)) {
|
|
63
|
+
this.logKo("You are not logged in. You should run paas:login first. Aborting.");
|
|
64
|
+
process.exit(1);
|
|
65
|
+
}
|
|
66
|
+
const credentials = JSON.parse(fs_1.default.readFileSync(projectFile, "utf8"));
|
|
67
|
+
return credentials.apiKey;
|
|
68
|
+
}
|
|
59
69
|
}
|
|
60
70
|
exports.PaasKommand = PaasKommand;
|
|
61
71
|
PaasKommand.initSdk = false;
|
|
@@ -81,6 +81,7 @@ class AbstractDumper {
|
|
|
81
81
|
* @returns a promise resolving when the dump is finished.
|
|
82
82
|
*/
|
|
83
83
|
async dump() {
|
|
84
|
+
fs_1.default.mkdirSync(this.collectionDir, { recursive: true });
|
|
84
85
|
this.filename = path_1.default.join(this.collectionDir, `documents.${this.fileExtension}`);
|
|
85
86
|
this.writeStream = fs_1.default.createWriteStream(this.filename);
|
|
86
87
|
const waitWrite = new Promise((resolve, reject) => this.writeStream ? this.writeStream.on("finish", resolve) : reject());
|
package/lib/support/kuzzle.js
CHANGED
|
@@ -164,7 +164,7 @@ class KuzzleSDK {
|
|
|
164
164
|
const options = {
|
|
165
165
|
method: "POST",
|
|
166
166
|
headers: {
|
|
167
|
-
|
|
167
|
+
Authorization: `Bearer ${this.sdk.jwt}`,
|
|
168
168
|
"Content-Length": Buffer.byteLength(body),
|
|
169
169
|
"Content-Type": "application/json",
|
|
170
170
|
},
|
|
@@ -24,6 +24,7 @@ class Elasticsearch {
|
|
|
24
24
|
delete specifications.settings.index.uuid;
|
|
25
25
|
delete specifications.settings.index.version;
|
|
26
26
|
delete specifications.settings.index.routing;
|
|
27
|
+
delete specifications.settings.index.history;
|
|
27
28
|
return specifications;
|
|
28
29
|
}
|
|
29
30
|
async createIndex(index, specifications) {
|
|
@@ -6,18 +6,16 @@ const fs_1 = (0, tslib_1.__importDefault)(require("fs"));
|
|
|
6
6
|
const chalk_1 = (0, tslib_1.__importDefault)(require("chalk"));
|
|
7
7
|
const ndjson_1 = (0, tslib_1.__importDefault)(require("ndjson"));
|
|
8
8
|
function handleError(log, dumpFile, error) {
|
|
9
|
-
if (error.
|
|
9
|
+
if (error.errors) {
|
|
10
10
|
const errorFile = `${dumpFile
|
|
11
11
|
.split(".")
|
|
12
12
|
.slice(0, -1)
|
|
13
13
|
.join(".")}-errors.jsonl`;
|
|
14
14
|
const writeStream = fs_1.default.createWriteStream(errorFile, { flags: "a" });
|
|
15
|
-
const serialize = ndjson_1.default.stringify().pipe(writeStream);
|
|
16
|
-
serialize.on("data", (line) => writeStream.write(line));
|
|
17
15
|
for (const partialError of error.errors) {
|
|
18
|
-
|
|
16
|
+
writeStream.write(JSON.stringify(partialError) + '\n');
|
|
19
17
|
}
|
|
20
|
-
|
|
18
|
+
writeStream.end();
|
|
21
19
|
log(chalk_1.default.red(`[X] Error importing ${dumpFile}. See errors in ${errorFile}`));
|
|
22
20
|
}
|
|
23
21
|
else {
|
|
@@ -31,6 +29,7 @@ async function restoreCollectionData(sdk, log, batchSize, dumpFile, index, colle
|
|
|
31
29
|
action: "mWrite",
|
|
32
30
|
index: "",
|
|
33
31
|
collection: "",
|
|
32
|
+
strict: true,
|
|
34
33
|
body: {
|
|
35
34
|
documents: [{}],
|
|
36
35
|
},
|
|
@@ -90,8 +89,8 @@ async function restoreCollectionData(sdk, log, batchSize, dumpFile, index, colle
|
|
|
90
89
|
mWriteRequest.body.documents = documents;
|
|
91
90
|
sdk
|
|
92
91
|
.query(mWriteRequest)
|
|
93
|
-
.then(() => {
|
|
94
|
-
total +=
|
|
92
|
+
.then((response) => {
|
|
93
|
+
total += response.result.successes.length;
|
|
95
94
|
process.stdout.write(` ${total} documents imported`);
|
|
96
95
|
process.stdout.write("\r");
|
|
97
96
|
resolve(undefined);
|