kuzzle 2.17.8 → 2.19.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/index.d.ts +1 -0
- package/index.js +3 -0
- package/lib/api/controllers/adminController.js +9 -0
- package/lib/api/controllers/authController.js +8 -2
- package/lib/api/controllers/debugController.d.ts +59 -0
- package/lib/api/controllers/debugController.js +285 -0
- package/lib/api/controllers/documentController.js +49 -31
- package/lib/api/controllers/index.js +1 -0
- package/lib/api/controllers/indexController.js +10 -6
- package/lib/api/controllers/securityController.js +81 -43
- package/lib/api/controllers/serverController.js +2 -1
- package/lib/api/documentExtractor.js +51 -9
- package/lib/api/funnel.js +30 -8
- package/lib/api/httpRoutes.js +8 -1
- package/lib/api/openapi/OpenApiManager.js +3 -0
- package/lib/api/openapi/components/document/get.yaml +1 -1
- package/lib/api/openapi/components/document/update.yaml +1 -1
- package/lib/api/openapi/components/index.d.ts +1 -0
- package/lib/api/openapi/components/index.js +1 -0
- package/lib/api/openapi/components/security/index.d.ts +2 -0
- package/lib/api/openapi/components/security/index.js +10 -0
- package/lib/api/openapi/components/security/upsertUser.yaml +59 -0
- package/lib/api/request/kuzzleRequest.d.ts +58 -4
- package/lib/api/request/kuzzleRequest.js +163 -31
- package/lib/api/request/requestResponse.js +25 -0
- package/lib/cluster/idCardHandler.js +1 -1
- package/lib/config/default.config.js +3 -0
- package/lib/config/documentEventAliases.d.ts +7 -0
- package/lib/config/documentEventAliases.js +26 -12
- package/lib/core/backend/backend.d.ts +4 -0
- package/lib/core/backend/backend.js +9 -0
- package/lib/core/backend/backendController.d.ts +7 -1
- package/lib/core/backend/backendController.js +15 -3
- package/lib/core/network/protocols/httpwsProtocol.js +14 -6
- package/lib/core/plugin/plugin.js +7 -0
- package/lib/core/shared/sdk/embeddedSdk.d.ts +3 -3
- package/lib/core/shared/sdk/embeddedSdk.js +33 -0
- package/lib/core/shared/sdk/funnelProtocol.d.ts +1 -2
- package/lib/kerror/codes/0-core.json +35 -0
- package/lib/kerror/codes/1-services.json +1 -1
- package/lib/kerror/codes/2-api.json +6 -0
- package/lib/kerror/errors/kuzzleError.d.ts +1 -1
- package/lib/kuzzle/kuzzle.d.ts +1 -1
- package/lib/kuzzle/kuzzle.js +27 -8
- package/lib/model/security/user.js +5 -6
- package/lib/model/storage/apiKey.js +1 -6
- package/lib/service/storage/elasticsearch.js +143 -47
- package/lib/types/DebugModule.d.ts +23 -0
- package/lib/types/DebugModule.js +39 -0
- package/lib/types/config/SecurityConfiguration.d.ts +10 -0
- package/lib/types/index.d.ts +0 -1
- package/lib/types/index.js +0 -1
- package/lib/util/crypto.d.ts +1 -0
- package/lib/util/crypto.js +12 -0
- package/lib/util/dump-collection.d.ts +35 -0
- package/lib/util/dump-collection.js +11 -8
- package/lib/util/name-generator.d.ts +79 -0
- package/lib/util/name-generator.js +1409 -1345
- package/lib/util/time.d.ts +1 -0
- package/lib/util/time.js +9 -0
- package/package.json +19 -21
- package/lib/core/security/README.md +0 -224
- package/lib/core/shared/README.md +0 -3
- package/package-lock.json +0 -8403
package/index.d.ts
CHANGED
|
@@ -6,5 +6,6 @@ export * from './lib/api/request';
|
|
|
6
6
|
export * from './lib/kerror/errors';
|
|
7
7
|
export * from './lib/util/mutex';
|
|
8
8
|
export * from './lib/util/inflector';
|
|
9
|
+
export { NameGenerator } from './lib/util/name-generator';
|
|
9
10
|
export * from 'kuzzle-sdk';
|
|
10
11
|
export * from './lib/core/shared/KoncordeWrapper';
|
package/index.js
CHANGED
|
@@ -14,6 +14,7 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
|
14
14
|
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
15
|
};
|
|
16
16
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
exports.NameGenerator = void 0;
|
|
17
18
|
__exportStar(require("./lib/core/backend"), exports);
|
|
18
19
|
__exportStar(require("./lib/types"), exports);
|
|
19
20
|
__exportStar(require("./lib/core/plugin/pluginContext"), exports);
|
|
@@ -22,6 +23,8 @@ __exportStar(require("./lib/api/request"), exports);
|
|
|
22
23
|
__exportStar(require("./lib/kerror/errors"), exports);
|
|
23
24
|
__exportStar(require("./lib/util/mutex"), exports);
|
|
24
25
|
__exportStar(require("./lib/util/inflector"), exports);
|
|
26
|
+
var name_generator_1 = require("./lib/util/name-generator");
|
|
27
|
+
Object.defineProperty(exports, "NameGenerator", { enumerable: true, get: function () { return name_generator_1.NameGenerator; } });
|
|
25
28
|
__exportStar(require("kuzzle-sdk"), exports);
|
|
26
29
|
__exportStar(require("./lib/core/shared/KoncordeWrapper"), exports);
|
|
27
30
|
//# sourceMappingURL=index.js.map
|
|
@@ -26,6 +26,7 @@ const Bluebird = require('bluebird');
|
|
|
26
26
|
const kerror = require('../../kerror');
|
|
27
27
|
const { NativeController } = require('./baseController');
|
|
28
28
|
const { Mutex } = require('../../util/mutex');
|
|
29
|
+
const { BACKEND_IMPORT_KEY } = require('../../kuzzle/kuzzle');
|
|
29
30
|
|
|
30
31
|
/**
|
|
31
32
|
* @class AdminController
|
|
@@ -97,6 +98,10 @@ class AdminController extends NativeController {
|
|
|
97
98
|
options);
|
|
98
99
|
|
|
99
100
|
await global.kuzzle.internalIndex.createInitialSecurities();
|
|
101
|
+
|
|
102
|
+
await this.ask(
|
|
103
|
+
'core:cache:internal:del',
|
|
104
|
+
`${BACKEND_IMPORT_KEY}:permissions`);
|
|
100
105
|
}
|
|
101
106
|
finally {
|
|
102
107
|
await mutex.unlock();
|
|
@@ -119,6 +124,10 @@ class AdminController extends NativeController {
|
|
|
119
124
|
const indexes = await this.ask('core:storage:public:index:list');
|
|
120
125
|
await this.ask('core:storage:public:index:mDelete', indexes);
|
|
121
126
|
|
|
127
|
+
await this.ask(
|
|
128
|
+
'core:cache:internal:del',
|
|
129
|
+
`${BACKEND_IMPORT_KEY}:mappings`);
|
|
130
|
+
|
|
122
131
|
return { acknowledge: true };
|
|
123
132
|
}
|
|
124
133
|
finally {
|
|
@@ -35,6 +35,7 @@ const { NativeController } = require('./baseController');
|
|
|
35
35
|
const formatProcessing = require('../../core/auth/formatProcessing');
|
|
36
36
|
const { User } = require('../../model/security/user');
|
|
37
37
|
const ApiKey = require('../../model/storage/apiKey');
|
|
38
|
+
const SecurityController = require('./securityController');
|
|
38
39
|
|
|
39
40
|
/**
|
|
40
41
|
* @class AuthController
|
|
@@ -471,7 +472,7 @@ class AuthController extends NativeController {
|
|
|
471
472
|
userId,
|
|
472
473
|
});
|
|
473
474
|
|
|
474
|
-
global.kuzzle.log.info(`[SECURITY]
|
|
475
|
+
global.kuzzle.log.info(`[SECURITY] ${SecurityController.userOrSdk(userId)} applied action "${request.input.action}" on user "${userId}."`);
|
|
475
476
|
|
|
476
477
|
return formatProcessing.serializeUser(user);
|
|
477
478
|
}
|
|
@@ -646,7 +647,12 @@ class AuthController extends NativeController {
|
|
|
646
647
|
|
|
647
648
|
assertIsAuthenticated (request) {
|
|
648
649
|
if (request.context.user._id === this.anonymousId) {
|
|
649
|
-
throw kerror.get(
|
|
650
|
+
throw kerror.get(
|
|
651
|
+
'security',
|
|
652
|
+
'rights',
|
|
653
|
+
'unauthorized',
|
|
654
|
+
request.input.controller,
|
|
655
|
+
request.input.action);
|
|
650
656
|
}
|
|
651
657
|
}
|
|
652
658
|
}
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import { KuzzleRequest } from '../request';
|
|
2
|
+
import { NativeController } from './baseController';
|
|
3
|
+
/**
|
|
4
|
+
* @class DebugController
|
|
5
|
+
*/
|
|
6
|
+
export declare class DebugController extends NativeController {
|
|
7
|
+
private inspector;
|
|
8
|
+
private debuggerStatus;
|
|
9
|
+
/**
|
|
10
|
+
* Map<eventName, Set<connectionId>>
|
|
11
|
+
*/
|
|
12
|
+
private events;
|
|
13
|
+
/**
|
|
14
|
+
* Map of functions from the DebugModules
|
|
15
|
+
*/
|
|
16
|
+
private kuzzlePostMethods;
|
|
17
|
+
/**
|
|
18
|
+
* List of DebugModule for DebugController
|
|
19
|
+
* Used to add new methods and events to the protocol
|
|
20
|
+
*/
|
|
21
|
+
private modules;
|
|
22
|
+
constructor();
|
|
23
|
+
init(): Promise<void>;
|
|
24
|
+
nodeVersion(): Promise<string>;
|
|
25
|
+
/**
|
|
26
|
+
* Connect the debugger
|
|
27
|
+
*/
|
|
28
|
+
enable(): Promise<void>;
|
|
29
|
+
/**
|
|
30
|
+
* Disconnect the debugger and clears all the events listeners
|
|
31
|
+
*/
|
|
32
|
+
disable(): Promise<void>;
|
|
33
|
+
/**
|
|
34
|
+
* Trigger action from debugger directly following the Chrome Debug Protocol
|
|
35
|
+
* See: https://chromedevtools.github.io/devtools-protocol/v8/
|
|
36
|
+
*/
|
|
37
|
+
post(request: KuzzleRequest): Promise<any>;
|
|
38
|
+
/**
|
|
39
|
+
* Make the websocket connection listen and receive events from Chrome Debug Protocol
|
|
40
|
+
* See events from: https://chromedevtools.github.io/devtools-protocol/v8/
|
|
41
|
+
*/
|
|
42
|
+
addListener(request: KuzzleRequest): Promise<void>;
|
|
43
|
+
/**
|
|
44
|
+
* Remove the websocket connection from the events' listeners
|
|
45
|
+
*/
|
|
46
|
+
removeListener(request: KuzzleRequest): Promise<void>;
|
|
47
|
+
/**
|
|
48
|
+
* Execute a method using the Chrome Debug Protocol
|
|
49
|
+
* @param method Chrome Debug Protocol method to execute
|
|
50
|
+
* @param params
|
|
51
|
+
* @returns
|
|
52
|
+
*/
|
|
53
|
+
private inspectorPost;
|
|
54
|
+
/**
|
|
55
|
+
* Sends a direct notification to a websocket connection without having to listen to a specific room
|
|
56
|
+
*/
|
|
57
|
+
private notifyConnection;
|
|
58
|
+
private notifyGlobalListeners;
|
|
59
|
+
}
|
|
@@ -0,0 +1,285 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/*
|
|
3
|
+
* Kuzzle, a backend software, self-hostable and ready to use
|
|
4
|
+
* to power modern apps
|
|
5
|
+
*
|
|
6
|
+
* Copyright 2015-2022 Kuzzle
|
|
7
|
+
* mailto: support AT kuzzle.io
|
|
8
|
+
* website: http://kuzzle.io
|
|
9
|
+
*
|
|
10
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
11
|
+
* you may not use this file except in compliance with the License.
|
|
12
|
+
* You may obtain a copy of the License at
|
|
13
|
+
*
|
|
14
|
+
* https://www.apache.org/licenses/LICENSE-2.0
|
|
15
|
+
*
|
|
16
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
17
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
18
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
19
|
+
* See the License for the specific language governing permissions and
|
|
20
|
+
* limitations under the License.
|
|
21
|
+
*/
|
|
22
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
23
|
+
if (k2 === undefined) k2 = k;
|
|
24
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
25
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
26
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
27
|
+
}
|
|
28
|
+
Object.defineProperty(o, k2, desc);
|
|
29
|
+
}) : (function(o, m, k, k2) {
|
|
30
|
+
if (k2 === undefined) k2 = k;
|
|
31
|
+
o[k2] = m[k];
|
|
32
|
+
}));
|
|
33
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
34
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
35
|
+
}) : function(o, v) {
|
|
36
|
+
o["default"] = v;
|
|
37
|
+
});
|
|
38
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
39
|
+
if (mod && mod.__esModule) return mod;
|
|
40
|
+
var result = {};
|
|
41
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
42
|
+
__setModuleDefault(result, mod);
|
|
43
|
+
return result;
|
|
44
|
+
};
|
|
45
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
46
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
47
|
+
};
|
|
48
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
49
|
+
exports.DebugController = void 0;
|
|
50
|
+
const baseController_1 = require("./baseController");
|
|
51
|
+
const inspector_1 = __importDefault(require("inspector"));
|
|
52
|
+
const kerror = __importStar(require("../../kerror"));
|
|
53
|
+
const get_1 = __importDefault(require("lodash/get"));
|
|
54
|
+
const DEBUGGER_EVENT = 'kuzzle-debugger-event';
|
|
55
|
+
/**
|
|
56
|
+
* @class DebugController
|
|
57
|
+
*/
|
|
58
|
+
class DebugController extends baseController_1.NativeController {
|
|
59
|
+
constructor() {
|
|
60
|
+
super([
|
|
61
|
+
'nodeVersion',
|
|
62
|
+
'enable',
|
|
63
|
+
'disable',
|
|
64
|
+
'post',
|
|
65
|
+
'addListener',
|
|
66
|
+
'removeListener',
|
|
67
|
+
]);
|
|
68
|
+
this.debuggerStatus = false;
|
|
69
|
+
/**
|
|
70
|
+
* Map<eventName, Set<connectionId>>
|
|
71
|
+
*/
|
|
72
|
+
this.events = new Map();
|
|
73
|
+
/**
|
|
74
|
+
* Map of functions from the DebugModules
|
|
75
|
+
*/
|
|
76
|
+
this.kuzzlePostMethods = new Map();
|
|
77
|
+
/**
|
|
78
|
+
* List of DebugModule for DebugController
|
|
79
|
+
* Used to add new methods and events to the protocol
|
|
80
|
+
*/
|
|
81
|
+
this.modules = [];
|
|
82
|
+
}
|
|
83
|
+
async init() {
|
|
84
|
+
super.init();
|
|
85
|
+
this.inspector = new inspector_1.default.Session();
|
|
86
|
+
// Remove connection id from the list of listeners for each event
|
|
87
|
+
global.kuzzle.on('connection:remove', connectionId => {
|
|
88
|
+
if (!this.debuggerStatus) {
|
|
89
|
+
return;
|
|
90
|
+
}
|
|
91
|
+
for (const listener of this.events.values()) {
|
|
92
|
+
listener.delete(connectionId);
|
|
93
|
+
}
|
|
94
|
+
});
|
|
95
|
+
this.inspector.on('inspectorNotification', async (payload) => {
|
|
96
|
+
if (!this.debuggerStatus) {
|
|
97
|
+
return;
|
|
98
|
+
}
|
|
99
|
+
await this.notifyGlobalListeners(payload.method, payload);
|
|
100
|
+
const listeners = this.events.get(payload.method);
|
|
101
|
+
if (!listeners) {
|
|
102
|
+
return;
|
|
103
|
+
}
|
|
104
|
+
const promises = [];
|
|
105
|
+
for (const connectionId of listeners) {
|
|
106
|
+
promises.push(this.notifyConnection(connectionId, DEBUGGER_EVENT, {
|
|
107
|
+
event: payload.method,
|
|
108
|
+
result: payload
|
|
109
|
+
}));
|
|
110
|
+
}
|
|
111
|
+
// No need to catch, notify is already try-catched
|
|
112
|
+
await Promise.all(promises);
|
|
113
|
+
});
|
|
114
|
+
}
|
|
115
|
+
async nodeVersion() {
|
|
116
|
+
return process.version;
|
|
117
|
+
}
|
|
118
|
+
/**
|
|
119
|
+
* Connect the debugger
|
|
120
|
+
*/
|
|
121
|
+
async enable() {
|
|
122
|
+
if (this.debuggerStatus) {
|
|
123
|
+
return;
|
|
124
|
+
}
|
|
125
|
+
this.inspector.connect();
|
|
126
|
+
this.debuggerStatus = true;
|
|
127
|
+
for (const module of this.modules) {
|
|
128
|
+
await module.init(this.inspector);
|
|
129
|
+
for (const methodName of module.methods) {
|
|
130
|
+
if (!module[methodName]) {
|
|
131
|
+
throw new Error(`Missing implementation of method "${methodName}" inside DebugModule "${module.name}"`);
|
|
132
|
+
}
|
|
133
|
+
this.kuzzlePostMethods.set(`Kuzzle.${module.name}.${methodName}`, module[methodName].bind(module));
|
|
134
|
+
}
|
|
135
|
+
for (const eventName of module.events) {
|
|
136
|
+
module.on(eventName, async (payload) => {
|
|
137
|
+
if (!this.debuggerStatus) {
|
|
138
|
+
return;
|
|
139
|
+
}
|
|
140
|
+
const event = `Kuzzle.${module.name}.${eventName}`;
|
|
141
|
+
await this.notifyGlobalListeners(event, payload);
|
|
142
|
+
const listeners = this.events.get(event);
|
|
143
|
+
if (!listeners) {
|
|
144
|
+
return;
|
|
145
|
+
}
|
|
146
|
+
const promises = [];
|
|
147
|
+
for (const connectionId of listeners) {
|
|
148
|
+
promises.push(this.notifyConnection(connectionId, DEBUGGER_EVENT, {
|
|
149
|
+
event,
|
|
150
|
+
result: payload
|
|
151
|
+
}));
|
|
152
|
+
}
|
|
153
|
+
// No need to catch, notify is already try-catched
|
|
154
|
+
await Promise.all(promises);
|
|
155
|
+
});
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
/**
|
|
160
|
+
* Disconnect the debugger and clears all the events listeners
|
|
161
|
+
*/
|
|
162
|
+
async disable() {
|
|
163
|
+
if (!this.debuggerStatus) {
|
|
164
|
+
return;
|
|
165
|
+
}
|
|
166
|
+
for (const module of this.modules) {
|
|
167
|
+
for (const eventName of module.events) {
|
|
168
|
+
module.removeAllListeners(eventName);
|
|
169
|
+
}
|
|
170
|
+
await module.cleanup();
|
|
171
|
+
}
|
|
172
|
+
this.inspector.disconnect();
|
|
173
|
+
this.debuggerStatus = false;
|
|
174
|
+
this.events.clear();
|
|
175
|
+
this.kuzzlePostMethods.clear();
|
|
176
|
+
}
|
|
177
|
+
/**
|
|
178
|
+
* Trigger action from debugger directly following the Chrome Debug Protocol
|
|
179
|
+
* See: https://chromedevtools.github.io/devtools-protocol/v8/
|
|
180
|
+
*/
|
|
181
|
+
async post(request) {
|
|
182
|
+
if (!this.debuggerStatus) {
|
|
183
|
+
throw kerror.get('core', 'debugger', 'not_enabled');
|
|
184
|
+
}
|
|
185
|
+
const method = request.getBodyString('method');
|
|
186
|
+
const params = request.getBodyObject('params', {});
|
|
187
|
+
if (method.startsWith('Kuzzle.')) {
|
|
188
|
+
const debugModuleMethod = this.kuzzlePostMethods.get(method);
|
|
189
|
+
if (debugModuleMethod) {
|
|
190
|
+
return debugModuleMethod(params);
|
|
191
|
+
}
|
|
192
|
+
throw kerror.get('core', 'debugger', 'method_not_found', method);
|
|
193
|
+
}
|
|
194
|
+
if (!(0, get_1.default)(global.kuzzle.config, 'security.debug.native_debug_protocol')) {
|
|
195
|
+
throw kerror.get('core', 'debugger', 'native_debug_protocol_usage_denied');
|
|
196
|
+
}
|
|
197
|
+
return this.inspectorPost(method, params);
|
|
198
|
+
}
|
|
199
|
+
/**
|
|
200
|
+
* Make the websocket connection listen and receive events from Chrome Debug Protocol
|
|
201
|
+
* See events from: https://chromedevtools.github.io/devtools-protocol/v8/
|
|
202
|
+
*/
|
|
203
|
+
async addListener(request) {
|
|
204
|
+
if (request.context.connection.protocol !== 'websocket') {
|
|
205
|
+
throw kerror.get('api', 'assert', 'unsupported_protocol', request.context.connection.protocol, 'debug:addListener');
|
|
206
|
+
}
|
|
207
|
+
if (!this.debuggerStatus) {
|
|
208
|
+
throw kerror.get('core', 'debugger', 'not_enabled');
|
|
209
|
+
}
|
|
210
|
+
const event = request.getBodyString('event');
|
|
211
|
+
let listeners = this.events.get(event);
|
|
212
|
+
if (!listeners) {
|
|
213
|
+
listeners = new Set();
|
|
214
|
+
this.events.set(event, listeners);
|
|
215
|
+
}
|
|
216
|
+
listeners.add(request.context.connection.id);
|
|
217
|
+
}
|
|
218
|
+
/**
|
|
219
|
+
* Remove the websocket connection from the events' listeners
|
|
220
|
+
*/
|
|
221
|
+
async removeListener(request) {
|
|
222
|
+
if (request.context.connection.protocol !== 'websocket') {
|
|
223
|
+
throw kerror.get('api', 'assert', 'unsupported_protocol', request.context.connection.protocol, 'debug:removeListener');
|
|
224
|
+
}
|
|
225
|
+
if (!this.debuggerStatus) {
|
|
226
|
+
throw kerror.get('core', 'debugger', 'not_enabled');
|
|
227
|
+
}
|
|
228
|
+
const event = request.getBodyString('event');
|
|
229
|
+
const listeners = this.events.get(event);
|
|
230
|
+
if (listeners) {
|
|
231
|
+
listeners.delete(request.context.connection.id);
|
|
232
|
+
}
|
|
233
|
+
}
|
|
234
|
+
/**
|
|
235
|
+
* Execute a method using the Chrome Debug Protocol
|
|
236
|
+
* @param method Chrome Debug Protocol method to execute
|
|
237
|
+
* @param params
|
|
238
|
+
* @returns
|
|
239
|
+
*/
|
|
240
|
+
async inspectorPost(method, params) {
|
|
241
|
+
if (!this.debuggerStatus) {
|
|
242
|
+
throw kerror.get('core', 'debugger', 'not_enabled');
|
|
243
|
+
}
|
|
244
|
+
let resolve;
|
|
245
|
+
const promise = new Promise(res => {
|
|
246
|
+
resolve = res;
|
|
247
|
+
});
|
|
248
|
+
this.inspector.post(method, params, (err, res) => {
|
|
249
|
+
if (err) {
|
|
250
|
+
resolve({ error: JSON.stringify(Object.getOwnPropertyDescriptors(err)) });
|
|
251
|
+
}
|
|
252
|
+
else {
|
|
253
|
+
resolve(res);
|
|
254
|
+
}
|
|
255
|
+
});
|
|
256
|
+
return promise;
|
|
257
|
+
}
|
|
258
|
+
/**
|
|
259
|
+
* Sends a direct notification to a websocket connection without having to listen to a specific room
|
|
260
|
+
*/
|
|
261
|
+
async notifyConnection(connectionId, event, payload) {
|
|
262
|
+
global.kuzzle.entryPoint._notify({
|
|
263
|
+
channels: [event],
|
|
264
|
+
connectionId,
|
|
265
|
+
payload,
|
|
266
|
+
});
|
|
267
|
+
}
|
|
268
|
+
async notifyGlobalListeners(event, payload) {
|
|
269
|
+
const listeners = this.events.get('*');
|
|
270
|
+
if (!listeners) {
|
|
271
|
+
return;
|
|
272
|
+
}
|
|
273
|
+
const promises = [];
|
|
274
|
+
for (const connectionId of listeners) {
|
|
275
|
+
promises.push(this.notifyConnection(connectionId, DEBUGGER_EVENT, {
|
|
276
|
+
event,
|
|
277
|
+
result: payload
|
|
278
|
+
}));
|
|
279
|
+
}
|
|
280
|
+
// No need to catch, notify is already try-catched
|
|
281
|
+
await Promise.all(promises);
|
|
282
|
+
}
|
|
283
|
+
}
|
|
284
|
+
exports.DebugController = DebugController;
|
|
285
|
+
//# sourceMappingURL=debugController.js.map
|
|
@@ -30,37 +30,51 @@ const {
|
|
|
30
30
|
} = require('../../util/requestAssertions');
|
|
31
31
|
const extractFields = require('../../util/extractFields');
|
|
32
32
|
const { dumpCollectionDocuments } = require('../../util/dump-collection');
|
|
33
|
+
/**
|
|
34
|
+
* @description actions available on the document Controller (used by generic events)
|
|
35
|
+
* @key actions
|
|
36
|
+
* @value event type (empty for actions that are not linked to events)
|
|
37
|
+
*/
|
|
38
|
+
const actions = {
|
|
39
|
+
count: '',
|
|
40
|
+
create: 'write',
|
|
41
|
+
createOrReplace: 'write',
|
|
42
|
+
delete: 'delete',
|
|
43
|
+
deleteByQuery: 'delete',
|
|
44
|
+
deleteFields: 'update',
|
|
45
|
+
exists: 'get',
|
|
46
|
+
export: 'get',
|
|
47
|
+
get: 'get',
|
|
48
|
+
mCreate: 'write',
|
|
49
|
+
mCreateOrReplace: 'write',
|
|
50
|
+
mDelete: 'delete',
|
|
51
|
+
mExists: 'get',
|
|
52
|
+
mGet: 'get',
|
|
53
|
+
mReplace: 'write',
|
|
54
|
+
mUpdate: 'update',
|
|
55
|
+
mUpsert: 'update',
|
|
56
|
+
replace: 'write',
|
|
57
|
+
scroll: '',
|
|
58
|
+
search: 'get',
|
|
59
|
+
update: 'update',
|
|
60
|
+
updateByQuery: 'update',
|
|
61
|
+
upsert: 'update',
|
|
62
|
+
validate: '',
|
|
63
|
+
};
|
|
64
|
+
|
|
33
65
|
/**
|
|
34
66
|
* @class DocumentController
|
|
35
67
|
*/
|
|
36
68
|
class DocumentController extends NativeController {
|
|
37
69
|
constructor () {
|
|
38
|
-
super(
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
'export',
|
|
47
|
-
'get',
|
|
48
|
-
'mCreate',
|
|
49
|
-
'mCreateOrReplace',
|
|
50
|
-
'mDelete',
|
|
51
|
-
'mExists',
|
|
52
|
-
'mGet',
|
|
53
|
-
'mReplace',
|
|
54
|
-
'mUpdate',
|
|
55
|
-
'mUpsert',
|
|
56
|
-
'replace',
|
|
57
|
-
'scroll',
|
|
58
|
-
'search',
|
|
59
|
-
'update',
|
|
60
|
-
'upsert',
|
|
61
|
-
'updateByQuery',
|
|
62
|
-
'validate'
|
|
63
|
-
]);
|
|
70
|
+
super(Object.keys(actions));
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
/**
|
|
74
|
+
* @returns {Record<string, unknown>}
|
|
75
|
+
*/
|
|
76
|
+
static get actions () {
|
|
77
|
+
return actions;
|
|
64
78
|
}
|
|
65
79
|
|
|
66
80
|
/**
|
|
@@ -69,8 +83,8 @@ class DocumentController extends NativeController {
|
|
|
69
83
|
*/
|
|
70
84
|
async search (request) {
|
|
71
85
|
const { from, size, scrollTTL, searchBody } = request.getSearchParams();
|
|
72
|
-
const index = request.
|
|
73
|
-
const collection = request.
|
|
86
|
+
const index = request.getIndex({ required: false });
|
|
87
|
+
const collection = request.getCollection({ required: false });
|
|
74
88
|
const targets = request.getArray('targets', []);
|
|
75
89
|
const lang = request.getLangParam();
|
|
76
90
|
|
|
@@ -118,7 +132,7 @@ class DocumentController extends NativeController {
|
|
|
118
132
|
searchBody,
|
|
119
133
|
{ from, scroll: scrollTTL, size });
|
|
120
134
|
}
|
|
121
|
-
|
|
135
|
+
|
|
122
136
|
return {
|
|
123
137
|
aggregations: result.aggregations,
|
|
124
138
|
hits: result.hits,
|
|
@@ -228,8 +242,12 @@ class DocumentController extends NativeController {
|
|
|
228
242
|
mimeType = 'text/csv';
|
|
229
243
|
}
|
|
230
244
|
|
|
231
|
-
request.response.
|
|
232
|
-
|
|
245
|
+
request.response.configure({
|
|
246
|
+
headers: {
|
|
247
|
+
'Content-Disposition': `attachment; filename="${index}-${collection}.${format}"`,
|
|
248
|
+
'Content-Type': mimeType,
|
|
249
|
+
}
|
|
250
|
+
});
|
|
233
251
|
|
|
234
252
|
return dumpCollectionDocuments(
|
|
235
253
|
index,
|
|
@@ -27,6 +27,7 @@ module.exports = {
|
|
|
27
27
|
BulkController: require('./bulkController'),
|
|
28
28
|
ClusterController: require('./clusterController'),
|
|
29
29
|
CollectionController: require('./collectionController'),
|
|
30
|
+
DebugController: require('./debugController').DebugController,
|
|
30
31
|
DocumentController: require('./documentController'),
|
|
31
32
|
IndexController: require('./indexController'),
|
|
32
33
|
MemoryStorageController: require('./memoryStorageController'),
|
|
@@ -21,8 +21,6 @@
|
|
|
21
21
|
|
|
22
22
|
'use strict';
|
|
23
23
|
|
|
24
|
-
const Bluebird = require('bluebird');
|
|
25
|
-
|
|
26
24
|
const { Request } = require('../request');
|
|
27
25
|
const { NativeController } = require('./baseController');
|
|
28
26
|
|
|
@@ -119,7 +117,7 @@ class IndexController extends NativeController {
|
|
|
119
117
|
);
|
|
120
118
|
}
|
|
121
119
|
|
|
122
|
-
await
|
|
120
|
+
await Promise.all(promises);
|
|
123
121
|
}
|
|
124
122
|
|
|
125
123
|
return response;
|
|
@@ -148,12 +146,18 @@ class IndexController extends NativeController {
|
|
|
148
146
|
}
|
|
149
147
|
|
|
150
148
|
/**
|
|
151
|
-
* Returns a list of indexes allowed to be deleted by the user
|
|
149
|
+
* Returns a list of indexes allowed to be deleted by the user.
|
|
150
|
+
*
|
|
151
|
+
* Returns entire list of public indexes when called from EmbeddedSDK
|
|
152
152
|
*
|
|
153
153
|
* @param {Request} request
|
|
154
|
-
* @param {String[]} publicIndexes -
|
|
154
|
+
* @param {String[]} publicIndexes - Public indexes list
|
|
155
155
|
*/
|
|
156
156
|
_allowedIndexes (request, publicIndexes) {
|
|
157
|
+
if (request.getUser() === null) {
|
|
158
|
+
return publicIndexes;
|
|
159
|
+
}
|
|
160
|
+
|
|
157
161
|
const allowedIndexes = [];
|
|
158
162
|
|
|
159
163
|
const promises = publicIndexes
|
|
@@ -171,7 +175,7 @@ class IndexController extends NativeController {
|
|
|
171
175
|
});
|
|
172
176
|
});
|
|
173
177
|
|
|
174
|
-
return
|
|
178
|
+
return Promise.all(promises)
|
|
175
179
|
.then(() => allowedIndexes);
|
|
176
180
|
}
|
|
177
181
|
}
|