UNPKG

@iobroker/js-controller-common-db

Version:

The Library contains the common utils for the ioBroker controller which can be used by db classes too, as they do not rely on the db (circular dependencies).

84 lines (83 loc) 3.46 kB
"use strict"; var __create = Object.create; var __defProp = Object.defineProperty; var __getOwnPropDesc = Object.getOwnPropertyDescriptor; var __getOwnPropNames = Object.getOwnPropertyNames; var __getProtoOf = Object.getPrototypeOf; var __hasOwnProp = Object.prototype.hasOwnProperty; var __export = (target, all) => { for (var name in all) __defProp(target, name, { get: all[name], enumerable: true }); }; var __copyProps = (to, from, except, desc) => { if (from && typeof from === "object" || typeof from === "function") { for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable }); } return to; }; var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps( isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target, mod )); var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod); var interview_exports = {}; __export(interview_exports, { defaultRedisInterview: () => defaultRedisInterview }); module.exports = __toCommonJS(interview_exports); var import_readline_sync = __toESM(require("readline-sync"), 1); var import_fs_extra = __toESM(require("fs-extra"), 1); const YES_NO_REGEX = /^[YyNn]?$/; async function defaultRedisInterview(options) { const { type, config } = options; let answer = import_readline_sync.default.question(`Do you use a TLS connection for your "${type}" redis-server? [y/N]:`, { limit: YES_NO_REGEX, defaultInput: "N" }); if (answer.toLowerCase() === "n") { return config; } config.options.tls = {}; answer = import_readline_sync.default.question(`Do you use a self-signed certificate for your "${type}" redis-server? [y/N]:`, { limit: YES_NO_REGEX, defaultInput: "N" }); if (answer.toLowerCase() === "y") { config.options.tls.rejectUnauthorized = false; } do { answer = import_readline_sync.default.question(`Please specify the path to your "${type}" redis-server "certificate" file:`); try { const certContent = await import_fs_extra.default.readFile(answer, { encoding: "utf8" }); config.options.tls.cert = certContent; } catch (e) { console.warn(`Could not read the "certificate" file: ${e.message}`); } } while (!config.options.tls.cert); do { answer = import_readline_sync.default.question(`Please specify the path to your "${type}" redis-server "key" file:`); try { const keyContent = await import_fs_extra.default.readFile(answer, { encoding: "utf8" }); config.options.tls.key = keyContent; } catch (e) { console.warn(`Could not read the "key" file: ${e.message}`); } } while (!config.options.tls.key); do { answer = import_readline_sync.default.question(`Please specify the path to your "${type}" redis-server "CA" file:`); try { const caContent = await import_fs_extra.default.readFile(answer, { encoding: "utf8" }); config.options.tls.ca = caContent; } catch (e) { console.warn(`Could not read the "CA" file: ${e.message}`); } } while (!config.options.tls.ca); return config; } // Annotate the CommonJS export names for ESM import in node: 0 && (module.exports = { defaultRedisInterview }); //# sourceMappingURL=interview.js.map