UNPKG

local-elastic-docker

Version:

A package for creating / tearing down local Elasticsearch / Kibana single node clusters via Docker.

132 lines (131 loc) 4.85 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); var path = require("path"); var utils_1 = require("../utils"); var BaseContainer = /** @class */ (function () { function BaseContainer(v) { this._set_cluster_name(v); this._set_env(v); this._set_es_version(v); this._set_hsize(v); this._set_image(v); this._set_khsize(v); this._set_kibana(v); this._set_kibana_port(v); this._set_name(v); this._set_node_name(v); this._set_port(v); this._set_volume_dir(v); if (this.kibana_port === this.port) { throw Error('kibana port cant be the same as the elastic port.'); } else if (this.kibana && !this.kibana_port) { throw Error('since you specified this is a kibana container, you must provide ' + 'a port for kibana.'); } } BaseContainer.prototype._get_major_version = function () { return Number(this.es_version.split('.')[0]); }; BaseContainer.prototype._set_cluster_name = function (v) { if (utils_1.Utils.is_string(v.cluster_name) && v.cluster_name && !/ /.test(v.cluster_name)) { this.cluster_name = v.cluster_name; } else if (utils_1.Utils.is_defined(v.cluster_name)) { throw Error('not a valid string'); } }; BaseContainer.prototype._set_env = function (v) { if (v.env) { v.env.forEach(function (s) { if (!utils_1.Utils.is_string(s)) { throw Error('invalid environment string'); } else if (s.indexOf('=') < 0) { throw Error(s + ' has an invalid env format!'); } }); } this.env = v.env ? v.env : []; }; BaseContainer.prototype._set_es_version = function (v) { if (!/\d+.\d+.\d+/.test(v.es_version)) { throw Error(v + " is an invalid version."); } this.es_version = v.es_version; }; BaseContainer.prototype._set_hsize = function (v) { if (!utils_1.Utils.is_integer(v.hsize)) { throw Error('es heap size not an integer'); } this.hsize = v.hsize; }; BaseContainer.prototype._set_image = function (v) { if (!utils_1.Utils.is_string(v.image) || !v.image || / /.test(v.image)) { throw Error(v.image + " is an invalid image name"); } this.image = v.image; }; BaseContainer.prototype._set_khsize = function (v) { var val = v.khsize; if (utils_1.Utils.is_defined(val)) { if (!utils_1.Utils.is_integer(val)) { throw Error('kibana heap size not an integer'); } } this.khsize = val ? val : 512; }; BaseContainer.prototype._set_kibana = function (v) { if (utils_1.Utils.is_bool(v.kibana)) { this.kibana = v.kibana; } else if (utils_1.Utils.is_defined(v.kibana)) { throw Error('not a boolean'); } else { this.kibana = false; } }; BaseContainer.prototype._set_kibana_port = function (v) { if (utils_1.Utils.is_defined(v.kibana_port) && (!utils_1.Utils.is_integer(v.kibana_port) || (v.kibana_port < 1) || (v.kibana_port > 65535))) { throw Error(v.kibana_port + " is an invalid kibana port"); } else if (v.kibana_port) { this.kibana_port = v.kibana_port; } }; BaseContainer.prototype._set_name = function (v) { if (!utils_1.Utils.is_string(v.name) || !v.name || / /.test(v.name)) { throw Error('not a valid string'); } this.name = v.name; }; BaseContainer.prototype._set_node_name = function (v) { if (utils_1.Utils.is_string(v.node_name) && v.node_name && !/ /.test(v.node_name)) { this.node_name = v.node_name; } else if (utils_1.Utils.is_defined(v.node_name)) { throw Error('not a valid string'); } }; BaseContainer.prototype._set_port = function (v) { if (!utils_1.Utils.is_integer(v.port)) { throw Error('not an integer'); } else if ((v.port < 1) || (v.port > 65535)) { throw Error('port out of range.'); } this.port = v.port; }; BaseContainer.prototype._set_volume_dir = function (v) { if (utils_1.Utils.is_string(v.volume_dir) && v.volume_dir && !/ /.test(v.volume_dir)) { this.volume_dir = path.resolve(process.cwd(), v.volume_dir); } else if (utils_1.Utils.is_defined(v.volume_dir)) { throw Error('not a valid string'); } }; return BaseContainer; }()); exports.BaseContainer = BaseContainer;