feat: add new parameter yaml.file_with_secrets

This commit is contained in:
egarette@silique.fr 2025-02-10 09:23:33 +01:00
parent b0fdef7a52
commit d4f81987e6
13 changed files with 100 additions and 19 deletions

View file

@ -5,8 +5,8 @@
msgid "" msgid ""
msgstr "" msgstr ""
"Project-Id-Version: \n" "Project-Id-Version: \n"
"POT-Creation-Date: 2024-12-11 21:26+0100\n" "POT-Creation-Date: 2025-02-10 09:21+0100\n"
"PO-Revision-Date: 2024-12-11 21:27+0100\n" "PO-Revision-Date: 2025-02-10 09:22+0100\n"
"Last-Translator: \n" "Last-Translator: \n"
"Language-Team: \n" "Language-Team: \n"
"Language: fr\n" "Language: fr\n"
@ -20,16 +20,28 @@ msgstr ""
msgid "yaml is not set in step.user_data" msgid "yaml is not set in step.user_data"
msgstr "\"yaml\" n'est pas défini dans step.user_data" msgstr "\"yaml\" n'est pas défini dans step.user_data"
#: src/rougail/user_data_yaml/__init__.py:61 #: src/rougail/user_data_yaml/__init__.py:62
msgid "cannot load \"{0}\", the root value is not a dict but \"{1}\"" msgid "cannot load \"{0}\", the root value is not a dict but \"{1}\""
msgstr "" msgstr ""
"ne peut charger \"{0}\", la valeur racine n'est pas une dictionnaire mais " "ne peut charger \"{0}\", la valeur racine n'est pas une dictionnaire mais "
"\"{1}\"" "\"{1}\""
#: src/rougail/user_data_yaml/__init__.py:74 #: src/rougail/user_data_yaml/__init__.py:85
msgid "yaml ({0})" msgid "yaml ({0})"
msgstr "fichier yaml ({0})" msgstr "fichier yaml ({0})"
#: src/rougail/user_data_yaml/__init__.py:103 #: src/rougail/user_data_yaml/__init__.py:116
msgid "\"{0}\" in {1} has an unknown value" msgid "\"{0}\" in {1} has an unknown value"
msgstr "\"{0}\" dans {1} a une valeur inconnue" msgstr "\"{0}\" dans {1} a une valeur inconnue"
#: src/rougail/user_data_yaml/config.py:29
msgid "Configuration rougail-user-data-yaml"
msgstr "Configuration de rougail-user-data-yaml"
#: src/rougail/user_data_yaml/config.py:38
msgid "Filename"
msgstr "Nom du fichier"
#: src/rougail/user_data_yaml/config.py:49
msgid "File that may contain secrets"
msgstr "Le fichier peut contenir des secrets"

View file

@ -5,7 +5,7 @@
msgid "" msgid ""
msgstr "" msgstr ""
"Project-Id-Version: PACKAGE VERSION\n" "Project-Id-Version: PACKAGE VERSION\n"
"POT-Creation-Date: 2024-12-11 21:27+0100\n" "POT-Creation-Date: 2025-02-10 09:22+0100\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n" "Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <LL@li.org>\n" "Language-Team: LANGUAGE <LL@li.org>\n"
@ -19,15 +19,27 @@ msgstr ""
msgid "yaml is not set in step.user_data" msgid "yaml is not set in step.user_data"
msgstr "" msgstr ""
#: src/rougail/user_data_yaml/__init__.py:61 #: src/rougail/user_data_yaml/__init__.py:62
msgid "cannot load \"{0}\", the root value is not a dict but \"{1}\"" msgid "cannot load \"{0}\", the root value is not a dict but \"{1}\""
msgstr "" msgstr ""
#: src/rougail/user_data_yaml/__init__.py:74 #: src/rougail/user_data_yaml/__init__.py:85
msgid "yaml ({0})" msgid "yaml ({0})"
msgstr "" msgstr ""
#: src/rougail/user_data_yaml/__init__.py:103 #: src/rougail/user_data_yaml/__init__.py:116
msgid "\"{0}\" in {1} has an unknown value" msgid "\"{0}\" in {1} has an unknown value"
msgstr "" msgstr ""
#: src/rougail/user_data_yaml/config.py:29
msgid "Configuration rougail-user-data-yaml"
msgstr ""
#: src/rougail/user_data_yaml/config.py:38
msgid "Filename"
msgstr ""
#: src/rougail/user_data_yaml/config.py:49
msgid "File that may contain secrets"
msgstr ""

View file

@ -1,6 +1,6 @@
""" """
Silique (https://www.silique.fr) Silique (https://www.silique.fr)
Copyright (C) 2024 Copyright (C) 2024-2025
This program is free software: you can redistribute it and/or modify it 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 under the terms of the GNU Lesser General Public License as published by the
@ -17,7 +17,6 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
""" """
from ruamel.yaml import YAML from ruamel.yaml import YAML
from rougail import RougailConfig
from rougail.error import ExtentionError from rougail.error import ExtentionError
from tiramisu.error import ValueOptionError, PropertiesOptionError, LeadershipError from tiramisu.error import ValueOptionError, PropertiesOptionError, LeadershipError
@ -32,6 +31,7 @@ class RougailUserDataYaml:
rougailconfig=None, rougailconfig=None,
) -> None: ) -> None:
if rougailconfig is None: if rougailconfig is None:
from rougail import RougailConfig
rougailconfig = RougailConfig rougailconfig = RougailConfig
user_data = rougailconfig["step.user_data"] user_data = rougailconfig["step.user_data"]
if "yaml" not in user_data: if "yaml" not in user_data:
@ -42,6 +42,7 @@ class RougailUserDataYaml:
raise ExtentionError(_("yaml is not set in step.user_data")) raise ExtentionError(_("yaml is not set in step.user_data"))
self.rougailconfig = rougailconfig self.rougailconfig = rougailconfig
self.filenames = self.rougailconfig["yaml.filename"] self.filenames = self.rougailconfig["yaml.filename"]
self.file_with_secrets = self.rougailconfig["yaml.file_with_secrets"]
self.config = config self.config = config
self.errors = [] self.errors = []
self.warnings = [] self.warnings = []
@ -51,7 +52,7 @@ class RougailUserDataYaml:
) -> None: ) -> None:
self.yaml = YAML() self.yaml = YAML()
user_datas = [] user_datas = []
for filename in self.filenames: for idx, filename in enumerate(self.filenames):
file_values = self.open(filename) file_values = self.open(filename)
if not file_values: if not file_values:
continue continue
@ -69,12 +70,24 @@ class RougailUserDataYaml:
file_values, file_values,
filename, filename,
) )
if self.file_with_secrets == 'none':
allow_secrets_variables = False
elif self.file_with_secrets == 'first':
allow_secrets_variables = idx == 0
elif self.file_with_secrets == 'last':
if not idx:
last_filenames = len(self.filenames) - 1
allow_secrets_variables = idx == last_filenames
else:
allow_secrets_variables = True
user_datas.append( user_datas.append(
{ {
"source": _("yaml ({0})").format(filename), "source": _("yaml ({0})").format(filename),
"errors": self.errors, "errors": self.errors,
"warnings": self.warnings, "warnings": self.warnings,
"values": values, "values": values,
'options': {'allow_secrets_variables': allow_secrets_variables,
},
} }
) )
return user_datas return user_datas

View file

@ -2,7 +2,7 @@
Config yaml for Rougail-user-data Config yaml for Rougail-user-data
Silique (https://www.silique.fr) Silique (https://www.silique.fr)
Copyright (C) 2024 Copyright (C) 2024-2025
This program is free software: you can redistribute it and/or modify it 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 under the terms of the GNU Lesser General Public License as published by the
@ -17,23 +17,25 @@ details.
You should have received a copy of the GNU Lesser General Public License You should have received a copy of the GNU Lesser General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>. along with this program. If not, see <http://www.gnu.org/licenses/>.
""" """
from .i18n import _
def get_rougail_config( def get_rougail_config(
*, *,
backward_compatibility=True, backward_compatibility=True,
) -> dict: ) -> dict:
options = """ options = f"""
yaml: yaml:
description: Configuration rougail-user-data-yaml description: {_("Configuration rougail-user-data-yaml")}
disabled: disabled:
type: jinja type: jinja
jinja: | jinja: |
{% if 'yaml' not in step.user_data %} {{% if 'yaml' not in step.user_data %}}
disabled disabled
{% endif %} {{% endif %}}
filename: filename:
description: Filename description: {_("Filename")}
alternative_name: ff alternative_name: ff
type: unix_filename type: unix_filename
multi: true multi: true
@ -42,6 +44,15 @@ yaml:
test_existence: True test_existence: True
types: types:
- file - file
file_with_secrets:
description: {_("File that may contain secrets")}
default: all
choices:
- all
- first
- last
- none
""" """
return { return {
"name": "yaml", "name": "yaml",

View file

@ -1,6 +1,6 @@
"""Internationalisation utilities """Internationalisation utilities
Silique (https://www.silique.fr) Silique (https://www.silique.fr)
Copyright (C) 2024 Copyright (C) 2024-2025
This program is free software: you can redistribute it and/or modify it 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 under the terms of the GNU Lesser General Public License as published by the

View file

@ -0,0 +1,4 @@
{
"errors": [],
"warnings": []
}

View file

@ -0,0 +1,4 @@
{
"errors": [],
"warnings": []
}

View file

@ -0,0 +1,6 @@
{
"rougail": {
"secret1": "string1",
"secret2": "string1"
}
}

View file

@ -0,0 +1,6 @@
{
"rougail": {
"secret1": "string1",
"secret2": "string1"
}
}

View file

@ -0,0 +1,5 @@
{
"rougail": {
"secret1": "string1"
}
}

View file

@ -0,0 +1,4 @@
{
"rougail.secret1": "string1",
"rougail.secret2": "string1"
}

View file

@ -0,0 +1,4 @@
{
"rougail.secret1": "string1",
"rougail.secret2": "value"
}