mirror of
https://github.com/rancher/rancher-docs.git
synced 2026-09-25 12:38:05 +00:00
EIO-247: add converters scripts
This commit is contained in:
Executable
+18
@@ -0,0 +1,18 @@
|
||||
#!/bin/bash -e
|
||||
|
||||
usage() {
|
||||
echo -n "[command] [command_options]
|
||||
|
||||
commands:
|
||||
results_to_md: take json output from kube-bench as source and outputs markdown
|
||||
options:
|
||||
-s, --source source json from kube-bench default: /source/results.json
|
||||
"
|
||||
}
|
||||
|
||||
if [[ $# -eq 0 ]]; then
|
||||
usage
|
||||
exit 2
|
||||
fi
|
||||
|
||||
scripts/${1}.sh
|
||||
Executable
+6
@@ -0,0 +1,6 @@
|
||||
#!/bin/bash -e
|
||||
|
||||
md_source="/source/source.md"
|
||||
|
||||
pandoc -s --template="templates/default.html" -f markdown-smart --toc -c css/style-portrait.css "${md_source}" -o "source.html"
|
||||
python3 -m weasyprint source.html /output/output.pdf
|
||||
Executable
+117
@@ -0,0 +1,117 @@
|
||||
results_file="${1:-/source/results.json}"
|
||||
test_helpers="${2:-/test_helpers}"
|
||||
|
||||
get_ids() {
|
||||
jq -r .id ${results_file} | sort -n
|
||||
}
|
||||
|
||||
get_id_text() {
|
||||
id=${1}
|
||||
jq -r --arg id "${id}" 'select(.id==$id) | .text' ${results_file}
|
||||
}
|
||||
|
||||
get_section_ids() {
|
||||
id=${1}
|
||||
jq -r --arg id "${id}" 'select(.id==$id) | .tests[].section' ${results_file}
|
||||
}
|
||||
|
||||
get_section_desc() {
|
||||
id=${1}
|
||||
section=${2}
|
||||
jq -r --arg id "${id}" --arg section "${section}" 'select(.id==$id).tests[] | select(.section==$section).desc' ${results_file}
|
||||
}
|
||||
|
||||
get_tests() {
|
||||
id=${1}
|
||||
section=${2}
|
||||
jq -r --arg id "${id}" --arg section "${section}" 'select(.id==$id).tests[] | select(.section==$section).results[].test_number' ${results_file}
|
||||
}
|
||||
|
||||
get_test() {
|
||||
id=${1}
|
||||
section=${2}
|
||||
test_number=${3}
|
||||
jq -r --arg id "${id}" --arg section "${section}" --arg test_number "${test_number}" 'select(.id==$id).tests[] | select(.section==$section).results[] | select(.test_number==$test_number)' ${results_file}
|
||||
}
|
||||
|
||||
cat headers/header-2.3.5.md
|
||||
|
||||
for id in $(get_ids); do
|
||||
echo "## ${id} $(get_id_text ${id})"
|
||||
for section in $(get_section_ids ${id}); do
|
||||
echo "### ${section} $(get_section_desc ${id} ${section})"
|
||||
echo
|
||||
for test in $(get_tests ${id} ${section}); do
|
||||
result=$(get_test ${id} ${section} ${test})
|
||||
test_desc=$(echo ${result} | jq -r '.test_desc')
|
||||
audit=$(echo ${result} | jq -r '.audit')
|
||||
audit_config=$(echo ${result} | jq -r '.AuditConfig')
|
||||
actual_value=$(echo ${result} | jq -r '.actual_value')
|
||||
type=$(echo ${result} | jq -r '.type')
|
||||
status=$(echo ${result} | jq -r '.status')
|
||||
remediation=$(echo ${result} | jq -r '.remediation')
|
||||
expected_result=$(echo ${result} | jq -r '.expected_result')
|
||||
echo "#### ${test} ${test_desc}"
|
||||
echo
|
||||
if [ "${type}" = "skip" ]; then
|
||||
echo "**Result:** Not Applicable"
|
||||
echo
|
||||
else
|
||||
echo "**Result:** ${status}"
|
||||
echo
|
||||
fi
|
||||
if [ ! -z "${remediation}" ]; then
|
||||
echo "**Remediation:**"
|
||||
echo "${remediation}"
|
||||
echo
|
||||
fi
|
||||
if [ ! -z "${audit}" ] && [ ${status} != "INFO" ]; then
|
||||
if [[ ${audit} =~ "test_helpers" ]]; then
|
||||
audit_script=$(basename ${audit})
|
||||
test_helper="${test_helpers}/${audit_script}"
|
||||
echo "**Audit Script:** ${audit_script}"
|
||||
echo
|
||||
echo '```'
|
||||
cat "${test_helper}"
|
||||
echo '```'
|
||||
echo
|
||||
echo "**Audit Execution:**"
|
||||
echo
|
||||
echo '```'
|
||||
echo "./${audit_script} $(echo ${audit} | awk '{print $2}')"
|
||||
echo '```'
|
||||
echo
|
||||
else
|
||||
echo "**Audit:**"
|
||||
echo
|
||||
echo '```'
|
||||
echo "${audit}"
|
||||
echo '```'
|
||||
echo
|
||||
fi
|
||||
fi
|
||||
if [ ! -z "${audit_config}" ] && [ ${status} != "INFO" ]; then
|
||||
echo "**Audit Config:**"
|
||||
echo
|
||||
echo '```'
|
||||
echo "${audit_config}"
|
||||
echo '```'
|
||||
echo
|
||||
fi
|
||||
if [ ! -z "${actual_value}" ] && [ ${status} != "PASS" ]; then
|
||||
echo "**Returned Value**:"
|
||||
echo
|
||||
echo "\`${actual_value}\`"
|
||||
echo
|
||||
fi
|
||||
if [ ! -z "${expected_result}" ]; then
|
||||
echo "**Expected result**:"
|
||||
echo
|
||||
echo '```'
|
||||
echo ${expected_result}
|
||||
echo '```'
|
||||
echo
|
||||
fi
|
||||
done
|
||||
done
|
||||
done
|
||||
Reference in New Issue
Block a user