UNPKG

@provisioner/common

Version:
99 lines 4.38 kB
"use strict"; var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { if (k2 === undefined) k2 = k; Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } }); }) : (function(o, m, k, k2) { if (k2 === undefined) k2 = k; o[k2] = m[k]; })); var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { Object.defineProperty(o, "default", { enumerable: true, value: v }); }) : function(o, v) { o["default"] = v; }); var __importStar = (this && this.__importStar) || function (mod) { if (mod && mod.__esModule) return mod; var result = {}; if (mod != null) for (var k in mod) if (k !== "default" && Object.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); __setModuleDefault(result, mod); return result; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.ProvisionerBase = exports.ProvisionerBasePrivate = void 0; const mixwith_1 = require("mixwith"); const path = __importStar(require("path")); const fs_1 = require("fs"); const contracts_1 = require("@provisioner/contracts"); const mixins_1 = require("./mixins"); class ProvisionerBasePrivate { } exports.ProvisionerBasePrivate = ProvisionerBasePrivate; const provisionerBaseMixin = mixwith_1.mix(ProvisionerBasePrivate).with(mixins_1.optionsMixin); class ProvisionerBase extends provisionerBaseMixin { get edition() { var _a, _b, _c; return (_c = (_b = (_a = this.controller) === null || _a === void 0 ? void 0 : _a.resource) === null || _b === void 0 ? void 0 : _b.metadata) === null || _c === void 0 ? void 0 : _c.labels['system.codezero.io/edition']; } get documentHelper() { if (this._documentHelper) return this._documentHelper; if (!this.controller.resource) return; return this._documentHelper = new contracts_1.AppHelper(this.controller.resource); } help(command, options, messages) { } serve(req, res, serverRoot = 'lib/ui') { const root = path.resolve(this.moduleLocation, serverRoot); res.sendFile(req.url, { root }); } async serveApi(req, res) { var _a, _b; const routes = (_a = this.routes) === null || _a === void 0 ? void 0 : _a.call(this); const resource = routes[req.url.toLowerCase()]; let routeFunction; switch (req.method) { case 'GET': routeFunction = resource === null || resource === void 0 ? void 0 : resource.get; break; case 'POST': routeFunction = resource === null || resource === void 0 ? void 0 : resource.post; break; case 'PUT': routeFunction = resource === null || resource === void 0 ? void 0 : resource.put; break; case 'DELETE': routeFunction = resource === null || resource === void 0 ? void 0 : resource.delete; break; } if (routeFunction) { const response = await ((_b = routeFunction.func) === null || _b === void 0 ? void 0 : _b.apply(this, routeFunction === null || routeFunction === void 0 ? void 0 : routeFunction.params(req.query, req.body))); if (response) res.json(response); } throw Error('Function not found'); } async readFile(...args) { const buffer = await fs_1.promises.readFile(path.resolve(...args)); return buffer.toString('utf-8'); } async getIngressGatewayServiceClusterIp() { var _a, _b, _c; const service = { apiVersion: 'v1', kind: 'Service', metadata: { namespace: 'istio-system', name: 'istio-ingressgateway', labels: { app: 'istio-ingressgateway' } } }; const result = await this.controller.cluster.read(service); if (result.error) { (_a = this.logger) === null || _a === void 0 ? void 0 : _a.error(result.error); throw result.error; } return (_c = (_b = result.object) === null || _b === void 0 ? void 0 : _b.spec) === null || _c === void 0 ? void 0 : _c.clusterIP; } } exports.ProvisionerBase = ProvisionerBase; //# sourceMappingURL=provisioner.js.map