kuzzle 2.16.11 → 2.17.2
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/lib/api/controllers/adminController.js +3 -3
- package/lib/api/controllers/authController.js +12 -12
- 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 +50 -50
- package/lib/api/controllers/serverController.js +73 -27
- package/lib/api/documentExtractor.js +3 -3
- package/lib/api/funnel.js +44 -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.js +8 -6
- package/lib/cluster/node.js +9 -9
- package/lib/cluster/publisher.js +1 -1
- package/lib/cluster/state.js +20 -4
- package/lib/cluster/subscriber.js +1 -1
- package/lib/cluster/workers/IDCardRenewer.js +2 -2
- 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 +11 -3
- package/lib/core/backend/backend.js +22 -17
- package/lib/core/backend/backendConfig.d.ts +5 -1
- package/lib/core/backend/backendConfig.js +25 -2
- package/lib/core/backend/backendController.js +21 -5
- package/lib/core/backend/backendErrors.d.ts +58 -0
- package/lib/core/backend/backendErrors.js +121 -0
- package/lib/core/backend/backendHook.js +21 -5
- package/lib/core/backend/backendImport.js +21 -5
- package/lib/core/backend/backendOpenApi.d.ts +9 -0
- package/lib/core/backend/backendOpenApi.js +69 -0
- package/lib/core/backend/backendPipe.js +21 -5
- package/lib/core/backend/backendPlugin.js +22 -3
- package/lib/core/backend/backendVault.js +21 -2
- package/lib/core/backend/index.d.ts +2 -0
- package/lib/core/backend/index.js +2 -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 +228 -50
- 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.js +22 -3
- 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/channel.js +20 -4
- package/lib/core/realtime/hotelClerk.js +24 -5
- 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 +445 -443
- package/lib/core/security/roleRepository.js +16 -16
- package/lib/core/security/securityLoader.js +2 -2
- package/lib/core/security/tokenRepository.js +11 -11
- package/lib/core/security/userRepository.js +8 -8
- package/lib/core/shared/abstractManifest.js +4 -4
- package/lib/core/shared/repository.js +5 -5
- package/lib/core/shared/sdk/embeddedSdk.js +21 -2
- 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/storage/indexCache.js +20 -4
- 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/errors/multipleErrorsError.d.ts +1 -1
- package/lib/kerror/errors/multipleErrorsError.js +3 -3
- package/lib/kerror/index.d.ts +82 -0
- package/lib/kerror/index.js +176 -143
- 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 +59 -9
- 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 +192 -232
- package/lib/model/security/rights.js +1 -1
- package/lib/model/security/role.d.ts +40 -0
- package/lib/model/security/role.js +174 -190
- package/lib/model/security/user.d.ts +29 -0
- package/lib/model/security/user.js +103 -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/Plugin.js +20 -4
- package/lib/types/Policy.d.ts +25 -0
- package/lib/types/{InternalLogger.js → Policy.js} +2 -2
- 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/errors/ErrorDefinition.d.ts +27 -0
- package/lib/types/errors/ErrorDefinition.js +3 -0
- package/lib/types/errors/ErrorDomains.d.ts +17 -0
- package/lib/types/errors/ErrorDomains.js +3 -0
- package/lib/types/index.d.ts +9 -1
- package/lib/types/index.js +9 -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 +284 -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/mutex.js +21 -2
- package/lib/util/requestAssertions.js +7 -7
- package/lib/util/wildcard.js +55 -0
- package/package-lock.json +535 -75
- package/package.json +5 -3
- package/lib/api/openApiGenerator.d.ts +0 -7
- package/lib/api/openApiGenerator.js +0 -197
- package/lib/types/InternalLogger.d.ts +0 -25
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
"use strict";
|
|
1
2
|
/*
|
|
2
3
|
* Kuzzle, a backend software, self-hostable and ready to use
|
|
3
4
|
* to power modern apps
|
|
@@ -18,259 +19,218 @@
|
|
|
18
19
|
* See the License for the specific language governing permissions and
|
|
19
20
|
* limitations under the License.
|
|
20
21
|
*/
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
22
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
23
|
+
if (k2 === undefined) k2 = k;
|
|
24
|
+
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
|
|
25
|
+
}) : (function(o, m, k, k2) {
|
|
26
|
+
if (k2 === undefined) k2 = k;
|
|
27
|
+
o[k2] = m[k];
|
|
28
|
+
}));
|
|
29
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
30
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
31
|
+
}) : function(o, v) {
|
|
32
|
+
o["default"] = v;
|
|
33
|
+
});
|
|
34
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
35
|
+
if (mod && mod.__esModule) return mod;
|
|
36
|
+
var result = {};
|
|
37
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
38
|
+
__setModuleDefault(result, mod);
|
|
39
|
+
return result;
|
|
40
|
+
};
|
|
41
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
42
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
43
|
+
};
|
|
44
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
45
|
+
exports.Profile = void 0;
|
|
46
|
+
const lodash_1 = __importDefault(require("lodash"));
|
|
47
|
+
const bluebird_1 = __importDefault(require("bluebird"));
|
|
48
|
+
const rights_1 = __importDefault(require("./rights"));
|
|
49
|
+
const kerror = __importStar(require("../../kerror"));
|
|
50
|
+
const safeObject_1 = require("../../util/safeObject");
|
|
31
51
|
const assertionError = kerror.wrap('api', 'assert');
|
|
32
|
-
|
|
33
52
|
/**
|
|
34
53
|
* @class Profile
|
|
35
54
|
*/
|
|
36
55
|
class Profile {
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
/**
|
|
44
|
-
* @param {Kuzzle} kuzzle
|
|
45
|
-
*
|
|
46
|
-
* @returns {Promise}
|
|
47
|
-
*/
|
|
48
|
-
async getPolicies() {
|
|
49
|
-
if (!global.kuzzle) {
|
|
50
|
-
throw kerror.get('security', 'profile', 'uninitialized', this._id);
|
|
56
|
+
constructor() {
|
|
57
|
+
this._id = null;
|
|
58
|
+
this.policies = [];
|
|
59
|
+
this.optimizedPolicies = [];
|
|
60
|
+
this.rateLimit = 0;
|
|
51
61
|
}
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
if (this.policies === undefined || this.policies.length === 0) {
|
|
66
|
-
return false;
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
const policies = await this.getPolicies();
|
|
70
|
-
|
|
71
|
-
const results = await Bluebird.map(
|
|
72
|
-
policies,
|
|
73
|
-
policy => policy.role.isActionAllowed(request, policy.restrictedTo));
|
|
74
|
-
|
|
75
|
-
return results.includes(true);
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
/**
|
|
79
|
-
* Validates the Profile format
|
|
80
|
-
*
|
|
81
|
-
* @param {Object} [options]
|
|
82
|
-
* @param {boolean} [options.strict] - If true, only allows resctrictions on
|
|
83
|
-
* existing indexes/collections
|
|
84
|
-
* @returns {Promise}
|
|
85
|
-
*/
|
|
86
|
-
async validateDefinition({ strict = false } = {}) {
|
|
87
|
-
this.validateRateLimit();
|
|
88
|
-
|
|
89
|
-
if (!this.policies) {
|
|
90
|
-
throw assertionError.get('missing_argument', `${this._id}.policies`);
|
|
62
|
+
/**
|
|
63
|
+
* @param {Kuzzle} kuzzle
|
|
64
|
+
*
|
|
65
|
+
* @returns {Promise}
|
|
66
|
+
*/
|
|
67
|
+
async getPolicies() {
|
|
68
|
+
if (!global.kuzzle) {
|
|
69
|
+
throw kerror.get('security', 'profile', 'uninitialized', this._id);
|
|
70
|
+
}
|
|
71
|
+
return bluebird_1.default.map(this.optimizedPolicies, async ({ restrictedTo, roleId }) => {
|
|
72
|
+
const role = await global.kuzzle.ask('core:security:role:get', roleId);
|
|
73
|
+
return { restrictedTo, role };
|
|
74
|
+
});
|
|
91
75
|
}
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
76
|
+
/**
|
|
77
|
+
* @param {Request} request
|
|
78
|
+
* @returns {Promise}
|
|
79
|
+
*/
|
|
80
|
+
async getAllowedPolicies(request) {
|
|
81
|
+
if (this.optimizedPolicies === undefined || this.optimizedPolicies.length === 0) {
|
|
82
|
+
return [];
|
|
83
|
+
}
|
|
84
|
+
const policies = await this.getPolicies();
|
|
85
|
+
return policies.filter(policy => policy.role.isActionAllowed(request));
|
|
95
86
|
}
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
87
|
+
/**
|
|
88
|
+
* @param {Request} request
|
|
89
|
+
* @returns {Promise<boolean>}
|
|
90
|
+
*/
|
|
91
|
+
async isActionAllowed(request) {
|
|
92
|
+
if (this.optimizedPolicies === undefined || this.optimizedPolicies.length === 0) {
|
|
93
|
+
return false;
|
|
94
|
+
}
|
|
95
|
+
const allowedPolicies = await this.getAllowedPolicies(request);
|
|
96
|
+
return allowedPolicies
|
|
97
|
+
.some(policy => policy.role.checkRestrictions(request.input.args.index, request.input.args.collection, policy.restrictedTo));
|
|
99
98
|
}
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
`${this._id}.policies
|
|
112
|
-
'"roleId", "restrictedTo"');
|
|
99
|
+
/**
|
|
100
|
+
* Validates the Profile format
|
|
101
|
+
*
|
|
102
|
+
* @param {Object} [options]
|
|
103
|
+
* @param {boolean} [options.strict] - If true, only allows resctrictions on
|
|
104
|
+
* existing indexes/collections
|
|
105
|
+
* @returns {Promise}
|
|
106
|
+
*/
|
|
107
|
+
async validateDefinition({ strict = false } = {}) {
|
|
108
|
+
this.validateRateLimit();
|
|
109
|
+
if (!this.policies) {
|
|
110
|
+
throw assertionError.get('missing_argument', `${this._id}.policies`);
|
|
113
111
|
}
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
if (policy.restrictedTo) {
|
|
117
|
-
if (!Array.isArray(policy.restrictedTo)) {
|
|
118
|
-
throw assertionError.get(
|
|
119
|
-
'invalid_type',
|
|
120
|
-
`${this._id}.policies[${i}].restrictedTo`,
|
|
121
|
-
'object[]');
|
|
112
|
+
if (!Array.isArray(this.policies)) {
|
|
113
|
+
throw assertionError.get('invalid_type', `${this._id}.policies`, 'object[]');
|
|
122
114
|
}
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
'object');
|
|
131
|
-
}
|
|
132
|
-
|
|
133
|
-
if (restriction.index === null || restriction.index === undefined) {
|
|
134
|
-
throw assertionError.get(
|
|
135
|
-
'missing_argument',
|
|
136
|
-
`${this._id}.policies[${i}].restrictedTo[${j}].index`);
|
|
137
|
-
}
|
|
138
|
-
|
|
139
|
-
if (strict) {
|
|
140
|
-
const indexExists = await global.kuzzle.ask(
|
|
141
|
-
'core:storage:public:index:exist',
|
|
142
|
-
restriction.index);
|
|
143
|
-
|
|
144
|
-
if (!indexExists) {
|
|
145
|
-
throw kerror.get(
|
|
146
|
-
'services',
|
|
147
|
-
'storage',
|
|
148
|
-
'unknown_index',
|
|
149
|
-
restriction.index);
|
|
150
|
-
}
|
|
151
|
-
}
|
|
152
|
-
|
|
153
|
-
if ( restriction.collections !== undefined
|
|
154
|
-
&& restriction.collections !== null
|
|
155
|
-
) {
|
|
156
|
-
if (!Array.isArray(restriction.collections)) {
|
|
157
|
-
throw assertionError.get(
|
|
158
|
-
'invalid_type',
|
|
159
|
-
`${this._id}.policies[${i}].restrictedTo[${j}].collections`,
|
|
160
|
-
'string[]');
|
|
115
|
+
if (this.policies.length === 0) {
|
|
116
|
+
throw assertionError.get('empty_argument', `${this._id}.policies`);
|
|
117
|
+
}
|
|
118
|
+
let i = 0;
|
|
119
|
+
for (const policy of this.policies) {
|
|
120
|
+
if (!policy.roleId) {
|
|
121
|
+
throw assertionError.get('missing_argument', `${this._id}.policies[${i}].roleId`);
|
|
161
122
|
}
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
for (const collection of restriction.collections) {
|
|
166
|
-
const isValid = await global.kuzzle.ask(
|
|
167
|
-
'core:storage:public:collection:exist',
|
|
168
|
-
restriction.index,
|
|
169
|
-
collection);
|
|
170
|
-
|
|
171
|
-
if (!isValid) {
|
|
172
|
-
invalidCollections.push(collection);
|
|
123
|
+
for (const member of Object.keys(policy)) {
|
|
124
|
+
if (member !== 'roleId' && member !== 'restrictedTo') {
|
|
125
|
+
throw assertionError.get('unexpected_argument', `${this._id}.policies[${i}].${member}`, '"roleId", "restrictedTo"');
|
|
173
126
|
}
|
|
174
|
-
}
|
|
175
|
-
|
|
176
|
-
if (invalidCollections.length > 0) {
|
|
177
|
-
throw kerror.get(
|
|
178
|
-
'services',
|
|
179
|
-
'storage',
|
|
180
|
-
'unknown_collection',
|
|
181
|
-
restriction.index,
|
|
182
|
-
invalidCollections);
|
|
183
|
-
}
|
|
184
127
|
}
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
128
|
+
if (policy.restrictedTo) {
|
|
129
|
+
if (!Array.isArray(policy.restrictedTo)) {
|
|
130
|
+
throw assertionError.get('invalid_type', `${this._id}.policies[${i}].restrictedTo`, 'object[]');
|
|
131
|
+
}
|
|
132
|
+
let j = 0;
|
|
133
|
+
for (const restriction of policy.restrictedTo) {
|
|
134
|
+
if (!(0, safeObject_1.isPlainObject)(restriction)) {
|
|
135
|
+
throw assertionError.get('invalid_type', `${this._id}.policies[${i}].restrictedTo[${restriction}]`, 'object');
|
|
136
|
+
}
|
|
137
|
+
if (restriction.index === null || restriction.index === undefined) {
|
|
138
|
+
throw assertionError.get('missing_argument', `${this._id}.policies[${i}].restrictedTo[${j}].index`);
|
|
139
|
+
}
|
|
140
|
+
if (strict) {
|
|
141
|
+
const indexExists = await global.kuzzle.ask('core:storage:public:index:exist', restriction.index);
|
|
142
|
+
if (!indexExists) {
|
|
143
|
+
throw kerror.get('services', 'storage', 'unknown_index', restriction.index);
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
if (restriction.collections !== undefined
|
|
147
|
+
&& restriction.collections !== null) {
|
|
148
|
+
if (!Array.isArray(restriction.collections)) {
|
|
149
|
+
throw assertionError.get('invalid_type', `${this._id}.policies[${i}].restrictedTo[${j}].collections`, 'string[]');
|
|
150
|
+
}
|
|
151
|
+
if (strict) {
|
|
152
|
+
const invalidCollections = [];
|
|
153
|
+
for (const collection of restriction.collections) {
|
|
154
|
+
const isValid = await global.kuzzle.ask('core:storage:public:collection:exist', restriction.index, collection);
|
|
155
|
+
if (!isValid) {
|
|
156
|
+
invalidCollections.push(collection);
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
if (invalidCollections.length > 0) {
|
|
160
|
+
throw kerror.get('services', 'storage', 'unknown_collection', restriction.index, invalidCollections);
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
for (const member of Object.keys(restriction)) {
|
|
165
|
+
if (member !== 'index' && member !== 'collections') {
|
|
166
|
+
throw assertionError.get('unexpected_argument', `${this._id}.policies[${i}].restrictedTo[${j}].${member}`, '"index", "collections"');
|
|
167
|
+
}
|
|
168
|
+
}
|
|
169
|
+
j++;
|
|
170
|
+
}
|
|
193
171
|
}
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
j++;
|
|
172
|
+
i++;
|
|
197
173
|
}
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
i++;
|
|
174
|
+
return true;
|
|
201
175
|
}
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
for (const policy of policies) {
|
|
217
|
-
const role = policy.role;
|
|
218
|
-
let restrictedTo = _.cloneDeep(policy.restrictedTo);
|
|
219
|
-
|
|
220
|
-
if (restrictedTo === undefined || restrictedTo.length === 0) {
|
|
221
|
-
restrictedTo = [{collections: ['*'], index: '*'}];
|
|
222
|
-
}
|
|
223
|
-
|
|
224
|
-
for (const [controller, rights] of Object.entries(role.controllers)) {
|
|
225
|
-
for (const [action, actionRights] of Object.entries(rights.actions)) {
|
|
226
|
-
for (const restriction of restrictedTo) {
|
|
227
|
-
if (restriction.collections === undefined
|
|
228
|
-
|| restriction.collections.length === 0
|
|
229
|
-
) {
|
|
230
|
-
restriction.collections = ['*'];
|
|
176
|
+
/**
|
|
177
|
+
* Resolves an array of rights related to the profile's roles.
|
|
178
|
+
*
|
|
179
|
+
* @returns {Promise}
|
|
180
|
+
*/
|
|
181
|
+
async getRights() {
|
|
182
|
+
const profileRights = {};
|
|
183
|
+
const policies = await this.getPolicies();
|
|
184
|
+
for (const policy of policies) {
|
|
185
|
+
const role = policy.role;
|
|
186
|
+
let restrictedTo = lodash_1.default.cloneDeep(policy.restrictedTo);
|
|
187
|
+
if (restrictedTo === undefined || restrictedTo.size === 0) {
|
|
188
|
+
restrictedTo = new Map([['*', ['*']]]);
|
|
231
189
|
}
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
190
|
+
for (const [controller, rights] of Object.entries(role.controllers)) {
|
|
191
|
+
for (const [action, actionRights] of Object.entries(rights.actions)) {
|
|
192
|
+
for (const [restrictedIndex, restrictedCollections] of restrictedTo.entries()) {
|
|
193
|
+
let collections = restrictedCollections;
|
|
194
|
+
if (restrictedCollections === undefined
|
|
195
|
+
|| restrictedCollections.length === 0) {
|
|
196
|
+
collections = ['*'];
|
|
197
|
+
}
|
|
198
|
+
for (const collection of collections) {
|
|
199
|
+
const rightsItem = {
|
|
200
|
+
action,
|
|
201
|
+
collection,
|
|
202
|
+
controller,
|
|
203
|
+
index: restrictedIndex,
|
|
204
|
+
value: actionRights
|
|
205
|
+
};
|
|
206
|
+
const rightsObject = {
|
|
207
|
+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
208
|
+
// @ts-ignore
|
|
209
|
+
[this.constructor._hash(rightsItem)]: rightsItem
|
|
210
|
+
};
|
|
211
|
+
lodash_1.default.assignWith(profileRights, rightsObject, rights_1.default.merge);
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
}
|
|
246
215
|
}
|
|
247
|
-
}
|
|
248
216
|
}
|
|
249
|
-
|
|
250
|
-
}
|
|
251
|
-
|
|
252
|
-
return profileRights;
|
|
253
|
-
}
|
|
254
|
-
|
|
255
|
-
static _hash () {
|
|
256
|
-
return false;
|
|
257
|
-
}
|
|
258
|
-
|
|
259
|
-
validateRateLimit () {
|
|
260
|
-
if (this.rateLimit === null || this.rateLimit === undefined) {
|
|
261
|
-
this.rateLimit = 0;
|
|
217
|
+
return profileRights;
|
|
262
218
|
}
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|| !Number.isInteger(this.rateLimit)
|
|
266
|
-
) {
|
|
267
|
-
throw assertionError.get('invalid_type', 'rateLimit', 'integer');
|
|
219
|
+
static _hash() {
|
|
220
|
+
return false;
|
|
268
221
|
}
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
222
|
+
validateRateLimit() {
|
|
223
|
+
if (this.rateLimit === null || this.rateLimit === undefined) {
|
|
224
|
+
this.rateLimit = 0;
|
|
225
|
+
}
|
|
226
|
+
if (typeof this.rateLimit !== 'number'
|
|
227
|
+
|| !Number.isInteger(this.rateLimit)) {
|
|
228
|
+
throw assertionError.get('invalid_type', 'rateLimit', 'integer');
|
|
229
|
+
}
|
|
230
|
+
if (this.rateLimit < 0) {
|
|
231
|
+
throw assertionError.get('invalid_argument', 'rateLimit', 'positive integer, or zero');
|
|
232
|
+
}
|
|
272
233
|
}
|
|
273
|
-
}
|
|
274
234
|
}
|
|
275
|
-
|
|
276
|
-
|
|
235
|
+
exports.Profile = Profile;
|
|
236
|
+
//# sourceMappingURL=profile.js.map
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { ControllerRight, ControllerRights } from '../../types/ControllerRights';
|
|
2
|
+
import { KuzzleRequest } from '../../../index';
|
|
3
|
+
import { OptimizedPolicyRestrictions } from '../../types/PolicyRestrictions';
|
|
4
|
+
/**
|
|
5
|
+
* @class Role
|
|
6
|
+
*/
|
|
7
|
+
export declare class Role {
|
|
8
|
+
controllers: ControllerRights;
|
|
9
|
+
_id: string;
|
|
10
|
+
constructor();
|
|
11
|
+
/**
|
|
12
|
+
* @param {Request} request
|
|
13
|
+
* @returns {boolean}
|
|
14
|
+
*/
|
|
15
|
+
isActionAllowed(request: KuzzleRequest): boolean;
|
|
16
|
+
/**
|
|
17
|
+
* @returns {Promise}
|
|
18
|
+
*/
|
|
19
|
+
validateDefinition(): Promise<void>;
|
|
20
|
+
/**
|
|
21
|
+
* @param {String} index
|
|
22
|
+
* @param {String} collection
|
|
23
|
+
* @param {Map<string, string[]>} restrictedTo Restricted indexes
|
|
24
|
+
* @returns {Boolean} resolves to a Boolean value
|
|
25
|
+
*/
|
|
26
|
+
checkRestrictions(index: string, collection: string, restrictedTo: OptimizedPolicyRestrictions): boolean;
|
|
27
|
+
/**
|
|
28
|
+
* Verifies that a controller rights definition is correct
|
|
29
|
+
*
|
|
30
|
+
* @param {Array.<string, Object>}
|
|
31
|
+
* @throws If the controller definition is invalid
|
|
32
|
+
*/
|
|
33
|
+
validateControllerRights(name: string, controller: ControllerRight): void;
|
|
34
|
+
/**
|
|
35
|
+
* Checks if current role allows to log in
|
|
36
|
+
*
|
|
37
|
+
* @returns {boolean}
|
|
38
|
+
*/
|
|
39
|
+
canLogIn(): boolean;
|
|
40
|
+
}
|