kuzzle 2.16.8 → 2.17.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 +11 -0
- package/lib/api/controllers/adminController.js +7 -6
- package/lib/api/controllers/authController.js +11 -11
- package/lib/api/controllers/baseController.js +60 -3
- package/lib/api/controllers/clusterController.js +1 -1
- package/lib/api/controllers/collectionController.js +7 -5
- package/lib/api/controllers/documentController.js +130 -17
- package/lib/api/controllers/indexController.js +1 -1
- package/lib/api/controllers/memoryStorageController.js +39 -38
- package/lib/api/controllers/realtimeController.js +1 -1
- package/lib/api/controllers/securityController.js +49 -49
- package/lib/api/controllers/serverController.js +73 -27
- package/lib/api/documentExtractor.js +3 -3
- package/lib/api/funnel.js +40 -21
- package/lib/api/httpRoutes.js +9 -4
- package/lib/api/openapi/OpenApiManager.d.ts +11 -0
- package/lib/api/openapi/OpenApiManager.js +96 -0
- package/lib/api/openapi/{document → components/document}/count.yaml +2 -2
- package/lib/api/openapi/{document → components/document}/create.yaml +2 -2
- package/lib/api/openapi/{document → components/document}/createOrReplace.yaml +2 -2
- package/lib/api/openapi/{document → components/document}/delete.yaml +1 -1
- package/lib/api/openapi/{document → components/document}/deleteByQuery.yaml +2 -2
- package/lib/api/openapi/{document → components/document}/exists.yaml +1 -1
- package/lib/api/openapi/{document → components/document}/get.yaml +1 -1
- package/lib/api/openapi/{document → components/document}/index.d.ts +2 -0
- package/lib/api/openapi/{document → components/document}/index.js +7 -2
- package/lib/api/openapi/{document → components/document}/replace.yaml +2 -2
- package/lib/api/openapi/{document → components/document}/scroll.yaml +1 -1
- package/lib/api/openapi/{document → components/document}/update.yaml +2 -2
- package/lib/api/openapi/components/document/validate.yaml +42 -0
- package/lib/api/openapi/components/index.d.ts +2 -0
- package/lib/api/openapi/components/index.js +18 -0
- package/lib/api/openapi/{payloads.yaml → components/payloads.yaml} +0 -0
- package/lib/api/openapi/index.d.ts +1 -2
- package/lib/api/openapi/index.js +1 -5
- package/lib/api/openapi/openApiGenerator.d.ts +7 -0
- package/lib/api/openapi/openApiGenerator.js +133 -0
- package/lib/api/request/kuzzleRequest.d.ts +11 -11
- package/lib/api/request/kuzzleRequest.js +38 -48
- package/lib/cluster/node.js +9 -9
- package/lib/cluster/publisher.js +1 -1
- package/lib/cluster/subscriber.js +1 -1
- package/lib/cluster/workers/IDCardRenewer.js +13 -4
- package/lib/config/default.config.js +1 -0
- package/lib/config/index.js +6 -6
- package/lib/core/auth/passportResponse.js +6 -6
- package/lib/core/auth/passportWrapper.js +5 -5
- package/lib/core/backend/backend.d.ts +5 -1
- package/lib/core/backend/backend.js +12 -8
- package/lib/core/backend/backendConfig.d.ts +5 -1
- package/lib/core/backend/backendConfig.js +4 -0
- package/lib/core/backend/backendOpenApi.d.ts +9 -0
- package/lib/core/backend/backendOpenApi.js +69 -0
- package/lib/core/backend/index.d.ts +1 -0
- package/lib/core/backend/index.js +1 -0
- package/lib/core/network/accessLogger.js +6 -6
- package/lib/core/network/clientConnection.js +1 -1
- package/lib/core/network/entryPoint.js +5 -5
- package/lib/core/network/httpRouter/index.js +5 -5
- package/lib/core/network/httpRouter/routeHandler.js +3 -3
- package/lib/core/network/httpRouter/routePart.js +5 -5
- package/lib/core/network/protocolManifest.js +1 -1
- package/lib/core/network/protocols/httpMessage.js +2 -2
- package/lib/core/network/protocols/httpwsProtocol.js +207 -46
- package/lib/core/network/protocols/mqttProtocol.js +3 -3
- package/lib/core/network/protocols/protocol.js +3 -3
- package/lib/core/network/router.js +7 -6
- package/lib/core/plugin/plugin.js +38 -64
- package/lib/core/plugin/pluginContext.d.ts +10 -1
- package/lib/core/plugin/pluginContext.js +2 -0
- package/lib/core/plugin/pluginManifest.js +3 -3
- package/lib/core/plugin/pluginRepository.js +5 -5
- package/lib/core/plugin/pluginsManager.js +29 -28
- package/lib/core/realtime/notification/server.js +1 -1
- package/lib/core/realtime/notification/user.js +1 -1
- package/lib/core/realtime/notifier.js +5 -5
- package/lib/core/security/index.js +1 -1
- package/lib/core/security/profileRepository.d.ts +176 -0
- package/lib/core/security/profileRepository.js +426 -443
- package/lib/core/security/roleRepository.js +16 -16
- package/lib/core/security/securityLoader.js +3 -3
- package/lib/core/security/tokenRepository.js +18 -21
- package/lib/core/security/userRepository.js +8 -8
- package/lib/core/shared/abstractManifest.js +4 -4
- package/lib/core/shared/repository.js +6 -6
- package/lib/core/shared/sdk/funnelProtocol.js +1 -1
- package/lib/core/shared/sdk/impersonatedSdk.js +1 -1
- package/lib/core/shared/store.js +30 -23
- package/lib/core/statistics/statistics.js +17 -17
- package/lib/core/storage/clientAdapter.js +45 -10
- package/lib/core/validation/baseType.js +5 -5
- package/lib/core/validation/types/anything.js +1 -1
- package/lib/core/validation/types/boolean.js +2 -2
- package/lib/core/validation/types/date.js +9 -9
- package/lib/core/validation/types/email.js +5 -5
- package/lib/core/validation/types/enum.js +6 -6
- package/lib/core/validation/types/geoPoint.js +2 -2
- package/lib/core/validation/types/geoShape.js +28 -25
- package/lib/core/validation/types/integer.js +4 -4
- package/lib/core/validation/types/ipAddress.js +7 -6
- package/lib/core/validation/types/numeric.js +4 -4
- package/lib/core/validation/types/object.js +5 -5
- package/lib/core/validation/types/string.js +5 -5
- package/lib/core/validation/types/url.js +7 -6
- package/lib/core/validation/validation.js +95 -84
- package/lib/kerror/codes/1-services.json +12 -0
- package/lib/kerror/codes/2-api.json +12 -0
- package/lib/kerror/codes/3-network.json +12 -0
- package/lib/kerror/codes/4-plugin.json +6 -0
- package/lib/kerror/codes/index.js +11 -11
- package/lib/kerror/index.js +1 -1
- package/lib/kuzzle/dumpGenerator.js +3 -3
- package/lib/kuzzle/event/kuzzleEventEmitter.js +4 -4
- package/lib/kuzzle/event/pipeRunner.js +1 -1
- package/lib/kuzzle/event/waterfall.js +6 -6
- package/lib/kuzzle/kuzzle.js +36 -5
- package/lib/kuzzle/log.js +3 -3
- package/lib/kuzzle/vault.js +3 -3
- package/lib/model/security/profile.d.ts +54 -0
- package/lib/model/security/profile.js +174 -233
- package/lib/model/security/rights.js +1 -1
- package/lib/model/security/role.d.ts +40 -0
- package/lib/model/security/role.js +159 -191
- package/lib/model/security/user.d.ts +29 -0
- package/lib/model/security/user.js +84 -52
- package/lib/model/storage/apiKey.js +2 -2
- package/lib/model/storage/baseModel.js +3 -3
- package/lib/service/cache/redis.js +7 -7
- package/lib/service/storage/elasticsearch.js +152 -90
- package/lib/service/storage/esWrapper.js +2 -3
- package/lib/types/ControllerDefinition.d.ts +3 -3
- package/lib/types/ControllerRights.d.ts +22 -0
- package/lib/types/ControllerRights.js +23 -0
- package/lib/types/HttpStream.d.ts +32 -0
- package/lib/types/HttpStream.js +70 -0
- package/lib/types/OpenApiDefinition.d.ts +43 -0
- package/lib/types/{config/StorageService/StorageServiceElasticsearchConfiguration.js → OpenApiDefinition.js} +1 -1
- package/lib/types/Policy.d.ts +25 -0
- package/lib/types/Policy.js +23 -0
- package/lib/types/PolicyRestrictions.d.ts +21 -0
- package/lib/types/PolicyRestrictions.js +23 -0
- package/lib/types/Target.d.ts +15 -0
- package/lib/types/Target.js +23 -0
- package/lib/types/config/KuzzleConfiguration.d.ts +4 -0
- package/lib/types/config/ServicesConfiguration.d.ts +2 -2
- package/lib/types/config/{StorageService/StorageServiceElasticsearchConfiguration.d.ts → storageEngine/StorageEngineElasticsearchConfiguration.d.ts} +10 -3
- package/lib/types/config/storageEngine/StorageEngineElasticsearchConfiguration.js +3 -0
- package/lib/types/index.d.ts +7 -1
- package/lib/types/index.js +7 -1
- package/lib/util/array.d.ts +11 -0
- package/lib/util/array.js +57 -0
- package/lib/util/assertType.js +6 -6
- package/lib/util/bufferedPassThrough.d.ts +76 -0
- package/lib/util/bufferedPassThrough.js +161 -0
- package/lib/util/deprecate.js +7 -5
- package/lib/util/didYouMean.js +1 -1
- package/lib/util/dump-collection.d.ts +3 -0
- package/lib/util/dump-collection.js +265 -0
- package/lib/util/extractFields.js +2 -2
- package/lib/util/inflector.d.ts +8 -0
- package/lib/util/inflector.js +16 -0
- package/lib/util/requestAssertions.js +7 -7
- package/lib/util/wildcard.js +55 -0
- package/package-lock.json +881 -431
- package/package.json +23 -20
- package/lib/api/openApiGenerator.d.ts +0 -7
- package/lib/api/openApiGenerator.js +0 -197
|
@@ -36,7 +36,7 @@ let mapping;
|
|
|
36
36
|
* @class MemoryStorageController
|
|
37
37
|
*/
|
|
38
38
|
class MemoryStorageController extends NativeController {
|
|
39
|
-
constructor() {
|
|
39
|
+
constructor () {
|
|
40
40
|
super();
|
|
41
41
|
|
|
42
42
|
initMapping();
|
|
@@ -117,8 +117,8 @@ function initMapping () {
|
|
|
117
117
|
},
|
|
118
118
|
bitcount: {
|
|
119
119
|
key: ['resource', '_id'],
|
|
120
|
-
start: {skip: true, path: ['args', 'start']},
|
|
121
|
-
end: {skip: true, path: ['args', 'end']}
|
|
120
|
+
start: { skip: true, path: ['args', 'start'] },
|
|
121
|
+
end: { skip: true, path: ['args', 'end'] }
|
|
122
122
|
},
|
|
123
123
|
bitop: {
|
|
124
124
|
operation: ['body', 'operation'],
|
|
@@ -128,8 +128,8 @@ function initMapping () {
|
|
|
128
128
|
bitpos: {
|
|
129
129
|
key: ['resource', '_id'],
|
|
130
130
|
bit: ['args', 'bit'],
|
|
131
|
-
start: {skip: true, path
|
|
132
|
-
end: {skip: true, path: ['args', 'end']}
|
|
131
|
+
start: { skip: true, path: ['args', 'start'] },
|
|
132
|
+
end: { skip: true, path: ['args', 'end'] }
|
|
133
133
|
},
|
|
134
134
|
dbsize: null,
|
|
135
135
|
decrby: {
|
|
@@ -149,7 +149,7 @@ function initMapping () {
|
|
|
149
149
|
},
|
|
150
150
|
flushdb: null,
|
|
151
151
|
geoadd: {
|
|
152
|
-
key: {path: ['resource', '_id']},
|
|
152
|
+
key: { path: ['resource', '_id'] },
|
|
153
153
|
points: {
|
|
154
154
|
map: (val, request) => {
|
|
155
155
|
const result = [];
|
|
@@ -162,7 +162,7 @@ function initMapping () {
|
|
|
162
162
|
}
|
|
163
163
|
|
|
164
164
|
val.forEach(v => {
|
|
165
|
-
if (typeof v !== 'object' || !v.lon || !v.lat || !v.name) {
|
|
165
|
+
if (typeof v !== 'object' || ! v.lon || ! v.lat || ! v.name) {
|
|
166
166
|
throw kerror.get('invalid_argument', 'points', '<array of geopoints>');
|
|
167
167
|
}
|
|
168
168
|
|
|
@@ -182,7 +182,7 @@ function initMapping () {
|
|
|
182
182
|
key: ['resource', '_id'],
|
|
183
183
|
member1: ['args', 'member1'],
|
|
184
184
|
member2: ['args', 'member2'],
|
|
185
|
-
unit: {skip: true, path: ['args', 'unit']}
|
|
185
|
+
unit: { skip: true, path: ['args', 'unit'] }
|
|
186
186
|
},
|
|
187
187
|
geohash: {
|
|
188
188
|
key: ['resource', '_id'],
|
|
@@ -228,7 +228,7 @@ function initMapping () {
|
|
|
228
228
|
},
|
|
229
229
|
hdel: {
|
|
230
230
|
key: ['resource', '_id'],
|
|
231
|
-
fields: {skip: true, merge: true, path: ['body', 'fields']}
|
|
231
|
+
fields: { skip: true, merge: true, path: ['body', 'fields'] }
|
|
232
232
|
},
|
|
233
233
|
hmget: {
|
|
234
234
|
key: ['resource', '_id'],
|
|
@@ -257,7 +257,7 @@ function initMapping () {
|
|
|
257
257
|
kassert.assertBodyAttributeType(request, 'entries', 'array');
|
|
258
258
|
|
|
259
259
|
val.forEach(v => {
|
|
260
|
-
if (typeof v !== 'object' || !v.field || !v.value) {
|
|
260
|
+
if (typeof v !== 'object' || ! v.field || ! v.value) {
|
|
261
261
|
throw kerror.get('invalid_argument', 'entries', '<array of object>');
|
|
262
262
|
}
|
|
263
263
|
|
|
@@ -294,7 +294,7 @@ function initMapping () {
|
|
|
294
294
|
},
|
|
295
295
|
lpush: {
|
|
296
296
|
key: ['resource', '_id'],
|
|
297
|
-
values: {skip: true, merge: true, path: ['body', 'values']}
|
|
297
|
+
values: { skip: true, merge: true, path: ['body', 'values'] }
|
|
298
298
|
},
|
|
299
299
|
lrange: {
|
|
300
300
|
key: ['resource', '_id'],
|
|
@@ -334,7 +334,7 @@ function initMapping () {
|
|
|
334
334
|
kassert.assertBodyHasAttribute(request, 'entries');
|
|
335
335
|
kassert.assertBodyAttributeType(request, 'entries', 'array');
|
|
336
336
|
val.forEach(entry => {
|
|
337
|
-
if (typeof entry !== 'object' || !entry.key || !entry.value) {
|
|
337
|
+
if (typeof entry !== 'object' || ! entry.key || ! entry.value) {
|
|
338
338
|
throw kerror.get('invalid_argument', 'entries', '<array of objects>');
|
|
339
339
|
}
|
|
340
340
|
|
|
@@ -361,11 +361,11 @@ function initMapping () {
|
|
|
361
361
|
},
|
|
362
362
|
pfadd: {
|
|
363
363
|
key: ['resource', '_id'],
|
|
364
|
-
elements: {skip: true, merge: true, path: ['body', 'elements']}
|
|
364
|
+
elements: { skip: true, merge: true, path: ['body', 'elements'] }
|
|
365
365
|
},
|
|
366
366
|
pfmerge: {
|
|
367
367
|
key: ['resource', '_id'],
|
|
368
|
-
sources: {skip: true, merge: true, path: ['body', 'sources']}
|
|
368
|
+
sources: { skip: true, merge: true, path: ['body', 'sources'] }
|
|
369
369
|
},
|
|
370
370
|
ping: null,
|
|
371
371
|
psetex: {
|
|
@@ -388,7 +388,7 @@ function initMapping () {
|
|
|
388
388
|
},
|
|
389
389
|
sadd: {
|
|
390
390
|
key: ['resource', '_id'],
|
|
391
|
-
members: {skip: true, merge: true, path: ['body', 'members']}
|
|
391
|
+
members: { skip: true, merge: true, path: ['body', 'members'] }
|
|
392
392
|
},
|
|
393
393
|
scan: {
|
|
394
394
|
cursor: ['args', 'cursor'],
|
|
@@ -406,7 +406,7 @@ function initMapping () {
|
|
|
406
406
|
sdiffstore: {
|
|
407
407
|
destination: ['body', 'destination'],
|
|
408
408
|
key: ['resource', '_id'],
|
|
409
|
-
keys: {merge: true, path: ['body', 'keys']}
|
|
409
|
+
keys: { merge: true, path: ['body', 'keys'] }
|
|
410
410
|
},
|
|
411
411
|
set: null, // handled by extractArgumentsFromRequestForSet
|
|
412
412
|
setex: {
|
|
@@ -420,7 +420,7 @@ function initMapping () {
|
|
|
420
420
|
},
|
|
421
421
|
sinterstore: {
|
|
422
422
|
destination: ['body', 'destination'],
|
|
423
|
-
keys: {merge: true, path: ['body', 'keys']}
|
|
423
|
+
keys: { merge: true, path: ['body', 'keys'] }
|
|
424
424
|
},
|
|
425
425
|
sismember: {
|
|
426
426
|
key: ['resource', '_id'],
|
|
@@ -434,15 +434,15 @@ function initMapping () {
|
|
|
434
434
|
sort: null, // handled by extractArgumentsFromRequestForSort
|
|
435
435
|
spop: {
|
|
436
436
|
key: ['resource', '_id'],
|
|
437
|
-
count: {skip: true, path: ['body', 'count']}
|
|
437
|
+
count: { skip: true, path: ['body', 'count'] }
|
|
438
438
|
},
|
|
439
439
|
srandmember: {
|
|
440
440
|
key: ['resource', '_id'],
|
|
441
|
-
count: {skip: true, path: ['args', 'count']}
|
|
441
|
+
count: { skip: true, path: ['args', 'count'] }
|
|
442
442
|
},
|
|
443
443
|
srem: {
|
|
444
444
|
key: ['resource', '_id'],
|
|
445
|
-
members: {skip: true, merge: true, path: ['body', 'members']}
|
|
445
|
+
members: { skip: true, merge: true, path: ['body', 'members'] }
|
|
446
446
|
},
|
|
447
447
|
sscan: {
|
|
448
448
|
key: ['resource', '_id'],
|
|
@@ -459,11 +459,11 @@ function initMapping () {
|
|
|
459
459
|
},
|
|
460
460
|
sunionstore: {
|
|
461
461
|
destination: ['body', 'destination'],
|
|
462
|
-
keys: {merge: true, path: ['body', 'keys']}
|
|
462
|
+
keys: { merge: true, path: ['body', 'keys'] }
|
|
463
463
|
},
|
|
464
464
|
time: null,
|
|
465
465
|
touch: {
|
|
466
|
-
keys: {merge: true, path: ['body', 'keys']}
|
|
466
|
+
keys: { merge: true, path: ['body', 'keys'] }
|
|
467
467
|
},
|
|
468
468
|
zadd: null, // handled by extractArgumentsFromRequestForZAdd
|
|
469
469
|
zcount: {
|
|
@@ -490,7 +490,7 @@ function initMapping () {
|
|
|
490
490
|
skip: true,
|
|
491
491
|
merge: true,
|
|
492
492
|
map: val => sanitizeArrayArgument(val),
|
|
493
|
-
path: ['args', 'options']}
|
|
493
|
+
path: ['args', 'options'] }
|
|
494
494
|
},
|
|
495
495
|
zrangebylex: {
|
|
496
496
|
key: ['resource', '_id'],
|
|
@@ -512,7 +512,7 @@ function initMapping () {
|
|
|
512
512
|
},
|
|
513
513
|
zrem: {
|
|
514
514
|
key: ['resource', '_id'],
|
|
515
|
-
members: {merge: true, path: ['body', 'members']}
|
|
515
|
+
members: { merge: true, path: ['body', 'members'] }
|
|
516
516
|
},
|
|
517
517
|
zremrangebylex: {
|
|
518
518
|
key: ['resource', '_id'],
|
|
@@ -610,20 +610,20 @@ function extractArgumentsFromRequest (command, request) {
|
|
|
610
610
|
return extractArgumentsFromRequestForMExecute(request);
|
|
611
611
|
}
|
|
612
612
|
|
|
613
|
-
if (!mapping[command]) {
|
|
613
|
+
if (! mapping[command]) {
|
|
614
614
|
return [];
|
|
615
615
|
}
|
|
616
616
|
|
|
617
|
-
if (!request.input.body) {
|
|
617
|
+
if (! request.input.body) {
|
|
618
618
|
request.input.body = {};
|
|
619
619
|
}
|
|
620
620
|
|
|
621
621
|
Object.keys(mapping[command]).forEach(key => {
|
|
622
622
|
const data = mapping[command][key];
|
|
623
623
|
const path = Array.isArray(data) ? data : data.path;
|
|
624
|
-
const toMerge = !Array.isArray(data) && data.merge === true;
|
|
625
|
-
const map = !Array.isArray(data) && data.map;
|
|
626
|
-
const skip = !Array.isArray(data) && data.skip === true;
|
|
624
|
+
const toMerge = ! Array.isArray(data) && data.merge === true;
|
|
625
|
+
const map = ! Array.isArray(data) && data.map;
|
|
626
|
+
const skip = ! Array.isArray(data) && data.skip === true;
|
|
627
627
|
|
|
628
628
|
let value = path.reduce(
|
|
629
629
|
(previousValue, currentValue, currentIndex, array) => {
|
|
@@ -649,7 +649,8 @@ function extractArgumentsFromRequest (command, request) {
|
|
|
649
649
|
if (value !== undefined) {
|
|
650
650
|
if (toMerge && Array.isArray(value)) {
|
|
651
651
|
args = args.concat(value);
|
|
652
|
-
}
|
|
652
|
+
}
|
|
653
|
+
else {
|
|
653
654
|
args.push(value);
|
|
654
655
|
}
|
|
655
656
|
}
|
|
@@ -769,19 +770,19 @@ function extractArgumentsFromRequestForMExecute (request) {
|
|
|
769
770
|
const actions = request.input.body.actions;
|
|
770
771
|
|
|
771
772
|
return actions.map(command => {
|
|
772
|
-
if (!has(command, 'action')) {
|
|
773
|
+
if (! has(command, 'action')) {
|
|
773
774
|
throw kerror.get('missing_argument', 'action');
|
|
774
775
|
}
|
|
775
|
-
if (!has(command, 'args')) {
|
|
776
|
+
if (! has(command, 'args')) {
|
|
776
777
|
throw kerror.get('missing_argument', 'args');
|
|
777
778
|
}
|
|
778
|
-
if (!isPlainObject(command.args)) {
|
|
779
|
+
if (! isPlainObject(command.args)) {
|
|
779
780
|
throw kerror.get('invalid_type', 'args', 'object');
|
|
780
781
|
}
|
|
781
782
|
if (command.action === 'mexecute') {
|
|
782
783
|
throw kerror.get('forbidden_argument', 'mexecute');
|
|
783
784
|
}
|
|
784
|
-
if (!has(mapping, command.action)) {
|
|
785
|
+
if (! has(mapping, command.action)) {
|
|
785
786
|
throw kerror.get('forbidden_argument', command.action);
|
|
786
787
|
}
|
|
787
788
|
const subRequest = new Request(command.args);
|
|
@@ -832,11 +833,11 @@ function extractArgumentsFromRequestForZAdd (request) {
|
|
|
832
833
|
}
|
|
833
834
|
|
|
834
835
|
request.input.body.elements.forEach((element, index) => {
|
|
835
|
-
if (!isPlainObject(element)) {
|
|
836
|
+
if (! isPlainObject(element)) {
|
|
836
837
|
throw kerror.get('invalid_argument', 'elements', '<array of objects>');
|
|
837
838
|
}
|
|
838
839
|
|
|
839
|
-
if (!element.member) {
|
|
840
|
+
if (! element.member) {
|
|
840
841
|
throw kerror.get('missing_argument', `elements[${index}].member`);
|
|
841
842
|
}
|
|
842
843
|
|
|
@@ -901,7 +902,7 @@ function extractArgumentsFromRequestForZInterstore (request) {
|
|
|
901
902
|
* @param {*} value of the tested parameter
|
|
902
903
|
* @throws
|
|
903
904
|
*/
|
|
904
|
-
function assertFloat(request, name, value) {
|
|
905
|
+
function assertFloat (request, name, value) {
|
|
905
906
|
// Number.parseXxx computes the 1st member of an array if one is provided
|
|
906
907
|
if (Array.isArray(value) || Number.isNaN(Number.parseFloat(value))) {
|
|
907
908
|
throw kerror.get('invalid_type', name, 'number');
|
|
@@ -917,7 +918,7 @@ function assertFloat(request, name, value) {
|
|
|
917
918
|
* @param {*} value of the tested parameter
|
|
918
919
|
* @throws
|
|
919
920
|
*/
|
|
920
|
-
function assertInt(request, name, value) {
|
|
921
|
+
function assertInt (request, name, value) {
|
|
921
922
|
// Number.parseXxx computes the 1st member of an array if one is provided
|
|
922
923
|
if (Array.isArray(value) || Number.isNaN(Number.parseInt(value))) {
|
|
923
924
|
throw kerror.get('invalid_type', name, 'integer');
|
|
@@ -38,7 +38,7 @@ const { generateRandomName } = require('../../util/name-generator');
|
|
|
38
38
|
* @class SecurityController
|
|
39
39
|
*/
|
|
40
40
|
class SecurityController extends NativeController {
|
|
41
|
-
constructor() {
|
|
41
|
+
constructor () {
|
|
42
42
|
super([
|
|
43
43
|
'checkRights',
|
|
44
44
|
'createApiKey',
|
|
@@ -229,9 +229,9 @@ class SecurityController extends NativeController {
|
|
|
229
229
|
* @returns {Promise}
|
|
230
230
|
*/
|
|
231
231
|
async getProfileMapping () {
|
|
232
|
-
const {properties} = await global.kuzzle.internalIndex.getMapping('profiles');
|
|
232
|
+
const { properties } = await global.kuzzle.internalIndex.getMapping('profiles');
|
|
233
233
|
|
|
234
|
-
return {mapping: properties};
|
|
234
|
+
return { mapping: properties };
|
|
235
235
|
}
|
|
236
236
|
|
|
237
237
|
/**
|
|
@@ -252,9 +252,9 @@ class SecurityController extends NativeController {
|
|
|
252
252
|
* @returns {Promise}
|
|
253
253
|
*/
|
|
254
254
|
async getUserMapping () {
|
|
255
|
-
const {properties} = await global.kuzzle.internalIndex.getMapping('users');
|
|
255
|
+
const { properties } = await global.kuzzle.internalIndex.getMapping('users');
|
|
256
256
|
|
|
257
|
-
return {mapping: properties};
|
|
257
|
+
return { mapping: properties };
|
|
258
258
|
}
|
|
259
259
|
|
|
260
260
|
/**
|
|
@@ -275,7 +275,7 @@ class SecurityController extends NativeController {
|
|
|
275
275
|
* @param {Request} request
|
|
276
276
|
* @returns {Promise<Object>}
|
|
277
277
|
*/
|
|
278
|
-
async getRole(request) {
|
|
278
|
+
async getRole (request) {
|
|
279
279
|
const id = request.getId();
|
|
280
280
|
|
|
281
281
|
const role = await this.ask('core:security:role:get', id);
|
|
@@ -289,7 +289,7 @@ class SecurityController extends NativeController {
|
|
|
289
289
|
* @param {Request} request
|
|
290
290
|
* @returns {Promise<Object>}
|
|
291
291
|
*/
|
|
292
|
-
async mGetRoles(request) {
|
|
292
|
+
async mGetRoles (request) {
|
|
293
293
|
const ids = request.getBodyArray('ids');
|
|
294
294
|
const roles = await this.ask('core:security:role:mGet', ids);
|
|
295
295
|
|
|
@@ -305,7 +305,7 @@ class SecurityController extends NativeController {
|
|
|
305
305
|
async refresh (request) {
|
|
306
306
|
const collection = request.getCollection();
|
|
307
307
|
|
|
308
|
-
if (!this.securityCollections.includes(collection)) {
|
|
308
|
+
if (! this.securityCollections.includes(collection)) {
|
|
309
309
|
throw kerror.get(
|
|
310
310
|
'api',
|
|
311
311
|
'assert',
|
|
@@ -360,7 +360,7 @@ class SecurityController extends NativeController {
|
|
|
360
360
|
* @param {Request} request
|
|
361
361
|
* @returns {Promise<Object>}
|
|
362
362
|
*/
|
|
363
|
-
async createOrReplaceRole(request) {
|
|
363
|
+
async createOrReplaceRole (request) {
|
|
364
364
|
const id = request.getId();
|
|
365
365
|
const body = request.getBody();
|
|
366
366
|
const userId = request.getKuid();
|
|
@@ -402,7 +402,7 @@ class SecurityController extends NativeController {
|
|
|
402
402
|
* @param {Request} request
|
|
403
403
|
* @returns {Promise<Object>}
|
|
404
404
|
*/
|
|
405
|
-
async deleteRole(request) {
|
|
405
|
+
async deleteRole (request) {
|
|
406
406
|
const id = request.getId();
|
|
407
407
|
|
|
408
408
|
await this.ask('core:security:role:delete', id, {
|
|
@@ -422,7 +422,7 @@ class SecurityController extends NativeController {
|
|
|
422
422
|
* @param {Request} request
|
|
423
423
|
* @returns {Promise<Object>}
|
|
424
424
|
*/
|
|
425
|
-
async getProfile(request) {
|
|
425
|
+
async getProfile (request) {
|
|
426
426
|
const id = request.getId();
|
|
427
427
|
|
|
428
428
|
const profile = await this.ask('core:security:profile:get', id);
|
|
@@ -436,7 +436,7 @@ class SecurityController extends NativeController {
|
|
|
436
436
|
* @param {Request} request
|
|
437
437
|
* @returns {Promise<Object>}
|
|
438
438
|
*/
|
|
439
|
-
async mGetProfiles(request) {
|
|
439
|
+
async mGetProfiles (request) {
|
|
440
440
|
const ids = request.getBodyArray('ids');
|
|
441
441
|
|
|
442
442
|
const profiles = await this.ask('core:security:profile:mGet', ids);
|
|
@@ -512,7 +512,7 @@ class SecurityController extends NativeController {
|
|
|
512
512
|
* @param {Request} request
|
|
513
513
|
* @returns {Promise<Object>}
|
|
514
514
|
*/
|
|
515
|
-
async deleteProfile(request) {
|
|
515
|
+
async deleteProfile (request) {
|
|
516
516
|
const id = request.getId();
|
|
517
517
|
const userId = request.getKuid();
|
|
518
518
|
const options = {
|
|
@@ -579,7 +579,7 @@ class SecurityController extends NativeController {
|
|
|
579
579
|
* @param {Request} request
|
|
580
580
|
* @returns {Promise<Object>}
|
|
581
581
|
*/
|
|
582
|
-
async getUser(request) {
|
|
582
|
+
async getUser (request) {
|
|
583
583
|
const id = request.getId();
|
|
584
584
|
const user = await this.ask('core:security:user:get', id);
|
|
585
585
|
|
|
@@ -592,7 +592,7 @@ class SecurityController extends NativeController {
|
|
|
592
592
|
* @param {Request} request
|
|
593
593
|
* @returns {Promise.<Object>}
|
|
594
594
|
*/
|
|
595
|
-
async mGetUsers(request) {
|
|
595
|
+
async mGetUsers (request) {
|
|
596
596
|
let ids;
|
|
597
597
|
|
|
598
598
|
if ( request.input.body
|
|
@@ -616,7 +616,7 @@ class SecurityController extends NativeController {
|
|
|
616
616
|
* @param {Request} request
|
|
617
617
|
* @returns {Promise<Object>}
|
|
618
618
|
*/
|
|
619
|
-
async getProfileRights(request) {
|
|
619
|
+
async getProfileRights (request) {
|
|
620
620
|
const id = request.getId();
|
|
621
621
|
|
|
622
622
|
const profile = await this.ask('core:security:profile:get', id);
|
|
@@ -637,7 +637,7 @@ class SecurityController extends NativeController {
|
|
|
637
637
|
* @param {Request} request
|
|
638
638
|
* @returns {Promise<Object>}
|
|
639
639
|
*/
|
|
640
|
-
async getUserRights(request) {
|
|
640
|
+
async getUserRights (request) {
|
|
641
641
|
const id = request.getId();
|
|
642
642
|
|
|
643
643
|
const user = await this.ask('core:security:user:get', id);
|
|
@@ -658,7 +658,7 @@ class SecurityController extends NativeController {
|
|
|
658
658
|
* @param {Request} request
|
|
659
659
|
* @returns {Promise<Object>}
|
|
660
660
|
*/
|
|
661
|
-
async getUserStrategies(request) {
|
|
661
|
+
async getUserStrategies (request) {
|
|
662
662
|
const userId = request.getId();
|
|
663
663
|
const checkPromises = [];
|
|
664
664
|
|
|
@@ -695,7 +695,7 @@ class SecurityController extends NativeController {
|
|
|
695
695
|
* @param {Request} request
|
|
696
696
|
* @returns {Promise<Object>}
|
|
697
697
|
*/
|
|
698
|
-
async searchUsers(request) {
|
|
698
|
+
async searchUsers (request) {
|
|
699
699
|
const size = this._getSearchPageSize(request);
|
|
700
700
|
const { from, scrollTTL, searchBody } = request.getSearchParams();
|
|
701
701
|
const lang = request.getLangParam();
|
|
@@ -751,7 +751,7 @@ class SecurityController extends NativeController {
|
|
|
751
751
|
* @param {Request} request
|
|
752
752
|
* @returns {Promise<Object>}
|
|
753
753
|
*/
|
|
754
|
-
async deleteUser(request) {
|
|
754
|
+
async deleteUser (request) {
|
|
755
755
|
const id = request.getId();
|
|
756
756
|
const options = { refresh: request.getRefresh('wait_for') };
|
|
757
757
|
|
|
@@ -768,7 +768,7 @@ class SecurityController extends NativeController {
|
|
|
768
768
|
* @param {Request} request
|
|
769
769
|
* @returns {Promise<Object>}
|
|
770
770
|
*/
|
|
771
|
-
async createUser(request) {
|
|
771
|
+
async createUser (request) {
|
|
772
772
|
const content = request.getBodyObject('content');
|
|
773
773
|
const profileIds = get(content, 'profileIds');
|
|
774
774
|
const humanReadableId = request.getString('kuid', 'human') !== 'uuid';
|
|
@@ -777,7 +777,7 @@ class SecurityController extends NativeController {
|
|
|
777
777
|
throw kerror.get('api', 'assert', 'missing_argument', 'body.content.profileIds');
|
|
778
778
|
}
|
|
779
779
|
|
|
780
|
-
if (!Array.isArray(profileIds)) {
|
|
780
|
+
if (! Array.isArray(profileIds)) {
|
|
781
781
|
throw kerror.get('api', 'assert', 'invalid_type', 'body.content.profileIds', 'array');
|
|
782
782
|
}
|
|
783
783
|
|
|
@@ -790,7 +790,7 @@ class SecurityController extends NativeController {
|
|
|
790
790
|
* @param {Request} request
|
|
791
791
|
* @returns {Promise<Object>}
|
|
792
792
|
*/
|
|
793
|
-
async createRestrictedUser(request) {
|
|
793
|
+
async createRestrictedUser (request) {
|
|
794
794
|
const content = request.getBodyObject('content', {});
|
|
795
795
|
const humanReadableId = request.getString('kuid', 'human') !== 'uuid';
|
|
796
796
|
|
|
@@ -811,7 +811,7 @@ class SecurityController extends NativeController {
|
|
|
811
811
|
* @param {Request} request
|
|
812
812
|
* @returns {Promise<Object>}
|
|
813
813
|
*/
|
|
814
|
-
async updateUser(request) {
|
|
814
|
+
async updateUser (request) {
|
|
815
815
|
const id = request.getId();
|
|
816
816
|
const content = request.getBody();
|
|
817
817
|
const userId = request.getKuid();
|
|
@@ -865,7 +865,7 @@ class SecurityController extends NativeController {
|
|
|
865
865
|
* @param {Request} request
|
|
866
866
|
* @returns {Promise<Object>}
|
|
867
867
|
*/
|
|
868
|
-
async updateProfile(request) {
|
|
868
|
+
async updateProfile (request) {
|
|
869
869
|
const id = request.getId();
|
|
870
870
|
const body = request.getBody();
|
|
871
871
|
const userId = request.getKuid();
|
|
@@ -887,7 +887,7 @@ class SecurityController extends NativeController {
|
|
|
887
887
|
* @param {Request} request
|
|
888
888
|
* @returns {Promise<Object>}
|
|
889
889
|
*/
|
|
890
|
-
async updateRole(request) {
|
|
890
|
+
async updateRole (request) {
|
|
891
891
|
const id = request.getId();
|
|
892
892
|
const body = request.getBody();
|
|
893
893
|
const userId = request.getKuid();
|
|
@@ -951,7 +951,7 @@ class SecurityController extends NativeController {
|
|
|
951
951
|
* @param {Request} request
|
|
952
952
|
* @returns {Promise<Object>}
|
|
953
953
|
*/
|
|
954
|
-
mDeleteProfiles(request) {
|
|
954
|
+
mDeleteProfiles (request) {
|
|
955
955
|
return this._mDelete('profile', request);
|
|
956
956
|
}
|
|
957
957
|
|
|
@@ -961,7 +961,7 @@ class SecurityController extends NativeController {
|
|
|
961
961
|
* @param {Request} request
|
|
962
962
|
* @returns {Promise<Object>}
|
|
963
963
|
*/
|
|
964
|
-
mDeleteRoles(request) {
|
|
964
|
+
mDeleteRoles (request) {
|
|
965
965
|
return this._mDelete('role', request);
|
|
966
966
|
}
|
|
967
967
|
|
|
@@ -971,7 +971,7 @@ class SecurityController extends NativeController {
|
|
|
971
971
|
* @param {Request} request
|
|
972
972
|
* @returns {Promise<Object>}
|
|
973
973
|
*/
|
|
974
|
-
mDeleteUsers(request) {
|
|
974
|
+
mDeleteUsers (request) {
|
|
975
975
|
return this._mDelete('user', request);
|
|
976
976
|
}
|
|
977
977
|
|
|
@@ -981,7 +981,7 @@ class SecurityController extends NativeController {
|
|
|
981
981
|
* @param {Request} request
|
|
982
982
|
* @returns {Promise<Object>}
|
|
983
983
|
*/
|
|
984
|
-
async scrollUsers(request) {
|
|
984
|
+
async scrollUsers (request) {
|
|
985
985
|
const id = request.getString('scrollId');
|
|
986
986
|
const ttl = request.getScrollTTLParam();
|
|
987
987
|
|
|
@@ -998,7 +998,7 @@ class SecurityController extends NativeController {
|
|
|
998
998
|
* @param {Request} request
|
|
999
999
|
* @returns {Promise<Object>}
|
|
1000
1000
|
*/
|
|
1001
|
-
async scrollProfiles(request) {
|
|
1001
|
+
async scrollProfiles (request) {
|
|
1002
1002
|
const id = request.getString('scrollId');
|
|
1003
1003
|
const ttl = request.getScrollTTLParam();
|
|
1004
1004
|
|
|
@@ -1013,7 +1013,7 @@ class SecurityController extends NativeController {
|
|
|
1013
1013
|
* @param {Request} request
|
|
1014
1014
|
* @returns {Promise<Object>}
|
|
1015
1015
|
*/
|
|
1016
|
-
async createCredentials(request) {
|
|
1016
|
+
async createCredentials (request) {
|
|
1017
1017
|
const id = request.getId();
|
|
1018
1018
|
const body = request.getBody();
|
|
1019
1019
|
const strategy = request.getString('strategy');
|
|
@@ -1037,7 +1037,7 @@ class SecurityController extends NativeController {
|
|
|
1037
1037
|
* @param {Request} request
|
|
1038
1038
|
* @returns {Promise<Object>}
|
|
1039
1039
|
*/
|
|
1040
|
-
async updateCredentials(request) {
|
|
1040
|
+
async updateCredentials (request) {
|
|
1041
1041
|
const id = request.getId();
|
|
1042
1042
|
const body = request.getBody();
|
|
1043
1043
|
const strategy = request.getString('strategy');
|
|
@@ -1062,7 +1062,7 @@ class SecurityController extends NativeController {
|
|
|
1062
1062
|
* @param {Request} request
|
|
1063
1063
|
* @returns {Promise.<Object>}
|
|
1064
1064
|
*/
|
|
1065
|
-
async hasCredentials(request) {
|
|
1065
|
+
async hasCredentials (request) {
|
|
1066
1066
|
const id = request.getId();
|
|
1067
1067
|
const strategy = request.getString('strategy');
|
|
1068
1068
|
|
|
@@ -1077,7 +1077,7 @@ class SecurityController extends NativeController {
|
|
|
1077
1077
|
* @param {Request} request
|
|
1078
1078
|
* @returns {Promise.<Object>}
|
|
1079
1079
|
*/
|
|
1080
|
-
async validateCredentials(request) {
|
|
1080
|
+
async validateCredentials (request) {
|
|
1081
1081
|
const strategy = request.getString('strategy');
|
|
1082
1082
|
|
|
1083
1083
|
this.assertIsStrategyRegistered(strategy);
|
|
@@ -1096,7 +1096,7 @@ class SecurityController extends NativeController {
|
|
|
1096
1096
|
* @param {Request} request
|
|
1097
1097
|
* @returns {Promise<Object>}
|
|
1098
1098
|
*/
|
|
1099
|
-
async deleteCredentials(request) {
|
|
1099
|
+
async deleteCredentials (request) {
|
|
1100
1100
|
const id = request.getId();
|
|
1101
1101
|
const strategy = request.getString('strategy');
|
|
1102
1102
|
|
|
@@ -1108,14 +1108,14 @@ class SecurityController extends NativeController {
|
|
|
1108
1108
|
|
|
1109
1109
|
global.kuzzle.log.info(`[SECURITY] User "${request.getKuid()}" applied action "${request.input.action}" on user "${id}."`);
|
|
1110
1110
|
|
|
1111
|
-
return {acknowledged: true};
|
|
1111
|
+
return { acknowledged: true };
|
|
1112
1112
|
}
|
|
1113
1113
|
|
|
1114
1114
|
/**
|
|
1115
1115
|
* @param {Request} request
|
|
1116
1116
|
* @returns {Promise<Object>}
|
|
1117
1117
|
*/
|
|
1118
|
-
async getCredentials(request) {
|
|
1118
|
+
async getCredentials (request) {
|
|
1119
1119
|
const id = request.getId();
|
|
1120
1120
|
const strategy = request.getString('strategy');
|
|
1121
1121
|
|
|
@@ -1134,7 +1134,7 @@ class SecurityController extends NativeController {
|
|
|
1134
1134
|
* @param {Request} request
|
|
1135
1135
|
* @returns {Promise<Object>}
|
|
1136
1136
|
*/
|
|
1137
|
-
async getCredentialsById(request) {
|
|
1137
|
+
async getCredentialsById (request) {
|
|
1138
1138
|
const id = request.getId();
|
|
1139
1139
|
const strategy = request.getString('strategy');
|
|
1140
1140
|
|
|
@@ -1153,7 +1153,7 @@ class SecurityController extends NativeController {
|
|
|
1153
1153
|
* @param {Request} request
|
|
1154
1154
|
* @returns {Promise<Object>}
|
|
1155
1155
|
*/
|
|
1156
|
-
async getCredentialFields(request) {
|
|
1156
|
+
async getCredentialFields (request) {
|
|
1157
1157
|
const strategy = request.getString('strategy');
|
|
1158
1158
|
|
|
1159
1159
|
this.assertIsStrategyRegistered(strategy);
|
|
@@ -1164,7 +1164,7 @@ class SecurityController extends NativeController {
|
|
|
1164
1164
|
/**
|
|
1165
1165
|
* @returns {Promise<Object>}
|
|
1166
1166
|
*/
|
|
1167
|
-
async getAllCredentialFields() {
|
|
1167
|
+
async getAllCredentialFields () {
|
|
1168
1168
|
const strategyFields = {};
|
|
1169
1169
|
|
|
1170
1170
|
global.kuzzle.pluginsManager.listStrategies()
|
|
@@ -1180,7 +1180,7 @@ class SecurityController extends NativeController {
|
|
|
1180
1180
|
* @param {Request} request
|
|
1181
1181
|
* @returns {Promise.<null>}
|
|
1182
1182
|
*/
|
|
1183
|
-
async revokeTokens(request) {
|
|
1183
|
+
async revokeTokens (request) {
|
|
1184
1184
|
const id = request.getId();
|
|
1185
1185
|
|
|
1186
1186
|
await this.ask('core:security:token:deleteByKuid', id);
|
|
@@ -1207,7 +1207,7 @@ class SecurityController extends NativeController {
|
|
|
1207
1207
|
|
|
1208
1208
|
await Bluebird.map(
|
|
1209
1209
|
ids,
|
|
1210
|
-
id => this.ask(`core:security:${type}:delete`, id, {refresh})
|
|
1210
|
+
id => this.ask(`core:security:${type}:delete`, id, { refresh })
|
|
1211
1211
|
.then(() => successes.push(id))
|
|
1212
1212
|
.catch(err => errors.push(err)));
|
|
1213
1213
|
|
|
@@ -1231,7 +1231,7 @@ class SecurityController extends NativeController {
|
|
|
1231
1231
|
* @returns {Promise}
|
|
1232
1232
|
* @private
|
|
1233
1233
|
*/
|
|
1234
|
-
async _persistUser(request, profileIds, content, { humanReadableId=true } = {}) {
|
|
1234
|
+
async _persistUser (request, profileIds, content, { humanReadableId = true } = {}) {
|
|
1235
1235
|
const credentials = request.getBodyObject('credentials', {});
|
|
1236
1236
|
const strategies = Object.keys(credentials);
|
|
1237
1237
|
const generator = humanReadableId
|
|
@@ -1253,7 +1253,7 @@ class SecurityController extends NativeController {
|
|
|
1253
1253
|
});
|
|
1254
1254
|
|
|
1255
1255
|
for (const strategy of strategies) {
|
|
1256
|
-
if (!global.kuzzle.pluginsManager.listStrategies().includes(strategy)) {
|
|
1256
|
+
if (! global.kuzzle.pluginsManager.listStrategies().includes(strategy)) {
|
|
1257
1257
|
throw kerror.get(
|
|
1258
1258
|
'security',
|
|
1259
1259
|
'credentials',
|
|
@@ -1293,12 +1293,12 @@ class SecurityController extends NativeController {
|
|
|
1293
1293
|
|
|
1294
1294
|
for (const strategy of strategies) {
|
|
1295
1295
|
try {
|
|
1296
|
-
const validate = this.getStrategyMethod(strategy,'validate');
|
|
1296
|
+
const validate = this.getStrategyMethod(strategy, 'validate');
|
|
1297
1297
|
|
|
1298
1298
|
await validate(request, credentials[strategy], id, strategy, false);
|
|
1299
1299
|
}
|
|
1300
1300
|
catch (error) {
|
|
1301
|
-
creationFailure = {error, validation: true};
|
|
1301
|
+
creationFailure = { error, validation: true };
|
|
1302
1302
|
break;
|
|
1303
1303
|
}
|
|
1304
1304
|
|
|
@@ -1309,7 +1309,7 @@ class SecurityController extends NativeController {
|
|
|
1309
1309
|
createdStrategies.push(strategy);
|
|
1310
1310
|
}
|
|
1311
1311
|
catch (error) {
|
|
1312
|
-
creationFailure = {error, validation: false};
|
|
1312
|
+
creationFailure = { error, validation: false };
|
|
1313
1313
|
break;
|
|
1314
1314
|
}
|
|
1315
1315
|
}
|
|
@@ -1379,7 +1379,7 @@ class SecurityController extends NativeController {
|
|
|
1379
1379
|
* @param {number} limit
|
|
1380
1380
|
* @throws
|
|
1381
1381
|
*/
|
|
1382
|
-
_getSearchPageSize(request) {
|
|
1382
|
+
_getSearchPageSize (request) {
|
|
1383
1383
|
const size = request.getInteger(
|
|
1384
1384
|
'size',
|
|
1385
1385
|
global.kuzzle.config.limits.documentsFetchCount);
|