2021-01-30 15:52:48 +00:00
|
|
|
from nested_lookup import nested_lookup
|
|
|
|
|
|
|
|
from ansiblelater.standard import StandardBase
|
|
|
|
|
|
|
|
|
|
|
|
class CheckMetaMain(StandardBase):
|
|
|
|
|
|
|
|
sid = "ANSIBLE0002"
|
|
|
|
description = "Roles must contain suitable meta/main.yml"
|
2021-01-31 13:22:04 +00:00
|
|
|
helptext = "file should contain `{key}` key"
|
2021-01-30 15:52:48 +00:00
|
|
|
version = "0.1"
|
|
|
|
types = ["meta"]
|
|
|
|
|
|
|
|
def check(self, candidate, settings):
|
|
|
|
content, errors = self.get_raw_yaml(candidate, settings)
|
2021-02-04 20:08:38 +00:00
|
|
|
keys = ["author", "description", "min_ansible_version", "platforms"]
|
2021-01-30 15:52:48 +00:00
|
|
|
|
|
|
|
if not errors:
|
2023-02-10 07:51:17 +00:00
|
|
|
has_galaxy_info = (isinstance(content, dict) and "galaxy_info" in content)
|
|
|
|
has_dependencies = (isinstance(content, dict) and "dependencies" in content)
|
2021-02-04 20:08:38 +00:00
|
|
|
|
2021-01-31 12:33:57 +00:00
|
|
|
if not has_galaxy_info:
|
|
|
|
errors.append(self.Error(None, self.helptext.format(key="galaxy_info")))
|
|
|
|
|
2021-02-04 20:08:38 +00:00
|
|
|
if not has_dependencies:
|
|
|
|
errors.append(self.Error(None, self.helptext.format(key="dependencies")))
|
|
|
|
|
2021-01-30 15:52:48 +00:00
|
|
|
for key in keys:
|
2021-01-31 12:33:57 +00:00
|
|
|
if has_galaxy_info and not nested_lookup(key, content.get("galaxy_info", {})):
|
2021-01-30 15:52:48 +00:00
|
|
|
errors.append(self.Error(None, self.helptext.format(key=key)))
|
|
|
|
|
|
|
|
return self.Result(candidate.path, errors)
|