| Server IP : 34.87.99.72 / Your IP : 216.73.217.31 Web Server : Apache/2.4.46 (Unix) OpenSSL/1.1.1n System : Linux zlock-bitnami-lamp-prod-v2-vm 4.19.0-16-cloud-amd64 #1 SMP Debian 4.19.181-1 (2021-03-19) x86_64 User : bitnami ( 1000) PHP Version : 7.4.18 Disable Function : NONE MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : ON | Sudo : ON | Pkexec : OFF Directory : /opt/bitnami/nami/node_modules/nami-core/lib/components/ |
Upload File : |
'use strict';
const _ = require('lodash');
const Component = require('./component.js');
const Service = require('./service.js');
const DatabaseService = require('./database_service.js');
const schemas = require('./schemas');
const supportedTypes = {
Component: Component,
DatabaseService,
Service: Service
};
// Here we should do some validation, for now we will just instantiate
// and fail if we cannot find it
function sanitizeComponentType(type) {
if (!type) {
return 'Component';
} else {
return _.isArray(type) ? type[0] : type;
}
}
function getComponentClass(type) {
return supportedTypes[type];
}
function getComponent(spec, pkgData, options) {
const type = sanitizeComponentType(spec.extends);
const id = spec.id;
options = _.defaults(options || {}, {softSchemaValidation: false, logger: null});
const Schema = schemas[type] || schemas.Component;
const schema = new Schema();
const result = schema.validate(spec);
if (result.error) {
if (options.softSchemaValidation) {
if (options.logger) {
options.logger.warn(`Package ${id} failed schema validation`);
options.logger.trace(`Package ${id} failed schema validation: ${result.error.message}`);
}
} else {
throw new Error(`Error loading metadata: ${result.error.message}`);
}
}
const sanitizedSpec = result.value;
const Class = getComponentClass(type);
const obj = new Class(sanitizedSpec, pkgData);
return obj;
}
exports.getComponent = getComponent;