Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add formatting and validation for content generation artifacts #1104

Open
wants to merge 7 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .github/workflows/content-artifacts.yml
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,12 @@ jobs:
- name: Auto-convert Content
run: make build-content
working-directory: git-content
- name: Format output Content
run: make format-content
working-directory: git-content
- name: Test output Content
run: make test-dist-content
working-directory: git-content
- name: Setup SSH key
# Only do this on GSA/master
if: github.repository == env.HOME_REPO && github.ref == 'refs/heads/master'
Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ clean-oci-image:

test: build-validations ## Test all

build: init-content test-content build-content ## Build all artifacts and copy into dist directory
build: init-content test-content build-content format-content test-dist-content ## Build all artifacts and copy into dist directory

build-oci-image: ## Build OCI image
docker build \
Expand Down
12,834 changes: 12,761 additions & 73 deletions dist/content/rev5/baselines/xml/FedRAMP_rev5_HIGH-baseline_profile.xml

Large diffs are not rendered by default.

2,715 changes: 2,709 additions & 6 deletions dist/content/rev5/baselines/xml/FedRAMP_rev5_LI-SaaS-baseline_profile.xml

Large diffs are not rendered by default.

7,304 changes: 7,235 additions & 69 deletions dist/content/rev5/baselines/xml/FedRAMP_rev5_LOW-baseline_profile.xml

Large diffs are not rendered by default.

11,177 changes: 11,105 additions & 72 deletions dist/content/rev5/baselines/xml/FedRAMP_rev5_MODERATE-baseline_profile.xml

Large diffs are not rendered by default.

25 changes: 20 additions & 5 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@
"inquirer": "^10.1.8",
"js-yaml": "^4.1.0",
"jsdom": "^25.0.0",
"oscal": "2.0.7",
"oscal": "2.0.8-rc8",
"prettier": "^3.4.2",
"ts-node": "^10.9.2",
"xml-formatter": "^3.6.3",
"xml2js": "^0.6.2"
Expand Down
82 changes: 78 additions & 4 deletions src/content/module.mk
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,22 @@ DIST_DIR = ./dist
XML_DIR = $(DIST_DIR)/content/rev5/baselines/xml
JSON_DIR = $(DIST_DIR)/content/rev5/baselines/json
YAML_DIR = $(DIST_DIR)/content/rev5/baselines/yaml
XMLLINT := $(shell command -v xmllint 2>/dev/null || command -v /usr/bin/xmllint 2>/dev/null || command -v /mingw64/bin/xmllint 2>/dev/null)

# Format configuration
XML_FILES := $(shell find $(XML_DIR) -type f -name "*.xml" 2>/dev/null)
JSON_FILES := $(shell find $(JSON_DIR) -type f -name "*.json" 2>/dev/null)
YAML_FILES := $(shell find $(YAML_DIR) -type f -name "*.yaml" -o -name "*.yml" 2>/dev/null)
wandmagic marked this conversation as resolved.
Show resolved Hide resolved

.PHONY: init-content
init-content:
@npm install
$(OSCAL_CLI) use $(OSCAL_CLI_VERSION)
$(OSCAL_CLI) server update
$(OSCAL_CLI) server start -bg
@(command -v xmllint >/dev/null 2>&1 || (command -v apt-get >/dev/null 2>&1 && sudo apt-get install -y libxml2-utils) || (command -v brew >/dev/null 2>&1 && brew install libxml2) || (command -v choco >/dev/null 2>&1 && choco install xsltproc) || echo "Please install xmllint manually")


# Generate content and perform conversions
.PHONY: build-content
build-content:
Expand Down Expand Up @@ -42,13 +51,78 @@ build-content:
@echo "Converting Profiles to YAML..."
$(OSCAL_CLI) convert -f $(XML_DIR) -o $(YAML_DIR) -t YAML -s

# Format files
.PHONY: format-xml
format-xml:
@echo "Formatting XML files..."
@for file in $(XML_FILES); do \
echo "Formatting $$file..."; \
$(XMLLINT) --format --output "$$file" "$$file"; \
done

.PHONY: format-json
format-json:
@echo "Formatting JSON files..."
@for file in $(JSON_FILES); do \
if ! echo "$$file" | grep -q "min"; then \
echo "Formatting $$file..."; \
npx prettier --write --parser json "$$file"; \
fi \
done
.PHONY: format-yaml
format-yaml:
@echo "Formatting YAML files..."
@for file in $(YAML_FILES); do \
echo "Formatting $$file..."; \
npx prettier --write --parser yaml "$$file"; \
done

# Combined format target
.PHONY: format-content
format-content: format-xml format-json format-yaml
@echo "All formatting complete!"

.PHONY: test-content
test-content:
test-content:
@echo "Validating Source files"
@$(OSCAL_CLI) validate -f $(SRC_DIR)/content/rev5/baselines/ -r -s
@$(OSCAL_CLI) validate -f $(SRC_DIR)/content/rev5/baselines/xml/FedRAMP_rev5_HIGH-baseline_profile.xml -s
@$(OSCAL_CLI) validate -f $(SRC_DIR)/content/rev5/baselines/xml/FedRAMP_rev5_LI-SaaS-baseline_profile.xml -s
@$(OSCAL_CLI) validate -f $(SRC_DIR)/content/rev5/baselines/xml/FedRAMP_rev5_LOW-baseline_profile.xml -s
@$(OSCAL_CLI) validate -f $(SRC_DIR)/content/rev5/baselines/xml/FedRAMP_rev5_MODERATE-baseline_profile.xml -s


.PHONY: test-dist-content
test-dist-content:
@echo "Validating Output files"
@set -e; \
validation_failed=0; \
for file in $(YAML_FILES); do \
echo "Validating $$file..."; \
if ! $(OSCAL_CLI) validate -s -f "$$file"; then \
echo "Error: Validation failed for YAML file: $$file"; \
validation_failed=1; \
fi; \
done; \
for file in $(JSON_FILES); do \
echo "Validating $$file..."; \
if ! $(OSCAL_CLI) validate -s -f "$$file"; then \
echo "Error: Validation failed for JSON file: $$file"; \
validation_failed=1; \
fi; \
done; \
for file in $(XML_FILES); do \
echo "Validating $$file..."; \
if ! $(OSCAL_CLI) validate -s -f "$$file"; then \
echo "Error: Validation failed for XML file: $$file"; \
validation_failed=1; \
fi; \
done; \
if [ $$validation_failed -eq 1 ]; then \
echo "One or more validations failed"; \
exit 1; \
fi

.PHONY: test-legacy-content
test-legacy-content:
test-legacy-content: format
@echo "Validating Source files"
@$(OSCAL_CLI) validate -f $(SRC_DIR)/content/rev4/baselines/ -r -s
@$(OSCAL_CLI) validate -f $(SRC_DIR)/content/rev4/baselines/ -r -s
Original file line number Diff line number Diff line change
Expand Up @@ -5883,7 +5883,7 @@
<prop name="label" value="(a) Requirement:"/>
<p>The service provider develops test plans in accordance with NIST Special Publication 800-34 (as amended); plans are approved by the JAB/AO prior to initiating testing.</p>
</part>
<part id="cp-4_fr_smt.2" name="item" ns="http://fedramp.gov/ns/oscal">
<part id="cp-4_fr_smt.2" name="item">
<prop name="label" value="(b) Requirement:"/>
<p>The service provider must include the Contingency Plan test results with the security package within the Contingency Plan-designated appendix (Appendix G, Contingency Plan Test Report).</p>
</part>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5112,7 +5112,7 @@
<prop name="label" value="(a) Requirement:"/>
<p>The service provider develops test plans in accordance with NIST Special Publication 800-34 (as amended); plans are approved by the JAB/AO prior to initiating testing.</p>
</part>
<part id="cp-4_fr_smt.2" name="item" ns="http://fedramp.gov/ns/oscal">
<part id="cp-4_fr_smt.2" name="item" ns="http://fedramp.gov/ns/oscal">
<prop name="label" value="(b) Requirement:"/>
<p>The service provider must include the Contingency Plan test results with the security package within the Contingency Plan-designated appendix (Appendix G, Contingency Plan Test Report).</p>
</part>
Expand Down
Loading