forked from devsecopsmaturitymodel/DevSecOps-MaturityModel
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfunctions.php
More file actions
218 lines (176 loc) · 4.24 KB
/
functions.php
File metadata and controls
218 lines (176 loc) · 4.24 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
<?php
/**
* functions.php
*
* @package default
* @param unknown $file
* @return unknown
*/
function readYaml($file) {
$fragment = null;
if (strpos($file, "#") != false) {
list($file, $fragment) = explode("#", $file, 2);
$fragment = trim($fragment, "/ ");
}
$ret = yaml_parse(
file_get_contents($file)
);
if ($fragment) {
foreach (explode("/", $fragment) as $key) {
$ret = $ret[$key];
}
}
return $ret;
}
/**
* Get dimensions from yaml file.
*
* @return unknown
*/
function getDimensions() {
$dimensions = readYaml("data/dimensions.yaml");
// reorder in-place $dimensions. This should wrap readYaml(data/dimensions.yaml)
ksort($dimensions);
foreach ($dimensions as $dimensionName => $subDimension) {
ksort($subDimension);
foreach ($subDimension as $subDimensionName => $elements) {
// Q: should I retain this?
if (substr($subDimensionName, 0, 1) == "_")
continue;
// Upgrade old configuration to `references:`
// this code can be modified to other models.
foreach ($elements as $activityName => $content) {
if ($content["references"] ?? null) // ignore new lines
continue;
$content["references"]["samm2"] = $content["samm2"] ?? array();
unset($content["samm2"]);
$content["references"]["iso27001-2017"] = $content["iso27001-2017"] ?? array();
unset($content["iso27001-2017"]);
//echo var_dump($elements[$activityName]);
//echo "<hr>";
$elements[$activityName] = $content;
}
$newElements = $elements;
ksort($newElements);
$dimensions[$dimensionName][$subDimensionName] = $newElements;
}
}
return $dimensions;
}
/**
* This function should be a sort of db wrapper.
*
* @param unknown $dimensions
*/
function getActions($dimensions) {
ksort($dimensions);
foreach ($dimensions as $dimension => $subdimensions) {
ksort($subdimensions);
foreach ($subdimensions as $subdimension => $element) {
if (substr($subdimension, 0, 1) == "_")
continue;
yield array($dimension, $subdimension, $element);
}
}
}
/**
*
* @return unknown
*/
function getReferenceLabels() {
return readYaml("data/strings.yml#/strings/en/references");
}
/**
*
* @param unknown $reference_id
* @return unknown
*/
function getReferenceLabel($reference_id) {
$referenceLabels = readYaml("data/strings.yml#/strings/en/references");
return $referenceLabels[$reference_id]["label"] ?? $reference_id;
}
/**
*
* @param unknown $headings
*/
function thead($headings) {
echo '<thead><tr><th scope="col">'
.implode('</th><th scope="col">', $headings)
.'</th></tr></thead>';
}
/**
*
* @param unknown $title
* @param unknown $html_content
* @param unknown $html_tooltip
* @return unknown
*/
function div_tooltip($title, $html_content, $html_tooltip) {
$tooltip = "<div class='popoverdetails'>" .$html_tooltip . "</div>";
return "<div data-toggle=\"popover\"
data-title=\"$title\"
data-activity=\".$html_tooltip\"
type=\"button\" data-html=\"true \">" . $html_content . "</div>";
}
/**
*
* @param unknown $samm_reference
* @return unknown
*/
function renderSamm($samm_reference) {
return "$samm_reference";
}
/**
*
* @param unknown $items
*/
function as_list($items) {
if (is_array($items)) {
yield from $items;
} else {
yield $items;
}
}
/**
*
* @param unknown $samm_references
* @param unknown $callback (optional)
* @return unknown
*/
function ul($samm_references, $callback='renderSamm') {
if ( ! is_array($samm_references) ) {
return ($callback)($samm_references);
}
$ret = "<ul><li>"
. implode("</li><li>", array_map($callback, $samm_references))
."</li></ul>";
return $ret;
}
/**
*
* @param unknown $references
*/
function getReferences($references) {
foreach ($references as $r_name => $rlist) {
}
}
// TODO create testcases
/**
*
*/
function test_getActions() {
$dimensions = readYaml("data/dimensions.yaml");
echo var_dump(getActions($dimensions));
}
/**
*
*/
function test_readYaml() {
$ret = readYaml("data/strings.yml");
echo var_dump($ret);
echo "<hr>";
$ret = readYaml("data/strings.yml#/strings/en");
echo var_dump($ret);
echo "<hr>";
}
?>