From 19fbc1a3f38b31a3a13f747f81595094778ef135 Mon Sep 17 00:00:00 2001 From: Ajinkya Udgirkar Date: Tue, 23 May 2023 16:30:12 +0530 Subject: [PATCH 1/2] Add missing become_method plugins to the schema --- .config/dictionary.txt | 3 + src/ansiblelint/schemas/__store__.json | 2 +- src/ansiblelint/schemas/ansible.json | 27 ++- src/ansiblelint/schemas/playbook.json | 29 ++- src/ansiblelint/schemas/tasks.json | 29 ++- .../playbooks/tasks/become_method_invalid.yml | 4 + .../tasks/become_method_invalid.yml.md | 203 ++++++++++++++++++ .../tasks/become_method_untemplated.yml | 4 - .../tasks/become_method_untemplated.yml.md | 40 +++- 9 files changed, 300 insertions(+), 41 deletions(-) create mode 100644 test/schemas/negative_test/playbooks/tasks/become_method_invalid.yml create mode 100644 test/schemas/negative_test/playbooks/tasks/become_method_invalid.yml.md delete mode 100644 test/schemas/negative_test/playbooks/tasks/become_method_untemplated.yml diff --git a/.config/dictionary.txt b/.config/dictionary.txt index 41916f207d..447895a921 100644 --- a/.config/dictionary.txt +++ b/.config/dictionary.txt @@ -258,6 +258,7 @@ pkgs placefolder pluggy pluginmanager +pmrun podman portchannel prerun @@ -313,6 +314,7 @@ sdist sdists sectionauthor seealso +sesu setenv setuptools shortdesc @@ -339,6 +341,7 @@ subschema subschemas substrs subtest +sudosu superfences supervisorctl swdepot diff --git a/src/ansiblelint/schemas/__store__.json b/src/ansiblelint/schemas/__store__.json index 78e9239985..d6e802e909 100644 --- a/src/ansiblelint/schemas/__store__.json +++ b/src/ansiblelint/schemas/__store__.json @@ -12,7 +12,7 @@ "url": "https://raw.githubusercontent.com/ansible/ansible-lint/main/src/ansiblelint/schemas/changelog.json" }, "execution-environment": { - "etag": "fb343322c706fe2a571adf4f33e01a4bc86dc1d4ec548c22911eb116ccb355de", + "etag": "f3abb1716134227ccd667607840dd7bdebfd02a8980603df031282126dc78264", "url": "https://raw.githubusercontent.com/ansible/ansible-lint/main/src/ansiblelint/schemas/execution-environment.json" }, "galaxy": { diff --git a/src/ansiblelint/schemas/ansible.json b/src/ansiblelint/schemas/ansible.json index 9c75f09a31..3918739dc5 100644 --- a/src/ansiblelint/schemas/ansible.json +++ b/src/ansiblelint/schemas/ansible.json @@ -42,23 +42,30 @@ }, "become_method": { "markdownDescription": "See [become](https://docs.ansible.com/ansible/latest/user_guide/become.html)", - "oneOf": [ + "anyOf": [ { "enum": [ - "sudo", - "su", - "pbrun", - "pfexec", - "runas", - "dzdo", - "ksu", - "doas", - "machinectl" + "ansible.builtin.sudo", + "ansible.builtin.su", + "community.general.pbrun", + "community.general.pfexec", + "ansible.builtin.runas", + "community.general.dzdo", + "community.general.ksu", + "community.general.doas", + "community.general.machinectl", + "community.general.pmrun", + "community.general.sesu", + "community.general.sudosu" ], "type": "string" }, { "$ref": "#/$defs/full-jinja" + }, + { + "pattern": "[A-Za-z0-9_\\.]+", + "type": "string" } ], "title": "Become Method" diff --git a/src/ansiblelint/schemas/playbook.json b/src/ansiblelint/schemas/playbook.json index c5c9e7e3e5..d9c704e05e 100644 --- a/src/ansiblelint/schemas/playbook.json +++ b/src/ansiblelint/schemas/playbook.json @@ -50,26 +50,33 @@ "type": "object" }, "become_method": { - "markdownDescription": "See [become](https://docs.ansible.com/ansible/latest/user_guide/become.html)", - "oneOf": [ + "anyOf": [ { "enum": [ - "sudo", - "su", - "pbrun", - "pfexec", - "runas", - "dzdo", - "ksu", - "doas", - "machinectl" + "ansible.builtin.sudo", + "ansible.builtin.su", + "community.general.pbrun", + "community.general.pfexec", + "ansible.builtin.runas", + "community.general.dzdo", + "community.general.ksu", + "community.general.doas", + "community.general.machinectl", + "community.general.pmrun", + "community.general.sesu", + "community.general.sudosu" ], "type": "string" }, { "$ref": "#/$defs/full-jinja" + }, + { + "pattern": "[A-Za-z0-9_\\.]+", + "type": "string" } ], + "markdownDescription": "See [become](https://docs.ansible.com/ansible/latest/user_guide/become.html)", "title": "Become Method" }, "block": { diff --git a/src/ansiblelint/schemas/tasks.json b/src/ansiblelint/schemas/tasks.json index 3e8367e92a..ec7f85dbc7 100644 --- a/src/ansiblelint/schemas/tasks.json +++ b/src/ansiblelint/schemas/tasks.json @@ -2,26 +2,33 @@ "$comment": "Generated from ansible.json, do not edit.", "$defs": { "become_method": { - "markdownDescription": "See [become](https://docs.ansible.com/ansible/latest/user_guide/become.html)", - "oneOf": [ + "anyOf": [ { "enum": [ - "sudo", - "su", - "pbrun", - "pfexec", - "runas", - "dzdo", - "ksu", - "doas", - "machinectl" + "ansible.builtin.sudo", + "ansible.builtin.su", + "community.general.pbrun", + "community.general.pfexec", + "ansible.builtin.runas", + "community.general.dzdo", + "community.general.ksu", + "community.general.doas", + "community.general.machinectl", + "community.general.pmrun", + "community.general.sesu", + "community.general.sudosu" ], "type": "string" }, { "$ref": "#/$defs/full-jinja" + }, + { + "pattern": "[A-Za-z0-9_\\.]+", + "type": "string" } ], + "markdownDescription": "See [become](https://docs.ansible.com/ansible/latest/user_guide/become.html)", "title": "Become Method" }, "block": { diff --git a/test/schemas/negative_test/playbooks/tasks/become_method_invalid.yml b/test/schemas/negative_test/playbooks/tasks/become_method_invalid.yml new file mode 100644 index 0000000000..9a6bc992fc --- /dev/null +++ b/test/schemas/negative_test/playbooks/tasks/become_method_invalid.yml @@ -0,0 +1,4 @@ +- command: echo 123 + vars: + sudo_var: doo + become_method: true diff --git a/test/schemas/negative_test/playbooks/tasks/become_method_invalid.yml.md b/test/schemas/negative_test/playbooks/tasks/become_method_invalid.yml.md new file mode 100644 index 0000000000..fc1e692f8b --- /dev/null +++ b/test/schemas/negative_test/playbooks/tasks/become_method_invalid.yml.md @@ -0,0 +1,203 @@ +# ajv errors + +```json +[ + { + "instancePath": "/0", + "keyword": "required", + "message": "must have required property 'block'", + "params": { + "missingProperty": "block" + }, + "schemaPath": "#/required" + }, + { + "instancePath": "/0/become_method", + "keyword": "type", + "message": "must be string", + "params": { + "type": "string" + }, + "schemaPath": "#/anyOf/0/type" + }, + { + "instancePath": "/0/become_method", + "keyword": "enum", + "message": "must be equal to one of the allowed values", + "params": { + "allowedValues": [ + "ansible.builtin.sudo", + "ansible.builtin.su", + "community.general.pbrun", + "community.general.pfexec", + "ansible.builtin.runas", + "community.general.dzdo", + "community.general.ksu", + "community.general.doas", + "community.general.machinectl", + "community.general.pmrun", + "community.general.sesu", + "community.general.sudosu" + ] + }, + "schemaPath": "#/anyOf/0/enum" + }, + { + "instancePath": "/0/become_method", + "keyword": "type", + "message": "must be string", + "params": { + "type": "string" + }, + "schemaPath": "#/$defs/full-jinja/type" + }, + { + "instancePath": "/0/become_method", + "keyword": "type", + "message": "must be string", + "params": { + "type": "string" + }, + "schemaPath": "#/anyOf/2/type" + }, + { + "instancePath": "/0/become_method", + "keyword": "anyOf", + "message": "must match a schema in anyOf", + "params": {}, + "schemaPath": "#/anyOf" + }, + { + "instancePath": "/0/become_method", + "keyword": "type", + "message": "must be string", + "params": { + "type": "string" + }, + "schemaPath": "#/anyOf/0/type" + }, + { + "instancePath": "/0/become_method", + "keyword": "enum", + "message": "must be equal to one of the allowed values", + "params": { + "allowedValues": [ + "ansible.builtin.sudo", + "ansible.builtin.su", + "community.general.pbrun", + "community.general.pfexec", + "ansible.builtin.runas", + "community.general.dzdo", + "community.general.ksu", + "community.general.doas", + "community.general.machinectl", + "community.general.pmrun", + "community.general.sesu", + "community.general.sudosu" + ] + }, + "schemaPath": "#/anyOf/0/enum" + }, + { + "instancePath": "/0/become_method", + "keyword": "type", + "message": "must be string", + "params": { + "type": "string" + }, + "schemaPath": "#/$defs/full-jinja/type" + }, + { + "instancePath": "/0/become_method", + "keyword": "type", + "message": "must be string", + "params": { + "type": "string" + }, + "schemaPath": "#/anyOf/2/type" + }, + { + "instancePath": "/0/become_method", + "keyword": "anyOf", + "message": "must match a schema in anyOf", + "params": {}, + "schemaPath": "#/anyOf" + }, + { + "instancePath": "/0", + "keyword": "anyOf", + "message": "must match a schema in anyOf", + "params": {}, + "schemaPath": "#/items/anyOf" + } +] +``` + +# check-jsonschema + +stdout: + +```json +{ + "status": "fail", + "errors": [ + { + "filename": "negative_test/playbooks/tasks/become_method_invalid.yml", + "path": "$[0]", + "message": "{'command': 'echo 123', 'vars': {'sudo_var': 'doo'}, 'become_method': True} is not valid under any of the given schemas", + "has_sub_errors": true, + "best_match": { + "path": "$[0]", + "message": "'block' is a required property" + }, + "sub_errors": [ + { + "path": "$[0].become_method", + "message": "True is not valid under any of the given schemas" + }, + { + "path": "$[0].become_method", + "message": "True is not one of ['ansible.builtin.sudo', 'ansible.builtin.su', 'community.general.pbrun', 'community.general.pfexec', 'ansible.builtin.runas', 'community.general.dzdo', 'community.general.ksu', 'community.general.doas', 'community.general.machinectl', 'community.general.pmrun', 'community.general.sesu', 'community.general.sudosu']" + }, + { + "path": "$[0].become_method", + "message": "True is not of type 'string'" + }, + { + "path": "$[0].become_method", + "message": "True is not of type 'string'" + }, + { + "path": "$[0].become_method", + "message": "True is not of type 'string'" + }, + { + "path": "$[0]", + "message": "'block' is a required property" + }, + { + "path": "$[0].become_method", + "message": "True is not valid under any of the given schemas" + }, + { + "path": "$[0].become_method", + "message": "True is not one of ['ansible.builtin.sudo', 'ansible.builtin.su', 'community.general.pbrun', 'community.general.pfexec', 'ansible.builtin.runas', 'community.general.dzdo', 'community.general.ksu', 'community.general.doas', 'community.general.machinectl', 'community.general.pmrun', 'community.general.sesu', 'community.general.sudosu']" + }, + { + "path": "$[0].become_method", + "message": "True is not of type 'string'" + }, + { + "path": "$[0].become_method", + "message": "True is not of type 'string'" + }, + { + "path": "$[0].become_method", + "message": "True is not of type 'string'" + } + ] + } + ], + "parse_errors": [] +} +``` diff --git a/test/schemas/negative_test/playbooks/tasks/become_method_untemplated.yml b/test/schemas/negative_test/playbooks/tasks/become_method_untemplated.yml deleted file mode 100644 index bc7217f054..0000000000 --- a/test/schemas/negative_test/playbooks/tasks/become_method_untemplated.yml +++ /dev/null @@ -1,4 +0,0 @@ -- command: echo 123 - vars: - sudo_var: doo - become_method: sudo_var # templating requires {{ }} diff --git a/test/schemas/negative_test/playbooks/tasks/become_method_untemplated.yml.md b/test/schemas/negative_test/playbooks/tasks/become_method_untemplated.yml.md index 25d37040ad..47a6554336 100644 --- a/test/schemas/negative_test/playbooks/tasks/become_method_untemplated.yml.md +++ b/test/schemas/negative_test/playbooks/tasks/become_method_untemplated.yml.md @@ -25,7 +25,10 @@ "dzdo", "ksu", "doas", - "machinectl" + "machinectl", + "pmrun", + "sesu", + "sudosu" ] }, "schemaPath": "#/oneOf/0/enum" @@ -39,6 +42,15 @@ }, "schemaPath": "#/$defs/full-jinja/pattern" }, + { + "instancePath": "/0/become_method", + "keyword": "pattern", + "message": "must match pattern \"^[A-Z][a-z][0-9]._$\"", + "params": { + "pattern": "^[A-Z][a-z][0-9]._$" + }, + "schemaPath": "#/oneOf/2/pattern" + }, { "instancePath": "/0/become_method", "keyword": "oneOf", @@ -62,7 +74,10 @@ "dzdo", "ksu", "doas", - "machinectl" + "machinectl", + "pmrun", + "sesu", + "sudosu" ] }, "schemaPath": "#/oneOf/0/enum" @@ -76,6 +91,15 @@ }, "schemaPath": "#/$defs/full-jinja/pattern" }, + { + "instancePath": "/0/become_method", + "keyword": "pattern", + "message": "must match pattern \"^[A-Z][a-z][0-9]._$\"", + "params": { + "pattern": "^[A-Z][a-z][0-9]._$" + }, + "schemaPath": "#/oneOf/2/pattern" + }, { "instancePath": "/0/become_method", "keyword": "oneOf", @@ -119,12 +143,16 @@ stdout: }, { "path": "$[0].become_method", - "message": "'sudo_var' is not one of ['sudo', 'su', 'pbrun', 'pfexec', 'runas', 'dzdo', 'ksu', 'doas', 'machinectl']" + "message": "'sudo_var' is not one of ['sudo', 'su', 'pbrun', 'pfexec', 'runas', 'dzdo', 'ksu', 'doas', 'machinectl', 'pmrun', 'sesu', 'sudosu']" }, { "path": "$[0].become_method", "message": "'sudo_var' does not match '^\\\\{[\\\\{%](.|[\\r\\n])*[\\\\}%]\\\\}$'" }, + { + "path": "$[0].become_method", + "message": "'sudo_var' does not match '^[A-Z][a-z][0-9]._$'" + }, { "path": "$[0]", "message": "'block' is a required property" @@ -135,11 +163,15 @@ stdout: }, { "path": "$[0].become_method", - "message": "'sudo_var' is not one of ['sudo', 'su', 'pbrun', 'pfexec', 'runas', 'dzdo', 'ksu', 'doas', 'machinectl']" + "message": "'sudo_var' is not one of ['sudo', 'su', 'pbrun', 'pfexec', 'runas', 'dzdo', 'ksu', 'doas', 'machinectl', 'pmrun', 'sesu', 'sudosu']" }, { "path": "$[0].become_method", "message": "'sudo_var' does not match '^\\\\{[\\\\{%](.|[\\r\\n])*[\\\\}%]\\\\}$'" + }, + { + "path": "$[0].become_method", + "message": "'sudo_var' does not match '^[A-Z][a-z][0-9]._$'" } ] } From 32146d377aaa461327caa05edbf95b300d662dfd Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Tue, 23 May 2023 15:13:32 +0000 Subject: [PATCH 2/2] chore: auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- src/ansiblelint/schemas/ansible.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ansiblelint/schemas/ansible.json b/src/ansiblelint/schemas/ansible.json index 3918739dc5..3272790fb0 100644 --- a/src/ansiblelint/schemas/ansible.json +++ b/src/ansiblelint/schemas/ansible.json @@ -41,7 +41,6 @@ "type": "object" }, "become_method": { - "markdownDescription": "See [become](https://docs.ansible.com/ansible/latest/user_guide/become.html)", "anyOf": [ { "enum": [ @@ -68,6 +67,7 @@ "type": "string" } ], + "markdownDescription": "See [become](https://docs.ansible.com/ansible/latest/user_guide/become.html)", "title": "Become Method" }, "block": {