diff options
Diffstat (limited to 'ui/imports/api/environments')
10 files changed, 0 insertions, 1068 deletions
diff --git a/ui/imports/api/environments/configuration-groups/aci-configuration.js b/ui/imports/api/environments/configuration-groups/aci-configuration.js deleted file mode 100644 index dd2c089..0000000 --- a/ui/imports/api/environments/configuration-groups/aci-configuration.js +++ /dev/null @@ -1,29 +0,0 @@ -///////////////////////////////////////////////////////////////////////////////////////// -// Copyright (c) 2017 Koren Lev (Cisco Systems), Yaron Yogev (Cisco Systems) and others / -// / -// All rights reserved. This program and the accompanying materials / -// are made available under the terms of the Apache License, Version 2.0 / -// which accompanies this distribution, and is available at / -// http://www.apache.org/licenses/LICENSE-2.0 / -///////////////////////////////////////////////////////////////////////////////////////// -import { SimpleSchema } from 'meteor/aldeed:simple-schema'; - -export const AciSchema = new SimpleSchema({ - name: { - type: String, - autoValue: function () { return 'ACI'; } - }, - host: { - type: String, - regEx: SimpleSchema.RegEx.IP, - defaultValue: '10.0.0.1', - }, - user: { - type: String, - defaultValue: 'admin' - }, - pwd: { - type: String, - defaultValue: '123456' - }, -}); diff --git a/ui/imports/api/environments/configuration-groups/amqp-configuration.js b/ui/imports/api/environments/configuration-groups/amqp-configuration.js deleted file mode 100644 index 7b7ddaf..0000000 --- a/ui/imports/api/environments/configuration-groups/amqp-configuration.js +++ /dev/null @@ -1,29 +0,0 @@ -///////////////////////////////////////////////////////////////////////////////////////// -// Copyright (c) 2017 Koren Lev (Cisco Systems), Yaron Yogev (Cisco Systems) and others / -// / -// All rights reserved. This program and the accompanying materials / -// are made available under the terms of the Apache License, Version 2.0 / -// which accompanies this distribution, and is available at / -// http://www.apache.org/licenses/LICENSE-2.0 / -///////////////////////////////////////////////////////////////////////////////////////// -import { SimpleSchema } from 'meteor/aldeed:simple-schema'; -import { portRegEx } from '/imports/lib/general-regex'; - -export const AMQPSchema = new SimpleSchema({ - name: { type: String, autoValue: function () { return 'AMQP'; } }, - host: { - type: String, - regEx: SimpleSchema.RegEx.IP, - defaultValue: '10.0.0.1', - }, - port: { - type: String, - regEx: portRegEx, - defaultValue: '5673', - }, - user: { - type: String, - defaultValue: 'rabbitmquser' - }, - pwd: { type: String }, -}); diff --git a/ui/imports/api/environments/configuration-groups/cli-configuration.js b/ui/imports/api/environments/configuration-groups/cli-configuration.js deleted file mode 100644 index c651359..0000000 --- a/ui/imports/api/environments/configuration-groups/cli-configuration.js +++ /dev/null @@ -1,69 +0,0 @@ -///////////////////////////////////////////////////////////////////////////////////////// -// Copyright (c) 2017 Koren Lev (Cisco Systems), Yaron Yogev (Cisco Systems) and others / -// / -// All rights reserved. This program and the accompanying materials / -// are made available under the terms of the Apache License, Version 2.0 / -// which accompanies this distribution, and is available at / -// http://www.apache.org/licenses/LICENSE-2.0 / -///////////////////////////////////////////////////////////////////////////////////////// -import * as R from 'ramda'; -import { SimpleSchema } from 'meteor/aldeed:simple-schema'; -import { pathRegEx } from '/imports/lib/general-regex'; - -export const CLISchema = new SimpleSchema({ - name: { type: String, autoValue: function () { return 'CLI'; } }, - host: { - type: String, - defaultValue: '10.0.0.1' - }, - key: { - type: String, - regEx: pathRegEx, - optional: true - }, - user: { - type: String, - defaultValue: 'sshuser' - }, - pwd: { - type: String, - optional: true - }, -}); - -CLISchema.addValidator(function () { - let that = this; - - let conf = {}; - if (isConfEmpty(conf)) { - return; - } - - let validationResult = R.find((validationFn) => { - return validationFn(that).isError; - }, [ keyPasswordValidation ]); - - if (R.isNil(validationResult)) { return; } - - throw validationResult(that); -}); - -function keyPasswordValidation(schemaItem) { - let password = schemaItem.field('pwd'); - let key = schemaItem.field('key'); - - if (key.value || password.value) { return { isError: false }; } - - return { - isError: true, - type: 'subGroupError', - data: [], - message: 'Master Host Group: At least one required: key or password' - }; -} - -function isConfEmpty(conf) { - return R.find((key) => { - return !(R.isNil(conf[key])); - }, R.keys(conf)); -} diff --git a/ui/imports/api/environments/configuration-groups/monitoring-configuration.js b/ui/imports/api/environments/configuration-groups/monitoring-configuration.js deleted file mode 100644 index edeaaad..0000000 --- a/ui/imports/api/environments/configuration-groups/monitoring-configuration.js +++ /dev/null @@ -1,122 +0,0 @@ -///////////////////////////////////////////////////////////////////////////////////////// -// Copyright (c) 2017 Koren Lev (Cisco Systems), Yaron Yogev (Cisco Systems) and others / -// / -// All rights reserved. This program and the accompanying materials / -// are made available under the terms of the Apache License, Version 2.0 / -// which accompanies this distribution, and is available at / -// http://www.apache.org/licenses/LICENSE-2.0 / -///////////////////////////////////////////////////////////////////////////////////////// -import { SimpleSchema } from 'meteor/aldeed:simple-schema'; -import * as R from 'ramda'; -import { Constants } from '/imports/api/constants/constants'; -import { portRegEx } from '/imports/lib/general-regex'; -import { hostnameRegex } from '/imports/lib/general-regex'; -import { ipAddressRegex } from '/imports/lib/general-regex'; -import { pathRegEx } from '/imports/lib/general-regex'; - -export const MonitoringSchema = new SimpleSchema({ - name: { type: String, autoValue: function () { return 'Monitoring'; } }, - //app_path: { type: String, autoValue: function () { return '/etc/calipso/monitoring'; } }, - - config_folder: { - type: String, - defaultValue: '/local_dir/sensu_config', - regEx: pathRegEx, - }, - - env_type: { - type: String, - defaultValue: 'production', - custom: function () { - let that = this; - let EnvTypesRec = Constants.findOne({ name: 'env_types' }); - - if (R.isNil(EnvTypesRec.data)) { return 'notAllowed'; } - let EnvTypes = EnvTypesRec.data; - - if (R.isNil(R.find(R.propEq('value', that.value), EnvTypes))) { - return 'notAllowed'; - } - }, - }, - - rabbitmq_port: { - type: String, - defaultValue: '5671', - regEx: portRegEx, - }, - - rabbitmq_user: { - type: String, - defaultValue: 'sensu' - }, - - rabbitmq_pass: { - type: String, - defaultValue: 'osdna' - }, - - server_ip: { - type: String, - regEx: new RegExp(hostnameRegex.source + '|' + ipAddressRegex.soure), - defaultValue: '10.0.0.1', - }, - - server_name: { - type: String, - defaultValue: 'sensu_server', - }, - - type: { - type: String, - defaultValue: 'Sensu', - custom: function () { - let that = this; - let values = Constants.findOne({ name: 'environment_monitoring_types' }).data; - - if (R.isNil(values)) { return 'notAllowed'; } - - if (R.isNil(R.find(R.propEq('value', that.value), values))) { - return 'notAllowed'; - } - }, - }, - - provision: { - type: String, - defaultValue: 'None', - custom: function () { - let that = this; - let values = Constants.findOne({ name: 'environment_provision_types' }).data; - - if (R.isNil(values)) { return 'notAllowed'; } - - if (R.isNil(R.find(R.propEq('value', that.value), values))) { - return 'notAllowed'; - } - }, - }, - - ssh_port: { - type: String, - defaultValue: '20022', - optional: true - }, - - ssh_user: { - type: String, - defaultValue: 'root', - optional: true - }, - - ssh_password: { - type: String, - defaultValue: 'osdna', - optional: true - }, - - api_port: { - type: Number, - defaultValue: 4567, - }, -}); diff --git a/ui/imports/api/environments/configuration-groups/mysql-configuration.js b/ui/imports/api/environments/configuration-groups/mysql-configuration.js deleted file mode 100644 index 97eab29..0000000 --- a/ui/imports/api/environments/configuration-groups/mysql-configuration.js +++ /dev/null @@ -1,33 +0,0 @@ -///////////////////////////////////////////////////////////////////////////////////////// -// Copyright (c) 2017 Koren Lev (Cisco Systems), Yaron Yogev (Cisco Systems) and others / -// / -// All rights reserved. This program and the accompanying materials / -// are made available under the terms of the Apache License, Version 2.0 / -// which accompanies this distribution, and is available at / -// http://www.apache.org/licenses/LICENSE-2.0 / -///////////////////////////////////////////////////////////////////////////////////////// -import { SimpleSchema } from 'meteor/aldeed:simple-schema'; -import { portRegEx } from '/imports/lib/general-regex'; - -export const MysqlSchema = new SimpleSchema({ - name: { - type: String, - autoValue: function () { return 'mysql'; } - }, - host: { - type: String, - regEx: SimpleSchema.RegEx.IP, - defaultValue: '10.0.0.1' - }, - pwd: { type: String }, - port: { - type: String, - regEx: portRegEx, - defaultValue: '3307' - }, - user: { - type: String, - min: 3, - defaultValue: 'mysqluser' - }, -}); diff --git a/ui/imports/api/environments/configuration-groups/nfv-provider-configuration.js b/ui/imports/api/environments/configuration-groups/nfv-provider-configuration.js deleted file mode 100644 index 3638e3b..0000000 --- a/ui/imports/api/environments/configuration-groups/nfv-provider-configuration.js +++ /dev/null @@ -1,25 +0,0 @@ -///////////////////////////////////////////////////////////////////////////////////////// -// Copyright (c) 2017 Koren Lev (Cisco Systems), Yaron Yogev (Cisco Systems) and others / -// / -// All rights reserved. This program and the accompanying materials / -// are made available under the terms of the Apache License, Version 2.0 / -// which accompanies this distribution, and is available at / -// http://www.apache.org/licenses/LICENSE-2.0 / -///////////////////////////////////////////////////////////////////////////////////////// -import { SimpleSchema } from 'meteor/aldeed:simple-schema'; -import { portRegEx } from '/imports/lib/general-regex'; - -export const NfvProviderSchema = new SimpleSchema({ - name: { type: String, autoValue: function () { return 'NFV_provider'; } }, - host: { - type: String, - regEx: SimpleSchema.RegEx.IP, - }, - nfv_token: { type: String }, - port: { - type: String, - regEx: portRegEx - }, - user: { type: String }, - pwd: { type: String }, -}); diff --git a/ui/imports/api/environments/configuration-groups/open-stack-configuration.js b/ui/imports/api/environments/configuration-groups/open-stack-configuration.js deleted file mode 100644 index a0d710f..0000000 --- a/ui/imports/api/environments/configuration-groups/open-stack-configuration.js +++ /dev/null @@ -1,30 +0,0 @@ -///////////////////////////////////////////////////////////////////////////////////////// -// Copyright (c) 2017 Koren Lev (Cisco Systems), Yaron Yogev (Cisco Systems) and others / -// / -// All rights reserved. This program and the accompanying materials / -// are made available under the terms of the Apache License, Version 2.0 / -// which accompanies this distribution, and is available at / -// http://www.apache.org/licenses/LICENSE-2.0 / -///////////////////////////////////////////////////////////////////////////////////////// -import { SimpleSchema } from 'meteor/aldeed:simple-schema'; -import { portRegEx } from '/imports/lib/general-regex'; - -export const OpenStackSchema = new SimpleSchema({ - name: { type: String, autoValue: function () { return 'OpenStack'; } }, - host: { - type: String, - regEx: SimpleSchema.RegEx.IP, - defaultValue: '10.0.0.1', - }, - admin_token: { type: String }, - port: { - type: String, - regEx: portRegEx, - defaultValue: '5000', - }, - user: { - type: String, - defaultValue: 'adminuser' - }, - pwd: { type: String }, -}); diff --git a/ui/imports/api/environments/environments.js b/ui/imports/api/environments/environments.js deleted file mode 100644 index e196a69..0000000 --- a/ui/imports/api/environments/environments.js +++ /dev/null @@ -1,472 +0,0 @@ -///////////////////////////////////////////////////////////////////////////////////////// -// Copyright (c) 2017 Koren Lev (Cisco Systems), Yaron Yogev (Cisco Systems) and others / -// / -// All rights reserved. This program and the accompanying materials / -// are made available under the terms of the Apache License, Version 2.0 / -// which accompanies this distribution, and is available at / -// http://www.apache.org/licenses/LICENSE-2.0 / -///////////////////////////////////////////////////////////////////////////////////////// -import { Mongo } from 'meteor/mongo'; -import { SimpleSchema } from 'meteor/aldeed:simple-schema'; -import * as R from 'ramda'; -import { Constants } from '/imports/api/constants/constants'; -import { MysqlSchema } from './configuration-groups/mysql-configuration'; -import { OpenStackSchema } from './configuration-groups/open-stack-configuration'; -import { MonitoringSchema } from './configuration-groups/monitoring-configuration'; -import { CLISchema } from './configuration-groups/cli-configuration'; -import { AMQPSchema } from './configuration-groups/amqp-configuration'; -//import { NfvProviderSchema } from './configuration-groups/nfv-provider-configuration'; -import { AciSchema } from './configuration-groups/aci-configuration'; -import { - isMonitoringSupported, - isListeningSupported, -} from '/imports/api/supported_environments/supported_environments'; - -export const Environments = new Mongo.Collection( - 'environments_config', { idGeneration: 'MONGO' }); - -export const requiredConfGroups = [ - 'mysql', - 'OpenStack', - 'CLI', -]; - -export const optionalConfGroups = [ - // 'NFV_provider', - 'AMQP', - 'Monitoring', - 'ACI', -]; - -let simpleSchema = new SimpleSchema({ - _id: { type: { _str: { type: String, regEx: SimpleSchema.RegEx.Id } } }, - auth: { - type: Object, - blackbox: true, - defaultValue: { - 'view-env': [ - ], - 'edit-env': [ - ] - } - }, - configuration: { - type: [Object], - blackbox: true, - autoValue: function () { - console.log('start - autovalue - environment - configuration'); - //console.log(this); - let that = this; - - if (that.isSet) { - let confGroups = that.value; - - let { - isMonitoringSupportedRes, - isListeningSupportedRes, - enable_monitoring, - listen - } = extractCalcEnvSupportedRelatedValues(that); - let dbNode = getDbNode(that); - let aci_enabled = extractValue('aci_enabled', that, dbNode); - - if (enable_monitoring && isMonitoringSupportedRes) { - if (! R.find(R.propEq('name', 'Monitoring'), confGroups)) { - confGroups = R.append(createNewConfGroup('Monitoring'), confGroups); - } - } else { - console.log('env - configurations - autovalue - monitoring not supported'); - confGroups = R.reject(R.propEq('name', 'Monitoring'), confGroups); - } - - if (listen && isListeningSupportedRes) { - if (! R.find(R.propEq('name', 'AMQP'), confGroups)) { - confGroups = R.append(createNewConfGroup('AMQP'), confGroups); - } - } else { - console.log('env - configurations - autovalue - listening not supported'); - confGroups = R.reject(R.propEq('name', 'AMQP'), confGroups); - } - - if (aci_enabled) { - if (! R.find(R.propEq('name', 'ACI'), confGroups)) { - confGroups = R.append(createNewConfGroup('ACI'), confGroups); - } - } else { - console.log('env - configurations - autovalue - aci not requested'); - confGroups = R.reject(R.propEq('name', 'ACI'), confGroups); - } - - confGroups = cleanOptionalGroups(confGroups, optionalConfGroups); - console.log('env - configurations - autovalue - after clean optional groups'); - - let newValue = R.map(function(confGroup) { - let schema = getSchemaForGroupName(confGroup.name); - return schema.clean(confGroup); - }, confGroups); - - console.log('end - autovalue - environment - configurations'); - console.log(newValue); - return newValue; - - } else { - console.log('env - configurations - autovalue - is not set'); - let newValue = R.map((confName) => { - let schema = getSchemaForGroupName(confName); - return schema.clean({}); - }, requiredConfGroups); - console.log('end - autovalue - environment - configurations'); - console.log(newValue); - return newValue; - } - }, - custom: function () { - console.log('start - custom - environment - configurations'); - //console.log(this); - let that = this; - let configurationGroups = that.value; - - let subErrors = []; - - let { - isMonitoringSupportedRes, - isListeningSupportedRes, - enable_monitoring, - listen - } = extractCalcEnvSupportedRelatedValues(that); - - let requiredConfGroupsTemp = R.clone(requiredConfGroups); - if (enable_monitoring && isMonitoringSupportedRes) { - requiredConfGroupsTemp = R.append('Monitoring', requiredConfGroupsTemp); - } - if (listen && isListeningSupportedRes) { - requiredConfGroupsTemp = R.append('AMQP', requiredConfGroupsTemp); - } - - console.log('env - configurations - custom - after mon & listen check'); - - let invalidResult = R.find(function(groupName) { - subErrors = checkGroup(groupName, configurationGroups, true); - if (subErrors.length > 0) { return true; } - return false; - }, requiredConfGroupsTemp); - - console.log(`env - configurations - custom - after require groups check`); - - if (R.isNil(invalidResult)) { - invalidResult = R.find(function(groupName) { - subErrors = checkGroup(groupName, configurationGroups, false); - if (subErrors.length > 0) { return true; } - return false; - }, optionalConfGroups); - } - - console.log(`env - configurations - custom - after optional groups check`); - - if (! R.isNil(invalidResult)) { - console.log(`env - configrations - custom - invalid result end: ${R.toString(subErrors)}`); - throw { - isError: true, - type: 'subGroupError', - data: subErrors, - message: constructSubGroupErrorMessage(subErrors) - }; - } - }, - - }, - user: { - type: String, - }, - distribution: { - type: String, - defaultValue: 'Mirantis', - custom: function () { - let that = this; - let constsDist = Constants.findOne({ name: 'distributions' }); - - if (R.isNil(constsDist.data)) { return 'notAllowed'; } - let distributions = constsDist.data; - - if (R.isNil(R.find(R.propEq('value', that.value), distributions))) { - return 'notAllowed'; - } - }, - }, - distribution_version: { - type: String, - custom: function () { - let that = this; - let constsDist = Constants.findOne({ name: 'distribution_versions' }); - - if (R.isNil(constsDist.data)) { return 'notAllowed'; } - let dist_versions = constsDist.data; - - if (R.isNil(R.find(R.propEq('value', that.value), dist_versions))) { - return 'notAllowed'; - } - }, - }, - last_scanned: { - type: String, defaultValue: '' - }, - name: { - type: String, - defaultValue: 'MyEnvironmentName', - min: 6, - }, - type_drivers: { - type: String, - defaultValue: 'gre', - custom: function () { - let that = this; - let TypeDriversRec = Constants.findOne({ name: 'type_drivers' }); - - if (R.isNil(TypeDriversRec.data)) { return 'notAllowed'; } - let TypeDrivers = TypeDriversRec.data; - - if (R.isNil(R.find(R.propEq('value', that.value), TypeDrivers))) { - return 'notAllowed'; - } - }, - }, - - mechanism_drivers: { - type: [String], - defaultValue: ['OVS'], - minCount: 1, - custom: function () { - let that = this; - let consts = Constants.findOne({ name: 'mechanism_drivers' }); - - if (R.isNil(consts.data)) { return 'notAllowed'; } - let mechanismDrivers = consts.data; - - let result = R.find((driver) => { - if (R.find(R.propEq('value', driver), mechanismDrivers)) { - return false; - } - return true; - }, that.value); - - if (result) { return 'notAllowed'; } - - }, - }, - - operational: { - type: String, - allowedValues: ['stopped', 'running', 'error'], - defaultValue: 'stopped' - }, - - scanned: { type: Boolean, defaultValue: false }, - - type: { - type: String, - autoValue: function () { - return 'environment'; - }, - }, - - app_path: { - type: String, - autoValue: function () { - return '/home/scan/calipso_prod/app'; - } - }, - - listen: { - type: Boolean, - autoValue: function () { - console.log('env - listen - autoValue - start'); - let that = this; - let newValue = that.value; - console.log(`- current value: ${R.toString(newValue)}`); - - let { isListeningSupportedRes } = extractCalcEnvSupportedRelatedValues(that); - - if (!isListeningSupportedRes) { - console.log('* listening not supported'); - console.log(`* ${R.toString(isListeningSupportedRes)}`); - newValue = false; - } - - return newValue; - }, - }, - - enable_monitoring: { - type: Boolean, - autoValue: function () { - console.log('env - enable_monitoring - autoValue - start'); - let that = this; - let newValue = that.value; - console.log(`- current value: ${R.toString(newValue)}`); - - let { isMonitoringSupportedRes } = extractCalcEnvSupportedRelatedValues(that); - - if (!isMonitoringSupportedRes) { - console.log('* monitoring not supported'); - console.log(`* ${R.toString(isMonitoringSupportedRes)}`); - newValue = false; - } - - return newValue; - }, - }, - aci_enabled: { - type: Boolean, - defaultValue: false, - }, -}); - -/* -simpleSchema.addValidator(function () { - //let that = this; -}); -*/ - -// Bug in simple schema. cant add custom message to instance specific -// schema. -// https://github.com/aldeed/meteor-simple-schema/issues/559 -// Version 2 fixes it but it is rc. -//Environments.schema.messages({ -SimpleSchema.messages({ - confGroupInvalid: 'Configuration group is invalid.' -}); - -Environments.schema = simpleSchema; -Environments.attachSchema(Environments.schema); - -export function getSchemaForGroupName(groupName) { - switch (groupName) { - case 'mysql': - return MysqlSchema; - case 'OpenStack': - return OpenStackSchema; - case 'CLI': - return CLISchema; - case 'AMQP': - return AMQPSchema; - // case 'NFV_provider': - // return NfvProviderSchema; - case 'ACI': - return AciSchema; - case 'Monitoring': - return MonitoringSchema; - default: - throw 'group name is not recognized. group: ' + groupName; - } -} - -function constructSubGroupErrorMessage(errors) { - let message = 'Validation errors on sub groups:'; - message = message + R.reduce((acc, item) => { - return acc + '\n- ' + item.group + ': ' + item.message; - }, '', errors); - - return message; -} - -function checkGroup(groupName, configurationGroups, groupRequired) { - let subErrors = []; - let confGroup = R.find(R.propEq('name', groupName), configurationGroups); - - if (R.isNil(confGroup)) { - if (groupRequired) { - subErrors = R.append({ - field: 'configuration', - group: groupName, - message: 'group ' + groupName + ' is required' - }, subErrors); - } - return subErrors; - } - - let validationContext = getSchemaForGroupName(groupName).newContext(); - - if (! validationContext.validate(confGroup)) { - subErrors = R.reduce(function (acc, invalidField) { - return R.append({ - field: invalidField, - group: groupName, - message: validationContext.keyErrorMessage(invalidField.name), - }, acc); - }, [], validationContext.invalidKeys()); - - return subErrors; - } - - return subErrors; -} - -export function createNewConfGroup(groupName) { - let schema = getSchemaForGroupName(groupName); - return schema.clean({}); -} - -function cleanOptionalGroups(confGroups, optionalConfGroups) { - return R.filter((conf) => { - if (R.contains(conf.name, optionalConfGroups)) { - return !isConfEmpty(conf); - } - - return true; - }, confGroups); -} - -function isConfEmpty(conf) { - return ! R.any((key) => { - if (key === 'name') { return false; } // We ignore the key 'name'. It is a 'type' key. - let val = conf[key]; - return ! ( R.isNil(val) || R.isEmpty(val)); - })(R.keys(conf)); -} - -function extractValue(name, schemaValidator, dbNode) { - console.log('env - extract value'); - console.log(`-name: ${R.toString(name)}`); - //console.log(`-schemaValidator: ${R.toString(schemaValidator)}`); - console.log(`-dbNode: ${R.toString(dbNode)}`); - - let field = schemaValidator.field(name); - let value = field.value; - - console.log(`extract value - schema value: ${R.toString(value)}`); - - if (R.isNil(field.value) && !field.isSet && dbNode) { - console.log(`extract value - db value: ${R.toString(dbNode[name])}`); - value = dbNode[name]; - } - - console.log(`extract value - result: ${R.toString(value)}`); - return value; -} - -function getDbNode(schemaHelper) { - let _id = R.defaultTo(schemaHelper.docId, R.path(['value'], schemaHelper.field('_id'))); - let dbNode = R.defaultTo(null, Environments.findOne({ _id: _id })); - return dbNode; -} - -function extractCalcEnvSupportedRelatedValues(schemaHelper) { - let dbNode = getDbNode(schemaHelper); - - let dist = extractValue('distribution', schemaHelper, dbNode); - let dist_version = extractValue('distribution_version', schemaHelper, dbNode); - let typeDrivers = extractValue('type_drivers', schemaHelper, dbNode); - let mechDrivers = extractValue('mechanism_drivers', schemaHelper, dbNode); - let enable_monitoring = extractValue('enable_monitoring', schemaHelper, dbNode); - let listen = extractValue('listen', schemaHelper, dbNode); - - let isMonitoringSupportedRes = isMonitoringSupported(dist, dist_version, typeDrivers, mechDrivers); - let isListeningSupportedRes = isListeningSupported(dist, dist_version, typeDrivers, mechDrivers); - - return { - enable_monitoring, - listen, - isMonitoringSupportedRes, - isListeningSupportedRes, - }; -} diff --git a/ui/imports/api/environments/methods.js b/ui/imports/api/environments/methods.js deleted file mode 100644 index 66d1557..0000000 --- a/ui/imports/api/environments/methods.js +++ /dev/null @@ -1,157 +0,0 @@ -///////////////////////////////////////////////////////////////////////////////////////// -// Copyright (c) 2017 Koren Lev (Cisco Systems), Yaron Yogev (Cisco Systems) and others / -// / -// All rights reserved. This program and the accompanying materials / -// are made available under the terms of the Apache License, Version 2.0 / -// which accompanies this distribution, and is available at / -// http://www.apache.org/licenses/LICENSE-2.0 / -///////////////////////////////////////////////////////////////////////////////////////// -//import { Meteor } from 'meteor/meteor'; -import * as R from 'ramda'; -import { ValidatedMethod } from 'meteor/mdg:validated-method'; - -//import { SimpleSchema } from 'meteor/aldeed:simple-schema'; - -import { Environments } from './environments'; -import { Inventory } from '/imports/api/inventories/inventories'; -import { Links } from '/imports/api/links/links'; -import { Cliques } from '/imports/api/cliques/cliques'; -import { CliqueTypes } from '/imports/api/clique-types/clique-types'; -import { Messages } from '/imports/api/messages/messages'; -import { Scans } from '/imports/api/scans/scans'; -import { Roles } from 'meteor/alanning:roles'; - -export const insert = new ValidatedMethod({ - name: 'environments.insert', - validate: Environments.simpleSchema() - .pick([ - 'configuration', - 'configuration.$', - 'distribution', - 'distribution_version', - 'name', - 'type_drivers', - 'mechanism_drivers', - 'mechanism_drivers.$', - 'listen', - 'enable_monitoring', - 'aci_enabled', - ]).validator({ clean: true, filter: false }), - //validate: null, - run({ - configuration, - distribution, - distribution_version, - name, - type_drivers, - mechanism_drivers, - listen, - enable_monitoring, - aci_enabled, - }) { - // todo: create clean object instance. - let environment = Environments.schema.clean({ - user: Meteor.userId() - }); - - let auth = { - 'view-env': [ - Meteor.userId() - ], - 'edit-env': [ - Meteor.userId() - ] - }; - - environment = R.merge(environment, { - configuration, - distribution, - distribution_version, - name, - type_drivers, - mechanism_drivers, - listen, - enable_monitoring, - auth, - aci_enabled, - }); - - Environments.insert(environment); - }, -}); - -export const update = new ValidatedMethod({ - name: 'environments.update', - validate: Environments.simpleSchema().pick([ - '_id', - 'configuration', - 'configuration.$', - //'distribution', - //'name', - 'type_drivers', - 'mechanism_drivers', - 'mechanism_drivers.$', - 'listen', - 'enable_monitoring', - 'aci_enabled', - ]).validator({ clean: true, filter: false }), - run({ - _id, - configuration, - //distribution, - //name, - type_drivers, - mechanism_drivers, - listen, - enable_monitoring, - aci_enabled, - }) { - let env = Environments.findOne({ _id: _id }); - - if (! Roles.userIsInRole(Meteor.userId(), 'edit-env', 'default-group')) { - if (! R.contains(Meteor.userId(), R.path(['auth', 'edit-env'], env) )) { - throw new Meteor.Error('not-auth', 'unauthorized for updating env'); - } - } - - Environments.update(_id, { - $set: { - configuration: configuration, - //distribution: distribution, - //name: name, - type_drivers, - mechanism_drivers, - listen, - enable_monitoring, - aci_enabled, - }, - }); - } -}); - -export const remove = new ValidatedMethod({ - name: 'environments.remove', - validate: Environments.simpleSchema().pick([ - '_id', - ]).validator({ clean: true, filter: false }), - run({ - _id, - }) { - const env = Environments.findOne({ _id: _id }); - console.log('environment for remove: ', env); - - if (! Roles.userIsInRole(Meteor.userId(), 'edit-env', 'default-group')) { - if (! R.contains(Meteor.userId(), R.path(['auth', 'edit-env'], env) )) { - throw new Meteor.Error('not-auth', 'unauthorized for updating env'); - } - } - - Inventory.remove({ environment: env.name }); - Links.remove({ environment: env.name }); - Cliques.remove({ environment: env.name }); - CliqueTypes.remove({ environment: env.name }); - Messages.remove({ environment: env.name }); - Scans.remove({ environment: env.name }); - Environments.remove({ _id: _id }); - } -}); diff --git a/ui/imports/api/environments/server/publications.js b/ui/imports/api/environments/server/publications.js deleted file mode 100644 index 667ee8e..0000000 --- a/ui/imports/api/environments/server/publications.js +++ /dev/null @@ -1,102 +0,0 @@ -///////////////////////////////////////////////////////////////////////////////////////// -// Copyright (c) 2017 Koren Lev (Cisco Systems), Yaron Yogev (Cisco Systems) and others / -// / -// All rights reserved. This program and the accompanying materials / -// are made available under the terms of the Apache License, Version 2.0 / -// which accompanies this distribution, and is available at / -// http://www.apache.org/licenses/LICENSE-2.0 / -///////////////////////////////////////////////////////////////////////////////////////// -import { Meteor } from 'meteor/meteor'; -import * as R from 'ramda'; -import { Roles } from 'meteor/alanning:roles'; - -import { Environments } from '../environments.js'; - -Meteor.publish('environments_config', function () { - console.log('server subscribtion to: environments_config'); - let userId = this.userId; - - let query = { - type: 'environment', - }; - - if (! Roles.userIsInRole(userId, 'view-env', null)) { - query = R.merge(query, { - 'auth.view-env': { - $in: [ userId ] - } - }); - } - - console.log('-query: ', R.toString(query)); - return Environments.find(query); -}); - -const subsEnvViewEnvUserId = 'environments.view-env&userId'; -Meteor.publish(subsEnvViewEnvUserId, function (userId) { - console.log(`subscription - ${subsEnvViewEnvUserId} `); - console.log(`-userId: ${R.toString(userId)}`); - - let query = {}; - - let currentUser = this.userId; - if (! Roles.userIsInRole(currentUser, 'manage-users', Roles.GLOBAL_GROUP)) { - console.log(`* error: unauth`); - console.log(`- currentUser: ${R.toString(currentUser)}`); - this.error('unauthorized for this subscription'); - return; - } - - query = R.merge(query, { - 'auth.view-env': { - $in: [ userId ] - } - }); - - console.log(`* query: ${R.toString(query)}`); - return Environments.find(query); -}); - -const subsEnvEditEnvUserId = 'environments.edit-env&userId'; -Meteor.publish(subsEnvEditEnvUserId, function (userId) { - console.log(`subscription - ${subsEnvEditEnvUserId} `); - console.log(`-userId: ${R.toString(userId)}`); - let query = {}; - - let currentUser = this.userId; - if (! Roles.userIsInRole(currentUser, 'manage-users', Roles.GLOBAL_GROUP)) { - console.log(`* error: unauth`); - console.log(`- currentUser: ${R.toString(currentUser)}`); - this.error('unauthorized for this subscription'); - return; - } - - query = R.merge(query, { - 'auth.edit-env': { - $in: [ userId ] - } - }); - - console.log(`* query: ${R.toString(query)}`); - return Environments.find(query); -}); - -Meteor.publish('environments?name', function (name) { - console.log('server subscribtion to: environments?name=' + name.toString()); - let query = { - name: name, - user: this.userId - }; - return Environments.find(query); -}); - -Meteor.publish('environments?_id', function (_id) { - console.log('server subscribtion to: environments?_id'); - console.log('-_id: ', R.toString(_id)); - - let query = { - _id: _id, - user: this.userId - }; - return Environments.find(query); -}); |