2021-01-31 12:33:11 +00:00
|
|
|
# Copyright (c) 2018, Ansible Project
|
|
|
|
from nested_lookup import nested_lookup
|
|
|
|
|
2024-01-25 20:40:15 +00:00
|
|
|
from ansiblelater.rule import RuleBase
|
2021-01-31 12:33:11 +00:00
|
|
|
|
|
|
|
|
2024-01-25 20:40:15 +00:00
|
|
|
class CheckMetaChangeFromDefault(RuleBase):
|
2021-01-31 12:33:11 +00:00
|
|
|
sid = "ANSIBLE0021"
|
|
|
|
description = "Roles meta/main.yml default values should be changed"
|
|
|
|
helptext = "meta/main.yml default values should be changed for: `{field}`"
|
|
|
|
types = ["meta"]
|
|
|
|
|
|
|
|
def check(self, candidate, settings):
|
|
|
|
content, errors = self.get_raw_yaml(candidate, settings)
|
|
|
|
field_defaults = [
|
|
|
|
("author", "your name"),
|
|
|
|
("description", "your description"),
|
|
|
|
("company", "your company (optional)"),
|
|
|
|
("license", "license (GPLv2, CC-BY, etc)"),
|
|
|
|
("license", "license (GPL-2.0-or-later, MIT, etc)"),
|
|
|
|
]
|
|
|
|
|
|
|
|
if not errors:
|
|
|
|
for field, default in field_defaults:
|
2023-01-09 10:59:25 +00:00
|
|
|
pair = f"{field}: {default}"
|
2021-01-31 12:33:11 +00:00
|
|
|
lookup = nested_lookup(field, content)
|
|
|
|
if lookup and default in nested_lookup(field, content):
|
|
|
|
errors.append(self.Error(None, self.helptext.format(field=pair)))
|
|
|
|
|
|
|
|
return self.Result(candidate.path, errors)
|