-
Notifications
You must be signed in to change notification settings - Fork 6
Validate Command
The validate command validates bundled entities, focusing primarily on policy code validation. It ensures that policy code in JSON format conforms to the policy code schema, helping catch errors before deployment.
graphman validate --input <input-file>| Parameter | Description |
|---|---|
--input |
Input bundle file to validate |
The validate command currently validates:
- Policy Code: JSON-formatted policy code against policy code schema
- Services: Policy code within service entities
- Policies: Policy code within policy entities
- Reads the input bundle
- Identifies policies and services with policy code
- Validates JSON-formatted policy code against schema
- Reports validation errors with detailed messages
- Provides entity-level validation status
The validator checks policy code in:
-
policy.codefield (JSON format) -
policy.jsonfield (JSON format)
Note: XML and YAML policy formats are not validated.
Validate a bundle:
graphman validate --input bundle.jsonSample Output (Success):
info: validating policies
info: validating MyPolicy: ok
info: validating AnotherPolicy: ok
info: validating services
info: validating MyService: ok
Sample Output (Errors):
info: validating policies
info: validating MyPolicy: error(s)
warn: $.policy.code - MyPolicy - Missing required property: assertionId
warn: $.policy.code - MyPolicy - Invalid assertion type: UnknownAssertion
info: validating AnotherPolicy: ok
Validate exported configuration:
graphman export --gateway dev --output dev-config.json
graphman validate --input dev-config.jsonValidate before importing:
graphman validate --input deployment-bundle.json
if [ $? -eq 0 ]; then
graphman import --input deployment-bundle.json --gateway prod
else
echo "Validation failed, aborting import"
fiValidate combined bundles:
graphman combine --inputs bundle1.json bundle2.json --output combined.json
graphman validate --input combined.jsonValidate revised bundles:
graphman revise --input old-bundle.json --output revised.json --options.normalize true
graphman validate --input revised.jsonValidate after imploding:
graphman implode --input exploded/ --output bundle.json
graphman validate --input bundle.jsonValidate bundles before deploying to production:
#!/bin/bash
echo "Validating deployment bundle..."
if graphman validate --input deployment.json; then
echo "✓ Validation passed"
graphman import --input deployment.json --gateway prod
else
echo "✗ Validation failed - aborting deployment"
exit 1
fiIntegrate validation in CI/CD:
# .gitlab-ci.yml
validate:
script:
- graphman validate --input bundle.json
only:
- merge_requestsValidate during policy development:
# After editing policy code
graphman implode --input policy-dev/ --output policy.json
graphman validate --input policy.json
# If valid, deploy to dev
if [ $? -eq 0 ]; then
graphman import --input policy.json --gateway dev
fiValidate bundle quality before version control:
# Export and validate
graphman export --gateway dev --output dev-config.json
graphman validate --input dev-config.json
# If valid, commit
if [ $? -eq 0 ]; then
git add dev-config.json
git commit -m "Updated configuration"
fiValidate after policy migration:
# Migrate and validate
graphman revise --input old-policies.json --output new-policies.json
graphman validate --input new-policies.jsonValidate test bundles:
#!/bin/bash
for bundle in test-bundles/*.json; do
echo "Validating $bundle..."
if ! graphman validate --input "$bundle"; then
echo "Failed: $bundle"
exit 1
fi
done
echo "All bundles validated successfully"| Error Type | Description | Example |
|---|---|---|
| Missing Property | Required field is missing | Missing required property: assertionId |
| Invalid Type | Field has wrong data type | Expected string, got number |
| Unknown Assertion | Assertion type not recognized | Invalid assertion type: UnknownAssertion |
| Schema Violation | Doesn't conform to schema | Additional property not allowed: extraField |
| Invalid Reference | Reference to non-existent entity | Invalid policy reference: abc123 |
warn: <path> - <entity-name> - <error-message>
Example:
warn: $.policy.code - MyPolicy - Missing required property: assertionId
The validator uses policy code schema files:
<graphman-home>/schema/<version>/policy-code-schema.json
The policy code schema defines:
- Valid assertion types
- Required properties per assertion
- Property data types
- Nested structure rules
- Allowed values
- Policy Code Only: Only validates JSON-formatted policy code
- No XML Validation: XML policies are not validated
- No YAML Validation: YAML policies are not validated
- Limited Entity Types: Only policies and services are validated
- Schema-Based Only: Validation is limited to schema conformance
The following are not validated:
- Entity references (e.g., folder paths, key references)
- Business logic correctness
- Policy runtime behavior
- Configuration values
- Cluster properties
- JDBC connections
- Other entity types
- Policy Code Format: Only JSON format is validated
- Schema Version: Uses the configured schema version
- Non-Blocking: Validation errors don't prevent command execution
- Exit Code: Returns non-zero exit code on validation failure
- Detailed Output: Provides specific error locations and messages
- Entity-Level: Validation is performed per entity
- Multiple Errors: All errors for an entity are reported
| Exit Code | Meaning |
|---|---|
0 |
Validation successful (no errors) |
Non-zero |
Validation failed (errors found) |
graphman export --gateway dev --output bundle.json
graphman validate --input bundle.jsonif graphman validate --input bundle.json; then
graphman import --input bundle.json --gateway prod
figraphman combine --inputs b1.json b2.json --output combined.json
graphman validate --input combined.jsongraphman revise --input old.json --output new.json
graphman validate --input new.jsongraphman implode --input exploded/ --output bundle.json
graphman validate --input bundle.json- Always validate before import to production
- Integrate in CI/CD pipelines for automated validation
- Validate after transformations (combine, revise, implode)
- Use exit codes in scripts for flow control
- Review validation errors carefully before proceeding
- Keep policy code in JSON format for validation
- Validate during development to catch errors early
- Document validation requirements in deployment procedures
#!/bin/bash
set -e # Exit on error
echo "Step 1: Export from dev"
graphman export --gateway dev --output dev-bundle.json
echo "Step 2: Validate bundle"
graphman validate --input dev-bundle.json
echo "Step 3: Prepare for production"
graphman revise --input dev-bundle.json --output prod-bundle.json \
--options.normalize true \
--options.excludeGoids true
echo "Step 4: Validate again"
graphman validate --input prod-bundle.json
echo "Step 5: Deploy to production"
graphman import --input prod-bundle.json --gateway prod
echo "Deployment successful"#!/bin/bash
# Policy development workflow
# Edit policy code
vim policies/MyPolicy.cjson
# Implode
graphman implode --input policies/ --output policy-bundle.json
# Validate
if graphman validate --input policy-bundle.json; then
echo "✓ Policy is valid"
# Deploy to dev
graphman import --input policy-bundle.json --gateway dev
# Run tests
./run-tests.sh
else
echo "✗ Policy validation failed"
exit 1
fi#!/bin/bash
# Validate multiple bundles
FAILED=0
for bundle in bundles/*.json; do
echo "Validating $(basename $bundle)..."
if graphman validate --input "$bundle"; then
echo " ✓ Valid"
else
echo " ✗ Invalid"
FAILED=$((FAILED + 1))
fi
done
if [ $FAILED -eq 0 ]; then
echo "All bundles are valid"
exit 0
else
echo "$FAILED bundle(s) failed validation"
exit 1
fi- export: Export bundles for validation
- import: Import validated bundles
- revise: Revise bundles before validation
- implode: Implode and validate
If validation fails on exported bundles:
- Check Gateway version compatibility
- Verify policy code format
- Review assertion types
- Check schema version
If validation reports errors for valid policies:
- Verify schema version matches Gateway version
- Check if using latest Graphman version
- Review policy code schema
- Consider refreshing schema:
graphman schema --refresh true
If no validation occurs:
- Verify bundle contains policies or services
- Check that policy code is in JSON format
- Ensure
policy.codeorpolicy.jsonfields exist - Verify input file path is correct
Potential future validation capabilities:
- XML policy validation
- YAML policy validation
- Entity reference validation
- Cross-entity dependency validation
- Business rule validation
- Configuration value validation