Skip to content

Commit

Permalink
add formatting and validation for content generation artifacts
Browse files Browse the repository at this point in the history
  • Loading branch information
wandmagic committed Jan 16, 2025
1 parent f1b5515 commit f61d523
Show file tree
Hide file tree
Showing 4 changed files with 77 additions and 5 deletions.
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
16 changes: 16 additions & 0 deletions package-lock.json

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

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
"js-yaml": "^4.1.0",
"jsdom": "^25.0.0",
"oscal": "2.0.7",
"prettier": "^3.4.2",
"ts-node": "^10.9.2",
"xml-formatter": "^3.6.3",
"xml2js": "^0.6.2"
Expand Down
63 changes: 59 additions & 4 deletions src/content/module.mk
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,18 @@ XML_DIR = $(DIST_DIR)/content/rev5/baselines/xml
JSON_DIR = $(DIST_DIR)/content/rev5/baselines/json
YAML_DIR = $(DIST_DIR)/content/rev5/baselines/yaml

# 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)

.PHONY: init-content
init-content:
@npm install
$(OSCAL_CLI) use $(OSCAL_CLI_VERSION)
$(OSCAL_CLI) server update
$(OSCAL_CLI) server start -bg

# Generate content and perform conversions
.PHONY: build-content
build-content:
Expand Down Expand Up @@ -42,13 +48,62 @@ 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 \
echo "Formatting $$file..."; \
npx prettier --write --parser json "$$file"; \
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"
@for file in $(YAML_FILES); do \
echo "Validating $$file..."; \
$(OSCAL_CLI) validate -f -s "$$file"; \
done
@for file in $(JSON_FILES); do \
echo "Validating $$file..."; \
$(OSCAL_CLI) validate -f -s "$$file"; \
done
@for file in $(XML_FILES); do \
echo "Validating $$file..."; \
$(OSCAL_CLI) validate -f -s "$$file"; \
done

.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

0 comments on commit f61d523

Please sign in to comment.