@iobroker/js-controller-adapter 7.2.3 → 7.2.4

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.
@@ -338,6 +338,8 @@ export declare class AdapterClass extends EventEmitter {
338
338
  namespace: `${string}.${number}`;
339
339
  name: string;
340
340
  private _systemSecret?;
341
+ /** Attributes of `encryptedNative`: their values in `this.config` are decrypted on start */
342
+ private _decryptedNativeAttributes;
341
343
  /** Whether the adapter has already terminated */
342
344
  private terminated;
343
345
  /** The cache of usernames */
@@ -491,6 +493,15 @@ export declare class AdapterClass extends EventEmitter {
491
493
  *
492
494
  */
493
495
  disable(): ioBroker.SetObjectPromise;
496
+ /**
497
+ * Reads a parameter which is stored encrypted and returns its decrypted value.
498
+ *
499
+ * An attribute listed in `encryptedNative` is already decrypted in `this.config` when the adapter
500
+ * starts, and is returned as it is.
501
+ *
502
+ * @param attribute the config attribute to decrypt
503
+ * @param callback return result
504
+ */
494
505
  getEncryptedConfig(attribute: string, callback?: GetEncryptedConfigCallback): Promise<string | string[] | void>;
495
506
  private _getEncryptedConfig;
496
507
  /**
@@ -110,6 +110,8 @@ class AdapterClass extends import_node_events.EventEmitter {
110
110
  namespace;
111
111
  name;
112
112
  _systemSecret;
113
+ /** Attributes of `encryptedNative`: their values in `this.config` are decrypted on start */
114
+ _decryptedNativeAttributes = new Array();
113
115
  /** Whether the adapter has already terminated */
114
116
  terminated = false;
115
117
  /** The cache of usernames */
@@ -479,7 +481,12 @@ class AdapterClass extends import_node_events.EventEmitter {
479
481
  this._logger.info(`${this.namespaceLog} getSession not processed because States database not connected`);
480
482
  return import_js_controller_common.tools.maybeCallbackWithError(options.callback, import_js_controller_common.tools.ERRORS.ERROR_DB_CLOSED);
481
483
  }
482
- this.#states.getSession(options.id, options.callback);
484
+ this.#states.getSession(options.id, (err, session) => {
485
+ if (err) {
486
+ this._logger.error(`${this.namespaceLog} Cannot read session "${options.id}": ${err.message}`);
487
+ }
488
+ return import_js_controller_common.tools.maybeCallback(options.callback, session || null);
489
+ });
483
490
  }
484
491
  // unknown implementation guards
485
492
  setSession(id, ttl, data, callback) {
@@ -1389,7 +1396,7 @@ class AdapterClass extends import_node_events.EventEmitter {
1389
1396
  return this.setForeignObjectAsync(configObjId, obj);
1390
1397
  }
1391
1398
  /**
1392
- * Reads the encrypted parameter from config.
1399
+ * Reads a parameter which is stored encrypted and returns its decrypted value.
1393
1400
  *
1394
1401
  * It returns promise if no callback is provided.
1395
1402
  *
@@ -1404,14 +1411,12 @@ class AdapterClass extends import_node_events.EventEmitter {
1404
1411
  async _getEncryptedConfig(options) {
1405
1412
  const { attribute, callback } = options;
1406
1413
  const value = (0, import_utils.getObjectAttribute)(this.config, attribute);
1414
+ if ((Array.isArray(value) || typeof value === "string") && this._decryptedNativeAttributes.includes(attribute)) {
1415
+ return import_js_controller_common.tools.maybeCallbackWithError(callback, null, value);
1416
+ }
1407
1417
  if (Array.isArray(value)) {
1408
1418
  const secret = await this.getSystemSecret();
1409
- const result = [];
1410
- for (let i = 0; i < value.length; i++) {
1411
- if (typeof value[i] === "string") {
1412
- result[i] = import_js_controller_common.tools.decrypt(secret, value[i]);
1413
- }
1414
- }
1419
+ const result = value.map((item) => typeof item === "string" ? import_js_controller_common.tools.decrypt(secret, item) : item);
1415
1420
  return import_js_controller_common.tools.maybeCallbackWithError(callback, null, result);
1416
1421
  } else if (typeof value === "string") {
1417
1422
  const secret = await this.getSystemSecret();
@@ -5238,6 +5243,9 @@ class AdapterClass extends import_node_events.EventEmitter {
5238
5243
  return options;
5239
5244
  }
5240
5245
  _checkState(obj, options, command) {
5246
+ if (options.groups?.includes(import_constants.SYSTEM_ADMIN_GROUP)) {
5247
+ return true;
5248
+ }
5241
5249
  const limitToOwnerRights = options.limitToOwnerRights === true;
5242
5250
  if (obj?.acl) {
5243
5251
  obj.acl.state = obj.acl.state || obj.acl.object;
@@ -7746,12 +7754,15 @@ class AdapterClass extends import_node_events.EventEmitter {
7746
7754
  this.oObjects = await this.getAdapterObjectsAsync();
7747
7755
  await this.subscribeObjectsAsync("*");
7748
7756
  }
7749
- await this.getSystemSecret();
7750
- const promises = [];
7757
+ const secret = await this.getSystemSecret();
7751
7758
  if (Array.isArray(adapterConfig.encryptedNative)) {
7759
+ this._decryptedNativeAttributes = new Array();
7752
7760
  for (const attr of adapterConfig.encryptedNative) {
7753
- if (typeof this.config[attr] === "string") {
7754
- promises.push(this.getEncryptedConfig(attr).then((decryptedValue) => (0, import_utils.setObjectAttribute)(this.config, attr, decryptedValue)).catch((e) => this._logger.error(`${this.namespaceLog} Can not decrypt attribute ${attr}: ${e.message}`)));
7761
+ try {
7762
+ (0, import_utils.decryptArray)({ obj: this.config, secret, keys: [attr] });
7763
+ this._decryptedNativeAttributes.push(attr);
7764
+ } catch (e) {
7765
+ this._logger.error(`${this.namespaceLog} Can not decrypt attribute ${attr}: ${e.message}`);
7755
7766
  }
7756
7767
  }
7757
7768
  } else {
@@ -7760,7 +7771,6 @@ class AdapterClass extends import_node_events.EventEmitter {
7760
7771
  this.SUPPORTED_FEATURES.splice(idx, 1);
7761
7772
  }
7762
7773
  }
7763
- await Promise.all(promises);
7764
7774
  if (!this.#states) {
7765
7775
  return;
7766
7776
  }