Skip to content

Commit

Permalink
feat: add includes
Browse files Browse the repository at this point in the history
  • Loading branch information
wurstbrot committed Aug 30, 2024
1 parent c6d8242 commit bfb9a99
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 10 deletions.
45 changes: 44 additions & 1 deletion yaml-generation/functions.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,52 @@ function readYaml($file) {
}

}

if (isset($ret['_yaml_references'])) {
foreach ($ret['_yaml_references'] as $include) {
if (preg_match('/^include\((\w+),\s*(.+)\)$/', $include, $matches)) {
$team = $matches[1];
$baseDir = dirname($file);

$includeFile = $baseDir . DIRECTORY_SEPARATOR . $matches[2];
echo "In file $file, including $includeFile for team $team\n";
$includedContent = includeYamlAndSetTeamImplemented($includeFile, $team);
$ret = array_merge_recursive_ex($ret, $includedContent);
}
}
unset($ret['_yaml_references']);
}

return $ret;
}

function includeYamlAndSetTeamImplemented($filename, $team) {
echo "File to include $filename";
$content = yaml_parse_file($filename);
if ($content === false) {
echo "Error parsing YAML file: $filename\n";
return array();
}
// Add teamsImplemented for each activity
foreach ($content as $dimension => $subdimensions) {
foreach ($subdimensions as $subdimension => $elements) {
foreach ($elements as $activityName => $activity) {
if (is_array($elements) && (isset($activity['teamsEvidence']) || isset($activity['teamsImplemented']))) {
if (!isset($activity['teamsImplemented'])) {
echo "# setting teamsImplemented first time for team $team";
$content[$dimension][$subdimension][$activityName]['teamsImplemented'] = array();
}
if(array_key_exists('teamsEvidence', $activity)) {
echo "# adding team to teamsImplemented for team $team";
$content[$dimension][$subdimension][$activityName]['teamsImplemented'][$team] = true ;
}
}
}
}
}
return $content;

}

/**
* Get dimensions from yaml file.
Expand Down Expand Up @@ -275,4 +318,4 @@ function test_readYaml() {
}


?>
?>
30 changes: 21 additions & 9 deletions yaml-generation/generateDimensions.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
foreach ($files as $filename) {
//echo "Found $filename";
$dimensionCustom = getDimensions($filename);
$dimensionsCustom = array_merge_recursive($dimensionsCustom, $dimensionCustom);
$dimensionsCustom = array_merge_recursive_ex($dimensionsCustom, $dimensionCustom);
}
if (sizeof($files) > 0) {
$dimensions = array_merge_recursive_ex($dimensions, $dimensionsCustom);
Expand Down Expand Up @@ -75,24 +75,34 @@
$dimensionsAggregated[$dimension][$subdimension][$activityName]["teamsImplemented"] = array();
}
$evidenceImplemented = array();
if (array_key_exists("evidence", $activity) && is_array($activity["evidence"]) && IS_IMPLEMENTED_WHEN_EVIDENCE) {
foreach ($activity["evidence"] as $team => $evidenceForTeam) {
if (strlen($activity["evidence"][$team]) > 0) {
if (array_key_exists("teamsEvidence", $activity) && is_array($activity["teamsEvidence"]) && IS_IMPLEMENTED_WHEN_EVIDENCE) {
foreach ($activity["teamsEvidence"] as $team => $evidenceForTeam) {
if(!is_string($activity["teamsEvidence"][$team])) {
echo "teamsEvidence for team $team in $activityName is not a string, ignoring";
continue;
}
if (strlen($activity["teamsEvidence"][$team]) > 0) {
$evidenceImplemented[$team] = true;
} else {
echo "Warning: '$activityName -> evidence -> $team' has no evidence set but should have";
}
}
}

$dimensionsAggregated[$dimension][$subdimension][$activityName]["teamsImplemented"] =
array_merge(
$teamsImplemented,
$dimensionsAggregated[$dimension][$subdimension][$activityName]["teamsImplemented"],
$evidenceImplemented
);
if (!array_key_exists("openCRE", $activity["references"])) {
$dimensionsAggregated[$dimension][$subdimension][$activityName]["references"]["openCRE"] = array();
$dimensionsAggregated[$dimension][$subdimension][$activityName]["references"]["openCRE"][] = "https://www.opencre.org/rest/v1/standard/DevSecOps+Maturity+Model+(DSOMM)/" . $subdimension . "/" . $dimensionsAggregated[$dimension][$subdimension][$activityName]["uuid"];
}

$dimensionsAggregated[$dimension][$subdimension][$activityName]["teamsImplemented"] = array_merge($teamsImplemented, $dimensionsAggregated[$dimension][$subdimension][$activityName]["teamsImplemented"], $evidenceImplemented);
// can be removed in 2024
// can be removed in 2025
if (array_key_exists("isImplemented", $activity)) {
unset($dimensionsAggregated[$dimension][$subdimension][$activityName]["isImplemented"]);
}
if (array_key_exists("evidence", $activity)) {
unset($dimensionsAggregated[$dimension][$subdimension][$activityName]["evidence"]);
}
if (array_key_exists("dependsOn", $activity)) {
Expand Down Expand Up @@ -124,7 +134,9 @@
resolve_json_ref($dimensionsAggregated);

$dimensionsString = yaml_emit($dimensionsAggregated);
file_put_contents("src/assets/YAML/generated/generated.yaml", $dimensionsString);
$targetGeneratedFile = getcwd() . "/src/assets/YAML/generated/generated.yaml";
echo "\nStoring to $targetGeneratedFile\n";
file_put_contents($targetGeneratedFile, $dimensionsString);


/**
Expand Down

0 comments on commit bfb9a99

Please sign in to comment.