UNPKG

@lxdhub/api

Version:

Display, search and copy LXD-images using a web interface.

145 lines 5.93 kB
"use strict"; var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) { var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d; if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc); else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r; return c > 3 && r && Object.defineProperty(target, key, r), r; }; var __metadata = (this && this.__metadata) || function (k, v) { if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v); }; Object.defineProperty(exports, "__esModule", { value: true }); const clime_1 = require("clime"); const __1 = require("../../.."); const fs = require("fs"); class StartOptions extends clime_1.Options { constructor() { super(...arguments); this.port = 3000; this.host = '0.0.0.0'; this.databaseName = 'lxdhub'; this.databaseHost = 'localhost'; this.databasePassword = 'lxdhub'; this.databasePort = 5432; this.databaseUsername = 'lxdhub'; this.cert = `${process.env.HOME}/.config/lxc/client.crt`; this.key = `${process.env.HOME}/.config/lxc/client.key`; this.logLevel = 'info'; this.docUrl = '/api/v1/doc'; this.upload = false; } } __decorate([ clime_1.option({ flag: 'p', description: 'Port on which lxdhub-api should listen. Default is 3000', }), __metadata("design:type", Number) ], StartOptions.prototype, "port", void 0); __decorate([ clime_1.option({ flag: 'h', description: 'Hostname of lxdhub-api. Default is 0.0.0.0' }), __metadata("design:type", String) ], StartOptions.prototype, "host", void 0); __decorate([ clime_1.option({ description: 'The name of the database to connect to. Default is lxdhub' }), __metadata("design:type", Object) ], StartOptions.prototype, "databaseName", void 0); __decorate([ clime_1.option({ description: 'The host of the database to connect to. Default is localhost' }), __metadata("design:type", String) ], StartOptions.prototype, "databaseHost", void 0); __decorate([ clime_1.option({ description: 'The database password for the given user. Default is lxdhub' }), __metadata("design:type", String) ], StartOptions.prototype, "databasePassword", void 0); __decorate([ clime_1.option({ description: 'The database port to connect to. Default is 5432' }), __metadata("design:type", Number) ], StartOptions.prototype, "databasePort", void 0); __decorate([ clime_1.option({ description: 'The database username. Default is lxdhub' }), __metadata("design:type", String) ], StartOptions.prototype, "databaseUsername", void 0); __decorate([ clime_1.option({ description: 'The LXD certificate for the remote' }), __metadata("design:type", String) ], StartOptions.prototype, "cert", void 0); __decorate([ clime_1.option({ description: 'The LXC key for the remote' }), __metadata("design:type", String) ], StartOptions.prototype, "key", void 0); __decorate([ clime_1.option({ description: 'The log level' }), __metadata("design:type", String) ], StartOptions.prototype, "logLevel", void 0); __decorate([ clime_1.option({ description: 'The url to the swagger documentation' }), __metadata("design:type", String) ], StartOptions.prototype, "docUrl", void 0); __decorate([ clime_1.option({ description: 'If the image upload is enabled' }), __metadata("design:type", Boolean) ], StartOptions.prototype, "upload", void 0); exports.StartOptions = StartOptions; let default_1 = class default_1 extends clime_1.Command { async execute(options) { var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m; const apiOptions = { port: (_a = options.port, (_a !== null && _a !== void 0 ? _a : 3000)), hostUrl: (_b = options.host, (_b !== null && _b !== void 0 ? _b : '0.0.0.0')), logLevel: (_c = options.logLevel, (_c !== null && _c !== void 0 ? _c : 'info')), docUrl: (_d = options.docUrl, (_d !== null && _d !== void 0 ? _d : '/api/v1/doc')), database: { database: (_e = options.databaseName, (_e !== null && _e !== void 0 ? _e : 'lxdhub')), host: (_f = options.databaseHost, (_f !== null && _f !== void 0 ? _f : 'localhost')), password: (_g = options.databasePassword, (_g !== null && _g !== void 0 ? _g : 'lxdhub')), port: (_h = options.databasePort, (_h !== null && _h !== void 0 ? _h : 5432)), username: (_j = options.databaseUsername, (_j !== null && _j !== void 0 ? _j : 'lxdhub')) }, lxd: { // @ts-ignore cert: fs.readFileSync((_k = options.cert, (_k !== null && _k !== void 0 ? _k : `${process.env.HOME}/.config/lxc/client.crt`))), // @ts-ignore key: fs.readFileSync((_l = options.key, (_l !== null && _l !== void 0 ? _l : `${process.env.HOME}/.config/lxc/client.key`))) }, upload: (_m = options.upload, (_m !== null && _m !== void 0 ? _m : false)) }; await new __1.LXDHubAPI(apiOptions).run(); } }; __decorate([ clime_1.metadata, __metadata("design:type", Function), __metadata("design:paramtypes", [StartOptions]), __metadata("design:returntype", Promise) ], default_1.prototype, "execute", null); default_1 = __decorate([ clime_1.command({ description: 'Start the lxdhub api' }) ], default_1); exports.default = default_1; //# sourceMappingURL=default.js.map