forked from ComplianceAsCode/content
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request ComplianceAsCode#6584 from ggbecker/improve-yamlfi…
…le-value Improve yamlfile_value template
- Loading branch information
Showing
2 changed files
with
18 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,25 @@ | ||
def preprocess(data, lang): | ||
|
||
if data.get("xccdf_variable") and data.get("embedded_data") == "true": | ||
if not data.get("values"): | ||
values = data.get("values", [{}]) | ||
if len(values) > 1: | ||
raise ValueError( | ||
"Only a single value can be checked when querying " | ||
"for a 'xccdf_value' that returns an embedded value. " | ||
"Rule ID: {}".format(data["_rule_id"])) | ||
elif not values[0].get("value"): | ||
raise ValueError( | ||
"You should specify a capture regex in the 'value' field " | ||
"when querying for a 'xccdf_value' that returns an embedded value. " | ||
"Rule ID: {}".format(data["_rule_id"])) | ||
|
||
if data.get("xccdf_variable") and data.get("embedded_data") != "true": | ||
if data.get("values"): | ||
raise ValueError( | ||
"You cannot specify the 'value' field when querying " | ||
"for a 'xccdf_value' that doesn't return an embedded value. " | ||
"Rule ID: {}".format(data["_rule_id"])) | ||
|
||
data["embedded_data"] = data.get("embedded_data", "false") == "true" | ||
data["ocp_data"] = data.get("ocp_data", "false") == "true" | ||
return data |