UNPKG

@provisioner/appengine

Version:

CodeZero provisioner for appengine

51 lines 2.56 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.templateHelperMixin = void 0; const debug_1 = __importDefault(require("debug")); const generate_password_1 = require("generate-password"); const appengine_contracts_1 = require("@provisioner/appengine-contracts"); const debug = debug_1.default('@appengine:template'); exports.templateHelperMixin = (base) => class extends base { async ensureSystemProvisioner() { if (this.systemProvisioner) return; this.systemProvisioner = await this.controller.resolver.getProvisioner('c6o-system', 'c6o-system'); } async processTemplate(map, stageName) { var _a, _b, _c; try { (_a = this.controller.status) === null || _a === void 0 ? void 0 : _a.push(stageName); for (const key in map) { (_b = this.controller.status) === null || _b === void 0 ? void 0 : _b.info(`Evaluating key ${key}`); const value = map[key]; if (appengine_contracts_1.isGenerateOptions(value)) this._setPassword(map, key, value.generate); else if (typeof value === 'string') { await this.ensureSystemProvisioner(); if (value.includes('$PUBLIC_FQDN')) this._interpolateValue(map, key, '$PUBLIC_FQDN', await this.systemProvisioner.getApplicationFQDN(this.documentHelper.name, this.documentHelper.namespace)); else if (value.includes('$PUBLIC_URL')) this._interpolateValue(map, key, '$PUBLIC_URL', await this.systemProvisioner.getApplicationURL(this.documentHelper.name, this.documentHelper.namespace)); } else if (typeof value === 'number') map[key] = value.toString(); } } finally { (_c = this.controller.status) === null || _c === void 0 ? void 0 : _c.pop(); } } async _interpolateValue(map, key, template, value) { var _a; const currentValue = map[key]; (_a = this.controller.status) === null || _a === void 0 ? void 0 : _a.info(`Interpolating value ${currentValue}`); map[key] = currentValue.replace(template, value); } _setPassword(map, key, options) { map[key] = generate_password_1.generate(options); } }; //# sourceMappingURL=template.js.map