fix(vpn-node-config): resolve ansible-lint violations
OpenVPN Ansible / Deploy VPN Networking and OpenVPN (push) Canceled after 0s
OpenVPN Ansible / Generate SBOM (push) Canceled after 0s
OpenVPN Ansible / Scan SBOM with Trivy (push) Canceled after 0s
OpenVPN Ansible / Ansible Syntax Check (push) Canceled after 38s
OpenVPN Ansible / Ansible Lint (push) Canceled after 40s
OpenVPN Ansible / Deploy VPN Networking and OpenVPN (push) Canceled after 0s
OpenVPN Ansible / Generate SBOM (push) Canceled after 0s
OpenVPN Ansible / Scan SBOM with Trivy (push) Canceled after 0s
OpenVPN Ansible / Ansible Syntax Check (push) Canceled after 38s
OpenVPN Ansible / Ansible Lint (push) Canceled after 40s
This commit is contained in:
+71
@@ -0,0 +1,71 @@
|
||||
#!/usr/bin/env python
|
||||
# Copyright (c) Ansible Project
|
||||
# GNU General Public License v3.0+ (see LICENSES/GPL-3.0-or-later.txt or https://www.gnu.org/licenses/gpl-3.0.txt)
|
||||
# SPDX-License-Identifier: GPL-3.0-or-later
|
||||
"""Check extra collection docs with antsibull-docs."""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import glob
|
||||
import sys
|
||||
|
||||
import yaml
|
||||
|
||||
|
||||
def main():
|
||||
"""Main entry point."""
|
||||
with open(".azure-pipelines/azure-pipelines.yml", "rb") as f:
|
||||
azp = yaml.safe_load(f)
|
||||
|
||||
allowed_targets = {"azp/generic/1", "heavy"}
|
||||
for stage in azp["stages"]:
|
||||
if stage["stage"].startswith(("sanity", "unit", "Summary")):
|
||||
continue
|
||||
for job in stage["jobs"]:
|
||||
for param in job["parameters"]["targets"]:
|
||||
group = param["test"].rsplit("-", 1)[-1]
|
||||
allowed_targets.add(f"azp/posix/{group}")
|
||||
|
||||
paths = glob.glob("tests/integration/targets/*/aliases")
|
||||
|
||||
has_errors = False
|
||||
for path in paths:
|
||||
targets = []
|
||||
skip = False
|
||||
with open(path) as f:
|
||||
for line in f:
|
||||
if "#" in line:
|
||||
line = line[: line.find("#")]
|
||||
line = line.strip()
|
||||
if line.startswith("needs/"):
|
||||
continue
|
||||
if line.startswith("skip/"):
|
||||
continue
|
||||
if line.startswith("cloud/"):
|
||||
continue
|
||||
if line.startswith("context/"):
|
||||
continue
|
||||
if line in ("unsupported", "disabled", "hidden"):
|
||||
skip = True
|
||||
if line in ("destructive",):
|
||||
continue
|
||||
if "/" not in line and line not in ("heavy",):
|
||||
continue
|
||||
targets.append(line)
|
||||
if skip:
|
||||
continue
|
||||
if not targets:
|
||||
if "targets/setup_" in path:
|
||||
continue
|
||||
print(f"{path}: found no targets")
|
||||
has_errors = True
|
||||
for target in targets:
|
||||
if target not in allowed_targets:
|
||||
print(f'{path}: found invalid target "{target}"')
|
||||
has_errors = True
|
||||
|
||||
return 1 if has_errors else 0
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
sys.exit(main())
|
||||
+270
@@ -0,0 +1,270 @@
|
||||
#!/usr/bin/env python
|
||||
# Copyright (c) Ansible Project
|
||||
# GNU General Public License v3.0+ (see LICENSES/GPL-3.0-or-later.txt or https://www.gnu.org/licenses/gpl-3.0.txt)
|
||||
# SPDX-License-Identifier: GPL-3.0-or-later
|
||||
"""Check BOTMETA file."""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import os
|
||||
import re
|
||||
import sys
|
||||
import typing as t
|
||||
|
||||
import pydantic
|
||||
import yaml
|
||||
|
||||
IGNORE_NO_MAINTAINERS = [
|
||||
"docs/docsite/rst/filter_guide.rst",
|
||||
"docs/docsite/rst/filter_guide_abstract_informations.rst",
|
||||
"docs/docsite/rst/filter_guide_paths.rst",
|
||||
"docs/docsite/rst/filter_guide_selecting_json_data.rst",
|
||||
"plugins/cache/memcached.py",
|
||||
"plugins/cache/redis.py",
|
||||
"plugins/callback/cgroup_memory_recap.py",
|
||||
"plugins/callback/context_demo.py",
|
||||
"plugins/callback/counter_enabled.py",
|
||||
"plugins/callback/jabber.py",
|
||||
"plugins/callback/log_plays.py",
|
||||
"plugins/callback/logdna.py",
|
||||
"plugins/callback/logentries.py",
|
||||
"plugins/callback/null.py",
|
||||
"plugins/callback/selective.py",
|
||||
"plugins/callback/slack.py",
|
||||
"plugins/callback/splunk.py",
|
||||
"plugins/callback/yaml.py",
|
||||
"plugins/connection/chroot.py",
|
||||
"plugins/connection/iocage.py",
|
||||
"plugins/connection/lxc.py",
|
||||
"plugins/doc_fragments/_auth_basic.py",
|
||||
"plugins/filter/json_query.py",
|
||||
"plugins/filter/random_mac.py",
|
||||
"plugins/inventory/nmap.py",
|
||||
"plugins/inventory/virtualbox.py",
|
||||
"plugins/lookup/cartesian.py",
|
||||
"plugins/lookup/chef_databag.py",
|
||||
"plugins/lookup/consul_kv.py",
|
||||
"plugins/lookup/credstash.py",
|
||||
"plugins/lookup/cyberarkpassword.py",
|
||||
"plugins/lookup/flattened.py",
|
||||
"plugins/lookup/keyring.py",
|
||||
"plugins/lookup/lastpass.py",
|
||||
"plugins/lookup/passwordstore.py",
|
||||
"plugins/lookup/shelvefile.py",
|
||||
"plugins/module_utils/_lxd.py",
|
||||
"plugins/module_utils/_memset.py",
|
||||
"plugins/module_utils/_stormssh.py",
|
||||
"plugins/module_utils/_univention_umc.py",
|
||||
]
|
||||
|
||||
|
||||
class _BaseModel(pydantic.BaseModel):
|
||||
model_config = pydantic.ConfigDict(frozen=True, extra="forbid", validate_default=True)
|
||||
|
||||
|
||||
class File(_BaseModel):
|
||||
supershipit: t.Optional[str] = None
|
||||
support: t.Optional[t.Literal["community"]] = None
|
||||
maintainers: t.Optional[str] = None
|
||||
labels: t.Optional[str] = None
|
||||
keywords: t.Optional[str] = None
|
||||
notify: t.Optional[str] = None
|
||||
ignore: t.Optional[str] = None
|
||||
|
||||
|
||||
class BotMeta(_BaseModel):
|
||||
notifications: t.Optional[bool] = None
|
||||
automerge: t.Optional[bool] = None
|
||||
macros: dict[str, t.Optional[str]] = {}
|
||||
files: dict[str, File] = {}
|
||||
|
||||
|
||||
class BotmetaCheck:
|
||||
def __init__(self) -> None:
|
||||
self.errors: list[str] = []
|
||||
self.botmeta_filename = ".github/BOTMETA.yml"
|
||||
self.list_entries = frozenset(("supershipit", "maintainers", "labels", "keywords", "notify", "ignore"))
|
||||
self.author_regex = re.compile(r"^\w.*\(@([\w-]+)\)(?![\w.])")
|
||||
|
||||
def report_error(self, error: str) -> None:
|
||||
self.errors.append(error)
|
||||
|
||||
def read_authors(self, filename: str) -> list[str]:
|
||||
data = {}
|
||||
try:
|
||||
documentation = []
|
||||
in_docs = False
|
||||
with open(filename, encoding="utf-8") as f:
|
||||
for line in f:
|
||||
if line.startswith("DOCUMENTATION ="):
|
||||
in_docs = True
|
||||
elif line.startswith(("'''", '"""')) and in_docs:
|
||||
in_docs = False
|
||||
elif in_docs:
|
||||
documentation.append(line)
|
||||
if in_docs:
|
||||
self.report_error(f"{filename}: cannot find DOCUMENTATION end")
|
||||
return []
|
||||
if not documentation:
|
||||
self.report_error(f"{filename}: cannot find DOCUMENTATION")
|
||||
return []
|
||||
|
||||
data = yaml.safe_load("\n".join(documentation))
|
||||
|
||||
except Exception as e:
|
||||
self.report_error(f"{filename}:0:0: Cannot load DOCUMENTATION: {e}")
|
||||
return []
|
||||
|
||||
author = data.get("author") or []
|
||||
if isinstance(author, str):
|
||||
author = [author]
|
||||
return author
|
||||
|
||||
def extract_author_name(self, author: str) -> str | None:
|
||||
m = self.author_regex.match(author)
|
||||
if m:
|
||||
return m.group(1)
|
||||
if author == "Ansible Core Team":
|
||||
return "$team_ansible_core"
|
||||
return None
|
||||
|
||||
def validate(self, filename: str, filedata: dict) -> None:
|
||||
if not filename.startswith("plugins/"):
|
||||
return
|
||||
# Compile list of all active and inactive maintainers
|
||||
all_maintainers = filedata["maintainers"] + filedata["ignore"]
|
||||
if not filename.startswith(
|
||||
(
|
||||
"plugins/action/",
|
||||
"plugins/doc_fragments/",
|
||||
"plugins/filter/",
|
||||
"plugins/module_utils/",
|
||||
"plugins/plugin_utils/",
|
||||
)
|
||||
):
|
||||
maintainers = self.read_authors(filename)
|
||||
for maintainer_str in maintainers:
|
||||
maintainer = self.extract_author_name(maintainer_str)
|
||||
if maintainer is not None and maintainer not in all_maintainers:
|
||||
others = ", ".join(all_maintainers)
|
||||
msg = f"Author {maintainer} not mentioned as active or inactive maintainer for {filename} (mentioned are: {others})"
|
||||
self.report_error(f"{self.botmeta_filename}:0:0: {msg}")
|
||||
should_have_no_maintainer = filename in IGNORE_NO_MAINTAINERS
|
||||
if not all_maintainers and not should_have_no_maintainer:
|
||||
self.report_error(
|
||||
f"{self.botmeta_filename}:0:0: No (active or inactive) maintainer mentioned for {filename}"
|
||||
)
|
||||
if all_maintainers and should_have_no_maintainer:
|
||||
own_path = os.path.relpath(__file__, os.getcwd())
|
||||
self.report_error(
|
||||
f"{self.botmeta_filename}:0:0: Please remove {filename} from the ignore list of {own_path}"
|
||||
)
|
||||
|
||||
def run(self) -> None:
|
||||
try:
|
||||
with open(self.botmeta_filename, "rb") as f:
|
||||
botmeta = yaml.safe_load(f)
|
||||
except yaml.error.MarkedYAMLError as ex:
|
||||
msg = re.sub(r"\s+", " ", str(ex))
|
||||
self.report_error(
|
||||
"f{self.botmeta_filename}:{ex.context_mark.line + 1}:{ex.context_mark.column + 1}: YAML load failed: {msg}"
|
||||
)
|
||||
return
|
||||
except Exception as ex: # pylint: disable=broad-except
|
||||
msg = re.sub(r"\s+", " ", str(ex))
|
||||
self.report_error(f"{self.botmeta_filename}:0:0: YAML load failed: {msg}")
|
||||
return
|
||||
|
||||
# Validate schema
|
||||
try:
|
||||
BotMeta.model_validate(botmeta)
|
||||
except pydantic.ValidationError as ex:
|
||||
for error in ex.errors():
|
||||
location = " -> ".join(str(loc) for loc in error["loc"])
|
||||
message = f"{location}: {error['msg']}"
|
||||
|
||||
# No way to get line/column numbers
|
||||
self.report_error(f"{self.botmeta_filename}:0:0: {message}")
|
||||
return
|
||||
|
||||
yaml_files = botmeta.get("files") or {}
|
||||
|
||||
# Check order
|
||||
expected = sorted(yaml_files)
|
||||
for i, (exp, act) in enumerate(zip(expected, yaml_files)):
|
||||
if exp != act:
|
||||
self.report_error(f"{self.botmeta_filename}:0:0: Entry #{i + 1} should be {exp!r}, but is {act!r}")
|
||||
|
||||
# Preprocess (substitute macros, convert to lists)
|
||||
macros = botmeta.get("macros") or {}
|
||||
macro_re = re.compile(r"\$([a-zA-Z_]+)")
|
||||
|
||||
def convert_macros(text, macros):
|
||||
def f(m):
|
||||
macro = m.group(1)
|
||||
replacement = macros[macro] or ""
|
||||
if macro == "team_ansible_core":
|
||||
return f"$team_ansible_core {replacement}"
|
||||
return replacement
|
||||
|
||||
return macro_re.sub(f, text)
|
||||
|
||||
files = {}
|
||||
try:
|
||||
for file, filedata in yaml_files.items():
|
||||
file = convert_macros(file, macros)
|
||||
filedata = {k: convert_macros(v, macros) for k, v in filedata.items()}
|
||||
files[file] = filedata
|
||||
for k, v in filedata.items():
|
||||
if k in self.list_entries:
|
||||
filedata[k] = v.split()
|
||||
except KeyError as e:
|
||||
self.report_error(f"{self.botmeta_filename}:0:0: Found unknown macro {e}")
|
||||
return
|
||||
|
||||
# Scan all files
|
||||
unmatched = set(files)
|
||||
for dirs in ("docs/docsite/rst", "plugins", "tests", "changelogs"):
|
||||
for dirpath, _dirnames, filenames in os.walk(dirs):
|
||||
for file in sorted(filenames):
|
||||
if file.endswith(".pyc"):
|
||||
continue
|
||||
filename = os.path.join(dirpath, file)
|
||||
if os.path.islink(filename):
|
||||
continue
|
||||
if os.path.isfile(filename):
|
||||
matching_files = []
|
||||
for file, filedata in files.items():
|
||||
if filename.startswith(file):
|
||||
matching_files.append((file, filedata))
|
||||
if file in unmatched:
|
||||
unmatched.remove(file)
|
||||
if not matching_files:
|
||||
self.report_error(f"{self.botmeta_filename}:0:0: Did not find any entry for {filename}")
|
||||
|
||||
matching_files.sort(key=lambda kv: kv[0])
|
||||
filedata = {}
|
||||
for k in self.list_entries:
|
||||
filedata[k] = []
|
||||
for dummy, data in matching_files:
|
||||
for k, v in data.items():
|
||||
if k in self.list_entries:
|
||||
v = filedata[k] + v
|
||||
filedata[k] = v
|
||||
self.validate(filename, filedata)
|
||||
|
||||
for file in unmatched:
|
||||
self.report_error(f"{self.botmeta_filename}:0:0: Entry {file} was not used")
|
||||
|
||||
|
||||
def main() -> int:
|
||||
"""Main entry point."""
|
||||
check = BotmetaCheck()
|
||||
check.run()
|
||||
for error in sorted(check.errors):
|
||||
print(error)
|
||||
return 1 if check.errors else 0
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
sys.exit(main())
|
||||
+9
@@ -0,0 +1,9 @@
|
||||
plugins/module_utils/_crypt.py import-3.11 # Uses deprecated stdlib library 'crypt'
|
||||
plugins/module_utils/_crypt.py import-3.12 # Uses deprecated stdlib library 'crypt'
|
||||
plugins/modules/consul_session.py validate-modules:parameter-state-invalid-choice
|
||||
plugins/modules/iptables_state.py validate-modules:undocumented-parameter # params _back and _timeout used by action plugin
|
||||
plugins/modules/osx_defaults.py validate-modules:parameter-state-invalid-choice
|
||||
plugins/modules/parted.py validate-modules:parameter-state-invalid-choice
|
||||
plugins/modules/rhevm.py validate-modules:parameter-state-invalid-choice
|
||||
plugins/modules/xfconf.py validate-modules:return-syntax-error
|
||||
tests/unit/plugins/modules/test_gio_mime.yaml no-smart-quotes
|
||||
+3
@@ -0,0 +1,3 @@
|
||||
GNU General Public License v3.0+ (see LICENSES/GPL-3.0-or-later.txt or https://www.gnu.org/licenses/gpl-3.0.txt)
|
||||
SPDX-License-Identifier: GPL-3.0-or-later
|
||||
SPDX-FileCopyrightText: Ansible Project
|
||||
+9
@@ -0,0 +1,9 @@
|
||||
plugins/module_utils/_crypt.py import-3.11 # Uses deprecated stdlib library 'crypt'
|
||||
plugins/module_utils/_crypt.py import-3.12 # Uses deprecated stdlib library 'crypt'
|
||||
plugins/modules/consul_session.py validate-modules:parameter-state-invalid-choice
|
||||
plugins/modules/iptables_state.py validate-modules:undocumented-parameter # params _back and _timeout used by action plugin
|
||||
plugins/modules/osx_defaults.py validate-modules:parameter-state-invalid-choice
|
||||
plugins/modules/parted.py validate-modules:parameter-state-invalid-choice
|
||||
plugins/modules/rhevm.py validate-modules:parameter-state-invalid-choice
|
||||
plugins/modules/xfconf.py validate-modules:return-syntax-error
|
||||
tests/unit/plugins/modules/test_gio_mime.yaml no-smart-quotes
|
||||
+3
@@ -0,0 +1,3 @@
|
||||
GNU General Public License v3.0+ (see LICENSES/GPL-3.0-or-later.txt or https://www.gnu.org/licenses/gpl-3.0.txt)
|
||||
SPDX-License-Identifier: GPL-3.0-or-later
|
||||
SPDX-FileCopyrightText: Ansible Project
|
||||
+15
@@ -0,0 +1,15 @@
|
||||
plugins/module_utils/_crypt.py import-3.11 # Uses deprecated stdlib library 'crypt'
|
||||
plugins/module_utils/_crypt.py import-3.12 # Uses deprecated stdlib library 'crypt'
|
||||
plugins/module_utils/_lxc.py pylint:ansible-bad-function # needs to use Popen() to stream logs
|
||||
plugins/modules/ansible_galaxy_install.py validate-modules:bad-return-value-key # TODO: rename offending return values if possible, or adjust this comment in case the name is OK
|
||||
plugins/modules/consul_session.py validate-modules:parameter-state-invalid-choice
|
||||
plugins/modules/gandi_livedns.py validate-modules:bad-return-value-key # TODO: rename offending return values if possible, or adjust this comment in case the name is OK
|
||||
plugins/modules/interfaces_file.py validate-modules:bad-return-value-key # TODO: rename offending return values if possible, or adjust this comment in case the name is OK
|
||||
plugins/modules/iptables_state.py validate-modules:undocumented-parameter # params _back and _timeout used by action plugin
|
||||
plugins/modules/nosh.py validate-modules:bad-return-value-key # TODO: rename offending return values if possible, or adjust this comment in case the name is OK
|
||||
plugins/modules/omapi_host.py validate-modules:bad-return-value-key # TODO: rename offending return values if possible, or adjust this comment in case the name is OK
|
||||
plugins/modules/osx_defaults.py validate-modules:parameter-state-invalid-choice
|
||||
plugins/modules/parted.py validate-modules:parameter-state-invalid-choice
|
||||
plugins/modules/rhevm.py validate-modules:parameter-state-invalid-choice
|
||||
plugins/modules/xfconf.py validate-modules:return-syntax-error
|
||||
tests/unit/plugins/modules/test_gio_mime.yaml no-smart-quotes
|
||||
+3
@@ -0,0 +1,3 @@
|
||||
GNU General Public License v3.0+ (see LICENSES/GPL-3.0-or-later.txt or https://www.gnu.org/licenses/gpl-3.0.txt)
|
||||
SPDX-License-Identifier: GPL-3.0-or-later
|
||||
SPDX-FileCopyrightText: Ansible Project
|
||||
+15
@@ -0,0 +1,15 @@
|
||||
plugins/module_utils/_crypt.py import-3.11 # Uses deprecated stdlib library 'crypt'
|
||||
plugins/module_utils/_crypt.py import-3.12 # Uses deprecated stdlib library 'crypt'
|
||||
plugins/module_utils/_lxc.py pylint:ansible-bad-function # needs to use Popen() to stream logs
|
||||
plugins/modules/ansible_galaxy_install.py validate-modules:bad-return-value-key # TODO: rename offending return values if possible, or adjust this comment in case the name is OK
|
||||
plugins/modules/consul_session.py validate-modules:parameter-state-invalid-choice
|
||||
plugins/modules/gandi_livedns.py validate-modules:bad-return-value-key # TODO: rename offending return values if possible, or adjust this comment in case the name is OK
|
||||
plugins/modules/interfaces_file.py validate-modules:bad-return-value-key # TODO: rename offending return values if possible, or adjust this comment in case the name is OK
|
||||
plugins/modules/iptables_state.py validate-modules:undocumented-parameter # params _back and _timeout used by action plugin
|
||||
plugins/modules/nosh.py validate-modules:bad-return-value-key # TODO: rename offending return values if possible, or adjust this comment in case the name is OK
|
||||
plugins/modules/omapi_host.py validate-modules:bad-return-value-key # TODO: rename offending return values if possible, or adjust this comment in case the name is OK
|
||||
plugins/modules/osx_defaults.py validate-modules:parameter-state-invalid-choice
|
||||
plugins/modules/parted.py validate-modules:parameter-state-invalid-choice
|
||||
plugins/modules/rhevm.py validate-modules:parameter-state-invalid-choice
|
||||
plugins/modules/xfconf.py validate-modules:return-syntax-error
|
||||
tests/unit/plugins/modules/test_gio_mime.yaml no-smart-quotes
|
||||
+3
@@ -0,0 +1,3 @@
|
||||
GNU General Public License v3.0+ (see LICENSES/GPL-3.0-or-later.txt or https://www.gnu.org/licenses/gpl-3.0.txt)
|
||||
SPDX-License-Identifier: GPL-3.0-or-later
|
||||
SPDX-FileCopyrightText: Ansible Project
|
||||
+15
@@ -0,0 +1,15 @@
|
||||
plugins/module_utils/_crypt.py import-3.11 # Uses deprecated stdlib library 'crypt'
|
||||
plugins/module_utils/_crypt.py import-3.12 # Uses deprecated stdlib library 'crypt'
|
||||
plugins/module_utils/_lxc.py pylint:ansible-bad-function # needs to use Popen() to stream logs
|
||||
plugins/modules/ansible_galaxy_install.py validate-modules:bad-return-value-key # TODO: rename offending return values if possible, or adjust this comment in case the name is OK
|
||||
plugins/modules/consul_session.py validate-modules:parameter-state-invalid-choice
|
||||
plugins/modules/gandi_livedns.py validate-modules:bad-return-value-key # TODO: rename offending return values if possible, or adjust this comment in case the name is OK
|
||||
plugins/modules/interfaces_file.py validate-modules:bad-return-value-key # TODO: rename offending return values if possible, or adjust this comment in case the name is OK
|
||||
plugins/modules/iptables_state.py validate-modules:undocumented-parameter # params _back and _timeout used by action plugin
|
||||
plugins/modules/nosh.py validate-modules:bad-return-value-key # TODO: rename offending return values if possible, or adjust this comment in case the name is OK
|
||||
plugins/modules/omapi_host.py validate-modules:bad-return-value-key # TODO: rename offending return values if possible, or adjust this comment in case the name is OK
|
||||
plugins/modules/osx_defaults.py validate-modules:parameter-state-invalid-choice
|
||||
plugins/modules/parted.py validate-modules:parameter-state-invalid-choice
|
||||
plugins/modules/rhevm.py validate-modules:parameter-state-invalid-choice
|
||||
plugins/modules/xfconf.py validate-modules:return-syntax-error
|
||||
tests/unit/plugins/modules/test_gio_mime.yaml no-smart-quotes
|
||||
+3
@@ -0,0 +1,3 @@
|
||||
GNU General Public License v3.0+ (see LICENSES/GPL-3.0-or-later.txt or https://www.gnu.org/licenses/gpl-3.0.txt)
|
||||
SPDX-License-Identifier: GPL-3.0-or-later
|
||||
SPDX-FileCopyrightText: Ansible Project
|
||||
Reference in New Issue
Block a user