kourou 0.24.2 → 0.25.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 +98 -12
- package/lib/commands/api-key/check.d.ts +3 -3
- package/lib/commands/api-key/check.js +5 -7
- package/lib/commands/api-key/create.d.ts +3 -3
- package/lib/commands/api-key/create.js +8 -10
- package/lib/commands/api-key/delete.d.ts +3 -3
- package/lib/commands/api-key/delete.js +4 -6
- package/lib/commands/api-key/search.d.ts +3 -3
- package/lib/commands/api-key/search.js +5 -7
- package/lib/commands/app/debug-proxy.d.ts +3 -3
- package/lib/commands/app/debug-proxy.js +57 -55
- package/lib/commands/app/doctor.d.ts +24 -0
- package/lib/commands/app/doctor.js +201 -0
- package/lib/commands/app/scaffold.d.ts +2 -2
- package/lib/commands/app/scaffold.js +20 -15
- package/lib/commands/app/start-services.d.ts +1 -1
- package/lib/commands/app/start-services.js +26 -26
- package/lib/commands/collection/create.d.ts +3 -3
- package/lib/commands/collection/create.js +9 -6
- package/lib/commands/collection/export.d.ts +5 -5
- package/lib/commands/collection/export.js +25 -26
- package/lib/commands/collection/import.d.ts +5 -5
- package/lib/commands/collection/import.js +17 -17
- package/lib/commands/collection/migrate.d.ts +27 -0
- package/lib/commands/collection/migrate.js +43 -0
- package/lib/commands/config/diff.d.ts +1 -1
- package/lib/commands/config/diff.js +27 -21
- package/lib/commands/document/search.d.ts +3 -3
- package/lib/commands/document/search.js +20 -20
- package/lib/commands/es/aliases/cat.d.ts +12 -0
- package/lib/commands/es/aliases/cat.js +36 -0
- package/lib/commands/es/indices/cat.d.ts +2 -2
- package/lib/commands/es/indices/cat.js +8 -8
- package/lib/commands/es/indices/get.d.ts +2 -2
- package/lib/commands/es/indices/get.js +7 -7
- package/lib/commands/es/indices/insert.d.ts +2 -2
- package/lib/commands/es/indices/insert.js +9 -9
- package/lib/commands/es/migrate.d.ts +10 -8
- package/lib/commands/es/migrate.js +86 -82
- package/lib/commands/es/snapshot/create-repository.d.ts +2 -2
- package/lib/commands/es/snapshot/create-repository.js +16 -12
- package/lib/commands/es/snapshot/create.d.ts +2 -2
- package/lib/commands/es/snapshot/create.js +7 -7
- package/lib/commands/es/snapshot/list.d.ts +2 -2
- package/lib/commands/es/snapshot/list.js +12 -8
- package/lib/commands/file/decrypt.d.ts +4 -4
- package/lib/commands/file/decrypt.js +21 -21
- package/lib/commands/file/encrypt.d.ts +4 -4
- package/lib/commands/file/encrypt.js +20 -22
- package/lib/commands/file/test.d.ts +3 -3
- package/lib/commands/file/test.js +13 -13
- package/lib/commands/import.d.ts +5 -5
- package/lib/commands/import.js +39 -28
- package/lib/commands/index/export.d.ts +5 -4
- package/lib/commands/index/export.js +21 -19
- package/lib/commands/index/import.d.ts +5 -5
- package/lib/commands/index/import.js +21 -19
- package/lib/commands/instance/kill.d.ts +2 -2
- package/lib/commands/instance/kill.js +34 -34
- package/lib/commands/instance/list.d.ts +1 -1
- package/lib/commands/instance/list.js +33 -30
- package/lib/commands/instance/logs.d.ts +2 -2
- package/lib/commands/instance/logs.js +26 -22
- package/lib/commands/instance/spawn.d.ts +2 -2
- package/lib/commands/instance/spawn.js +46 -40
- package/lib/commands/paas/deploy.d.ts +2 -2
- package/lib/commands/paas/deploy.js +33 -21
- package/lib/commands/paas/init.d.ts +1 -1
- package/lib/commands/paas/init.js +10 -6
- package/lib/commands/paas/login.d.ts +3 -3
- package/lib/commands/paas/login.js +30 -19
- package/lib/commands/paas/logs.d.ts +27 -0
- package/lib/commands/paas/logs.js +137 -18
- package/lib/commands/profile/export.d.ts +3 -3
- package/lib/commands/profile/export.js +12 -12
- package/lib/commands/profile/import.d.ts +3 -3
- package/lib/commands/profile/import.js +6 -8
- package/lib/commands/realtime/subscribe.d.ts +3 -3
- package/lib/commands/realtime/subscribe.js +25 -25
- package/lib/commands/redis/list-keys.d.ts +3 -3
- package/lib/commands/redis/list-keys.js +15 -11
- package/lib/commands/role/export.d.ts +3 -3
- package/lib/commands/role/export.js +11 -11
- package/lib/commands/role/import.d.ts +4 -4
- package/lib/commands/role/import.js +10 -12
- package/lib/commands/sdk/execute.d.ts +5 -5
- package/lib/commands/sdk/execute.js +23 -19
- package/lib/commands/sdk/query.d.ts +5 -4
- package/lib/commands/sdk/query.js +30 -24
- package/lib/commands/user/export-mappings.d.ts +3 -3
- package/lib/commands/user/export-mappings.js +11 -11
- package/lib/commands/user/export.d.ts +6 -6
- package/lib/commands/user/export.js +34 -33
- package/lib/commands/user/import-mappings.d.ts +3 -3
- package/lib/commands/user/import-mappings.js +7 -7
- package/lib/commands/user/import.d.ts +3 -3
- package/lib/commands/user/import.js +6 -8
- package/lib/commands/vault/add.d.ts +3 -3
- package/lib/commands/vault/add.js +27 -19
- package/lib/commands/vault/decrypt.d.ts +4 -4
- package/lib/commands/vault/decrypt.js +24 -20
- package/lib/commands/vault/encrypt.d.ts +4 -4
- package/lib/commands/vault/encrypt.js +24 -20
- package/lib/commands/vault/show.d.ts +3 -3
- package/lib/commands/vault/show.js +24 -20
- package/lib/commands/vault/test.d.ts +3 -3
- package/lib/commands/vault/test.js +16 -12
- package/lib/common.d.ts +3 -3
- package/lib/common.js +28 -29
- package/lib/hooks/command_not_found/api-action.d.ts +2 -2
- package/lib/hooks/command_not_found/api-action.js +20 -22
- package/lib/index.d.ts +1 -1
- package/lib/support/PaasKommand.d.ts +2 -2
- package/lib/support/PaasKommand.js +9 -9
- package/lib/support/dump-collection.js +50 -41
- package/lib/support/editor.js +12 -10
- package/lib/support/execute.d.ts +6 -1
- package/lib/support/execute.js +9 -8
- package/lib/support/kuzzle.d.ts +12 -4
- package/lib/support/kuzzle.js +65 -31
- package/lib/support/migrate/providers/elasticsearch.d.ts +16 -0
- package/lib/support/migrate/providers/elasticsearch.js +74 -0
- package/lib/support/migrate/providers/file.d.ts +15 -0
- package/lib/support/migrate/providers/file.js +74 -0
- package/lib/support/migrate/providers/index.d.ts +12 -0
- package/lib/support/migrate/providers/index.js +16 -0
- package/lib/support/migrate/types.d.ts +8 -0
- package/lib/support/migrate/types.js +2 -0
- package/lib/support/restore-collection.d.ts +2 -1
- package/lib/support/restore-collection.js +37 -26
- package/lib/support/restore-securities.js +22 -19
- package/package.json +16 -15
|
@@ -1,27 +1,27 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
const tslib_1 = require("tslib");
|
|
4
|
-
const fs_1 = tslib_1.__importDefault(require("fs"));
|
|
5
|
-
const path_1 = tslib_1.__importDefault(require("path"));
|
|
4
|
+
const fs_1 = (0, tslib_1.__importDefault)(require("fs"));
|
|
5
|
+
const path_1 = (0, tslib_1.__importDefault)(require("path"));
|
|
6
6
|
const command_1 = require("@oclif/command");
|
|
7
7
|
const common_1 = require("../../common");
|
|
8
8
|
const kuzzle_1 = require("../../support/kuzzle");
|
|
9
9
|
class RoleDump extends common_1.Kommand {
|
|
10
10
|
async runSafe() {
|
|
11
|
-
const filename = path_1.default.join(this.flags.path,
|
|
11
|
+
const filename = path_1.default.join(this.flags.path, "roles.json");
|
|
12
12
|
this.logInfo(`Exporting roles in ${filename} ...`);
|
|
13
13
|
fs_1.default.mkdirSync(this.flags.path, { recursive: true });
|
|
14
14
|
const roles = await this._dumpRoles();
|
|
15
15
|
const dump = {
|
|
16
|
-
type:
|
|
17
|
-
content: roles
|
|
16
|
+
type: "roles",
|
|
17
|
+
content: roles,
|
|
18
18
|
};
|
|
19
19
|
fs_1.default.writeFileSync(filename, JSON.stringify(dump, null, 2));
|
|
20
20
|
this.logOk(`${Object.keys(roles).length} roles dumped`);
|
|
21
21
|
}
|
|
22
22
|
async _dumpRoles() {
|
|
23
23
|
const options = {
|
|
24
|
-
size: 100
|
|
24
|
+
size: 100,
|
|
25
25
|
};
|
|
26
26
|
let result = await this.sdk.security.searchRoles({}, options);
|
|
27
27
|
const roles = {};
|
|
@@ -35,11 +35,11 @@ class RoleDump extends common_1.Kommand {
|
|
|
35
35
|
}
|
|
36
36
|
}
|
|
37
37
|
exports.default = RoleDump;
|
|
38
|
-
RoleDump.description =
|
|
38
|
+
RoleDump.description = "Exports roles";
|
|
39
39
|
RoleDump.flags = Object.assign(Object.assign({ help: command_1.flags.help({}), path: command_1.flags.string({
|
|
40
|
-
description:
|
|
41
|
-
default:
|
|
40
|
+
description: "Dump directory",
|
|
41
|
+
default: "roles",
|
|
42
42
|
}) }, kuzzle_1.kuzzleFlags), { protocol: command_1.flags.string({
|
|
43
|
-
description:
|
|
44
|
-
default:
|
|
43
|
+
description: "Kuzzle protocol (http or websocket)",
|
|
44
|
+
default: "ws",
|
|
45
45
|
}) });
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { flags } from
|
|
2
|
-
import { Kommand } from
|
|
1
|
+
import { flags } from "@oclif/command";
|
|
2
|
+
import { Kommand } from "../../common";
|
|
3
3
|
export default class RoleImport extends Kommand {
|
|
4
4
|
static description: string;
|
|
5
5
|
static flags: {
|
|
@@ -10,8 +10,8 @@ export default class RoleImport extends Kommand {
|
|
|
10
10
|
username: flags.IOptionFlag<string>;
|
|
11
11
|
password: flags.IOptionFlag<string | undefined>;
|
|
12
12
|
as: flags.IOptionFlag<string | undefined>;
|
|
13
|
-
|
|
14
|
-
|
|
13
|
+
"api-key": flags.IOptionFlag<string | undefined>;
|
|
14
|
+
"preserve-anonymous": import("@oclif/parser/lib/flags").IBooleanFlag<boolean>;
|
|
15
15
|
help: import("@oclif/parser/lib/flags").IBooleanFlag<void>;
|
|
16
16
|
};
|
|
17
17
|
static args: {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
const tslib_1 = require("tslib");
|
|
4
|
-
const fs_1 = tslib_1.__importDefault(require("fs"));
|
|
4
|
+
const fs_1 = (0, tslib_1.__importDefault)(require("fs"));
|
|
5
5
|
const command_1 = require("@oclif/command");
|
|
6
6
|
const common_1 = require("../../common");
|
|
7
7
|
const kuzzle_1 = require("../../support/kuzzle");
|
|
@@ -9,20 +9,18 @@ const restore_securities_1 = require("../../support/restore-securities");
|
|
|
9
9
|
class RoleImport extends common_1.Kommand {
|
|
10
10
|
async runSafe() {
|
|
11
11
|
this.logInfo(`Importing roles from ${this.args.path} ...`);
|
|
12
|
-
const dump = JSON.parse(fs_1.default.readFileSync(this.args.path,
|
|
13
|
-
const count = await (0, restore_securities_1.restoreRoles)(this, dump, this.flags[
|
|
12
|
+
const dump = JSON.parse(fs_1.default.readFileSync(this.args.path, "utf-8"));
|
|
13
|
+
const count = await (0, restore_securities_1.restoreRoles)(this, dump, this.flags["preserve-anonymous"]);
|
|
14
14
|
this.logOk(`${count} roles restored`);
|
|
15
15
|
}
|
|
16
16
|
}
|
|
17
17
|
exports.default = RoleImport;
|
|
18
|
-
RoleImport.description =
|
|
19
|
-
RoleImport.flags = Object.assign(Object.assign({
|
|
20
|
-
description:
|
|
21
|
-
default: false
|
|
18
|
+
RoleImport.description = "Import roles";
|
|
19
|
+
RoleImport.flags = Object.assign(Object.assign({ "preserve-anonymous": command_1.flags.boolean({
|
|
20
|
+
description: "Preserve anonymous rights",
|
|
21
|
+
default: false,
|
|
22
22
|
}), help: command_1.flags.help({}) }, kuzzle_1.kuzzleFlags), { protocol: command_1.flags.string({
|
|
23
|
-
description:
|
|
24
|
-
default:
|
|
23
|
+
description: "Kuzzle protocol (http or websocket)",
|
|
24
|
+
default: "ws",
|
|
25
25
|
}) });
|
|
26
|
-
RoleImport.args = [
|
|
27
|
-
{ name: 'path', description: 'Dump file', required: true },
|
|
28
|
-
];
|
|
26
|
+
RoleImport.args = [{ name: "path", description: "Dump file", required: true }];
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { flags } from
|
|
2
|
-
import { Kommand } from
|
|
1
|
+
import { flags } from "@oclif/command";
|
|
2
|
+
import { Kommand } from "../../common";
|
|
3
3
|
declare class SdkExecute extends Kommand {
|
|
4
4
|
static description: string;
|
|
5
5
|
static flags: {
|
|
@@ -10,12 +10,12 @@ declare class SdkExecute extends Kommand {
|
|
|
10
10
|
password: flags.IOptionFlag<string | undefined>;
|
|
11
11
|
protocol: flags.IOptionFlag<string>;
|
|
12
12
|
as: flags.IOptionFlag<string | undefined>;
|
|
13
|
-
|
|
13
|
+
"api-key": flags.IOptionFlag<string | undefined>;
|
|
14
14
|
help: import("@oclif/parser/lib/flags").IBooleanFlag<void>;
|
|
15
15
|
var: flags.IOptionFlag<string[]>;
|
|
16
16
|
editor: import("@oclif/parser/lib/flags").IBooleanFlag<boolean>;
|
|
17
|
-
|
|
18
|
-
|
|
17
|
+
"keep-alive": import("@oclif/parser/lib/flags").IBooleanFlag<boolean>;
|
|
18
|
+
"print-raw": import("@oclif/parser/lib/flags").IBooleanFlag<boolean>;
|
|
19
19
|
};
|
|
20
20
|
static args: {
|
|
21
21
|
name: string;
|
|
@@ -8,25 +8,25 @@ const kuzzle_1 = require("../../support/kuzzle");
|
|
|
8
8
|
class SdkExecute extends common_1.Kommand {
|
|
9
9
|
constructor() {
|
|
10
10
|
super(...arguments);
|
|
11
|
-
this.code =
|
|
11
|
+
this.code = "";
|
|
12
12
|
}
|
|
13
13
|
async beforeConnect() {
|
|
14
|
-
this.code = this.stdin || this.args.code ||
|
|
14
|
+
this.code = this.stdin || this.args.code || "// paste your code here";
|
|
15
15
|
if (this.haveSubscription) {
|
|
16
|
-
this.sdkOptions.protocol =
|
|
16
|
+
this.sdkOptions.protocol = "ws";
|
|
17
17
|
}
|
|
18
18
|
}
|
|
19
19
|
async runSafe() {
|
|
20
20
|
if ((0, lodash_1.isEmpty)(this.code)) {
|
|
21
|
-
throw new Error(
|
|
21
|
+
throw new Error("No code provided.");
|
|
22
22
|
}
|
|
23
23
|
let userError = null;
|
|
24
24
|
const variables = (this.flags.var || [])
|
|
25
25
|
.map((nameValue) => {
|
|
26
|
-
const [name, value] = nameValue.split(
|
|
26
|
+
const [name, value] = nameValue.split("=");
|
|
27
27
|
return ` let ${name} = ${value};`;
|
|
28
28
|
})
|
|
29
|
-
.join(
|
|
29
|
+
.join("\n");
|
|
30
30
|
this.code = `
|
|
31
31
|
(async () => {
|
|
32
32
|
try {
|
|
@@ -59,20 +59,20 @@ ${variables}
|
|
|
59
59
|
this.log(userError.stack);
|
|
60
60
|
}
|
|
61
61
|
else {
|
|
62
|
-
this.logOk(
|
|
62
|
+
this.logOk("Successfully executed SDK code");
|
|
63
63
|
if (result !== undefined) {
|
|
64
64
|
// eslint-disable-next-line no-console
|
|
65
65
|
console.log(JSON.stringify(result, null, 2));
|
|
66
66
|
}
|
|
67
67
|
}
|
|
68
|
-
if (!userError && (this.haveSubscription || this.flags[
|
|
69
|
-
this.logInfo(
|
|
68
|
+
if (!userError && (this.haveSubscription || this.flags["keep-alive"])) {
|
|
69
|
+
this.logInfo("Keep alive for realtime notifications ...");
|
|
70
70
|
// eslint-disable-next-line @typescript-eslint/no-empty-function
|
|
71
71
|
await new Promise(() => { });
|
|
72
72
|
}
|
|
73
73
|
}
|
|
74
74
|
get haveSubscription() {
|
|
75
|
-
return this.code.includes(
|
|
75
|
+
return this.code.includes("sdk.realtime.subscribe");
|
|
76
76
|
}
|
|
77
77
|
}
|
|
78
78
|
SdkExecute.description = `
|
|
@@ -105,18 +105,22 @@ Other
|
|
|
105
105
|
- kourou sdk:execute 'return await sdk.server.now()' --editor
|
|
106
106
|
`;
|
|
107
107
|
SdkExecute.flags = Object.assign({ help: command_1.flags.help(), var: command_1.flags.string({
|
|
108
|
-
char:
|
|
109
|
-
description:
|
|
110
|
-
multiple: true
|
|
108
|
+
char: "v",
|
|
109
|
+
description: "Additional arguments injected into the code. (eg: --var 'index=\"iot-data\"'",
|
|
110
|
+
multiple: true,
|
|
111
111
|
}), editor: command_1.flags.boolean({
|
|
112
|
-
description:
|
|
113
|
-
}),
|
|
114
|
-
description:
|
|
115
|
-
}),
|
|
116
|
-
description:
|
|
112
|
+
description: "Open an editor (EDITOR env variable) to edit the code before executing it.",
|
|
113
|
+
}), "keep-alive": command_1.flags.boolean({
|
|
114
|
+
description: "Keep the connection running (websocket only)",
|
|
115
|
+
}), "print-raw": command_1.flags.boolean({
|
|
116
|
+
description: "Print only the script result to stdout",
|
|
117
117
|
}) }, kuzzle_1.kuzzleFlags);
|
|
118
118
|
SdkExecute.args = [
|
|
119
|
-
{
|
|
119
|
+
{
|
|
120
|
+
name: "code",
|
|
121
|
+
description: "Code to execute. Will be read from STDIN if available.",
|
|
122
|
+
required: false,
|
|
123
|
+
},
|
|
120
124
|
];
|
|
121
125
|
SdkExecute.readStdin = true;
|
|
122
126
|
exports.default = SdkExecute;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { flags } from
|
|
2
|
-
import { Kommand } from
|
|
1
|
+
import { flags } from "@oclif/command";
|
|
2
|
+
import { Kommand } from "../../common";
|
|
3
3
|
declare class SdkQuery extends Kommand {
|
|
4
4
|
static description: string;
|
|
5
5
|
static flags: {
|
|
@@ -10,16 +10,17 @@ declare class SdkQuery extends Kommand {
|
|
|
10
10
|
password: flags.IOptionFlag<string | undefined>;
|
|
11
11
|
protocol: flags.IOptionFlag<string>;
|
|
12
12
|
as: flags.IOptionFlag<string | undefined>;
|
|
13
|
-
|
|
13
|
+
"api-key": flags.IOptionFlag<string | undefined>;
|
|
14
14
|
help: import("@oclif/parser/lib/flags").IBooleanFlag<void>;
|
|
15
15
|
arg: flags.IOptionFlag<string[]>;
|
|
16
16
|
body: flags.IOptionFlag<string>;
|
|
17
17
|
editor: import("@oclif/parser/lib/flags").IBooleanFlag<boolean>;
|
|
18
|
-
|
|
18
|
+
"body-editor": import("@oclif/parser/lib/flags").IBooleanFlag<boolean>;
|
|
19
19
|
index: flags.IOptionFlag<string | undefined>;
|
|
20
20
|
collection: flags.IOptionFlag<string | undefined>;
|
|
21
21
|
id: flags.IOptionFlag<string | undefined>;
|
|
22
22
|
display: flags.IOptionFlag<string>;
|
|
23
|
+
"print-raw": import("@oclif/parser/lib/flags").IBooleanFlag<boolean>;
|
|
23
24
|
};
|
|
24
25
|
static args: {
|
|
25
26
|
name: string;
|
|
@@ -2,39 +2,39 @@
|
|
|
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 lodash_1 = tslib_1.__importDefault(require("lodash"));
|
|
5
|
+
const lodash_1 = (0, tslib_1.__importDefault)(require("lodash"));
|
|
6
6
|
const common_1 = require("../../common");
|
|
7
7
|
const kuzzle_1 = require("../../support/kuzzle");
|
|
8
8
|
class SdkQuery extends common_1.Kommand {
|
|
9
9
|
async runSafe() {
|
|
10
|
-
const [controller, action] = this.args[
|
|
10
|
+
const [controller, action] = this.args["controller:action"].split(":");
|
|
11
11
|
const requestArgs = {};
|
|
12
12
|
requestArgs.index = this.flags.index;
|
|
13
13
|
requestArgs.collection = this.flags.collection;
|
|
14
14
|
requestArgs._id = this.flags.id;
|
|
15
15
|
for (const keyValue of this.flags.arg || []) {
|
|
16
|
-
const key = keyValue.substr(0, keyValue.indexOf(
|
|
17
|
-
const value = keyValue.substr(keyValue.indexOf(
|
|
16
|
+
const key = keyValue.substr(0, keyValue.indexOf("="));
|
|
17
|
+
const value = keyValue.substr(keyValue.indexOf("=") + 1);
|
|
18
18
|
requestArgs[key] = value;
|
|
19
19
|
}
|
|
20
20
|
const body = this.stdin ? this.stdin : this.flags.body;
|
|
21
21
|
let request = Object.assign(Object.assign({ controller,
|
|
22
22
|
action }, requestArgs), { body: this.parseJs(body) });
|
|
23
23
|
// content from user editor
|
|
24
|
-
if (this.flags.editor && this.flags[
|
|
25
|
-
throw new Error(
|
|
24
|
+
if (this.flags.editor && this.flags["body-editor"]) {
|
|
25
|
+
throw new Error("You cannot specify --editor and --body-editor at the same time");
|
|
26
26
|
}
|
|
27
27
|
else if (this.flags.editor) {
|
|
28
28
|
request = this.fromEditor(request, { json: true });
|
|
29
29
|
}
|
|
30
|
-
else if (this.flags[
|
|
30
|
+
else if (this.flags["body-editor"]) {
|
|
31
31
|
request.body = this.fromEditor(request.body, { json: true });
|
|
32
32
|
}
|
|
33
33
|
const response = await this.sdk.query(request);
|
|
34
|
-
const display = this.flags.display ===
|
|
34
|
+
const display = this.flags.display === ""
|
|
35
35
|
? response
|
|
36
36
|
: lodash_1.default.get(response, this.flags.display);
|
|
37
|
-
|
|
37
|
+
console.log(JSON.stringify(display, null, 2));
|
|
38
38
|
this.logOk(`Successfully executed "${controller}:${action}"`);
|
|
39
39
|
}
|
|
40
40
|
}
|
|
@@ -94,30 +94,36 @@ Default fallback to API action
|
|
|
94
94
|
- kourou admin:loadMappings < mappings.json
|
|
95
95
|
`;
|
|
96
96
|
SdkQuery.flags = Object.assign({ help: command_1.flags.help(), arg: command_1.flags.string({
|
|
97
|
-
char:
|
|
97
|
+
char: "a",
|
|
98
98
|
description: 'Additional argument. Repeatable. (e.g. "-a refresh=wait_for")',
|
|
99
|
-
multiple: true
|
|
99
|
+
multiple: true,
|
|
100
100
|
}), body: command_1.flags.string({
|
|
101
|
-
description:
|
|
102
|
-
default:
|
|
101
|
+
description: "Request body in JS or JSON format. Will be read from STDIN if available.",
|
|
102
|
+
default: "{}",
|
|
103
103
|
}), editor: command_1.flags.boolean({
|
|
104
|
-
description:
|
|
105
|
-
}),
|
|
106
|
-
description:
|
|
104
|
+
description: "Open an editor (EDITOR env variable) to edit the request before sending.",
|
|
105
|
+
}), "body-editor": command_1.flags.boolean({
|
|
106
|
+
description: "Open an editor (EDITOR env variable) to edit the body before sending.",
|
|
107
107
|
}), index: command_1.flags.string({
|
|
108
|
-
char:
|
|
109
|
-
description:
|
|
108
|
+
char: "i",
|
|
109
|
+
description: "Index argument",
|
|
110
110
|
}), collection: command_1.flags.string({
|
|
111
|
-
char:
|
|
112
|
-
description:
|
|
111
|
+
char: "c",
|
|
112
|
+
description: "Collection argument",
|
|
113
113
|
}), id: command_1.flags.string({
|
|
114
|
-
description:
|
|
114
|
+
description: "ID argument (_id)",
|
|
115
115
|
}), display: command_1.flags.string({
|
|
116
|
-
description:
|
|
117
|
-
default:
|
|
116
|
+
description: "Path of the property to display from the response (empty string to display the result)",
|
|
117
|
+
default: "result",
|
|
118
|
+
}), "print-raw": command_1.flags.boolean({
|
|
119
|
+
description: "Print only the query result to stdout",
|
|
118
120
|
}) }, kuzzle_1.kuzzleFlags);
|
|
119
121
|
SdkQuery.args = [
|
|
120
|
-
{
|
|
122
|
+
{
|
|
123
|
+
name: "controller:action",
|
|
124
|
+
description: 'Controller and action (eg: "server:now")',
|
|
125
|
+
required: true,
|
|
126
|
+
},
|
|
121
127
|
];
|
|
122
128
|
SdkQuery.readStdin = true;
|
|
123
129
|
exports.default = SdkQuery;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { flags } from
|
|
2
|
-
import { Kommand } from
|
|
1
|
+
import { flags } from "@oclif/command";
|
|
2
|
+
import { Kommand } from "../../common";
|
|
3
3
|
export default class UserExportMappings extends Kommand {
|
|
4
4
|
static description: string;
|
|
5
5
|
static flags: {
|
|
@@ -10,7 +10,7 @@ export default class UserExportMappings extends Kommand {
|
|
|
10
10
|
username: flags.IOptionFlag<string>;
|
|
11
11
|
password: flags.IOptionFlag<string | undefined>;
|
|
12
12
|
as: flags.IOptionFlag<string | undefined>;
|
|
13
|
-
|
|
13
|
+
"api-key": flags.IOptionFlag<string | undefined>;
|
|
14
14
|
help: import("@oclif/parser/lib/flags").IBooleanFlag<void>;
|
|
15
15
|
path: flags.IOptionFlag<string>;
|
|
16
16
|
};
|
|
@@ -1,31 +1,31 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
const tslib_1 = require("tslib");
|
|
4
|
-
const fs_1 = tslib_1.__importDefault(require("fs"));
|
|
5
|
-
const path_1 = tslib_1.__importDefault(require("path"));
|
|
4
|
+
const fs_1 = (0, tslib_1.__importDefault)(require("fs"));
|
|
5
|
+
const path_1 = (0, tslib_1.__importDefault)(require("path"));
|
|
6
6
|
const command_1 = require("@oclif/command");
|
|
7
7
|
const common_1 = require("../../common");
|
|
8
8
|
const kuzzle_1 = require("../../support/kuzzle");
|
|
9
9
|
class UserExportMappings extends common_1.Kommand {
|
|
10
10
|
async runSafe() {
|
|
11
|
-
const filename = path_1.default.join(this.flags.path,
|
|
11
|
+
const filename = path_1.default.join(this.flags.path, "users-collection-mappings.json");
|
|
12
12
|
this.logInfo(`Exporting users collection mappings in ${filename} ...`);
|
|
13
13
|
fs_1.default.mkdirSync(this.flags.path, { recursive: true });
|
|
14
14
|
const mapping = await this.sdk.security.getUserMapping();
|
|
15
15
|
const dump = {
|
|
16
|
-
type:
|
|
17
|
-
content: mapping
|
|
16
|
+
type: "usersMappings",
|
|
17
|
+
content: mapping,
|
|
18
18
|
};
|
|
19
19
|
fs_1.default.writeFileSync(filename, JSON.stringify(dump, null, 2));
|
|
20
|
-
this.logOk(
|
|
20
|
+
this.logOk("Users collection mappings dumped");
|
|
21
21
|
}
|
|
22
22
|
}
|
|
23
23
|
exports.default = UserExportMappings;
|
|
24
|
-
UserExportMappings.description =
|
|
24
|
+
UserExportMappings.description = "Exports users collection mappings to JSON.";
|
|
25
25
|
UserExportMappings.flags = Object.assign(Object.assign({ help: command_1.flags.help({}), path: command_1.flags.string({
|
|
26
|
-
description:
|
|
27
|
-
default:
|
|
26
|
+
description: "Dump directory",
|
|
27
|
+
default: "users",
|
|
28
28
|
}) }, kuzzle_1.kuzzleFlags), { protocol: command_1.flags.string({
|
|
29
|
-
description:
|
|
30
|
-
default:
|
|
29
|
+
description: "Kuzzle protocol (http or websocket)",
|
|
30
|
+
default: "ws",
|
|
31
31
|
}) });
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { flags } from
|
|
2
|
-
import { Kommand } from
|
|
1
|
+
import { flags } from "@oclif/command";
|
|
2
|
+
import { Kommand } from "../../common";
|
|
3
3
|
export default class UserExport extends Kommand {
|
|
4
4
|
static description: string;
|
|
5
5
|
static flags: {
|
|
@@ -10,13 +10,13 @@ export default class UserExport extends Kommand {
|
|
|
10
10
|
username: flags.IOptionFlag<string>;
|
|
11
11
|
password: flags.IOptionFlag<string | undefined>;
|
|
12
12
|
as: flags.IOptionFlag<string | undefined>;
|
|
13
|
-
|
|
13
|
+
"api-key": flags.IOptionFlag<string | undefined>;
|
|
14
14
|
help: import("@oclif/parser/lib/flags").IBooleanFlag<void>;
|
|
15
15
|
path: flags.IOptionFlag<string>;
|
|
16
16
|
exclude: flags.IOptionFlag<string[]>;
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
17
|
+
"generate-credentials": import("@oclif/parser/lib/flags").IBooleanFlag<boolean>;
|
|
18
|
+
"generated-username": flags.IOptionFlag<string>;
|
|
19
|
+
"batch-size": flags.IOptionFlag<string>;
|
|
20
20
|
};
|
|
21
21
|
private excludes;
|
|
22
22
|
beforeConnect(): Promise<void>;
|
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
const tslib_1 = require("tslib");
|
|
4
|
-
const fs_1 = tslib_1.__importDefault(require("fs"));
|
|
5
|
-
const lodash_1 = tslib_1.__importDefault(require("lodash"));
|
|
6
|
-
const crypto_1 = tslib_1.__importDefault(require("crypto"));
|
|
7
|
-
const path_1 = tslib_1.__importDefault(require("path"));
|
|
4
|
+
const fs_1 = (0, tslib_1.__importDefault)(require("fs"));
|
|
5
|
+
const lodash_1 = (0, tslib_1.__importDefault)(require("lodash"));
|
|
6
|
+
const crypto_1 = (0, tslib_1.__importDefault)(require("crypto"));
|
|
7
|
+
const path_1 = (0, tslib_1.__importDefault)(require("path"));
|
|
8
8
|
const command_1 = require("@oclif/command");
|
|
9
9
|
const common_1 = require("../../common");
|
|
10
10
|
const kuzzle_1 = require("../../support/kuzzle");
|
|
11
11
|
function randomPassword() {
|
|
12
|
-
return crypto_1.default.randomBytes(20).toString(
|
|
12
|
+
return crypto_1.default.randomBytes(20).toString("hex");
|
|
13
13
|
}
|
|
14
14
|
class UserExport extends common_1.Kommand {
|
|
15
15
|
constructor() {
|
|
@@ -17,45 +17,46 @@ class UserExport extends common_1.Kommand {
|
|
|
17
17
|
this.excludes = [];
|
|
18
18
|
}
|
|
19
19
|
async beforeConnect() {
|
|
20
|
-
if (this.flags[
|
|
20
|
+
if (this.flags["generated-username"] !== "_id" &&
|
|
21
|
+
!this.flags["generate-credentials"]) {
|
|
21
22
|
throw new Error('The "--generated-username" cannot be used without "--generate-credentials"');
|
|
22
23
|
}
|
|
23
24
|
}
|
|
24
25
|
async runSafe() {
|
|
25
|
-
const filename = path_1.default.join(this.flags.path,
|
|
26
|
+
const filename = path_1.default.join(this.flags.path, "users.json");
|
|
26
27
|
this.logInfo(`Exporting users in ${filename} ...`);
|
|
27
28
|
fs_1.default.mkdirSync(this.flags.path, { recursive: true });
|
|
28
29
|
this.excludes = this.flags.exclude || [];
|
|
29
30
|
const users = await this._dumpUsers();
|
|
30
31
|
const dump = {
|
|
31
|
-
type:
|
|
32
|
-
content: users
|
|
32
|
+
type: "users",
|
|
33
|
+
content: users,
|
|
33
34
|
};
|
|
34
35
|
fs_1.default.writeFileSync(filename, JSON.stringify(dump, null, 2));
|
|
35
36
|
this.logOk(`${Object.keys(users).length} users dumped`);
|
|
36
|
-
if (this.flags[
|
|
37
|
-
this.logOk(
|
|
37
|
+
if (this.flags["generate-credentials"]) {
|
|
38
|
+
this.logOk("Credentials have been generated");
|
|
38
39
|
}
|
|
39
40
|
}
|
|
40
41
|
async _dumpUsers() {
|
|
41
42
|
const users = {};
|
|
42
|
-
let results = await this.sdk.security.searchUsers({}, { scroll:
|
|
43
|
+
let results = await this.sdk.security.searchUsers({}, { scroll: "5s", size: this.flags["batch-size"] });
|
|
43
44
|
while (results) {
|
|
44
45
|
for (const user of results.hits) {
|
|
45
|
-
const shouldInclude = this.excludes.every((exclude) =>
|
|
46
|
+
const shouldInclude = this.excludes.every((exclude) => !user._id.match(new RegExp(exclude)));
|
|
46
47
|
if (!shouldInclude) {
|
|
47
48
|
continue;
|
|
48
49
|
}
|
|
49
50
|
users[user._id] = {
|
|
50
|
-
content: lodash_1.default.omit(user.content, [
|
|
51
|
-
credentials: {}
|
|
51
|
+
content: lodash_1.default.omit(user.content, ["_kuzzle_info"]),
|
|
52
|
+
credentials: {},
|
|
52
53
|
};
|
|
53
|
-
if (this.flags[
|
|
54
|
-
let username = `${lodash_1.default.get(user, this.flags[
|
|
54
|
+
if (this.flags["generate-credentials"]) {
|
|
55
|
+
let username = `${lodash_1.default.get(user, this.flags["generated-username"])}`;
|
|
55
56
|
const password = randomPassword();
|
|
56
57
|
// Check for empty string or undefined property converted to string
|
|
57
|
-
if (lodash_1.default.isEmpty(username) || username ===
|
|
58
|
-
this.logInfo(`User ${user._id} does not have a "${this.flags[
|
|
58
|
+
if (lodash_1.default.isEmpty(username) || username === "undefined") {
|
|
59
|
+
this.logInfo(`User ${user._id} does not have a "${this.flags["generated-username"]}" property. Use user ID instead.`);
|
|
59
60
|
username = user._id;
|
|
60
61
|
}
|
|
61
62
|
users[user._id].credentials.local = { username, password };
|
|
@@ -92,20 +93,20 @@ Examples:
|
|
|
92
93
|
- kourou user:export --generate-credentials --generated-username content.email
|
|
93
94
|
`;
|
|
94
95
|
UserExport.flags = Object.assign(Object.assign({ help: command_1.flags.help({}), path: command_1.flags.string({
|
|
95
|
-
description:
|
|
96
|
-
default:
|
|
96
|
+
description: "Dump directory",
|
|
97
|
+
default: "users",
|
|
97
98
|
}), exclude: command_1.flags.string({
|
|
98
|
-
description:
|
|
99
|
-
multiple: true
|
|
100
|
-
}),
|
|
101
|
-
description:
|
|
102
|
-
}),
|
|
103
|
-
description:
|
|
104
|
-
default:
|
|
105
|
-
}),
|
|
106
|
-
description:
|
|
107
|
-
default:
|
|
99
|
+
description: "Exclude users by matching their IDs with a regexp",
|
|
100
|
+
multiple: true,
|
|
101
|
+
}), "generate-credentials": command_1.flags.boolean({
|
|
102
|
+
description: "Generate credentials with a random password for users",
|
|
103
|
+
}), "generated-username": command_1.flags.string({
|
|
104
|
+
description: "User content property used as a username for local credentials",
|
|
105
|
+
default: "_id",
|
|
106
|
+
}), "batch-size": command_1.flags.string({
|
|
107
|
+
description: "Maximum batch size (see limits.documentsFetchCount config)",
|
|
108
|
+
default: "2000",
|
|
108
109
|
}) }, kuzzle_1.kuzzleFlags), { protocol: command_1.flags.string({
|
|
109
|
-
description:
|
|
110
|
-
default:
|
|
110
|
+
description: "Kuzzle protocol (http or websocket)",
|
|
111
|
+
default: "ws",
|
|
111
112
|
}) });
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { flags } from
|
|
2
|
-
import { Kommand } from
|
|
1
|
+
import { flags } from "@oclif/command";
|
|
2
|
+
import { Kommand } from "../../common";
|
|
3
3
|
export default class UserImportMappings extends Kommand {
|
|
4
4
|
static description: string;
|
|
5
5
|
static flags: {
|
|
@@ -10,7 +10,7 @@ export default class UserImportMappings extends Kommand {
|
|
|
10
10
|
username: flags.IOptionFlag<string>;
|
|
11
11
|
password: flags.IOptionFlag<string | undefined>;
|
|
12
12
|
as: flags.IOptionFlag<string | undefined>;
|
|
13
|
-
|
|
13
|
+
"api-key": flags.IOptionFlag<string | undefined>;
|
|
14
14
|
help: import("@oclif/parser/lib/flags").IBooleanFlag<void>;
|
|
15
15
|
};
|
|
16
16
|
static args: {
|
|
@@ -2,22 +2,22 @@
|
|
|
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 = tslib_1.__importDefault(require("fs"));
|
|
5
|
+
const fs_1 = (0, tslib_1.__importDefault)(require("fs"));
|
|
6
6
|
const common_1 = require("../../common");
|
|
7
7
|
const kuzzle_1 = require("../../support/kuzzle");
|
|
8
8
|
class UserImportMappings extends common_1.Kommand {
|
|
9
9
|
async runSafe() {
|
|
10
10
|
this.logInfo(`Importing users collection mappings from ${this.args.path} ...`);
|
|
11
|
-
const dump = JSON.parse(fs_1.default.readFileSync(this.args.path,
|
|
11
|
+
const dump = JSON.parse(fs_1.default.readFileSync(this.args.path, "utf-8"));
|
|
12
12
|
const mapping = dump.content.mapping;
|
|
13
13
|
await this.sdk.security.updateUserMapping({ properties: mapping });
|
|
14
|
-
this.logOk(
|
|
14
|
+
this.logOk("Users collecction mappings restored");
|
|
15
15
|
}
|
|
16
16
|
}
|
|
17
17
|
exports.default = UserImportMappings;
|
|
18
|
-
UserImportMappings.description =
|
|
18
|
+
UserImportMappings.description = "Imports users collection mappings";
|
|
19
19
|
UserImportMappings.flags = Object.assign(Object.assign({ help: command_1.flags.help({}) }, kuzzle_1.kuzzleFlags), { protocol: command_1.flags.string({
|
|
20
|
-
description:
|
|
21
|
-
default:
|
|
20
|
+
description: "Kuzzle protocol (http or websocket)",
|
|
21
|
+
default: "ws",
|
|
22
22
|
}) });
|
|
23
|
-
UserImportMappings.args = [{ name:
|
|
23
|
+
UserImportMappings.args = [{ name: "path", description: "Dump file", required: true }];
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { flags } from
|
|
2
|
-
import { Kommand } from
|
|
1
|
+
import { flags } from "@oclif/command";
|
|
2
|
+
import { Kommand } from "../../common";
|
|
3
3
|
export default class UserImport extends Kommand {
|
|
4
4
|
static description: string;
|
|
5
5
|
static flags: {
|
|
@@ -10,7 +10,7 @@ export default class UserImport extends Kommand {
|
|
|
10
10
|
username: flags.IOptionFlag<string>;
|
|
11
11
|
password: flags.IOptionFlag<string | undefined>;
|
|
12
12
|
as: flags.IOptionFlag<string | undefined>;
|
|
13
|
-
|
|
13
|
+
"api-key": flags.IOptionFlag<string | undefined>;
|
|
14
14
|
help: import("@oclif/parser/lib/flags").IBooleanFlag<void>;
|
|
15
15
|
};
|
|
16
16
|
static args: {
|