kuzzle 2.19.2 → 2.19.3
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 +94 -80
- package/lib/api/controllers/authController.js +239 -212
- package/lib/api/controllers/baseController.js +89 -51
- package/lib/api/controllers/bulkController.js +62 -49
- package/lib/api/controllers/clusterController.js +6 -8
- package/lib/api/controllers/collectionController.js +140 -129
- package/lib/api/controllers/debugController.d.ts +2 -2
- package/lib/api/controllers/debugController.js +33 -31
- package/lib/api/controllers/documentController.js +365 -274
- package/lib/api/controllers/index.js +13 -13
- package/lib/api/controllers/indexController.js +46 -50
- package/lib/api/controllers/memoryStorageController.js +410 -360
- package/lib/api/controllers/realtimeController.js +37 -36
- package/lib/api/controllers/securityController.js +553 -412
- package/lib/api/controllers/serverController.js +111 -104
- package/lib/api/documentExtractor.js +75 -68
- package/lib/api/funnel.js +411 -312
- package/lib/api/httpRoutes.js +1493 -324
- package/lib/api/openapi/OpenApiManager.d.ts +1 -1
- package/lib/api/openapi/OpenApiManager.js +22 -22
- package/lib/api/openapi/components/document/count.yaml +1 -1
- package/lib/api/openapi/components/document/create.yaml +2 -2
- package/lib/api/openapi/components/document/delete.yaml +1 -1
- package/lib/api/openapi/components/document/deleteByQuery.yaml +1 -1
- package/lib/api/openapi/components/document/exists.yaml +1 -1
- package/lib/api/openapi/components/document/get.yaml +2 -2
- package/lib/api/openapi/components/document/index.js +12 -12
- package/lib/api/openapi/components/document/replace.yaml +1 -1
- package/lib/api/openapi/components/document/scroll.yaml +1 -1
- package/lib/api/openapi/components/document/validate.yaml +1 -1
- package/lib/api/openapi/components/index.d.ts +2 -2
- package/lib/api/openapi/components/index.js +1 -1
- package/lib/api/openapi/components/security/index.js +1 -1
- package/lib/api/openapi/components/security/upsertUser.yaml +2 -3
- package/lib/api/openapi/index.d.ts +1 -1
- package/lib/api/openapi/openApiGenerator.d.ts +1 -1
- package/lib/api/openapi/openApiGenerator.js +7 -7
- package/lib/api/rateLimiter.js +12 -13
- package/lib/api/request/index.d.ts +4 -4
- package/lib/api/request/kuzzleRequest.d.ts +9 -9
- package/lib/api/request/kuzzleRequest.js +89 -87
- package/lib/api/request/requestContext.d.ts +2 -2
- package/lib/api/request/requestContext.js +17 -17
- package/lib/api/request/requestInput.d.ts +1 -1
- package/lib/api/request/requestInput.js +19 -19
- package/lib/api/request/requestResponse.d.ts +4 -4
- package/lib/api/request/requestResponse.js +31 -33
- package/lib/cluster/command.js +48 -44
- package/lib/cluster/idCardHandler.d.ts +1 -1
- package/lib/cluster/idCardHandler.js +15 -15
- package/lib/cluster/index.js +2 -2
- package/lib/cluster/node.js +301 -269
- package/lib/cluster/publisher.js +45 -46
- package/lib/cluster/state.d.ts +5 -5
- package/lib/cluster/state.js +8 -8
- package/lib/cluster/subscriber.js +163 -113
- package/lib/cluster/workers/IDCardRenewer.js +33 -32
- package/lib/config/default.config.d.ts +1 -1
- package/lib/config/default.config.js +212 -171
- package/lib/config/documentEventAliases.js +6 -6
- package/lib/config/index.js +161 -98
- package/lib/config/sdkCompatibility.json +8 -8
- package/lib/core/auth/formatProcessing.js +7 -7
- package/lib/core/auth/passportResponse.js +7 -7
- package/lib/core/auth/passportWrapper.js +34 -30
- package/lib/core/auth/tokenManager.d.ts +2 -2
- package/lib/core/auth/tokenManager.js +11 -10
- package/lib/core/backend/applicationManager.d.ts +1 -1
- package/lib/core/backend/applicationManager.js +2 -2
- package/lib/core/backend/backend.d.ts +3 -3
- package/lib/core/backend/backend.js +34 -31
- package/lib/core/backend/backendCluster.d.ts +2 -2
- package/lib/core/backend/backendCluster.js +5 -5
- package/lib/core/backend/backendConfig.d.ts +2 -2
- package/lib/core/backend/backendConfig.js +3 -3
- package/lib/core/backend/backendController.d.ts +2 -2
- package/lib/core/backend/backendController.js +9 -10
- package/lib/core/backend/backendErrors.d.ts +3 -3
- package/lib/core/backend/backendErrors.js +2 -1
- package/lib/core/backend/backendHook.d.ts +2 -2
- package/lib/core/backend/backendHook.js +5 -5
- package/lib/core/backend/backendImport.d.ts +3 -3
- package/lib/core/backend/backendImport.js +23 -23
- package/lib/core/backend/backendOpenApi.d.ts +2 -2
- package/lib/core/backend/backendOpenApi.js +16 -16
- package/lib/core/backend/backendPipe.d.ts +2 -2
- package/lib/core/backend/backendPipe.js +6 -6
- package/lib/core/backend/backendPlugin.d.ts +4 -4
- package/lib/core/backend/backendPlugin.js +14 -14
- package/lib/core/backend/backendStorage.d.ts +2 -2
- package/lib/core/backend/backendStorage.js +1 -2
- package/lib/core/backend/backendVault.d.ts +2 -2
- package/lib/core/backend/backendVault.js +3 -3
- package/lib/core/backend/index.d.ts +14 -14
- package/lib/core/backend/internalLogger.d.ts +1 -1
- package/lib/core/backend/internalLogger.js +5 -5
- package/lib/core/cache/cacheDbEnum.js +4 -4
- package/lib/core/cache/cacheEngine.js +79 -85
- package/lib/core/network/accessLogger.js +126 -120
- package/lib/core/network/clientConnection.js +5 -5
- package/lib/core/network/context.js +8 -8
- package/lib/core/network/entryPoint.js +100 -85
- package/lib/core/network/httpRouter/index.js +63 -60
- package/lib/core/network/httpRouter/routeHandler.js +18 -19
- package/lib/core/network/httpRouter/routePart.js +23 -19
- package/lib/core/network/protocolManifest.js +3 -3
- package/lib/core/network/protocols/httpMessage.js +8 -10
- package/lib/core/network/protocols/httpwsProtocol.js +305 -250
- package/lib/core/network/protocols/internalProtocol.js +27 -24
- package/lib/core/network/protocols/mqttProtocol.js +106 -96
- package/lib/core/network/protocols/protocol.js +20 -17
- package/lib/core/network/router.js +56 -46
- package/lib/core/plugin/plugin.js +151 -120
- package/lib/core/plugin/pluginContext.d.ts +7 -7
- package/lib/core/plugin/pluginContext.js +48 -44
- package/lib/core/plugin/pluginManifest.js +13 -12
- package/lib/core/plugin/pluginRepository.js +26 -27
- package/lib/core/plugin/pluginsManager.js +425 -304
- package/lib/core/plugin/privilegedContext.js +3 -3
- package/lib/core/realtime/actionEnum.js +1 -1
- package/lib/core/realtime/channel.d.ts +1 -1
- package/lib/core/realtime/channel.js +22 -22
- package/lib/core/realtime/connectionRooms.d.ts +1 -1
- package/lib/core/realtime/hotelClerk.d.ts +2 -2
- package/lib/core/realtime/hotelClerk.js +53 -50
- package/lib/core/realtime/index.js +5 -5
- package/lib/core/realtime/notification/document.js +25 -25
- package/lib/core/realtime/notification/index.js +4 -4
- package/lib/core/realtime/notification/server.js +3 -3
- package/lib/core/realtime/notification/user.js +4 -4
- package/lib/core/realtime/notifier.js +113 -75
- package/lib/core/realtime/room.d.ts +1 -1
- package/lib/core/realtime/subscription.d.ts +1 -1
- package/lib/core/realtime/subscription.js +1 -1
- package/lib/core/security/index.js +8 -8
- package/lib/core/security/profileRepository.d.ts +6 -6
- package/lib/core/security/profileRepository.js +48 -45
- package/lib/core/security/roleRepository.js +127 -115
- package/lib/core/security/securityLoader.js +70 -63
- package/lib/core/security/tokenRepository.js +132 -118
- package/lib/core/security/userRepository.js +104 -88
- package/lib/core/shared/KoncordeWrapper.d.ts +1 -1
- package/lib/core/shared/KoncordeWrapper.js +3 -1
- package/lib/core/shared/abstractManifest.js +22 -23
- package/lib/core/shared/repository.js +69 -67
- package/lib/core/shared/sdk/embeddedSdk.d.ts +2 -2
- package/lib/core/shared/sdk/embeddedSdk.js +36 -32
- package/lib/core/shared/sdk/funnelProtocol.d.ts +1 -1
- package/lib/core/shared/sdk/funnelProtocol.js +11 -11
- package/lib/core/shared/sdk/impersonatedSdk.js +19 -18
- package/lib/core/shared/store.js +127 -32
- package/lib/core/statistics/index.js +2 -2
- package/lib/core/statistics/statistics.js +99 -85
- package/lib/core/storage/clientAdapter.js +219 -136
- package/lib/core/storage/indexCache.js +3 -3
- package/lib/core/storage/storageEngine.js +10 -13
- package/lib/core/storage/storeScopeEnum.js +3 -3
- package/lib/core/validation/baseType.js +12 -10
- package/lib/core/validation/index.js +2 -2
- package/lib/core/validation/types/anything.js +4 -4
- package/lib/core/validation/types/boolean.js +7 -7
- package/lib/core/validation/types/date.js +165 -131
- package/lib/core/validation/types/email.js +18 -21
- package/lib/core/validation/types/enum.js +34 -21
- package/lib/core/validation/types/geoPoint.js +7 -7
- package/lib/core/validation/types/geoShape.js +148 -125
- package/lib/core/validation/types/integer.js +9 -9
- package/lib/core/validation/types/ipAddress.js +17 -19
- package/lib/core/validation/types/numeric.js +36 -29
- package/lib/core/validation/types/object.js +19 -19
- package/lib/core/validation/types/string.js +36 -29
- package/lib/core/validation/types/url.js +17 -19
- package/lib/core/validation/validation.js +422 -378
- package/lib/kerror/codes/1-services.json +7 -1
- package/lib/kerror/codes/4-plugin.json +2 -2
- package/lib/kerror/codes/index.js +85 -63
- package/lib/kerror/errors/badRequestError.d.ts +1 -1
- package/lib/kerror/errors/externalServiceError.d.ts +1 -1
- package/lib/kerror/errors/forbiddenError.d.ts +1 -1
- package/lib/kerror/errors/gatewayTimeoutError.d.ts +1 -1
- package/lib/kerror/errors/index.d.ts +15 -15
- package/lib/kerror/errors/internalError.d.ts +1 -1
- package/lib/kerror/errors/kuzzleError.d.ts +1 -1
- package/lib/kerror/errors/multipleErrorsError.d.ts +1 -1
- package/lib/kerror/errors/multipleErrorsError.js +1 -1
- package/lib/kerror/errors/notFoundError.d.ts +1 -1
- package/lib/kerror/errors/partialError.d.ts +1 -1
- package/lib/kerror/errors/partialError.js +1 -1
- package/lib/kerror/errors/pluginImplementationError.d.ts +1 -1
- package/lib/kerror/errors/pluginImplementationError.js +2 -1
- package/lib/kerror/errors/preconditionError.d.ts +1 -1
- package/lib/kerror/errors/serviceUnavailableError.d.ts +1 -1
- package/lib/kerror/errors/sizeLimitError.d.ts +1 -1
- package/lib/kerror/errors/tooManyRequestsError.d.ts +1 -1
- package/lib/kerror/errors/unauthorizedError.d.ts +1 -1
- package/lib/kerror/index.d.ts +3 -3
- package/lib/kerror/index.js +17 -16
- package/lib/kuzzle/dumpGenerator.js +130 -114
- package/lib/kuzzle/event/kuzzleEventEmitter.js +96 -70
- package/lib/kuzzle/event/pipeRunner.js +25 -24
- package/lib/kuzzle/event/waterfall.js +13 -15
- package/lib/kuzzle/index.js +2 -2
- package/lib/kuzzle/internalIndexHandler.js +80 -59
- package/lib/kuzzle/kuzzle.js +99 -99
- package/lib/kuzzle/kuzzleStateEnum.js +1 -1
- package/lib/kuzzle/log.js +23 -18
- package/lib/kuzzle/vault.js +34 -19
- package/lib/model/security/profile.d.ts +3 -3
- package/lib/model/security/profile.js +38 -37
- package/lib/model/security/rights.js +5 -5
- package/lib/model/security/role.d.ts +3 -3
- package/lib/model/security/role.js +25 -26
- package/lib/model/security/token.d.ts +1 -1
- package/lib/model/security/token.js +4 -4
- package/lib/model/security/user.d.ts +2 -2
- package/lib/model/security/user.js +9 -9
- package/lib/model/storage/apiKey.js +43 -33
- package/lib/model/storage/baseModel.js +49 -45
- package/lib/service/cache/redis.js +60 -55
- package/lib/service/service.js +17 -17
- package/lib/service/storage/elasticsearch.js +839 -755
- package/lib/service/storage/esWrapper.js +103 -86
- package/lib/service/storage/queryTranslator.js +52 -59
- package/lib/types/Controller.d.ts +3 -3
- package/lib/types/ControllerDefinition.d.ts +3 -3
- package/lib/types/DebugModule.d.ts +2 -2
- package/lib/types/DebugModule.js +1 -1
- package/lib/types/Global.d.ts +1 -1
- package/lib/types/HttpStream.d.ts +2 -1
- package/lib/types/HttpStream.js +7 -5
- package/lib/types/Kuzzle.d.ts +1 -1
- package/lib/types/KuzzleDocument.d.ts +1 -1
- package/lib/types/OpenApiDefinition.d.ts +1 -1
- package/lib/types/PasswordPolicy.d.ts +1 -1
- package/lib/types/Plugin.d.ts +6 -6
- package/lib/types/Plugin.js +2 -2
- package/lib/types/Policy.d.ts +1 -1
- package/lib/types/RequestPayload.d.ts +1 -1
- package/lib/types/ResponsePayload.d.ts +1 -1
- package/lib/types/Token.d.ts +1 -1
- package/lib/types/User.d.ts +1 -1
- package/lib/types/config/DumpConfiguration.d.ts +8 -8
- package/lib/types/config/HttpConfiguration.d.ts +1 -1
- package/lib/types/config/KuzzleConfiguration.d.ts +1 -1
- package/lib/types/config/LimitsConfiguration.d.ts +8 -8
- package/lib/types/config/PluginsConfiguration.d.ts +4 -4
- package/lib/types/config/SecurityConfiguration.d.ts +62 -62
- package/lib/types/config/ServerConfiguration.d.ts +55 -55
- package/lib/types/config/ServicesConfiguration.d.ts +2 -2
- package/lib/types/config/internalCache/InternalCacheRedisConfiguration.d.ts +10 -10
- package/lib/types/config/publicCache/PublicCacheRedisConfiguration.d.ts +3 -3
- package/lib/types/config/storageEngine/StorageEngineElasticsearchConfiguration.d.ts +194 -110
- package/lib/types/errors/ErrorDefinition.d.ts +1 -1
- package/lib/types/errors/ErrorDomains.d.ts +1 -1
- package/lib/types/index.d.ts +38 -38
- package/lib/types/realtime/RealtimeScope.d.ts +1 -1
- package/lib/types/realtime/RealtimeUsers.d.ts +1 -1
- package/lib/util/assertType.js +13 -11
- package/lib/util/async.d.ts +1 -0
- package/lib/util/async.js +61 -0
- package/lib/util/asyncStore.js +19 -21
- package/lib/util/bufferedPassThrough.d.ts +2 -2
- package/lib/util/bufferedPassThrough.js +4 -4
- package/lib/util/bytes.js +9 -13
- package/lib/util/crypto.js +1 -1
- package/lib/util/debug.js +5 -5
- package/lib/util/deprecate.js +24 -21
- package/lib/util/didYouMean.js +7 -7
- package/lib/util/dump-collection.d.ts +2 -2
- package/lib/util/dump-collection.js +26 -26
- package/lib/util/esRequest.d.ts +1 -0
- package/lib/util/esRequest.js +62 -0
- package/lib/util/extractFields.js +24 -25
- package/lib/util/inflector.js +5 -5
- package/lib/util/koncordeCompat.d.ts +2 -2
- package/lib/util/koncordeCompat.js +5 -5
- package/lib/util/memoize.js +3 -5
- package/lib/util/mutex.d.ts +19 -1
- package/lib/util/mutex.js +39 -12
- package/lib/util/name-generator.js +1331 -1331
- package/lib/util/promback.js +8 -10
- package/lib/util/readYamlFile.d.ts +1 -1
- package/lib/util/readYamlFile.js +1 -1
- package/lib/util/requestAssertions.js +34 -34
- package/lib/util/safeObject.js +5 -5
- package/lib/util/stackTrace.js +20 -22
- package/lib/util/wildcard.js +15 -15
- package/package.json +6 -6
- package/npm-shrinkwrap.json +0 -19422
package/lib/kuzzle/kuzzle.js
CHANGED
|
@@ -80,20 +80,20 @@ const package_json_1 = require("../../package.json");
|
|
|
80
80
|
const name_generator_1 = require("../util/name-generator");
|
|
81
81
|
const openapi_1 = require("../api/openapi");
|
|
82
82
|
const crypto_1 = require("../util/crypto");
|
|
83
|
-
exports.BACKEND_IMPORT_KEY =
|
|
83
|
+
exports.BACKEND_IMPORT_KEY = "backend:init:import";
|
|
84
84
|
let _kuzzle = null;
|
|
85
|
-
Reflect.defineProperty(global,
|
|
85
|
+
Reflect.defineProperty(global, "kuzzle", {
|
|
86
86
|
configurable: true,
|
|
87
87
|
enumerable: false,
|
|
88
88
|
get() {
|
|
89
89
|
if (_kuzzle === null) {
|
|
90
|
-
throw new Error(
|
|
90
|
+
throw new Error("Kuzzle instance not found. Did you try to use a live-only feature before starting your application?");
|
|
91
91
|
}
|
|
92
92
|
return _kuzzle;
|
|
93
93
|
},
|
|
94
94
|
set(value) {
|
|
95
95
|
if (_kuzzle !== null) {
|
|
96
|
-
throw new Error(
|
|
96
|
+
throw new Error("Cannot build a Kuzzle instance: another one already exists");
|
|
97
97
|
}
|
|
98
98
|
_kuzzle = value;
|
|
99
99
|
},
|
|
@@ -106,7 +106,7 @@ class Kuzzle extends kuzzleEventEmitter_1.default {
|
|
|
106
106
|
this._state = kuzzleStateEnum_1.default.STARTING;
|
|
107
107
|
this.config = config;
|
|
108
108
|
this.log = new log_1.default();
|
|
109
|
-
this.rootPath = path_1.default.resolve(path_1.default.join(__dirname,
|
|
109
|
+
this.rootPath = path_1.default.resolve(path_1.default.join(__dirname, "../.."));
|
|
110
110
|
this.internalIndex = new internalIndexHandler_1.default();
|
|
111
111
|
this.pluginsManager = new pluginsManager_1.default();
|
|
112
112
|
this.tokenManager = new tokenManager_1.TokenManager();
|
|
@@ -139,18 +139,18 @@ class Kuzzle extends kuzzleEventEmitter_1.default {
|
|
|
139
139
|
this.registerSignalHandlers();
|
|
140
140
|
try {
|
|
141
141
|
this.log.info(`[ℹ] Starting Kuzzle ${this.version} ...`);
|
|
142
|
-
await this.pipe(
|
|
142
|
+
await this.pipe("kuzzle:state:start");
|
|
143
143
|
// Koncorde realtime engine
|
|
144
144
|
this.koncorde = new koncorde_1.Koncorde({
|
|
145
145
|
maxConditions: this.config.limits.subscriptionConditionsCount,
|
|
146
|
-
regExpEngine: this.config.realtime.pcreSupport ?
|
|
147
|
-
seed: this.config.internal.hash.seed
|
|
146
|
+
regExpEngine: this.config.realtime.pcreSupport ? "js" : "re2",
|
|
147
|
+
seed: this.config.internal.hash.seed,
|
|
148
148
|
});
|
|
149
|
-
await
|
|
150
|
-
await
|
|
151
|
-
await
|
|
149
|
+
await new cacheEngine_1.default().init();
|
|
150
|
+
await new storageEngine_1.default().init();
|
|
151
|
+
await new realtime_1.default().init();
|
|
152
152
|
await this.internalIndex.init();
|
|
153
|
-
await
|
|
153
|
+
await new security_1.default().init();
|
|
154
154
|
// This will init the cluster module if enabled
|
|
155
155
|
this.id = await this.initKuzzleNode();
|
|
156
156
|
// Secret used to generate JWTs
|
|
@@ -166,24 +166,24 @@ class Kuzzle extends kuzzleEventEmitter_1.default {
|
|
|
166
166
|
await this.entryPoint.init();
|
|
167
167
|
this.pluginsManager.application = application;
|
|
168
168
|
await this.pluginsManager.init(options.plugins);
|
|
169
|
-
this.log.info(`[✔] Successfully loaded ${this.pluginsManager.loadedPlugins.length} plugins: ${this.pluginsManager.loadedPlugins.join(
|
|
169
|
+
this.log.info(`[✔] Successfully loaded ${this.pluginsManager.loadedPlugins.length} plugins: ${this.pluginsManager.loadedPlugins.join(", ")}`);
|
|
170
170
|
// Authentification plugins must be loaded before users import to avoid
|
|
171
171
|
// credentials related error which would prevent Kuzzle from starting
|
|
172
172
|
await this.loadInitialState(options.import, options.support);
|
|
173
|
-
await this.ask(
|
|
173
|
+
await this.ask("core:security:verify");
|
|
174
174
|
this.router.init();
|
|
175
|
-
this.log.info(
|
|
175
|
+
this.log.info("[✔] Core components loaded");
|
|
176
176
|
await this.install(options.installations);
|
|
177
177
|
this.log.info(`[✔] Start "${this.pluginsManager.application.name}" application`);
|
|
178
178
|
this.openApiManager = new openapi_1.OpenApiManager(application.openApi, this.config.http.routes, this.pluginsManager.routes);
|
|
179
179
|
// @deprecated
|
|
180
|
-
await this.pipe(
|
|
181
|
-
await this.pipe(
|
|
180
|
+
await this.pipe("kuzzle:start");
|
|
181
|
+
await this.pipe("kuzzle:state:live");
|
|
182
182
|
await this.entryPoint.startListening();
|
|
183
|
-
await this.pipe(
|
|
183
|
+
await this.pipe("kuzzle:state:ready");
|
|
184
184
|
this.log.info(`[✔] Kuzzle ${this.version} is ready (node name: ${this.id})`);
|
|
185
185
|
// @deprecated
|
|
186
|
-
this.emit(
|
|
186
|
+
this.emit("core:kuzzleStart", "Kuzzle is ready to accept requests");
|
|
187
187
|
this._state = kuzzleStateEnum_1.default.RUNNING;
|
|
188
188
|
}
|
|
189
189
|
catch (error) {
|
|
@@ -199,12 +199,12 @@ class Kuzzle extends kuzzleEventEmitter_1.default {
|
|
|
199
199
|
async initKuzzleNode() {
|
|
200
200
|
let id;
|
|
201
201
|
if (this.config.cluster.enabled) {
|
|
202
|
-
id = await
|
|
203
|
-
this.log.info(
|
|
202
|
+
id = await new cluster_1.default().init();
|
|
203
|
+
this.log.info("[✔] Cluster initialized");
|
|
204
204
|
}
|
|
205
205
|
else {
|
|
206
|
-
id = name_generator_1.NameGenerator.generateRandomName({ prefix:
|
|
207
|
-
this.log.info(
|
|
206
|
+
id = name_generator_1.NameGenerator.generateRandomName({ prefix: "knode" });
|
|
207
|
+
this.log.info("[X] Cluster disabled: single node mode.");
|
|
208
208
|
}
|
|
209
209
|
return id;
|
|
210
210
|
}
|
|
@@ -215,17 +215,17 @@ class Kuzzle extends kuzzleEventEmitter_1.default {
|
|
|
215
215
|
*/
|
|
216
216
|
async shutdown() {
|
|
217
217
|
this._state = kuzzleStateEnum_1.default.SHUTTING_DOWN;
|
|
218
|
-
this.log.info(
|
|
218
|
+
this.log.info("Initiating shutdown...");
|
|
219
219
|
// Ask the network layer to stop accepting new request
|
|
220
|
-
this.entryPoint.dispatch(
|
|
221
|
-
await this.pipe(
|
|
220
|
+
this.entryPoint.dispatch("shutdown");
|
|
221
|
+
await this.pipe("kuzzle:shutdown");
|
|
222
222
|
// @deprecated
|
|
223
|
-
this.emit(
|
|
223
|
+
this.emit("core:shutdown");
|
|
224
224
|
while (this.funnel.remainingRequests !== 0) {
|
|
225
225
|
this.log.info(`[shutdown] Waiting: ${this.funnel.remainingRequests} remaining requests`);
|
|
226
226
|
await bluebird_1.default.delay(1000);
|
|
227
227
|
}
|
|
228
|
-
this.log.info(
|
|
228
|
+
this.log.info("Halted.");
|
|
229
229
|
process.exit(0);
|
|
230
230
|
}
|
|
231
231
|
/**
|
|
@@ -239,22 +239,22 @@ class Kuzzle extends kuzzleEventEmitter_1.default {
|
|
|
239
239
|
if (!installations || !installations.length) {
|
|
240
240
|
return;
|
|
241
241
|
}
|
|
242
|
-
const mutex = new mutex_1.Mutex(
|
|
242
|
+
const mutex = new mutex_1.Mutex("backend:installations");
|
|
243
243
|
await mutex.lock();
|
|
244
244
|
try {
|
|
245
245
|
for (const installation of installations) {
|
|
246
|
-
const isAlreadyInstalled = await this.ask(
|
|
246
|
+
const isAlreadyInstalled = await this.ask("core:storage:private:document:exist", "kuzzle", "installations", installation.id);
|
|
247
247
|
if (!isAlreadyInstalled) {
|
|
248
248
|
try {
|
|
249
249
|
await installation.handler();
|
|
250
250
|
}
|
|
251
251
|
catch (error) {
|
|
252
|
-
throw kerror.get(
|
|
252
|
+
throw kerror.get("plugin", "runtime", "unexpected_installation_error", installation.id, error);
|
|
253
253
|
}
|
|
254
|
-
await this.ask(
|
|
254
|
+
await this.ask("core:storage:private:document:create", "kuzzle", "installations", {
|
|
255
255
|
description: installation.description,
|
|
256
256
|
handler: installation.handler.toString(),
|
|
257
|
-
installedAt: Date.now()
|
|
257
|
+
installedAt: Date.now(),
|
|
258
258
|
}, { id: installation.id });
|
|
259
259
|
this.log.info(`[✔] Install code "${installation.id}" successfully executed`);
|
|
260
260
|
}
|
|
@@ -282,19 +282,19 @@ class Kuzzle extends kuzzleEventEmitter_1.default {
|
|
|
282
282
|
}
|
|
283
283
|
const toImport = config.toImport;
|
|
284
284
|
if (!lodash_1.default.isEmpty(toImport.userMappings)) {
|
|
285
|
-
await this.internalIndex.updateMapping(
|
|
286
|
-
await this.internalIndex.refreshCollection(
|
|
287
|
-
this.log.info(
|
|
285
|
+
await this.internalIndex.updateMapping("users", toImport.userMappings);
|
|
286
|
+
await this.internalIndex.refreshCollection("users");
|
|
287
|
+
this.log.info("[✔] User mappings import successful");
|
|
288
288
|
}
|
|
289
289
|
}
|
|
290
290
|
async importMappings(config, status) {
|
|
291
291
|
const toImport = config.toImport;
|
|
292
292
|
const toSupport = config.toSupport;
|
|
293
293
|
if (!lodash_1.default.isEmpty(toSupport.mappings) && !lodash_1.default.isEmpty(toImport.mappings)) {
|
|
294
|
-
throw kerror.get(
|
|
294
|
+
throw kerror.get("plugin", "runtime", "incompatible", "_support.mappings", "import.mappings");
|
|
295
295
|
}
|
|
296
296
|
else if (!lodash_1.default.isEmpty(toSupport.mappings)) {
|
|
297
|
-
await this.ask(
|
|
297
|
+
await this.ask("core:storage:public:mappings:import", toSupport.mappings, {
|
|
298
298
|
/**
|
|
299
299
|
* If it's the first time the mapping are loaded and another node is already importing the mapping into the database
|
|
300
300
|
* we just want to load the mapping in our own index cache and not in the database.
|
|
@@ -304,10 +304,10 @@ class Kuzzle extends kuzzleEventEmitter_1.default {
|
|
|
304
304
|
rawMappings: true,
|
|
305
305
|
refresh: true,
|
|
306
306
|
});
|
|
307
|
-
this.log.info(
|
|
307
|
+
this.log.info("[✔] Mappings import successful");
|
|
308
308
|
}
|
|
309
309
|
else if (!lodash_1.default.isEmpty(toImport.mappings)) {
|
|
310
|
-
await this.ask(
|
|
310
|
+
await this.ask("core:storage:public:mappings:import", toImport.mappings, {
|
|
311
311
|
/**
|
|
312
312
|
* If it's the first time the mapping are loaded and another node is already importing the mapping into the database
|
|
313
313
|
* we just want to load the mapping in our own index cache and not in the database.
|
|
@@ -316,7 +316,7 @@ class Kuzzle extends kuzzleEventEmitter_1.default {
|
|
|
316
316
|
propagate: false,
|
|
317
317
|
refresh: true,
|
|
318
318
|
});
|
|
319
|
-
this.log.info(
|
|
319
|
+
this.log.info("[✔] Mappings import successful");
|
|
320
320
|
}
|
|
321
321
|
}
|
|
322
322
|
async importFixtures(config, status) {
|
|
@@ -325,8 +325,8 @@ class Kuzzle extends kuzzleEventEmitter_1.default {
|
|
|
325
325
|
}
|
|
326
326
|
const toSupport = config.toSupport;
|
|
327
327
|
if (!lodash_1.default.isEmpty(toSupport.fixtures)) {
|
|
328
|
-
await this.ask(
|
|
329
|
-
this.log.info(
|
|
328
|
+
await this.ask("core:storage:public:document:import", toSupport.fixtures);
|
|
329
|
+
this.log.info("[✔] Fixtures import successful");
|
|
330
330
|
}
|
|
331
331
|
}
|
|
332
332
|
async importPermissions(config, status) {
|
|
@@ -335,34 +335,34 @@ class Kuzzle extends kuzzleEventEmitter_1.default {
|
|
|
335
335
|
}
|
|
336
336
|
const toImport = config.toImport;
|
|
337
337
|
const toSupport = config.toSupport;
|
|
338
|
-
const isPermissionsToImport = !(lodash_1.default.isEmpty(toImport.profiles)
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
const isPermissionsToSupport = toSupport.securities
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
338
|
+
const isPermissionsToImport = !(lodash_1.default.isEmpty(toImport.profiles) &&
|
|
339
|
+
lodash_1.default.isEmpty(toImport.roles) &&
|
|
340
|
+
lodash_1.default.isEmpty(toImport.users));
|
|
341
|
+
const isPermissionsToSupport = toSupport.securities &&
|
|
342
|
+
!(lodash_1.default.isEmpty(toSupport.securities.profiles) &&
|
|
343
|
+
lodash_1.default.isEmpty(toSupport.securities.roles) &&
|
|
344
|
+
lodash_1.default.isEmpty(toSupport.securities.users));
|
|
345
345
|
if (isPermissionsToSupport && isPermissionsToImport) {
|
|
346
|
-
throw kerror.get(
|
|
346
|
+
throw kerror.get("plugin", "runtime", "incompatible", "_support.securities", "import profiles roles or users");
|
|
347
347
|
}
|
|
348
348
|
else if (isPermissionsToSupport) {
|
|
349
|
-
await this.ask(
|
|
349
|
+
await this.ask("core:security:load", toSupport.securities, {
|
|
350
350
|
force: true,
|
|
351
|
-
refresh:
|
|
351
|
+
refresh: "wait_for",
|
|
352
352
|
});
|
|
353
|
-
this.log.info(
|
|
353
|
+
this.log.info("[✔] Securities import successful");
|
|
354
354
|
}
|
|
355
355
|
else if (isPermissionsToImport) {
|
|
356
|
-
await this.ask(
|
|
356
|
+
await this.ask("core:security:load", {
|
|
357
357
|
profiles: toImport.profiles,
|
|
358
358
|
roles: toImport.roles,
|
|
359
359
|
users: toImport.users,
|
|
360
360
|
}, {
|
|
361
361
|
onExistingUsers: toImport.onExistingUsers,
|
|
362
362
|
onExistingUsersWarning: true,
|
|
363
|
-
refresh:
|
|
363
|
+
refresh: "wait_for",
|
|
364
364
|
});
|
|
365
|
-
this.log.info(
|
|
365
|
+
this.log.info("[✔] Permissions import successful");
|
|
366
366
|
}
|
|
367
367
|
}
|
|
368
368
|
/**
|
|
@@ -372,7 +372,7 @@ class Kuzzle extends kuzzleEventEmitter_1.default {
|
|
|
372
372
|
const importTypes = Object.keys(this.importTypes);
|
|
373
373
|
for (const importType of importTypes) {
|
|
374
374
|
// If the import is done, we pop it from the queue to check the next one
|
|
375
|
-
if (await this.ask(
|
|
375
|
+
if (await this.ask("core:cache:internal:get", `${exports.BACKEND_IMPORT_KEY}:${importType}`)) {
|
|
376
376
|
return;
|
|
377
377
|
}
|
|
378
378
|
await bluebird_1.default.delay(1000);
|
|
@@ -387,14 +387,14 @@ class Kuzzle extends kuzzleEventEmitter_1.default {
|
|
|
387
387
|
* @returns {Promise<void>}
|
|
388
388
|
*/
|
|
389
389
|
async loadInitialState(toImport = {}, toSupport = {}) {
|
|
390
|
-
if (lodash_1.default.isEmpty(toImport.mappings)
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
390
|
+
if (lodash_1.default.isEmpty(toImport.mappings) &&
|
|
391
|
+
lodash_1.default.isEmpty(toImport.profiles) &&
|
|
392
|
+
lodash_1.default.isEmpty(toImport.roles) &&
|
|
393
|
+
lodash_1.default.isEmpty(toImport.userMappings) &&
|
|
394
|
+
lodash_1.default.isEmpty(toImport.users) &&
|
|
395
|
+
lodash_1.default.isEmpty(toSupport.fixtures) &&
|
|
396
|
+
lodash_1.default.isEmpty(toSupport.mappings) &&
|
|
397
|
+
lodash_1.default.isEmpty(toSupport.securities)) {
|
|
398
398
|
return;
|
|
399
399
|
}
|
|
400
400
|
const lockedMutex = [];
|
|
@@ -402,23 +402,23 @@ class Kuzzle extends kuzzleEventEmitter_1.default {
|
|
|
402
402
|
for (const [type, importMethod] of Object.entries(this.importTypes)) {
|
|
403
403
|
const importPayload = {};
|
|
404
404
|
switch (type) {
|
|
405
|
-
case
|
|
406
|
-
lodash_1.default.set(importPayload,
|
|
405
|
+
case "fixtures":
|
|
406
|
+
lodash_1.default.set(importPayload, "toSupport.fixtures", toSupport.fixtures);
|
|
407
407
|
break;
|
|
408
|
-
case
|
|
409
|
-
lodash_1.default.set(importPayload,
|
|
410
|
-
lodash_1.default.set(importPayload,
|
|
408
|
+
case "mappings":
|
|
409
|
+
lodash_1.default.set(importPayload, "toSupport.mappings", toSupport.mappings);
|
|
410
|
+
lodash_1.default.set(importPayload, "toImport.mappings", toImport.mappings);
|
|
411
411
|
break;
|
|
412
|
-
case
|
|
413
|
-
lodash_1.default.set(importPayload,
|
|
414
|
-
lodash_1.default.set(importPayload,
|
|
415
|
-
lodash_1.default.set(importPayload,
|
|
416
|
-
lodash_1.default.set(importPayload,
|
|
412
|
+
case "permissions":
|
|
413
|
+
lodash_1.default.set(importPayload, "toSupport.securities", toSupport.securities);
|
|
414
|
+
lodash_1.default.set(importPayload, "toImport.profiles", toImport.profiles);
|
|
415
|
+
lodash_1.default.set(importPayload, "toImport.roles", toImport.roles);
|
|
416
|
+
lodash_1.default.set(importPayload, "toImport.users", toImport.users);
|
|
417
417
|
break;
|
|
418
418
|
}
|
|
419
419
|
const importPayloadHash = (0, crypto_1.sha256)((0, json_stable_stringify_1.default)(importPayload));
|
|
420
420
|
const mutex = new mutex_1.Mutex(`backend:import:${type}`, { timeout: 0 });
|
|
421
|
-
const existingHash = await this.ask(
|
|
421
|
+
const existingHash = await this.ask("core:cache:internal:get", `${exports.BACKEND_IMPORT_KEY}:${type}`);
|
|
422
422
|
const initialized = existingHash === importPayloadHash;
|
|
423
423
|
const locked = await mutex.lock();
|
|
424
424
|
await importMethod({ toImport, toSupport }, {
|
|
@@ -428,14 +428,14 @@ class Kuzzle extends kuzzleEventEmitter_1.default {
|
|
|
428
428
|
});
|
|
429
429
|
if (!initialized && locked) {
|
|
430
430
|
lockedMutex.push(mutex);
|
|
431
|
-
await this.ask(
|
|
431
|
+
await this.ask("core:cache:internal:store", `${exports.BACKEND_IMPORT_KEY}:${type}`, importPayloadHash);
|
|
432
432
|
}
|
|
433
433
|
}
|
|
434
434
|
await this._waitForImportToFinish();
|
|
435
|
-
this.log.info(
|
|
435
|
+
this.log.info("[✔] Import successful");
|
|
436
436
|
}
|
|
437
437
|
finally {
|
|
438
|
-
await Promise.all(lockedMutex.map(mutex => mutex.unlock()));
|
|
438
|
+
await Promise.all(lockedMutex.map((mutex) => mutex.unlock()));
|
|
439
439
|
}
|
|
440
440
|
}
|
|
441
441
|
dump(suffix) {
|
|
@@ -444,22 +444,22 @@ class Kuzzle extends kuzzleEventEmitter_1.default {
|
|
|
444
444
|
hash(input) {
|
|
445
445
|
let inString;
|
|
446
446
|
switch (typeof input) {
|
|
447
|
-
case
|
|
448
|
-
case
|
|
449
|
-
case
|
|
447
|
+
case "string":
|
|
448
|
+
case "number":
|
|
449
|
+
case "boolean":
|
|
450
450
|
inString = input;
|
|
451
451
|
break;
|
|
452
452
|
default:
|
|
453
453
|
inString = (0, json_stable_stringify_1.default)(input);
|
|
454
454
|
}
|
|
455
|
-
return (0, murmurhash_native_1.murmurHash128)(Buffer.from(inString),
|
|
455
|
+
return (0, murmurhash_native_1.murmurHash128)(Buffer.from(inString), "hex", this.config.internal.hash.seed);
|
|
456
456
|
}
|
|
457
457
|
get state() {
|
|
458
458
|
return this._state;
|
|
459
459
|
}
|
|
460
460
|
set state(value) {
|
|
461
461
|
this._state = value;
|
|
462
|
-
this.emit(
|
|
462
|
+
this.emit("kuzzle:state:change", value);
|
|
463
463
|
}
|
|
464
464
|
/**
|
|
465
465
|
* Register handlers and do a kuzzle dump for:
|
|
@@ -468,8 +468,8 @@ class Kuzzle extends kuzzleEventEmitter_1.default {
|
|
|
468
468
|
* - uncaught-exception
|
|
469
469
|
*/
|
|
470
470
|
registerSignalHandlers() {
|
|
471
|
-
process.removeAllListeners(
|
|
472
|
-
process.on(
|
|
471
|
+
process.removeAllListeners("unhandledRejection");
|
|
472
|
+
process.on("unhandledRejection", (reason, promise) => {
|
|
473
473
|
if (reason !== undefined) {
|
|
474
474
|
if (reason instanceof Error) {
|
|
475
475
|
this.log.error(`ERROR: unhandledRejection: ${reason.message}. Reason: ${reason.stack}`);
|
|
@@ -484,33 +484,33 @@ class Kuzzle extends kuzzleEventEmitter_1.default {
|
|
|
484
484
|
// Crashing on an unhandled rejection is a good idea during development
|
|
485
485
|
// as it helps spotting code errors. And according to the warning messages,
|
|
486
486
|
// this is what Node.js will do automatically in future versions anyway.
|
|
487
|
-
if (global.NODE_ENV ===
|
|
488
|
-
this.log.error(
|
|
487
|
+
if (global.NODE_ENV === "development") {
|
|
488
|
+
this.log.error("Kuzzle caught an unhandled rejected promise and will shutdown.");
|
|
489
489
|
this.log.error('This behavior is only triggered if global.NODE_ENV is set to "development"');
|
|
490
490
|
throw reason;
|
|
491
491
|
}
|
|
492
492
|
});
|
|
493
|
-
process.removeAllListeners(
|
|
494
|
-
process.on(
|
|
493
|
+
process.removeAllListeners("uncaughtException");
|
|
494
|
+
process.on("uncaughtException", (err) => {
|
|
495
495
|
this.log.error(`ERROR: uncaughtException: ${err.message}\n${err.stack}`);
|
|
496
|
-
this.dumpAndExit(
|
|
496
|
+
this.dumpAndExit("uncaught-exception");
|
|
497
497
|
});
|
|
498
498
|
// abnormal termination signals => generate a core dump
|
|
499
|
-
for (const signal of [
|
|
499
|
+
for (const signal of ["SIGQUIT", "SIGABRT"]) {
|
|
500
500
|
process.removeAllListeners(signal);
|
|
501
501
|
process.on(signal, () => {
|
|
502
502
|
this.log.error(`ERROR: Caught signal: ${signal}`);
|
|
503
|
-
this.dumpAndExit(
|
|
503
|
+
this.dumpAndExit("signal-".concat(signal.toLowerCase()));
|
|
504
504
|
});
|
|
505
505
|
}
|
|
506
506
|
// signal SIGTRAP is used to generate a kuzzle dump without stopping it
|
|
507
|
-
process.removeAllListeners(
|
|
508
|
-
process.on(
|
|
509
|
-
this.log.error(
|
|
510
|
-
this.dump(
|
|
507
|
+
process.removeAllListeners("SIGTRAP");
|
|
508
|
+
process.on("SIGTRAP", () => {
|
|
509
|
+
this.log.error("Caught signal SIGTRAP => generating a core dump");
|
|
510
|
+
this.dump("signal-sigtrap");
|
|
511
511
|
});
|
|
512
512
|
// gracefully exits on normal termination
|
|
513
|
-
for (const signal of [
|
|
513
|
+
for (const signal of ["SIGINT", "SIGTERM"]) {
|
|
514
514
|
process.removeAllListeners(signal);
|
|
515
515
|
process.on(signal, () => {
|
|
516
516
|
this.log.info(`Caught signal ${signal} => gracefully exit`);
|
package/lib/kuzzle/log.js
CHANGED
|
@@ -19,25 +19,25 @@
|
|
|
19
19
|
* limitations under the License.
|
|
20
20
|
*/
|
|
21
21
|
|
|
22
|
-
|
|
22
|
+
"use strict";
|
|
23
23
|
|
|
24
24
|
class Logger {
|
|
25
|
-
constructor
|
|
26
|
-
this.logMethods = [
|
|
25
|
+
constructor() {
|
|
26
|
+
this.logMethods = ["info", "warn", "error", "silly", "debug", "verbose"];
|
|
27
27
|
|
|
28
28
|
this.failsafeModeString = global.kuzzle.config.plugins.common.failsafeMode
|
|
29
|
-
?
|
|
30
|
-
:
|
|
29
|
+
? "[FAILSAFE MODE] "
|
|
30
|
+
: "";
|
|
31
31
|
|
|
32
32
|
this._useConsole();
|
|
33
33
|
|
|
34
|
-
global.kuzzle.once(
|
|
34
|
+
global.kuzzle.once("core:kuzzleStart", this._useLogger.bind(this));
|
|
35
35
|
}
|
|
36
36
|
|
|
37
|
-
_useConsole
|
|
37
|
+
_useConsole() {
|
|
38
38
|
// until kuzzle has started, use the console to print logs
|
|
39
39
|
for (const method of this.logMethods) {
|
|
40
|
-
this[method] = message => {
|
|
40
|
+
this[method] = (message) => {
|
|
41
41
|
/* eslint-disable-next-line no-console */
|
|
42
42
|
const writer = console[method] || console.log;
|
|
43
43
|
|
|
@@ -46,20 +46,25 @@ class Logger {
|
|
|
46
46
|
}
|
|
47
47
|
}
|
|
48
48
|
|
|
49
|
-
_useLogger
|
|
50
|
-
|
|
49
|
+
_useLogger() {
|
|
51
50
|
// when kuzzle has started, use the event to dispatch logs
|
|
52
51
|
for (const method of this.logMethods) {
|
|
53
|
-
this[method] = message => {
|
|
54
|
-
if (
|
|
55
|
-
|
|
52
|
+
this[method] = (message) => {
|
|
53
|
+
if (
|
|
54
|
+
global.kuzzle.asyncStore.exists() &&
|
|
55
|
+
global.kuzzle.asyncStore.has("REQUEST")
|
|
56
56
|
) {
|
|
57
|
-
const request = global.kuzzle.asyncStore.get(
|
|
57
|
+
const request = global.kuzzle.asyncStore.get("REQUEST");
|
|
58
58
|
|
|
59
|
-
global.kuzzle.emit(
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
59
|
+
global.kuzzle.emit(
|
|
60
|
+
`log:${method}`,
|
|
61
|
+
`[${global.kuzzle.id}] ${this.failsafeModeString}[${request.id}] ${message}`
|
|
62
|
+
);
|
|
63
|
+
} else {
|
|
64
|
+
global.kuzzle.emit(
|
|
65
|
+
`log:${method}`,
|
|
66
|
+
`[${global.kuzzle.id}] ${this.failsafeModeString}${message}`
|
|
67
|
+
);
|
|
63
68
|
}
|
|
64
69
|
};
|
|
65
70
|
}
|
package/lib/kuzzle/vault.js
CHANGED
|
@@ -19,48 +19,63 @@
|
|
|
19
19
|
* limitations under the License.
|
|
20
20
|
*/
|
|
21
21
|
|
|
22
|
-
|
|
22
|
+
"use strict";
|
|
23
23
|
|
|
24
|
-
const assert = require(
|
|
25
|
-
const fs = require(
|
|
26
|
-
const path = require(
|
|
27
|
-
const _ = require(
|
|
28
|
-
const { Vault } = require(
|
|
24
|
+
const assert = require("assert");
|
|
25
|
+
const fs = require("fs");
|
|
26
|
+
const path = require("path");
|
|
27
|
+
const _ = require("lodash");
|
|
28
|
+
const { Vault } = require("kuzzle-vault");
|
|
29
29
|
|
|
30
|
-
|
|
30
|
+
// The Vault package remove the variable from env after reading it and we have
|
|
31
|
+
// to instantiate the Vault two times with Kaaf (one before init and one after)
|
|
32
|
+
let ENV_VAULT_KEY;
|
|
33
|
+
|
|
34
|
+
function load(vaultKey, secretsFile) {
|
|
31
35
|
// Using KaaF kuzzle is an npm package and is located under node_modules folder
|
|
32
36
|
// We need to get back to root folder of the project to get the secret file
|
|
33
|
-
const defaultEncryptedSecretsFile = __dirname.endsWith(
|
|
34
|
-
|
|
35
|
-
|
|
37
|
+
const defaultEncryptedSecretsFile = __dirname.endsWith(
|
|
38
|
+
"/node_modules/kuzzle/lib/kuzzle"
|
|
39
|
+
)
|
|
40
|
+
? path.resolve(`${__dirname}/../../../../config/secrets.enc.json`)
|
|
41
|
+
: path.resolve(`${__dirname}/../../config/secrets.enc.json`);
|
|
36
42
|
|
|
37
43
|
const encryptedSecretsFile =
|
|
38
|
-
secretsFile ||
|
|
44
|
+
secretsFile ||
|
|
45
|
+
process.env.KUZZLE_SECRETS_FILE ||
|
|
46
|
+
defaultEncryptedSecretsFile;
|
|
39
47
|
|
|
40
48
|
let key = vaultKey;
|
|
41
|
-
if (
|
|
42
|
-
|
|
49
|
+
if (
|
|
50
|
+
_.isEmpty(vaultKey) &&
|
|
51
|
+
(!_.isEmpty(process.env.KUZZLE_VAULT_KEY) || !_.isEmpty(ENV_VAULT_KEY))
|
|
52
|
+
) {
|
|
53
|
+
// Keep the vault key value when reading it from the env
|
|
54
|
+
key = ENV_VAULT_KEY = process.env.KUZZLE_VAULT_KEY || ENV_VAULT_KEY;
|
|
43
55
|
}
|
|
44
56
|
|
|
45
57
|
const fileExists = fs.existsSync(encryptedSecretsFile);
|
|
46
58
|
// Abort if a custom secrets file has been provided but Kuzzle can't load it
|
|
47
|
-
if (!
|
|
59
|
+
if (!_.isEmpty(process.env.KUZZLE_SECRETS_FILE) || !_.isEmpty(secretsFile)) {
|
|
48
60
|
assert(
|
|
49
61
|
fileExists,
|
|
50
|
-
`A secret file has been provided but Kuzzle cannot find it at "${encryptedSecretsFile}".`
|
|
62
|
+
`A secret file has been provided but Kuzzle cannot find it at "${encryptedSecretsFile}".`
|
|
63
|
+
);
|
|
51
64
|
}
|
|
52
65
|
|
|
53
66
|
// Abort if a secret file is found (default or custom)
|
|
54
67
|
// but no vault key has been provided
|
|
55
68
|
assert(
|
|
56
|
-
!
|
|
57
|
-
|
|
69
|
+
!(fileExists && _.isEmpty(key)),
|
|
70
|
+
"A secret file has been provided but Kuzzle cannot find the Vault key. Aborting."
|
|
71
|
+
);
|
|
58
72
|
|
|
59
73
|
// Abort if a vault key has been provided
|
|
60
74
|
// but no secrets file can be loaded (default or custom)
|
|
61
75
|
assert(
|
|
62
|
-
!
|
|
63
|
-
`A Vault key is present but Kuzzle cannot find the secret file at "${encryptedSecretsFile}". Aborting.`
|
|
76
|
+
!(!_.isEmpty(key) && !fileExists),
|
|
77
|
+
`A Vault key is present but Kuzzle cannot find the secret file at "${encryptedSecretsFile}". Aborting.`
|
|
78
|
+
);
|
|
64
79
|
|
|
65
80
|
const vault = new Vault(key);
|
|
66
81
|
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { Policy, OptimizedPolicy, OptimizedPolicyRestrictions } from
|
|
2
|
-
import { Role } from
|
|
3
|
-
import { KuzzleRequest } from
|
|
1
|
+
import { Policy, OptimizedPolicy, OptimizedPolicyRestrictions } from "../../types/index";
|
|
2
|
+
import { Role } from "./role";
|
|
3
|
+
import { KuzzleRequest } from "../../../index";
|
|
4
4
|
/** @internal */
|
|
5
5
|
declare type InternalProfilePolicy = {
|
|
6
6
|
role: Role;
|