From b19b397ebf1e4b097ca64e2c9487117e7eb2b000 Mon Sep 17 00:00:00 2001 From: Emmanuel Garette Date: Mon, 25 Nov 2024 11:02:56 +0100 Subject: [PATCH] fix: new ansible plugin loader --- locale/fr/LC_MESSAGES/user_data_ansible.po | 21 ++++++ locale/user_data_ansible.pot | 21 ++++++ pyproject.toml | 41 ++++++++++++ .../fr/LC_MESSAGES/user_data_ansible.mo | Bin 0 -> 419 bytes src/rougail/user_data_ansible/__init__.py | 61 ++++++++++++++++++ src/rougail/user_data_ansible/config.py | 54 ++++++++++++++++ src/rougail/user_data_ansible/i18n.py | 26 ++++++++ 7 files changed, 224 insertions(+) create mode 100644 locale/fr/LC_MESSAGES/user_data_ansible.po create mode 100644 locale/user_data_ansible.pot create mode 100644 pyproject.toml create mode 100644 src/rougail/locale/fr/LC_MESSAGES/user_data_ansible.mo create mode 100644 src/rougail/user_data_ansible/__init__.py create mode 100644 src/rougail/user_data_ansible/config.py create mode 100644 src/rougail/user_data_ansible/i18n.py diff --git a/locale/fr/LC_MESSAGES/user_data_ansible.po b/locale/fr/LC_MESSAGES/user_data_ansible.po new file mode 100644 index 0000000..d57d2fe --- /dev/null +++ b/locale/fr/LC_MESSAGES/user_data_ansible.po @@ -0,0 +1,21 @@ +# SOME DESCRIPTIVE TITLE. +# Copyright (C) YEAR ORGANIZATION +# FIRST AUTHOR , YEAR. +# +msgid "" +msgstr "" +"Project-Id-Version: \n" +"POT-Creation-Date: 2024-11-25 10:49+0100\n" +"PO-Revision-Date: 2024-11-25 10:51+0100\n" +"Last-Translator: \n" +"Language-Team: \n" +"Language: fr\n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: 8bit\n" +"Generated-By: pygettext.py 1.5\n" +"X-Generator: Poedit 3.5\n" + +#: src/rougail/user_data_ansible/__init__.py:43 +msgid "ansible is not set in step.user_data" +msgstr "ansible n'est pas définit dans step.user_data" diff --git a/locale/user_data_ansible.pot b/locale/user_data_ansible.pot new file mode 100644 index 0000000..1ed7498 --- /dev/null +++ b/locale/user_data_ansible.pot @@ -0,0 +1,21 @@ +# SOME DESCRIPTIVE TITLE. +# Copyright (C) YEAR ORGANIZATION +# FIRST AUTHOR , YEAR. +# +msgid "" +msgstr "" +"Project-Id-Version: PACKAGE VERSION\n" +"POT-Creation-Date: 2024-11-25 10:53+0100\n" +"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" +"Last-Translator: FULL NAME \n" +"Language-Team: LANGUAGE \n" +"MIME-Version: 1.0\n" +"Content-Type: text/plain; charset=UTF-8\n" +"Content-Transfer-Encoding: 8bit\n" +"Generated-By: pygettext.py 1.5\n" + + +#: src/rougail/user_data_ansible/__init__.py:43 +msgid "ansible is not set in step.user_data" +msgstr "" + diff --git a/pyproject.toml b/pyproject.toml new file mode 100644 index 0000000..c2da998 --- /dev/null +++ b/pyproject.toml @@ -0,0 +1,41 @@ +[build-system] +build-backend = "flit_core.buildapi" +requires = ["flit_core >=3.8.0,<4"] + +[project] +name = "rougail.user_data_ansible" +version = "0.0.0" +authors = [{name = "Emmanuel Garette", email = "gnunux@gnunux.info"}] +readme = "README.md" +description = "Rougail user_data ansible" +requires-python = ">=3.8" +license = {file = "LICENSE"} +classifiers = [ + "License :: OSI Approved :: GNU Library or Lesser General Public License (LGPL)", + "Programming Language :: Python", + "Programming Language :: Python :: 3.8", + "Programming Language :: Python :: 3.9", + "Programming Language :: Python :: 3.10", + "Programming Language :: Python :: 3.11", + "Programming Language :: Python :: 3.12", + "Programming Language :: Python :: 3", + "Operating System :: OS Independent", + "Natural Language :: English", + "Natural Language :: French", + +] +dependencies = [ + "rougail-user-data-file >= 0.1,<2", + "ansible", +] + +[project.urls] +Home = "https://forge.cloud.silique.fr/stove/rougail-user-data-file" + +[tool.commitizen] +name = "cz_conventional_commits" +tag_format = "$version" +version_scheme = "pep440" +version_provider = "pep621" +update_changelog_on_bump = true +changelog_merge_prerelease = true diff --git a/src/rougail/locale/fr/LC_MESSAGES/user_data_ansible.mo b/src/rougail/locale/fr/LC_MESSAGES/user_data_ansible.mo new file mode 100644 index 0000000000000000000000000000000000000000..7128b266eebe04b78261770a28e06554b03ef07d GIT binary patch literal 419 zcmZ9I&q~8U5XPhEB}dO5<{)^`joE6TM7^k03N1#7;!U>MX+B*@^$~28fDv&5W8_g6s&z&P>>$$2?l&GHm#5qiTJRXh*OBb1>@u{=l# lz7yXC-HwGrZ3y=HKl(Y5-Nr!Br~vxyb!sfl1Cec0vFE literal 0 HcmV?d00001 diff --git a/src/rougail/user_data_ansible/__init__.py b/src/rougail/user_data_ansible/__init__.py new file mode 100644 index 0000000..a3ad815 --- /dev/null +++ b/src/rougail/user_data_ansible/__init__.py @@ -0,0 +1,61 @@ +""" +Silique (https://www.silique.fr) +Copyright (C) 2024 + +This program is free software: you can redistribute it and/or modify it +under the terms of the GNU Lesser General Public License as published by the +Free Software Foundation, either version 3 of the License, or (at your +option) any later version. + +This program is distributed in the hope that it will be useful, but WITHOUT +ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS +FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more +details. + +You should have received a copy of the GNU Lesser General Public License +along with this program. If not, see . +""" + +from rougail import RougailConfig +from rougail.user_data_file import RougailUserDataFile +from ansible.parsing.vault import VaultLib, PromptVaultSecret +from ansible.module_utils._text import to_bytes +from pathlib import Path + +from .i18n import _ + + +class RougailUserDataAnsible(RougailUserDataFile): + def __init__( + self, + config, + *, + rougailconfig=None, + ) -> None: + if rougailconfig is None: + rougailconfig = RougailConfig + user_data = rougailconfig["step.user_data"] + if "ansible" not in user_data: + user_data.append("ansible") + rougailconfig["step.user_data"] = user_data + user_data = rougailconfig["step.user_data"] + if "ansible" not in user_data: + raise Exception(_("ansible is not set in step.user_data")) + self.rougailconfig = rougailconfig + self.filenames = self.rougailconfig["ansible.filename"] + self.secret = self.rougailconfig["ansible.secret"] + self.config = config + self.errors = [] + self.warnings = [] + + def open(self, filename: str) -> dict: + prompt = PromptVaultSecret(to_bytes(self.secret), 'default', ["Vault password: "]) + vault = VaultLib([('default', prompt)]) + with Path(filename).open('rb') as fh: + return self.yaml.load(vault.decrypt(fh.read())) + + +RougailUserData = RougailUserDataAnsible + + +__all__ = ("RougailUserDataAnsible",) diff --git a/src/rougail/user_data_ansible/config.py b/src/rougail/user_data_ansible/config.py new file mode 100644 index 0000000..e55b11e --- /dev/null +++ b/src/rougail/user_data_ansible/config.py @@ -0,0 +1,54 @@ +""" +Silique (https://www.silique.fr) +Copyright (C) 2024 + +This program is free software: you can redistribute it and/or modify it +under the terms of the GNU Lesser General Public License as published by the +Free Software Foundation, either version 3 of the License, or (at your +option) any later version. + +This program is distributed in the hope that it will be useful, but WITHOUT +ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS +FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more +details. + +You should have received a copy of the GNU Lesser General Public License +along with this program. If not, see . +""" + + +def get_rougail_config( + *, + backward_compatibility=True, +) -> dict: + options = """ +ansible: + description: Configuration rougail-user-data-ansible + disabled: + type: jinja + jinja: | + {% if 'ansible' not in step.user_data %} + disabled + {% endif %} + filename: + description: Ansible filename inventory + type: unix_filename + multi: true + params: + allow_relative: True + test_existence: True + types: + - file + secret: + description: Secret to decrypt file + type: secret +""" + return { + "name": "ansible", + "process": "user data", + "options": options, + "level": 60, + } + + +__all__ = "get_rougail_config" diff --git a/src/rougail/user_data_ansible/i18n.py b/src/rougail/user_data_ansible/i18n.py new file mode 100644 index 0000000..605ae65 --- /dev/null +++ b/src/rougail/user_data_ansible/i18n.py @@ -0,0 +1,26 @@ +"""Internationalisation utilities +Silique (https://www.silique.fr) +Copyright (C) 2024 + +This program is free software: you can redistribute it and/or modify it +under the terms of the GNU Lesser General Public License as published by the +Free Software Foundation, either version 3 of the License, or (at your +option) any later version. + +This program is distributed in the hope that it will be useful, but WITHOUT +ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS +FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more +details. + +You should have received a copy of the GNU Lesser General Public License +along with this program. If not, see . +""" + +from gettext import translation +from pathlib import Path + +t = translation( + "rougail_user_data_ansible", str(Path(__file__).parent / "locale"), fallback=True +) + +_ = t.gettext