diff options
Diffstat (limited to 'ui/imports/api/scheduled-scans')
-rw-r--r-- | ui/imports/api/scheduled-scans/methods.js | 131 | ||||
-rw-r--r-- | ui/imports/api/scheduled-scans/scheduled-scans.js | 91 | ||||
-rw-r--r-- | ui/imports/api/scheduled-scans/server/methods.js | 27 | ||||
-rw-r--r-- | ui/imports/api/scheduled-scans/server/publications.js | 60 |
4 files changed, 309 insertions, 0 deletions
diff --git a/ui/imports/api/scheduled-scans/methods.js b/ui/imports/api/scheduled-scans/methods.js new file mode 100644 index 0000000..22f8110 --- /dev/null +++ b/ui/imports/api/scheduled-scans/methods.js @@ -0,0 +1,131 @@ +///////////////////////////////////////////////////////////////////////////////////////// +// 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 { ValidatedMethod } from 'meteor/mdg:validated-method'; +import * as R from 'ramda'; + +import { ScheduledScans } from './scheduled-scans'; + +export const insert = new ValidatedMethod({ + name: 'scheduled-scans.insert', + validate: ScheduledScans.simpleSchema() + .pick([ + 'environment', + 'object_id', + 'log_level', + 'clear', + 'loglevel', + 'scan_only_inventory', + 'scan_only_links', + 'scan_only_cliques', + 'freq', + ]).validator({ clean: true, filter: false }), + run({ + environment, + object_id, + log_level, + clear, + loglevel, + scan_only_inventory, + scan_only_links, + scan_only_cliques, + freq, + }) { + let scan = ScheduledScans.schema.clean({ }); + + scan = R.merge(scan, { + environment, + object_id, + log_level, + clear, + loglevel, + scan_only_inventory, + scan_only_links, + scan_only_cliques, + freq, + submit_timestamp: Date.now() + }); + + ScheduledScans.insert(scan); + }, + +}); + +export const update = new ValidatedMethod({ + name: 'scheduled_scans.update', + validate: ScheduledScans.simpleSchema() + .pick([ + '_id', + 'environment', + 'object_id', + 'log_level', + 'clear', + 'loglevel', + 'scan_only_inventory', + 'scan_only_links', + 'scan_only_cliques', + 'freq', + ]).validator({ clean: true, filter: false }), + run({ + _id, + environment, + object_id, + log_level, + clear, + loglevel, + scan_only_inventory, + scan_only_links, + scan_only_cliques, + freq, + }) { + let item = ScheduledScans.findOne({ _id: _id }); + console.log('scheduled scan for update: ', item); + + item = R.merge(R.pick([ + 'environment', + 'object_id', + 'log_level', + 'clear', + 'loglevel', + 'scan_only_inventory', + 'scan_only_links', + 'scan_only_cliques', + 'submit_timestamp', + 'freq', + ], item), { + environment, + object_id, + log_level, + clear, + loglevel, + scan_only_inventory, + scan_only_links, + scan_only_cliques, + freq, + submit_timestamp: Date.now() + }); + + ScheduledScans.update({ _id: _id }, { $set: item }); + } +}); + +export const remove = new ValidatedMethod({ + name: 'scheduled_scans.remove', + validate: ScheduledScans.simpleSchema() + .pick([ + '_id', + ]).validator({ clean: true, filter: false }), + run({ + _id + }) { + let item = ScheduledScans.findOne({ _id: _id }); + console.log('scheduled scan for remove: ', item); + + ScheduledScans.remove({ _id: _id }); + } +}); diff --git a/ui/imports/api/scheduled-scans/scheduled-scans.js b/ui/imports/api/scheduled-scans/scheduled-scans.js new file mode 100644 index 0000000..66ae5d1 --- /dev/null +++ b/ui/imports/api/scheduled-scans/scheduled-scans.js @@ -0,0 +1,91 @@ +///////////////////////////////////////////////////////////////////////////////////////// +// 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 { Constants } from '/imports/api/constants/constants'; +import * as R from 'ramda'; + +export const ScheduledScans = new Mongo.Collection('scheduled_scans', { idGeneration: 'MONGO' }); + +export const scansOnlyFields = ['scan_only_inventory', 'scan_only_links', 'scan_only_cliques']; + +let schema = new SimpleSchema({ + _id: { type: { _str: { type: String, regEx: SimpleSchema.RegEx.Id } } }, + environment: { + type: String + }, + object_id: { + type: String, + optional: true, + }, + log_level: { + type: String, + defaultValue: 'warning', + custom: function () { + let that = this; + let logLevels = Constants.findOne({ name: 'log_levels' }).data; + + if (R.isNil(R.find(R.propEq('value', that.value), logLevels))) { + return 'notAllowed'; + } + }, + }, + clear: { + type: Boolean, + defaultValue: true, + }, + scan_only_inventory: { + type: Boolean, + defaultValue: true, + }, + scan_only_links: { + type: Boolean, + defaultValue: false, + }, + scan_only_cliques: { + type: Boolean, + defaultValue: false, + }, + freq: { + type: String, + defaultValue: 'WEEKLY', + }, + submit_timestamp: { + type: Date, + defaultValue: null + }, + scheduled_timestamp: { + type: Date, + defaultValue: null, + optional: true, + } +}); + +schema.addValidator(function () { + let that = this; + let currentScansOnlyFields = + R.reject( f => that.field(f).value == false, scansOnlyFields); + + if(currentScansOnlyFields.length > 1) { + throw { + isError: true, + type: 'conflict', + data: currentScansOnlyFields, + message: `Only one of the scan only fields can be selected. ${R.toString(currentScansOnlyFields)}` + }; + } +}); + +ScheduledScans.schema = schema; +ScheduledScans.attachSchema(ScheduledScans.schema); + +export const subsScheduledScansPageAmountSorted = 'scheduled_scans?page&amount&sortField&sortDirection'; +export const subsScheduledScansPageAmountSortedCounter = `${subsScheduledScansPageAmountSorted}!counter`; + +export const subsScheduledScansId = 'scheduled_scans?_id'; diff --git a/ui/imports/api/scheduled-scans/server/methods.js b/ui/imports/api/scheduled-scans/server/methods.js new file mode 100644 index 0000000..17ed990 --- /dev/null +++ b/ui/imports/api/scheduled-scans/server/methods.js @@ -0,0 +1,27 @@ +///////////////////////////////////////////////////////////////////////////////////////// +// 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 { check } from 'meteor/check'; +import * as R from 'ramda'; +import { ScheduledScans } from '../scheduled-scans'; + +Meteor.methods({ + 'scheduledScansFind?env': function (env) { + console.log('method server: scheduledScansFind?env', R.toString(env)); + + check(env, String); + this.unblock(); + + let query = { environment: env }; + let scheduledScan = ScheduledScans.findOne(query, {}); + + return { + item: scheduledScan + }; + } +}); diff --git a/ui/imports/api/scheduled-scans/server/publications.js b/ui/imports/api/scheduled-scans/server/publications.js new file mode 100644 index 0000000..97acc21 --- /dev/null +++ b/ui/imports/api/scheduled-scans/server/publications.js @@ -0,0 +1,60 @@ +///////////////////////////////////////////////////////////////////////////////////////// +// 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 { Counts } from 'meteor/tmeasday:publish-counts'; + +import { ScheduledScans, + subsScheduledScansPageAmountSorted, + subsScheduledScansPageAmountSortedCounter, + subsScheduledScansId, +} from '../scheduled-scans.js'; + +Meteor.publish(subsScheduledScansPageAmountSorted, function ( + page, amountPerPage, sortField, sortDirection) { + + console.log(`server subscribtion: ${subsScheduledScansPageAmountSorted}`); + console.log('page: ', page); + console.log('amount: ', amountPerPage); + console.log('sortField: ', sortField, R.isNil(sortField)); + console.log('sortDirection: ', sortDirection); + + let skip = (page - 1) * amountPerPage; + + let query = {}; + console.log('-query: ', query); + let sortParams = {}; + + sortParams = R.ifElse(R.isNil, R.always(sortParams), + R.assoc(R.__, sortDirection, sortParams))(sortField); + + console.log('sort params:', sortParams); + + let qParams = { + limit: amountPerPage, + skip: skip, + sort: sortParams, + }; + + Counts.publish(this, subsScheduledScansPageAmountSortedCounter, ScheduledScans.find(query), { + noReady: true + }); + + return ScheduledScans.find(query, qParams); +}); + +Meteor.publish(subsScheduledScansId, function (_id) { + console.log(`server subscribtion: ${subsScheduledScansId}`); + console.log('-id: ', _id); + + //let that = this; + + let query = { _id: _id }; + return ScheduledScans.find(query); +}); |