nac-validate 2.1.0__tar.gz → 2.2.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {nac_validate-2.1.0 → nac_validate-2.2.0}/.github/workflows/release.yml +2 -2
- {nac_validate-2.1.0 → nac_validate-2.2.0}/.github/workflows/test.yml +3 -3
- nac_validate-2.2.0/CHANGELOG.md +140 -0
- {nac_validate-2.1.0 → nac_validate-2.2.0}/PKG-INFO +235 -8
- {nac_validate-2.1.0 → nac_validate-2.2.0}/README.md +232 -5
- {nac_validate-2.1.0 → nac_validate-2.2.0}/nac_validate/__init__.py +6 -3
- {nac_validate-2.1.0 → nac_validate-2.2.0}/nac_validate/cli/main.py +66 -18
- {nac_validate-2.1.0 → nac_validate-2.2.0}/nac_validate/cli/options.py +25 -0
- {nac_validate-2.1.0 → nac_validate-2.2.0}/nac_validate/constants.py +8 -4
- {nac_validate-2.1.0 → nac_validate-2.2.0}/nac_validate/exceptions.py +9 -2
- nac_validate-2.2.0/nac_validate/ignores.py +701 -0
- {nac_validate-2.1.0 → nac_validate-2.2.0}/nac_validate/layers.py +51 -6
- nac_validate-2.2.0/nac_validate/models.py +108 -0
- {nac_validate-2.1.0 → nac_validate-2.2.0}/nac_validate/output_formatter.py +175 -63
- nac_validate-2.2.0/nac_validate/schema/__init__.py +289 -0
- nac_validate-2.2.0/nac_validate/schema/base.py +108 -0
- nac_validate-2.2.0/nac_validate/schema/description.py +24 -0
- nac_validate-2.2.0/nac_validate/schema/ip_type.py +116 -0
- nac_validate-2.2.0/nac_validate/schema/ordered.py +24 -0
- {nac_validate-2.1.0 → nac_validate-2.2.0}/nac_validate/schema/primary_key.py +26 -41
- nac_validate-2.2.0/nac_validate/schema/reference.py +510 -0
- nac_validate-2.2.0/nac_validate/schema/unique.py +152 -0
- nac_validate-2.2.0/nac_validate/schema/values.py +107 -0
- nac_validate-2.2.0/nac_validate/schema/walker.py +721 -0
- nac_validate-2.2.0/nac_validate/tftpl.py +886 -0
- {nac_validate-2.1.0 → nac_validate-2.2.0}/nac_validate/validator.py +683 -112
- nac_validate-2.2.0/nac_validate/variables.py +1086 -0
- {nac_validate-2.1.0 → nac_validate-2.2.0}/pyproject.toml +3 -3
- nac_validate-2.2.0/release-notes.md +22 -0
- nac_validate-2.2.0/tests/conftest.py +19 -0
- nac_validate-2.2.0/tests/integration/fixtures/data_reference/file1.yaml +6 -0
- nac_validate-2.2.0/tests/integration/fixtures/data_reference/file2.yaml +9 -0
- nac_validate-2.2.0/tests/integration/fixtures/data_reference_error/file1.yaml +10 -0
- nac_validate-2.2.0/tests/integration/fixtures/data_unique/file1.yaml +10 -0
- nac_validate-2.2.0/tests/integration/fixtures/data_unique/file2.yaml +6 -0
- nac_validate-2.2.0/tests/integration/fixtures/data_unique_conflict/file1.yaml +5 -0
- nac_validate-2.2.0/tests/integration/fixtures/data_unique_conflict/file2.yaml +5 -0
- nac_validate-2.2.0/tests/integration/fixtures/schema_reference/schema.yaml +17 -0
- nac_validate-2.2.0/tests/integration/fixtures/schema_unique/schema.yaml +15 -0
- {nac_validate-2.1.0 → nac_validate-2.2.0}/tests/integration/test_integration.py +62 -0
- {nac_validate-2.1.0 → nac_validate-2.2.0}/tests/unit/conftest.py +1 -0
- nac_validate-2.2.0/tests/unit/fixtures/variable_merge.yaml +83 -0
- nac_validate-2.2.0/tests/unit/fixtures/variable_schema.yaml +187 -0
- nac_validate-2.2.0/tests/unit/test_api.py +397 -0
- {nac_validate-2.1.0 → nac_validate-2.2.0}/tests/unit/test_cli.py +555 -0
- nac_validate-2.2.0/tests/unit/test_ignores.py +390 -0
- {nac_validate-2.1.0 → nac_validate-2.2.0}/tests/unit/test_layers.py +88 -0
- {nac_validate-2.1.0 → nac_validate-2.2.0}/tests/unit/test_output_formatter.py +40 -0
- nac_validate-2.2.0/tests/unit/test_reference.py +586 -0
- nac_validate-2.2.0/tests/unit/test_schema.py +1328 -0
- nac_validate-2.2.0/tests/unit/test_tftpl.py +406 -0
- {nac_validate-2.1.0 → nac_validate-2.2.0}/tests/unit/test_validator.py +410 -2
- nac_validate-2.2.0/tests/unit/test_variables.py +698 -0
- nac_validate-2.2.0/uv.lock +1181 -0
- nac_validate-2.1.0/CHANGELOG.md +0 -116
- nac_validate-2.1.0/nac_validate/models.py +0 -58
- nac_validate-2.1.0/nac_validate/schema/__init__.py +0 -111
- nac_validate-2.1.0/nac_validate/schema/base.py +0 -60
- nac_validate-2.1.0/nac_validate/schema/walker.py +0 -160
- nac_validate-2.1.0/release-notes.md +0 -15
- nac_validate-2.1.0/tests/unit/test_schema.py +0 -527
- nac_validate-2.1.0/uv.lock +0 -932
- {nac_validate-2.1.0 → nac_validate-2.2.0}/.github/dependabot.yml +0 -0
- {nac_validate-2.1.0 → nac_validate-2.2.0}/.gitignore +0 -0
- {nac_validate-2.1.0 → nac_validate-2.2.0}/.pre-commit-config.yaml +0 -0
- {nac_validate-2.1.0 → nac_validate-2.2.0}/.pre-commit-hooks.yaml +0 -0
- {nac_validate-2.1.0 → nac_validate-2.2.0}/LICENSE +0 -0
- {nac_validate-2.1.0 → nac_validate-2.2.0}/nac_validate/__main__.py +0 -0
- {nac_validate-2.1.0 → nac_validate-2.2.0}/nac_validate/cli/__init__.py +0 -0
- {nac_validate-2.1.0 → nac_validate-2.2.0}/scripts/license-headers.sh +0 -0
- {nac_validate-2.1.0 → nac_validate-2.2.0}/tests/__init__.py +0 -0
- {nac_validate-2.1.0 → nac_validate-2.2.0}/tests/integration/__init__.py +0 -0
- {nac_validate-2.1.0 → nac_validate-2.2.0}/tests/integration/fixtures/additional_data/data.yaml +0 -0
- {nac_validate-2.1.0 → nac_validate-2.2.0}/tests/integration/fixtures/additional_data_schema/schema.yaml +0 -0
- {nac_validate-2.1.0 → nac_validate-2.2.0}/tests/integration/fixtures/data/data.yaml +0 -0
- {nac_validate-2.1.0 → nac_validate-2.2.0}/tests/integration/fixtures/data_composite_key_conflict/file1.yaml +0 -0
- {nac_validate-2.1.0 → nac_validate-2.2.0}/tests/integration/fixtures/data_composite_key_conflict/file2.yaml +0 -0
- {nac_validate-2.1.0 → nac_validate-2.2.0}/tests/integration/fixtures/data_empty/data.yaml +0 -0
- {nac_validate-2.1.0 → nac_validate-2.2.0}/tests/integration/fixtures/data_empty/empty.yaml +0 -0
- {nac_validate-2.1.0 → nac_validate-2.2.0}/tests/integration/fixtures/data_env/data.yaml +0 -0
- {nac_validate-2.1.0 → nac_validate-2.2.0}/tests/integration/fixtures/data_merge/file1.yaml +0 -0
- {nac_validate-2.1.0 → nac_validate-2.2.0}/tests/integration/fixtures/data_merge/file2.yaml +0 -0
- {nac_validate-2.1.0 → nac_validate-2.2.0}/tests/integration/fixtures/data_merge/result.yaml +0 -0
- {nac_validate-2.1.0 → nac_validate-2.2.0}/tests/integration/fixtures/data_non_strict/data.yaml +0 -0
- {nac_validate-2.1.0 → nac_validate-2.2.0}/tests/integration/fixtures/data_primary_key/file1.yaml +0 -0
- {nac_validate-2.1.0 → nac_validate-2.2.0}/tests/integration/fixtures/data_primary_key/file2.yaml +0 -0
- {nac_validate-2.1.0 → nac_validate-2.2.0}/tests/integration/fixtures/data_primary_key_conflict/file1.yaml +0 -0
- {nac_validate-2.1.0 → nac_validate-2.2.0}/tests/integration/fixtures/data_primary_key_conflict/file2.yaml +0 -0
- {nac_validate-2.1.0 → nac_validate-2.2.0}/tests/integration/fixtures/data_semantic_error/data.yaml +0 -0
- {nac_validate-2.1.0 → nac_validate-2.2.0}/tests/integration/fixtures/data_syntax_error/data.yaml +0 -0
- {nac_validate-2.1.0 → nac_validate-2.2.0}/tests/integration/fixtures/data_vault/data.yaml +0 -0
- {nac_validate-2.1.0 → nac_validate-2.2.0}/tests/integration/fixtures/rules/rule_101.py +0 -0
- {nac_validate-2.1.0 → nac_validate-2.2.0}/tests/integration/fixtures/rules/rule_102.py +0 -0
- {nac_validate-2.1.0 → nac_validate-2.2.0}/tests/integration/fixtures/rules_schema/rule_101.py +0 -0
- {nac_validate-2.1.0 → nac_validate-2.2.0}/tests/integration/fixtures/schema/schema.yaml +0 -0
- {nac_validate-2.1.0 → nac_validate-2.2.0}/tests/integration/fixtures/schema_composite_key/schema.yaml +0 -0
- {nac_validate-2.1.0 → nac_validate-2.2.0}/tests/integration/fixtures/schema_invalid_extension/schema.yaml +0 -0
- {nac_validate-2.1.0 → nac_validate-2.2.0}/tests/integration/fixtures/schema_primary_key/schema.yaml +0 -0
- {nac_validate-2.1.0 → nac_validate-2.2.0}/tests/unit/__init__.py +0 -0
- {nac_validate-2.1.0 → nac_validate-2.2.0}/tests/unit/helpers.py +0 -0
|
@@ -20,7 +20,7 @@ jobs:
|
|
|
20
20
|
- uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
|
|
21
21
|
|
|
22
22
|
- name: Install uv
|
|
23
|
-
uses: astral-sh/setup-uv@
|
|
23
|
+
uses: astral-sh/setup-uv@1db35dd8eee11c5894872e0b383ae6c406cf738d # v10.4.0
|
|
24
24
|
|
|
25
25
|
- name: Check tag matches project version
|
|
26
26
|
env:
|
|
@@ -102,7 +102,7 @@ jobs:
|
|
|
102
102
|
id-token: write # Required for PyPI trusted publishing
|
|
103
103
|
steps:
|
|
104
104
|
- name: Install uv
|
|
105
|
-
uses: astral-sh/setup-uv@
|
|
105
|
+
uses: astral-sh/setup-uv@1db35dd8eee11c5894872e0b383ae6c406cf738d # v10.4.0
|
|
106
106
|
|
|
107
107
|
- name: Download distributions
|
|
108
108
|
uses: actions/download-artifact@9000827ccba6bdab643e8b6fd33ac0654aef8333 # v8.0.2
|
|
@@ -21,7 +21,7 @@ jobs:
|
|
|
21
21
|
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
|
|
22
22
|
|
|
23
23
|
- name: Install uv
|
|
24
|
-
uses: astral-sh/setup-uv@
|
|
24
|
+
uses: astral-sh/setup-uv@1db35dd8eee11c5894872e0b383ae6c406cf738d # v10.4.0
|
|
25
25
|
with:
|
|
26
26
|
enable-cache: true
|
|
27
27
|
|
|
@@ -49,7 +49,7 @@ jobs:
|
|
|
49
49
|
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
|
|
50
50
|
|
|
51
51
|
- name: Install uv
|
|
52
|
-
uses: astral-sh/setup-uv@
|
|
52
|
+
uses: astral-sh/setup-uv@1db35dd8eee11c5894872e0b383ae6c406cf738d # v10.4.0
|
|
53
53
|
with:
|
|
54
54
|
enable-cache: true
|
|
55
55
|
|
|
@@ -89,7 +89,7 @@ jobs:
|
|
|
89
89
|
python-version: ${{ matrix.python }}
|
|
90
90
|
|
|
91
91
|
- name: Install uv
|
|
92
|
-
uses: astral-sh/setup-uv@
|
|
92
|
+
uses: astral-sh/setup-uv@1db35dd8eee11c5894872e0b383ae6c406cf738d # v10.4.0
|
|
93
93
|
with:
|
|
94
94
|
enable-cache: true
|
|
95
95
|
|
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
## 2.2.0
|
|
2
|
+
|
|
3
|
+
- Put the leading keys of list items first in the merged output (`--output`), like `yaml_encode` of the Terraform utils provider: the first present of `id`, `order`, `sequence`, `seq`, `sequence_number`, `sequence_id`, `name`, `number`, `ip`, `address`, `prefix` and `vrf`, and for items of a `devices` list `name`, `url`, `managed`, `configuration` and `cli_templates`. All other keys keep the order of the input files
|
|
4
|
+
- Check variable schemas (`variable_schema` of templates, device groups and `global`) with the syntax validation of the merged data: expressions, includes, the types of template defaults and undeclared references in templates (a conservative scan of `${...}` and `%{...}`) for every architecture, and on device models the variables a template sees where it is applied (deep merged like the renderer, with the template defaults below them) and the resolved variables of every device. Errors fail syntax validation; unused declarations and includes, Meraki variables no applied template declares and Meraki type overrides in template inheritance are warnings, listed under `variable_warnings` in the JSON output. Findings name the file that defines their path, e.g. the file of the template or the template instance. Data without `variable_schema` is not checked
|
|
5
|
+
- Add `nac_validate.variables` with `variable_findings()`, `VariableSchema`, `merge_variables()` and the reference scan (`scan_template()`, `scan_expression()`)
|
|
6
|
+
- Add ignore comments in data files to exempt objects from rules: `# nac-validate: ignore[505, 506] reason` after an entry or on the line above it, or `# nac-validate: ignore-file[413]`. Violations are matched by the list item selectors of their path (`devices[name=edge-1]`), so comments keep working when files are merged. Suppressed violations are counted in the summary and listed under `suppressed` in the JSON output; comments that suppressed nothing are reported as a warning and under `unused_ignores`. Files are only read again when a comment names a rule that reported violations
|
|
7
|
+
- Add `--fail-on {HIGH,MEDIUM,LOW}` option (`NAC_VALIDATE_FAIL_ON`) to set the lowest rule severity that fails semantic validation. Violations of less severe rules are still reported, counted as below the failure threshold in the summary and marked `"blocking": false` in the JSON output, but no longer affect the exit code. Defaults to `LOW`, so every violation fails as before
|
|
8
|
+
- Log a warning for rules declaring a severity other than `HIGH`, `MEDIUM` or `LOW` (case-insensitive), and treat them as `HIGH`. Before, such rules were counted as `LOW` in the summary
|
|
9
|
+
- Read `severity.rules` in `nac/overrides.yaml` (and in bundles' `overrides.yaml`) to change the severity of packaged rules of lower layers (`"205": LOW`). The new severity applies to the output, the JSON output and `--fail-on`, and `--list-artifacts` shows each change, entries matching no rule and entries without effect because the rule is shadowed. Two bundles setting different severities for the same rule are a configuration error unless the project sets it
|
|
10
|
+
- Skip bundles whose `overrides.yaml` only has entries for other tools (`disable.templates`), like bundles without schema or rules
|
|
11
|
+
- Refer to list items by their schema primary key instead of their index in error messages (`Duplicate unique key ip=x in items [name=a], [name=b]`)
|
|
12
|
+
- Update nac-yaml to 2.2.1: faster parsing, and files in directories are merged in sorted order
|
|
13
|
+
- Add a library API for tools such as editors: `Validator.check_file()`, `check_merged()` and `check_model()` return schema violations with path segments, `Validator.run_rules()` returns a `RuleResult` per rule and reports a rule that raises instead of stopping, and ignore comments can be read from text (`read_comments()`, `IgnoreMatcher(texts=...)`). `walk_data()`, `walk_schema_contexts()`, `ReferenceIndex`, `parse_path()` and `is_blocking()` are now public. `nac_validate.schema.schema_at(schema, path)` describes what the schema says about the value at a data path (`("nxos", "devices", 0)`) for completion and hover: its kinds, the keys of its maps, whether it is required, enum and bool values, constraints, references, the primary key of its lists and whether it can be a template variable
|
|
14
|
+
- Validate the files of a directory in merge order
|
|
15
|
+
- Check templates (`*.tftpl`) in the paths before they are rendered: directive, YAML and schema errors fail syntax validation, with the file, line and column; what can't be checked before rendering (interpolations in fields without template variables, keys made by interpolations, YAML made by an interpolation alone on its line, directives in the middle of a line) is a warning, listed under `template_warnings` in the JSON output. Templates are validated against the include named by `templates.file.root` in the manifest of the module or a bundle, else `device_configuration`. Syntax errors in the text output now show the line and column when known
|
|
16
|
+
- Add `nac_validate.tftpl` to check templates (`.tftpl`) before they are rendered: `mask_template()` replaces their HCL directives and interpolations by text of the same length and checks that directives are balanced, `check_template()` validates the YAML against the part of the schema the template renders into, `include_path()` finds that part by its include (e.g. `device_configuration`), and `template_findings()` and `find_templates()` give the CLI's results and files
|
|
17
|
+
- Schema errors at map keys containing dots or colons name the whole key, and Yamale's `path : message` errors are printed as `path: message`
|
|
18
|
+
- Fix ignore comments not applying to list items selected by a boolean, null or float field (`[enabled=True]` for `enabled: true`)
|
|
19
|
+
- Add `ordered` schema option for lists to document that the order of the items is significant (`list(str(), ordered=True)`). Without it, or with `ordered=False`, the order is not significant. It is not checked against the data
|
|
20
|
+
- Add `type` schema option for `ip()` to restrict the form of a value: `address` (`10.0.0.1`), `interface` (host address with prefix length, `10.0.0.1/24`, not the network or broadcast address) or `network` (no host bits set, `10.0.0.0/24`), or several comma-separated (`ip(type='address,network')`). Prefix lengths must be numbers, not netmasks
|
|
21
|
+
- Add `description` schema option on every validator (`str(description='Name of the tenant')`) to document schema elements. It is not checked against the data, only that it is a non-empty string
|
|
22
|
+
- Add reference schema options: `ref_name` on a list with a single-field `primary_key` registers its items' keys under a name (shared by several lists for references to any of them), `ref` on a field requires its value to be such a key. Targets are looked up following the nesting of the data (e.g. the VRFs of the same device); `ref_in` selects the enclosing items by fields of the referencing item (e.g. `tenant` + `vrf`), `ref_scope='any'` on a list lifts the isolation of its items, and `ref_implicit` lists values that exist without being defined (globs allowed). Checked on the merged data, also for a single file. `nac_validate.schema.references()` gives rules the references of the data, for visibility the schema can't express
|
|
23
|
+
- Add `unique` schema option for lists, for values that must be unique without identifying an item: `unique=True` on a list of single values (`list(str(), unique=True)`), or comma-separated fields of the items whose combination must be unique (`unique='prefix,vrf'`). Unlike `primary_key`, the fields may be optional: a field that is not set is a value of its own, and items setting none of the fields are not compared. Checked per file and on the merged data
|
|
24
|
+
|
|
25
|
+
## 2.1.0
|
|
26
|
+
|
|
27
|
+
- Add `primary_key` schema option for lists (`list(include('item'), primary_key='name')`): every item must set the key and its value must be unique within the list, checked per file and on the merged data. A composite key names several comma-separated fields (`primary_key='node_id,name'`), whose combination must be unique
|
|
28
|
+
- Fail loading a schema with an invalid schema option (e.g. `primary_key` on a `str()`), and log a warning for unknown keywords of schema validators, like a misspelled option
|
|
29
|
+
- Drop support for Python 3.10 (end of life); Python 3.11 or later is now required
|
|
30
|
+
- Update nac-yaml to 2.1.0: `!vault` values are now decrypted with the password from `ANSIBLE_VAULT_PASSWORD`
|
|
31
|
+
- Fix syntax validation failure for empty or comment-only YAML files
|
|
32
|
+
- **Packaged schema and rules** (EXPERIMENTAL, may change in future versions and is not subject to semantic versioning guarantees)
|
|
33
|
+
- Add `--artifacts/--no-artifacts` CLI option (env `NAC_VALIDATE_ARTIFACTS`) to opt in to loading schema and rules from bundles and modules; it is off by default for now (implied by `--bundle` and `--module-dir`) and will become the default in a future version
|
|
34
|
+
- Bundles and the module are looked up relative to the current working directory (`nac/bundles/`, `nac/overrides.yaml`, `.terraform/` or `TF_DATA_DIR`), not the location of the data, `-s` or `-r`
|
|
35
|
+
- Discover schema and rules packaged with an installed Terraform module (`nac/schema.yaml`, `nac/rules/`, located via `terraform init`'s `modules.json`) and with bundles dropped into the project (every `.zip`, `.tar.gz` or `.tgz` file and every directory in `nac/bundles/`, holding `schema.yaml` and `rules/` at the bundle root); local `-s`/`-r` and `.schema.yaml`/`.rules/` take priority over the bundle, which takes priority over the module (archives are extracted once into a git-ignored `nac/bundles/.cache/`)
|
|
36
|
+
- Add `--bundle` (repeatable) and `--module-dir` CLI options (env `NAC_VALIDATE_BUNDLE`, `NAC_VALIDATE_MODULE_DIR`). Several bundles are peers of one priority tier and may split rules and the schema between them; a rule ID or schema provided by two bundles is an error, as are two bundles with the same manifest `name` (e.g. an old and a new version left in `nac/bundles/`). Bundles in `nac/bundles/` that provide nothing for nac-validate (e.g. only test templates) are skipped
|
|
37
|
+
- Add `overrides.yaml` to disable rules of lower layers by rule ID (`disable: {rules: [...]}`): `nac/overrides.yaml` in the project disables rules of a bundle and the module, a bundle's `overrides.yaml` disables rules of the module. Local rules are never affected. Entries are declarative: one that matches nothing is not an error, and `--list-artifacts` shows disabled rules and entries that matched no rule
|
|
38
|
+
- Add `--list-artifacts` CLI option showing the effective schema, artifact layers and rules with their origin; `--list-rules` remains as an undocumented alias. Rules are read from their source instead of imported, so listing runs no rule code; a rule whose ID is not a literal is listed as having an unknown ID, and a rule file that is valid Python but incomplete (e.g. without an `id`) is listed instead of failing
|
|
39
|
+
- Fix duplicate rule IDs across multiple `-r` directories going undetected; they now raise an error instead of the later directory silently replacing the earlier rule. Setups that relied on a later `-r` directory replacing a rule now fail; remove or renumber one of the rules
|
|
40
|
+
- Fix unexpected error when a rule declaring an integer ID (`id = 101`) reports a violation; rule IDs are now stored as text when rules are loaded. An ID that is not a number logs a warning and is listed after the numeric IDs instead of breaking `--list-artifacts`; an ID that is not an int or a non-empty string fails loading the rule
|
|
41
|
+
|
|
42
|
+
## 2.0.0
|
|
43
|
+
|
|
44
|
+
- Add `RuleBase` base class for semantic validation rules
|
|
45
|
+
- Overhaul CLI output: validation results now show structured errors with file paths, line context, and rule identifiers, followed by a checklist-style summary per rule
|
|
46
|
+
- Add `--json` CLI option for machine-readable JSON validation output
|
|
47
|
+
- Add `--list-rules` CLI option to display available validation rules
|
|
48
|
+
- Add `--no-color` CLI option to disable colored terminal output
|
|
49
|
+
- Add `--compact` CLI option to reduce output verbosity
|
|
50
|
+
- BREAKING CHANGE (via `nac-yaml`): Rework list merge logic — within-file duplicates are now preserved; if any file contains duplicate dict items in a list, merging is disabled for that entire list and items are concatenated instead
|
|
51
|
+
- BREAKING CHANGE (via `nac-yaml`): Two dict items in a list now merge when all shared primitive fields match, even if both sides have additional unique primitive fields
|
|
52
|
+
|
|
53
|
+
## 1.2.0
|
|
54
|
+
|
|
55
|
+
- Add `jmespath` as a direct dependency
|
|
56
|
+
- Enhance displayed paths in error messages by showing keys instead of indexes for list items
|
|
57
|
+
|
|
58
|
+
## 1.1.0
|
|
59
|
+
|
|
60
|
+
- Enhance error handling and logging
|
|
61
|
+
- Migrate to `uv` package manager
|
|
62
|
+
- Update license references
|
|
63
|
+
|
|
64
|
+
## 1.0.0
|
|
65
|
+
|
|
66
|
+
- BREAKING CHANGE: Rename tool from `iac-validate` to `nac-validate`
|
|
67
|
+
- Modernize CLI interface using [typer](https://github.com/fastapi/typer)
|
|
68
|
+
- BREAKING CHANGE: Do not deduplicate items in a list of primitive values, for example a list of strings
|
|
69
|
+
- BREAKING CHANGE: Deduplicate items in a list of dictionaries consistently, regardless of whether they are in the same file or not
|
|
70
|
+
- Add option to get access to schema from semantic validation rules
|
|
71
|
+
|
|
72
|
+
## 0.2.7
|
|
73
|
+
|
|
74
|
+
- Suppress Yamale syntax warnings when running Python 3.12+
|
|
75
|
+
|
|
76
|
+
## 0.2.6
|
|
77
|
+
|
|
78
|
+
- Fix issue with directly nested lists in YAML files
|
|
79
|
+
|
|
80
|
+
## 0.2.5
|
|
81
|
+
|
|
82
|
+
- Check non-default schema and rules paths for existence
|
|
83
|
+
|
|
84
|
+
## 0.2.4
|
|
85
|
+
|
|
86
|
+
- Dependency updates
|
|
87
|
+
|
|
88
|
+
## 0.2.3
|
|
89
|
+
|
|
90
|
+
- Handle file errors gracefully
|
|
91
|
+
- Allow empty YAML files
|
|
92
|
+
|
|
93
|
+
## 0.2.2
|
|
94
|
+
|
|
95
|
+
- Add `--non-strict` CLI argument to accept unexpected elements in YAML files
|
|
96
|
+
|
|
97
|
+
## 0.2.1
|
|
98
|
+
|
|
99
|
+
- Do not merge YAML dictionary list items, where each list item has unique attributes with primitive values
|
|
100
|
+
|
|
101
|
+
## 0.2.0
|
|
102
|
+
|
|
103
|
+
- Preserve YAML quotes in output
|
|
104
|
+
- Add `!env` tag to read values from environment variables
|
|
105
|
+
|
|
106
|
+
## 0.1.8
|
|
107
|
+
|
|
108
|
+
- Use `ruamel.yaml` package consistently
|
|
109
|
+
|
|
110
|
+
## 0.1.7
|
|
111
|
+
|
|
112
|
+
- Add `output` CLI argument
|
|
113
|
+
|
|
114
|
+
## 0.1.6
|
|
115
|
+
|
|
116
|
+
- Add YAML syntax validation
|
|
117
|
+
|
|
118
|
+
## 0.1.5
|
|
119
|
+
|
|
120
|
+
- Add pre-commit config
|
|
121
|
+
|
|
122
|
+
## 0.1.4
|
|
123
|
+
|
|
124
|
+
- Add support for logging multiple error messsages
|
|
125
|
+
|
|
126
|
+
## 0.1.3
|
|
127
|
+
|
|
128
|
+
- Add support for Ansible Vault encrypted values
|
|
129
|
+
|
|
130
|
+
## 0.1.2
|
|
131
|
+
|
|
132
|
+
- Allow multiple paths as argument
|
|
133
|
+
|
|
134
|
+
## 0.1.1
|
|
135
|
+
|
|
136
|
+
- No changes
|
|
137
|
+
|
|
138
|
+
## 0.1.0
|
|
139
|
+
|
|
140
|
+
- Initial release
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.5
|
|
2
2
|
Name: nac-validate
|
|
3
|
-
Version: 2.
|
|
3
|
+
Version: 2.2.0
|
|
4
4
|
Summary: A CLI tool to perform syntactic and semantic validation of YAML files.
|
|
5
5
|
Project-URL: homepage, https://github.com/netascode/nac-validate
|
|
6
6
|
Project-URL: repository, https://github.com/netascode/nac-validate
|
|
@@ -23,8 +23,8 @@ Classifier: Programming Language :: Python :: 3.14
|
|
|
23
23
|
Classifier: Topic :: Software Development :: Testing
|
|
24
24
|
Requires-Python: >=3.11
|
|
25
25
|
Requires-Dist: jmespath>=1.1.0
|
|
26
|
-
Requires-Dist: nac-artifacts>=0.
|
|
27
|
-
Requires-Dist: nac-yaml>=2.1
|
|
26
|
+
Requires-Dist: nac-artifacts>=0.3.0
|
|
27
|
+
Requires-Dist: nac-yaml>=2.2.1
|
|
28
28
|
Requires-Dist: ruamel-yaml>=0.19.1
|
|
29
29
|
Requires-Dist: typer>=0.27.3
|
|
30
30
|
Requires-Dist: yamale<7,>=6.1.0
|
|
@@ -55,7 +55,8 @@ Usage: nac-validate [OPTIONS] [PATHS]...
|
|
|
55
55
|
A CLI tool to perform syntactic and semantic validation of YAML files.
|
|
56
56
|
|
|
57
57
|
Arguments:
|
|
58
|
-
[PATHS]... List of paths pointing to YAML files or
|
|
58
|
+
[PATHS]... List of paths pointing to YAML files, templates (.tftpl) or
|
|
59
|
+
directories
|
|
59
60
|
|
|
60
61
|
Options:
|
|
61
62
|
-v, --verbosity [DEBUG|INFO|WARNING|ERROR|CRITICAL]
|
|
@@ -73,6 +74,10 @@ Options:
|
|
|
73
74
|
--no-color Disable colored output [env: NO_COLOR]
|
|
74
75
|
--compact Use compact output format without rule context details
|
|
75
76
|
[env: NAC_VALIDATE_COMPACT]
|
|
77
|
+
--fail-on [HIGH|MEDIUM|LOW]
|
|
78
|
+
Lowest rule severity that fails validation. Violations of less
|
|
79
|
+
severe rules are still reported, but do not affect the exit code
|
|
80
|
+
[env: NAC_VALIDATE_FAIL_ON] [default: LOW]
|
|
76
81
|
--version Display version number
|
|
77
82
|
--list-artifacts List the effective schema, artifact layers and validation rules and exit
|
|
78
83
|
--artifacts / --no-artifacts
|
|
@@ -97,10 +102,108 @@ The CLI uses specific exit codes to help automation distinguish between error ty
|
|
|
97
102
|
| Exit Code | Meaning |
|
|
98
103
|
|-----------|---------|
|
|
99
104
|
| 0 | Validation passed |
|
|
100
|
-
| 1 | Semantic validation failed (
|
|
105
|
+
| 1 | Semantic validation failed (violations of rules at or above the `--fail-on` severity) |
|
|
101
106
|
| 2 | Syntax validation failed (YAML syntax or schema errors) |
|
|
102
107
|
| 3 | Configuration error (missing schema, invalid rules, etc.) |
|
|
103
108
|
|
|
109
|
+
## Failure Threshold
|
|
110
|
+
|
|
111
|
+
Every rule has a severity (`HIGH`, `MEDIUM` or `LOW`). By default a violation of any rule fails validation. `--fail-on` (or `NAC_VALIDATE_FAIL_ON`) sets the lowest severity that fails it, so rules can give advice without blocking a pipeline:
|
|
112
|
+
|
|
113
|
+
```text
|
|
114
|
+
$ nac-validate data/ -s schema.yaml -r rules/ --fail-on HIGH
|
|
115
|
+
...
|
|
116
|
+
✓ Semantic validation: PASSED (1 violation below failure threshold)
|
|
117
|
+
|
|
118
|
+
• 1 MEDIUM severity violation (rules: 205) (below failure threshold)
|
|
119
|
+
$ echo $?
|
|
120
|
+
0
|
|
121
|
+
```
|
|
122
|
+
|
|
123
|
+
Violations below the threshold are still printed and included in the JSON output, marked `"blocking": false`.
|
|
124
|
+
|
|
125
|
+
The severity of a rule packaged in a bundle or module can be changed in `nac/overrides.yaml` (see [Packaged Schema and Rules](#packaged-schema-and-rules-experimental)).
|
|
126
|
+
|
|
127
|
+
## Ignore Comments
|
|
128
|
+
|
|
129
|
+
A comment in a data file exempts an object from rules:
|
|
130
|
+
|
|
131
|
+
```yaml
|
|
132
|
+
iosxe:
|
|
133
|
+
devices:
|
|
134
|
+
- name: edge-1 # nac-validate: ignore[505, 506] legacy peer, CHG-1234
|
|
135
|
+
configuration:
|
|
136
|
+
# nac-validate: ignore[205] mixed modes during migration
|
|
137
|
+
interfaces:
|
|
138
|
+
...
|
|
139
|
+
# nac-validate: ignore-file[413]
|
|
140
|
+
```
|
|
141
|
+
|
|
142
|
+
- A comment after content applies to that entry and everything below it, a comment on its own line to the next entry, and `ignore-file` to every object in the file.
|
|
143
|
+
- Rule IDs are required. Text after them is the reason.
|
|
144
|
+
- Only violations with a `path` can be suppressed. List items are matched by the selectors in the path (`devices[name=edge-1]`), so comments keep working when files are merged.
|
|
145
|
+
|
|
146
|
+
Suppressed violations don't fail validation but are counted in the summary and listed in the JSON output. Comments that suppressed nothing are reported as a warning.
|
|
147
|
+
|
|
148
|
+
## Templates
|
|
149
|
+
|
|
150
|
+
Templates (`*.tftpl`, e.g. `bgp.yaml.tftpl`) in the paths are checked before they are rendered for a device:
|
|
151
|
+
|
|
152
|
+
```text
|
|
153
|
+
$ nac-validate data/ templates/
|
|
154
|
+
! templates/underlay.yaml.tftpl:40:15: system.nve_infra_vlans[0].vlans.ids[0]: '${try(vlan, 3600)}' is not a int. (an interpolation: what it renders to is not checked)
|
|
155
|
+
|
|
156
|
+
• templates/overlay.yaml.tftpl:12:5: routing.bgp.bogus: Unexpected element
|
|
157
|
+
• templates/overlay.yaml.tftpl:20:1: for without endfor
|
|
158
|
+
```
|
|
159
|
+
|
|
160
|
+
A template is YAML with HCL directives (`%{ if }`, `%{ for }`) and interpolations (`${ }`). Lines with only directives and assertions (`%{ if x < 0 }${fail("...")}%{ endif }`) are left out and every interpolation counts as a template variable, so the YAML can be validated against the part of the schema the template renders into. The body of a loop is checked once, and keys or list items repeated in different branches of an `if` are no error, nor are duplicates of interpolations.
|
|
161
|
+
|
|
162
|
+
- Errors fail syntax validation (exit code 2): unbalanced or unknown directives, unclosed `${`/`%{`, YAML syntax and schema violations.
|
|
163
|
+
- Warnings are what can't be checked before rendering: an interpolation in a field that takes no template variable (e.g. an item of a list of integers), keys made by interpolations (`${name}:`), YAML made by an interpolation alone on its line (`${indent(2, yamlencode(x))}`) and the keys missing beside it, and directives in the middle of a line. They don't fail validation.
|
|
164
|
+
|
|
165
|
+
Templates render into the include named by `templates.file.root` in the `manifest.yaml` of the installed module or a bundle (with `--artifacts`), else into `device_configuration`:
|
|
166
|
+
|
|
167
|
+
```yaml
|
|
168
|
+
templates:
|
|
169
|
+
file:
|
|
170
|
+
root: device_configuration
|
|
171
|
+
```
|
|
172
|
+
|
|
173
|
+
## Variable Schemas
|
|
174
|
+
|
|
175
|
+
Templates, device groups and `global` can declare their template variables in a `variable_schema`. String entries are variables, as one-line Yamale expressions; map entries are includes for structured values, local to their `variable_schema`:
|
|
176
|
+
|
|
177
|
+
```yaml
|
|
178
|
+
nxos:
|
|
179
|
+
device_groups:
|
|
180
|
+
- name: LEAFS
|
|
181
|
+
variable_schema:
|
|
182
|
+
loopback0_ip: ip() # every member device must have it
|
|
183
|
+
templates:
|
|
184
|
+
- name: service_l2
|
|
185
|
+
type: model
|
|
186
|
+
variables: # defaults, lowest precedence
|
|
187
|
+
rt_imports: []
|
|
188
|
+
variable_schema:
|
|
189
|
+
vlan_id: int(min=1, max=4094)
|
|
190
|
+
vlan_name: str(max=32, required=False)
|
|
191
|
+
rt_imports: list(str())
|
|
192
|
+
peers: list(include('peer'), required=False)
|
|
193
|
+
peer:
|
|
194
|
+
ip: ip()
|
|
195
|
+
asn: int(min=1, max=4294967295)
|
|
196
|
+
configuration: ...
|
|
197
|
+
```
|
|
198
|
+
|
|
199
|
+
They are checked with the syntax validation of the merged data, for any architecture (device models with `global`, `device_groups`, `devices` and `template_instances`, and Meraki templates with inheritance). Data without `variable_schema` is not checked.
|
|
200
|
+
|
|
201
|
+
- Errors fail syntax validation: expressions that don't parse, includes that aren't defined, template defaults (the template's `variables`) of the wrong type, and variables a template uses (`${...}`, `%{...}`) without declaring them. The scan of the template content is conservative: it can miss a reference, but never reports a false one. File templates are not scanned.
|
|
202
|
+
- On device models, the variables a template sees where it is applied are resolved and validated: the variables of `global`, the device groups and the device, deep merged, with the template defaults below them and the instance and item variables of template instances on top. Required variables, their types, and instance or item variables the template doesn't declare are errors, and so are the resolved variables of every device that don't satisfy the `variable_schema` of `global` and of its device groups. Each distinct set of values is validated once.
|
|
203
|
+
- Warnings: unused declarations and includes, Meraki network and device variables that no applied template declares (if every applied template has a `variable_schema`), and Meraki templates declaring a variable of a parent template with another type. They are listed in `variable_warnings` in the JSON output and don't fail validation.
|
|
204
|
+
|
|
205
|
+
Values only known when rendering are not checked: values with `${...}` or `%{...}`, and strings the renderer converts to a declared `int`, `num` or `bool` (e.g. of `!env` tags).
|
|
206
|
+
|
|
104
207
|
## How It Works
|
|
105
208
|
|
|
106
209
|
Syntactic validation is done by basic YAML syntax validation (e.g., indentation) and by providing a [Yamale](https://github.com/23andMe/Yamale) schema and validating all YAML files against that schema. Semantic validation is done by providing a set of rules (implemented in Python) which are then validated against the YAML data. Every rule is implemented as a Python class and should be placed in a `.py` file located in the `--rules` path.
|
|
@@ -133,6 +236,97 @@ interfaces: list(include('interface'), primary_key='node_id,name')
|
|
|
133
236
|
|
|
134
237
|
Values of different types are distinct (`1` and `"1"` do not collide). Primary keys are checked in every file and, once every file passed, on the data merged from all files: items with the same key are only merged when all their shared fields match, so the same key used with conflicting values in two files remains a duplicate.
|
|
135
238
|
|
|
239
|
+
### Unique Values
|
|
240
|
+
|
|
241
|
+
`unique` on a `list()` requires values to be unique within the list without making them the key of an item. `unique=True` applies to a list of single values (items that are maps or lists are not compared):
|
|
242
|
+
|
|
243
|
+
```yaml
|
|
244
|
+
features: list(str(), unique=True)
|
|
245
|
+
```
|
|
246
|
+
|
|
247
|
+
On a list of maps, `unique` names comma-separated fields whose combination must be unique. Unlike with `primary_key`, the fields may be optional: a field that is not set is a value of its own, so a route without a `vrf` does not collide with the same prefix in a VRF, and items setting none of the fields are not compared:
|
|
248
|
+
|
|
249
|
+
```yaml
|
|
250
|
+
routes: list(include('route'), unique='prefix,vrf')
|
|
251
|
+
```
|
|
252
|
+
|
|
253
|
+
It can be combined with a `primary_key`, but must not name the same fields:
|
|
254
|
+
|
|
255
|
+
```yaml
|
|
256
|
+
zone_pairs: list(include('zone_pair'), primary_key='name', unique='source,destination')
|
|
257
|
+
```
|
|
258
|
+
|
|
259
|
+
As with primary keys, values of different types are distinct, and `unique` is checked in every file and, once every file passed, on the data merged from all files, where items from different files that don't merge still collide.
|
|
260
|
+
|
|
261
|
+
### References
|
|
262
|
+
|
|
263
|
+
A list declares what its items can be referenced as with `ref_name`, a field what it refers to with `ref`. The value of the field must then be the key of an item of such a list:
|
|
264
|
+
|
|
265
|
+
```yaml
|
|
266
|
+
device:
|
|
267
|
+
vrfs: list(include('vrf'), primary_key='name', ref_name='vrf', ref_implicit='default,management')
|
|
268
|
+
interface:
|
|
269
|
+
vrf: str(ref='vrf', required=False)
|
|
270
|
+
vrfs: list(str(ref='vrf'), required=False)
|
|
271
|
+
```
|
|
272
|
+
|
|
273
|
+
- `ref_name` requires a single-field `primary_key`. Several lists may share a name, so a reference can name an item of any of them (e.g. hosts, networks and ranges as `network_object`)
|
|
274
|
+
- `ref_implicit` lists comma-separated values that exist without being defined in the data, such as default objects of the platform; `*` and `?` are globs (`system-*`)
|
|
275
|
+
- `ref` works on any validator of a single value, including the item validator of a list and `any()`. Values are compared as text, so an integer key matches its string form
|
|
276
|
+
|
|
277
|
+
Targets are looked up following the nesting of the data: for every list enclosing both the reference and a list of targets, both must be in the same item of it. A VRF defined in one device is not visible from another device, while a reference outside the `devices` list sees the VRFs of all devices.
|
|
278
|
+
|
|
279
|
+
`ref_in` names fields of the referencing item whose values select the items the target is in, the last one the innermost list's item. Paths are dotted and read from the nearest list item enclosing the reference. A selector that is not set falls back to nesting, and a selector naming an unknown item is only reported by its own `ref`:
|
|
280
|
+
|
|
281
|
+
```yaml
|
|
282
|
+
leak_destination:
|
|
283
|
+
tenant: str(ref='tenant')
|
|
284
|
+
vrf: str(ref='tenant_vrf', ref_in='tenant')
|
|
285
|
+
contract_master:
|
|
286
|
+
application_profile: str(ref='application_profile', required=False)
|
|
287
|
+
endpoint_group: str(ref='endpoint_group', ref_in='application_profile')
|
|
288
|
+
```
|
|
289
|
+
|
|
290
|
+
`ref_scope='any'` on a list with a single-field `primary_key` lifts the isolation of its items: a reference inside one tenant sees targets in all tenants.
|
|
291
|
+
|
|
292
|
+
### IP Forms
|
|
293
|
+
|
|
294
|
+
`type` on an `ip()` restricts the value to one or several comma-separated forms:
|
|
295
|
+
|
|
296
|
+
| Type | Accepted | Rejected |
|
|
297
|
+
|---|---|---|
|
|
298
|
+
| `address` | `10.0.0.1` | any prefix length |
|
|
299
|
+
| `interface` | `10.0.0.1/24` | no prefix length, network or broadcast address (`10.0.0.0/24`, `10.0.0.255/24`) |
|
|
300
|
+
| `network` | `10.0.0.0/24` | no prefix length, host bits set (`10.0.0.1/24`) |
|
|
301
|
+
|
|
302
|
+
```yaml
|
|
303
|
+
a: ip(version=4, type='address')
|
|
304
|
+
b: ip(type='interface')
|
|
305
|
+
c: ip(type='network')
|
|
306
|
+
d: ip(type='interface,network')
|
|
307
|
+
```
|
|
308
|
+
|
|
309
|
+
`interface` rejects the network address of the subnet, the IPv4 broadcast address and the IPv6 subnet-router anycast address (`2001:db8::/64`), except on IPv4 /31 and /32 and IPv6 /127 and /128 subnets. Prefix lengths must be numbers, netmasks like `10.0.0.1/255.255.255.0` are rejected.
|
|
310
|
+
|
|
311
|
+
### Ordered Lists
|
|
312
|
+
|
|
313
|
+
`ordered=True` on a `list()` marks the order of its items as significant. A list without it, or with `ordered=False`, has no significant order. It is not checked against the data:
|
|
314
|
+
|
|
315
|
+
```yaml
|
|
316
|
+
a: list(str(), ordered=True)
|
|
317
|
+
```
|
|
318
|
+
|
|
319
|
+
### Descriptions
|
|
320
|
+
|
|
321
|
+
`description` documents a schema element. It is supported on every validator and not checked against the data:
|
|
322
|
+
|
|
323
|
+
```yaml
|
|
324
|
+
tenants: list(include('tenant'), primary_key='name', description='Tenants of the fabric')
|
|
325
|
+
---
|
|
326
|
+
tenant:
|
|
327
|
+
name: str(description='Name of the tenant')
|
|
328
|
+
```
|
|
329
|
+
|
|
136
330
|
## Packaged Schema and Rules (Experimental)
|
|
137
331
|
|
|
138
332
|
> **Note:** This feature is experimental and may change in future versions. It is not subject to semantic versioning guarantees.
|
|
@@ -149,14 +343,19 @@ The layers are, highest priority first:
|
|
|
149
343
|
2. **Bundle**: every `.zip`, `.tar.gz` or `.tgz` archive and every directory in the project's `nac/bundles/` (or the paths given with `--bundle`), holding `manifest.yaml`, `schema.yaml` and `rules/` at its root
|
|
150
344
|
3. **Module**: the `nac/` directory (`nac/schema.yaml`, `nac/rules/`) of the Terraform module installed by `terraform init` (or the one given with `--module-dir`)
|
|
151
345
|
|
|
152
|
-
A higher layer replaces the schema of a lower one and rules with the same ID. Rules of lower layers can be disabled by ID in `nac/overrides.yaml`:
|
|
346
|
+
A higher layer replaces the schema of a lower one and rules with the same ID. Rules of lower layers can be disabled, or given another severity, by ID in `nac/overrides.yaml`:
|
|
153
347
|
|
|
154
348
|
```yaml
|
|
155
349
|
disable:
|
|
156
350
|
rules:
|
|
157
351
|
- "101"
|
|
352
|
+
severity:
|
|
353
|
+
rules:
|
|
354
|
+
"205": LOW # HIGH, MEDIUM or LOW
|
|
158
355
|
```
|
|
159
356
|
|
|
357
|
+
The severity replaces the one the rule declares, everywhere: in the output, the summary, the JSON output and the `--fail-on` check. Like disable entries, a bundle's `overrides.yaml` can set severities of module rules, and local rules are never affected (edit them instead). `--list-artifacts` shows each changed severity, who set it and what the rule declares, entries that match no rule, and entries without effect because a higher layer's rule shadows the rule they apply to.
|
|
358
|
+
|
|
160
359
|
Run `nac-validate --list-artifacts` to see the effective schema, the layers in use and where each rule comes from. It reads rules without running them: the `id`, `description` and `severity` of each rule are taken from the string or number literals in its `Rule` class, and a rule whose ID is not such a literal (computed or inherited) is listed as having an unknown ID. With `--artifacts` it still extracts bundle archives into `nac/bundles/.cache/`.
|
|
161
360
|
|
|
162
361
|
The project directory is the **current working directory**, not the location of the data, `--schema` or `--rules`: `nac/bundles/`, `nac/overrides.yaml` and the `.terraform/` directory (or `TF_DATA_DIR`) written by `terraform init` are looked up there. Run nac-validate from your root module directory, or point to the artifacts with `--module-dir` and `--bundle`.
|
|
@@ -275,7 +474,7 @@ All rules must subclass `RuleBase` and set at minimum `id` and `description`. Th
|
|
|
275
474
|
|-----------|----------|---------|-------------|
|
|
276
475
|
| `id` | Yes | — | Unique rule identifier, a number such as `"101"` or `101` (other IDs log a warning) |
|
|
277
476
|
| `description` | Yes | — | Short description of the rule |
|
|
278
|
-
| `severity` | No | `"HIGH"` | Severity level (`HIGH`, `MEDIUM`, `LOW`) |
|
|
477
|
+
| `severity` | No | `"HIGH"` | Severity level (`HIGH`, `MEDIUM`, `LOW`), compared against `--fail-on`. Any other value logs a warning and is treated as `HIGH`. Projects can change it for packaged rules in `nac/overrides.yaml` |
|
|
279
478
|
| `title` | No | `""` | Header displayed in violation output |
|
|
280
479
|
| `explanation` | No | `""` | Detailed explanation of why this matters |
|
|
281
480
|
| `recommendation` | No | `""` | How to fix the issue, with examples |
|
|
@@ -307,14 +506,42 @@ Output structure:
|
|
|
307
506
|
{
|
|
308
507
|
"rule_id": "301",
|
|
309
508
|
"description": "Verify Infra VLAN Is Defined When Referenced by AAEPs",
|
|
509
|
+
"severity": "HIGH",
|
|
310
510
|
"errors": [
|
|
311
511
|
"apic.access_policies.aaeps[name=INFRA-AAEP].infra_vlan - AAEP 'INFRA-AAEP' has infra_vlan enabled but global infra_vlan is not defined"
|
|
312
|
-
]
|
|
512
|
+
],
|
|
513
|
+
"blocking": true
|
|
313
514
|
}
|
|
314
515
|
]
|
|
315
516
|
}
|
|
316
517
|
```
|
|
317
518
|
|
|
519
|
+
`semantic_errors` lists every violated rule, including those below the `--fail-on` threshold; `blocking` tells whether the rule's violations fail validation.
|
|
520
|
+
|
|
521
|
+
Syntax errors of [templates](#templates) have a `line` and `column`; their warnings are listed in `template_warnings`, with the same fields. Warnings of [variable schemas](#variable-schemas) are listed in `variable_warnings`.
|
|
522
|
+
|
|
523
|
+
With [ignore comments](#ignore-comments), `suppressed` lists the suppressed violations (with the comment's file, line and reason) and `unused_ignores` the comments that suppressed nothing.
|
|
524
|
+
|
|
525
|
+
## Library API
|
|
526
|
+
|
|
527
|
+
Tools such as editors can run the checks of the CLI on data in memory, without printing or raising:
|
|
528
|
+
|
|
529
|
+
```python
|
|
530
|
+
from pathlib import Path
|
|
531
|
+
|
|
532
|
+
from nac_validate import Validator
|
|
533
|
+
|
|
534
|
+
validator = Validator.from_project(Path("."))
|
|
535
|
+
# One file: Yamale and the schema extensions checked per file
|
|
536
|
+
violations = validator.check_file(data)
|
|
537
|
+
# Data merged from two files: references, keys unique across files
|
|
538
|
+
violations += validator.check_merged(merged, files=2)
|
|
539
|
+
# A RuleResult per rule
|
|
540
|
+
results = validator.run_rules(merged)
|
|
541
|
+
```
|
|
542
|
+
|
|
543
|
+
Schema violations have the path segments of the data they are at (`("nxos", "devices", 0, "url")`). A rule that raises is reported with its exception instead of stopping the others. `nac_validate.ignores` reads [ignore comments](#ignore-comments) from text (`read_comments()`) and applies them (`IgnoreMatcher`), and `nac_validate.schema` walks the schema and the data (`walk_data()`, `walk_schema_contexts()`, `ReferenceIndex`). The names in `__all__` of `nac_validate`, `nac_validate.schema` and `nac_validate.ignores` are the public API. Loading schema and rules from bundles and modules (`from_project()`) is [experimental](#packaged-schema-and-rules-experimental); `Validator.from_paths()` loads a local schema and rules.
|
|
544
|
+
|
|
318
545
|
## Installation
|
|
319
546
|
|
|
320
547
|
Python 3.11+ is required to install `nac-validate`. Don't have Python 3.11 or later? See [Python 3 Installation & Setup Guide](https://realpython.com/installing-python/).
|