blob: 1841f1674d463058f4e80809afdea48ebf4b49f4 [file] [log] [blame]
Ivan Suzdal6d443fd2018-09-17 17:52:00 +04001package com.mirantis.mk
2
3/**
4 * Run salt oscap.eval xccdf
5 *
6 * @param target the target where the benchmark will be evaluated
7 * @param evaltype what to evaluate (xccdf or oval)
8 * @param benchmark the benchmark which will be evaluated by openscap
9 * @param resultsDir the directory where artifacts will be moved
10 * @param profile the XCCDF profile name
11 * @param xccdfVersion XCCDF benchmark version (default 1.2)
12 * @param tailoringId The id of your tailoring data (from the corresponding pillar)
13 */
14def openscapEval(master, target, evaltype, benchmark, resultsDir, profile = 'default', xccdfVersion = '1.2', tailoringId = 'None') {
15 def salt = new com.mirantis.mk.Salt()
16 def common = new com.mirantis.mk.Common()
17 salt.runSaltProcessStep(master, target, 'oscap.eval', [evaltype, benchmark, results_dir = resultsDir, profile = profile, xccdf_version = xccdfVersion, tailoring_id= tailoringId])
18}
19
20/**
21 * Upload results to the security dashboard
22 *
23 * @param apiUrl the security dashboard url
24 * @param file the file to upload
25 * @param cloud_name the cloud_name
26 * @param nodename the scanned node name
27 */
28def uploadScanResultsToDashboard(apiUrl, results, cloud_name, nodename) {
29 def common = new com.mirantis.mk.Common()
30 def http = new com.mirantis.mk.Http()
31 def data = [:]
32
33 // Skip authorization until there is no authorization in the worp
34
35 // Get cloud_id
36 data['name'] = cloud_name
37 def cloudId = common.parseJSON(http.sendHttpPostRequest(apiUrl+'/environment', data))['id']
38 // Get report_id
39 data['env_uuid'] = cloudId
40 def reportId = common.parseJSON(http.sendHttpPostRequest(apiUrl+'/reports/openscap/', data))['id']
41
42 // Create node
43 def nodes = []
44 nodes.add[nodename]
45 data['nodes'] = nodes
46 http.sendHttpPostRequest(apiUrl+'/environment/'+cloudId+'/nodes', data)
47
48 // Upload results
49 data['results'] = results
50 data['node'] = nodename
51 http.sendHttpPostRequest(apiUrl+'/reports/openscap/'+reportId, data)
52}