Skip to content

Commit

Permalink
Add support for json schema validation
Browse files Browse the repository at this point in the history
  • Loading branch information
ssbarnea committed Mar 22, 2022
1 parent aa305f7 commit e22324c
Show file tree
Hide file tree
Showing 19 changed files with 4,753 additions and 2 deletions.
1 change: 1 addition & 0 deletions .config/dictionary.txt
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ isdir
isdisjoint
iskeyword
isort
jsonschema
junitxml
kubernetes
libera
Expand Down
3 changes: 2 additions & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ repos:
examples/playbooks/templates/not-valid.yaml|
examples/playbooks/with-umlaut-.*|
examples/playbooks/with-skip-tag-id.yml|
test/fixtures/formatting-before/.*
test/fixtures/formatting-before/.*|
src/ansiblelint/schemas/.*
)$
additional_dependencies:
- prettier
Expand Down
1 change: 1 addition & 0 deletions cspell.config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,6 @@ ignorePaths:
- docs/requirements.in
# Test fixtures generated from outside
- test/**/*.result
- src/ansiblelint/schemas/*.json
# Other
- "*.svg"
1 change: 1 addition & 0 deletions setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@ install_requires =
ansible-compat>=2.0.2 # GPLv3
ansible-core>=2.12.0 # GPLv3
enrich>=1.2.6
jsonschema>=4.4.0
packaging
pyyaml
rich>=9.5.1
Expand Down
17 changes: 17 additions & 0 deletions src/ansiblelint/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,23 @@
]


# Maps kinds to JSON schemas
# See https://www.schemastore.org/json/
JSON_SCHEMAS = {
"playbook": "https://raw.githubusercontent.com/ansible-community/schemas/main/f/ansible-playbook.json",
"tasks": "https://raw.githubusercontent.com/ansible-community/schemas/main/f/ansible-tasks.json",
"vars": "https://raw.githubusercontent.com/ansible-community/schemas/main/f/ansible-vars.json",
"requirements": "https://raw.githubusercontent.com/ansible-community/schemas/main/f/ansible-requirements.json",
"meta": "https://raw.githubusercontent.com/ansible-community/schemas/main/f/ansible-meta.json",
"galaxy": "https://raw.githubusercontent.com/ansible-community/schemas/main/f/ansible-galaxy.json",
# unsupported yet:
"execution-environment": "https://raw.githubusercontent.com/ansible-community/schemas/main/f/ansible-ee.json",
"meta-runtime": "https://raw.githubusercontent.com/ansible-community/schemas/main/f/ansible-meta-runtime.json",
"inventory": "https://raw.githubusercontent.com/ansible-community/schemas/main/f/ansible-inventory.json",
"ansible-lint-config": "https://raw.githubusercontent.com/ansible-community/schemas/main/f/ansible-lint.json",
"ansible-navigator-config": "https://raw.githubusercontent.com/ansible-community/schemas/main/f/ansible-navigator.json",
}

options = Namespace(
cache_dir=None,
colored=True,
Expand Down
6 changes: 5 additions & 1 deletion src/ansiblelint/runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,11 @@ def run(self) -> List[MatchError]:
# -- phase 1 : syntax check in parallel --
def worker(lintable: Lintable) -> List[MatchError]:
# pylint: disable=protected-access
return AnsibleSyntaxCheckRule._get_ansible_syntax_check_matches(lintable)
result = []
result.extend(
AnsibleSyntaxCheckRule._get_ansible_syntax_check_matches(lintable)
)
return result

# playbooks: List[Lintable] = []
for lintable in self.lintables:
Expand Down
1 change: 1 addition & 0 deletions src/ansiblelint/schemas/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
"""Fake module containing cached JSON schemas."""
109 changes: 109 additions & 0 deletions src/ansiblelint/schemas/ansible-lint-config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
{
"$schema": "http://json-schema.org/draft-07/schema",
"additionalProperties": false,
"examples": [
".ansible-lint",
".config/ansiblelint.yml"
],
"properties": {
"exclude_paths": {
"items": {
"type": "string"
},
"title": "Exclude Paths",
"type": "array"
},
"extra_vars": {
"title": "Extra Vars",
"type": "object"
},
"kinds": {
"items": {
"additionalProperties": {
"type": "string"
},
"type": "object"
},
"title": "Kinds",
"type": "array"
},
"loop_var_prefix": {
"title": "Loop Var Prefix",
"type": "string"
},
"mock_modules": {
"items": {
"type": "string"
},
"title": "Mock Modules",
"type": "array"
},
"mock_roles": {
"items": {
"type": "string"
},
"title": "Mock Roles",
"type": "array"
},
"offline": {
"default": false,
"title": "Offline",
"type": "boolean"
},
"parseable": {
"default": true,
"title": "Parseable",
"type": "boolean"
},
"quiet": {
"default": true,
"title": "Quiet",
"type": "boolean"
},
"rulesdir": {
"items": {
"type": "string"
},
"title": "Rulesdir",
"type": "array"
},
"skip_action_validation": {
"default": false,
"title": "Skip Action Validation",
"type": "boolean"
},
"skip_list": {
"items": {
"type": "string"
},
"title": "Skip List",
"type": "array"
},
"tags": {
"items": {
"type": "string"
},
"title": "Tags",
"type": "array"
},
"use_default_rules": {
"default": true,
"title": "Use Default Rules",
"type": "boolean"
},
"verbosity": {
"default": 0,
"title": "Verbosity",
"type": "integer"
},
"warn_list": {
"items": {
"type": "string"
},
"title": "Warn List",
"type": "array"
}
},
"title": "Ansible-lint Configuration Schema",
"type": "object"
}

0 comments on commit e22324c

Please sign in to comment.