UNPKG

@vulcan-sql/extension-store-canner

Version:

Canner persistence store for Vulcan SQL

68 lines 3.27 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.CannerProfileReader = void 0; const tslib_1 = require("tslib"); const core_1 = require("@vulcan-sql/core"); const config_1 = require("../config"); const storageService_1 = require("../storageService"); const utils_1 = require("./utils"); /** * Used the string to identify the extension Id not by the enum "LocalFileProfileReader". * Because if we create another enum to extend the 'LocalFileProfileReader', it seems unnecessary to give the new enum only has 'Canner' as its type." * */ let CannerProfileReader = class CannerProfileReader extends core_1.ProfileReader { constructor() { super(...arguments); this.envConfig = (0, config_1.getEnvConfig)(); this.logger = this.getLogger(); } read(options) { return tslib_1.__awaiter(this, void 0, void 0, function* () { if (!options.path) throw new core_1.ConfigurationError('Canner profile reader needs options.path property'); const storageService = yield (0, storageService_1.createStorageService)(this.envConfig.storage); this.logger.debug('Canner storage service created'); const filesInfo = yield storageService.listObjects({ path: options.path, recursive: true, }); // get the indicator files path of each workspaces const files = yield (0, utils_1.getIndicatorFilesOfWorkspaces)(filesInfo); this.logger.debug(`Succeed to get the indicator files of each workspaces: ${JSON.stringify(files)}`); // generate profiles from the indicator files of each workspaces const { user, password, host, port, max } = this.envConfig.profile; const { rootUserId } = this.envConfig.properties; if (!user || !password || !host) throw new core_1.ConfigurationError('Canner profile reader needs username, password, host properties.'); const profiles = yield Promise.all(files.map(({ workspaceId, name }) => tslib_1.__awaiter(this, void 0, void 0, function* () { const buffer = yield storageService.downObjectAsBuffer({ name }); const indicator = JSON.parse(buffer.toString('utf-8')); const workspaceSqlName = indicator[workspaceId]; const profile = { name: `canner-${workspaceSqlName}`, type: 'canner', connection: { user, password, host, port, database: workspaceSqlName, max, }, allow: '*', properties: { rootUserId, }, }; this.logger.debug(`created "${profile.name}".`); return profile; }))); return profiles; }); } }; CannerProfileReader = tslib_1.__decorate([ (0, core_1.VulcanExtensionId)('Canner') ], CannerProfileReader); exports.CannerProfileReader = CannerProfileReader; //# sourceMappingURL=profileReader.js.map