fix: many improvment
This commit is contained in:
parent
abb4b87924
commit
971311e0f5
41 changed files with 681 additions and 209 deletions
98
locale/fr/LC_MESSAGES/user_data_bitwarden.po
Normal file
98
locale/fr/LC_MESSAGES/user_data_bitwarden.po
Normal file
|
@ -0,0 +1,98 @@
|
|||
# SOME DESCRIPTIVE TITLE.
|
||||
# Copyright (C) YEAR ORGANIZATION
|
||||
# FIRST AUTHOR <EMAIL@ADDRESS>, YEAR.
|
||||
#
|
||||
msgid ""
|
||||
msgstr ""
|
||||
"Project-Id-Version: \n"
|
||||
"POT-Creation-Date: 2025-02-12 15:36+0100\n"
|
||||
"PO-Revision-Date: 2025-02-12 15:39+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_bitwarden/annotator.py:46
|
||||
msgid ""
|
||||
"only \"unix_user\" or \"secret\" variable type can have \"bitwarden\" "
|
||||
"attribute, but \"{0}\" has type \"{1}\""
|
||||
msgstr ""
|
||||
"seule une variable de type \"unix_user\" ou \"secret\" peuvent avoir "
|
||||
"l'attribut \"bitwarden\", mais \"{0}\" a le type \"{1}\""
|
||||
|
||||
#: src/rougail/user_data_bitwarden/annotator.py:49
|
||||
msgid ""
|
||||
"the variable \"{0}\" has attribute \"bitwarden\" but is a multi variable"
|
||||
msgstr ""
|
||||
"la variable \"{0}\" a un attribut \"bitwarden\" mais est une variable "
|
||||
"multiple"
|
||||
|
||||
#: src/rougail/user_data_bitwarden/annotator.py:58
|
||||
msgid ""
|
||||
"the variable \"{0}\" is a follower and leader variable (\"{1}\") is also in "
|
||||
"Bitwarden so this variable could not have default value"
|
||||
msgstr ""
|
||||
"la variable \"{0}\" est une suiveuse et la variable leader (\"{1}\") est "
|
||||
"aussi dans Bitwarden donc cette variable ne peut avoir de valeur par défaut"
|
||||
|
||||
#: src/rougail/user_data_bitwarden/annotator.py:62
|
||||
msgid "the variable \"{0}\" is in Bitwarden so should have default value"
|
||||
msgstr ""
|
||||
"la variable \"{0}\" est dans Bitwarden donc doit avoir une valeur par défaut"
|
||||
|
||||
#: src/rougail/user_data_bitwarden/data.py:51
|
||||
msgid "\"bitwarden\" is not set in step.user_data"
|
||||
msgstr "\"bitwarden\" n'est pas dans step.user_data"
|
||||
|
||||
#: src/rougail/user_data_bitwarden/data.py:70
|
||||
msgid ""
|
||||
"the value for \"{0}\" at index {1} is already set while it should be filled "
|
||||
"in by Bitwarden"
|
||||
msgstr ""
|
||||
"la valeur de \"{0}\" à l'index {1} est déjà renseigné alors que celle doit "
|
||||
"devrait être renseigné par Bitwarden"
|
||||
|
||||
#: src/rougail/user_data_bitwarden/data.py:72
|
||||
msgid ""
|
||||
"the value for \"{0}\" is already set while it should be filled in by "
|
||||
"Bitwarden"
|
||||
msgstr ""
|
||||
"la valeur de \"{0}\" est déjà renseigné alors que celle doit devrait être "
|
||||
"renseigné par Bitwarden"
|
||||
|
||||
#: src/rougail/user_data_bitwarden/data.py:101
|
||||
msgid "the default value for \"{0}\" must be the Bitwarden item name"
|
||||
msgstr ""
|
||||
"la valeur par défaut pour \"{0}\" doit être un nom d'élément de Bitwarden"
|
||||
|
||||
#: src/rougail/user_data_bitwarden/data.py:110
|
||||
msgid "cannot execute the \"bw\" commandline from Bitwarden for \"{0}\": {1}"
|
||||
msgstr ""
|
||||
"ne peut exécuter la ligne de commande \"bw\" pour Bitwarden pour \"{0}\": {1}"
|
||||
|
||||
#: src/rougail/user_data_bitwarden/data.py:115
|
||||
msgid "cannot get {0} \"{1}\" from Bitwarden for \"{2}\": {3} ({4})"
|
||||
msgstr "ne peut récupérer {0} \"{1}\" pour Bitwarden pour \"{2}\": {3} ({4})"
|
||||
|
||||
#: src/rougail/user_data_bitwarden/data.py:120
|
||||
msgid "cannot load {0} \"{1}\" from Bitwarden for \"{2}\": {3}"
|
||||
msgstr "ne peut charger {0} \"{1}\" pour Bitwarden pour \"{2}\": {3}"
|
||||
|
||||
#: src/rougail/user_data_bitwarden/data.py:123
|
||||
msgid "cannot find {0} \"{1}\" from Bitwarden for \"{2}\""
|
||||
msgstr "ne peut trouver {0} \"{1}\" pour Bitwarden pour \"{2}\""
|
||||
|
||||
#: src/rougail/user_data_bitwarden/data.py:130
|
||||
msgid ""
|
||||
"several items found with name \"{0}\" from Bitwarden for \"{1}\": \"{2}\""
|
||||
msgstr ""
|
||||
"plusieurs éléments trouvés avec le nom \"{0}\" pour Bitwarden pour \"{1}\": "
|
||||
"\"{2}\""
|
||||
|
||||
#: src/rougail/user_data_bitwarden/data.py:140
|
||||
msgid "unexpected datas \"{0}\" from Bitwarden for \"{1}\": {2}"
|
||||
msgstr "données inattendues \"{0}\" pour Bitwarden pour \"{1}\": {2}"
|
|
@ -1,49 +0,0 @@
|
|||
# SOME DESCRIPTIVE TITLE.
|
||||
# Copyright (C) YEAR ORGANIZATION
|
||||
# FIRST AUTHOR <EMAIL@ADDRESS>, YEAR.
|
||||
#
|
||||
msgid ""
|
||||
msgstr ""
|
||||
"Project-Id-Version: \n"
|
||||
"POT-Creation-Date: 2025-02-05 11:18+0100\n"
|
||||
"PO-Revision-Date: 2025-02-05 11:21+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_bitwarden/data.py:50
|
||||
msgid "\"bitwarden\" is not set in step.user_data"
|
||||
msgstr "\"bitwarden\" n'est pas dans step.user_data"
|
||||
|
||||
#: src/rougail/user_data_bitwarden/data.py:67
|
||||
msgid "the default value for \"{0}\" must be the Bitwarden password name"
|
||||
msgstr "la valeur par défaut pour \"{0}\" doit être un nom de mot de passe de Bitwarden"
|
||||
|
||||
#: src/rougail/user_data_bitwarden/data.py:72
|
||||
msgid "cannot execute the \"bw\" commandline from Bitwarden for \"{0}\": {1}"
|
||||
msgstr "ne peut exécuter la ligne de commande \"bw\" pour Bitwarden pour \"{0}\": {1}"
|
||||
|
||||
#: src/rougail/user_data_bitwarden/data.py:77
|
||||
msgid "cannot get password \"{0}\" from Bitwarden for \"{1}\": {2} ({3})"
|
||||
msgstr "ne peut récupérer le mot de passe \"{0}\" pour Bitwarden pour \"{1}\": {2} ({3})"
|
||||
|
||||
#: src/rougail/user_data_bitwarden/data.py:82
|
||||
msgid "cannot load password \"{0}\" from Bitwarden for \"{1}\": {2}"
|
||||
msgstr "ne peut charger le mot de passe \"{0}\" pour Bitwarden pour \"{1}\": {2}"
|
||||
|
||||
#: src/rougail/user_data_bitwarden/data.py:85
|
||||
msgid "cannot find password \"{0}\" from Bitwarden for \"{1}\""
|
||||
msgstr "ne peut trouver le mot de passe \"{0}\" pour Bitwarden pour \"{1}\""
|
||||
|
||||
#: src/rougail/user_data_bitwarden/data.py:89
|
||||
msgid "several passwords found with name \"{0}\" from Bitwarden for \"{1}\": \"{2}\""
|
||||
msgstr "plusieurs mots de passe trouvés avec le nom \"{0}\" pour Bitwarden pour \"{1}\": \"{2}\""
|
||||
|
||||
#: src/rougail/user_data_bitwarden/data.py:94
|
||||
msgid "unexpected password \"{0}\" from Bitwarden for \"{1}\": {2}"
|
||||
msgstr "mot de passe inattendu \"{0}\" pour Bitwarden pour \"{1}\": {2}"
|
73
locale/rougail_user_data_bitwarden.pot
Normal file
73
locale/rougail_user_data_bitwarden.pot
Normal file
|
@ -0,0 +1,73 @@
|
|||
# SOME DESCRIPTIVE TITLE.
|
||||
# Copyright (C) YEAR ORGANIZATION
|
||||
# FIRST AUTHOR <EMAIL@ADDRESS>, YEAR.
|
||||
#
|
||||
msgid ""
|
||||
msgstr ""
|
||||
"Project-Id-Version: PACKAGE VERSION\n"
|
||||
"POT-Creation-Date: 2025-02-12 15:39+0100\n"
|
||||
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
|
||||
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
|
||||
"Language-Team: LANGUAGE <LL@li.org>\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_bitwarden/annotator.py:46
|
||||
msgid "only \"unix_user\" or \"secret\" variable type can have \"bitwarden\" attribute, but \"{0}\" has type \"{1}\""
|
||||
msgstr ""
|
||||
|
||||
#: src/rougail/user_data_bitwarden/annotator.py:49
|
||||
msgid "the variable \"{0}\" has attribute \"bitwarden\" but is a multi variable"
|
||||
msgstr ""
|
||||
|
||||
#: src/rougail/user_data_bitwarden/annotator.py:58
|
||||
msgid "the variable \"{0}\" is a follower and leader variable (\"{1}\") is also in Bitwarden so this variable could not have default value"
|
||||
msgstr ""
|
||||
|
||||
#: src/rougail/user_data_bitwarden/annotator.py:62
|
||||
msgid "the variable \"{0}\" is in Bitwarden so should have default value"
|
||||
msgstr ""
|
||||
|
||||
#: src/rougail/user_data_bitwarden/data.py:51
|
||||
msgid "\"bitwarden\" is not set in step.user_data"
|
||||
msgstr ""
|
||||
|
||||
#: src/rougail/user_data_bitwarden/data.py:70
|
||||
msgid "the value for \"{0}\" at index {1} is already set while it should be filled in by Bitwarden"
|
||||
msgstr ""
|
||||
|
||||
#: src/rougail/user_data_bitwarden/data.py:72
|
||||
msgid "the value for \"{0}\" is already set while it should be filled in by Bitwarden"
|
||||
msgstr ""
|
||||
|
||||
#: src/rougail/user_data_bitwarden/data.py:101
|
||||
msgid "the default value for \"{0}\" must be the Bitwarden item name"
|
||||
msgstr ""
|
||||
|
||||
#: src/rougail/user_data_bitwarden/data.py:110
|
||||
msgid "cannot execute the \"bw\" commandline from Bitwarden for \"{0}\": {1}"
|
||||
msgstr ""
|
||||
|
||||
#: src/rougail/user_data_bitwarden/data.py:115
|
||||
msgid "cannot get {0} \"{1}\" from Bitwarden for \"{2}\": {3} ({4})"
|
||||
msgstr ""
|
||||
|
||||
#: src/rougail/user_data_bitwarden/data.py:120
|
||||
msgid "cannot load {0} \"{1}\" from Bitwarden for \"{2}\": {3}"
|
||||
msgstr ""
|
||||
|
||||
#: src/rougail/user_data_bitwarden/data.py:123
|
||||
msgid "cannot find {0} \"{1}\" from Bitwarden for \"{2}\""
|
||||
msgstr ""
|
||||
|
||||
#: src/rougail/user_data_bitwarden/data.py:130
|
||||
msgid "several items found with name \"{0}\" from Bitwarden for \"{1}\": \"{2}\""
|
||||
msgstr ""
|
||||
|
||||
#: src/rougail/user_data_bitwarden/data.py:140
|
||||
msgid "unexpected datas \"{0}\" from Bitwarden for \"{1}\": {2}"
|
||||
msgstr ""
|
||||
|
|
@ -1,49 +0,0 @@
|
|||
# SOME DESCRIPTIVE TITLE.
|
||||
# Copyright (C) YEAR ORGANIZATION
|
||||
# FIRST AUTHOR <EMAIL@ADDRESS>, YEAR.
|
||||
#
|
||||
msgid ""
|
||||
msgstr ""
|
||||
"Project-Id-Version: PACKAGE VERSION\n"
|
||||
"POT-Creation-Date: 2025-02-05 11:21+0100\n"
|
||||
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
|
||||
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
|
||||
"Language-Team: LANGUAGE <LL@li.org>\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_bitwarden/data.py:50
|
||||
msgid "\"bitwarden\" is not set in step.user_data"
|
||||
msgstr ""
|
||||
|
||||
#: src/rougail/user_data_bitwarden/data.py:67
|
||||
msgid "the default value for \"{0}\" must be the Bitwarden password name"
|
||||
msgstr ""
|
||||
|
||||
#: src/rougail/user_data_bitwarden/data.py:72
|
||||
msgid "cannot execute the \"bw\" commandline from Bitwarden for \"{0}\": {1}"
|
||||
msgstr ""
|
||||
|
||||
#: src/rougail/user_data_bitwarden/data.py:77
|
||||
msgid "cannot get password \"{0}\" from Bitwarden for \"{1}\": {2} ({3})"
|
||||
msgstr ""
|
||||
|
||||
#: src/rougail/user_data_bitwarden/data.py:82
|
||||
msgid "cannot load password \"{0}\" from Bitwarden for \"{1}\": {2}"
|
||||
msgstr ""
|
||||
|
||||
#: src/rougail/user_data_bitwarden/data.py:85
|
||||
msgid "cannot find password \"{0}\" from Bitwarden for \"{1}\""
|
||||
msgstr ""
|
||||
|
||||
#: src/rougail/user_data_bitwarden/data.py:89
|
||||
msgid "several passwords found with name \"{0}\" from Bitwarden for \"{1}\": \"{2}\""
|
||||
msgstr ""
|
||||
|
||||
#: src/rougail/user_data_bitwarden/data.py:94
|
||||
msgid "unexpected password \"{0}\" from Bitwarden for \"{1}\": {2}"
|
||||
msgstr ""
|
||||
|
22
src/rougail/structural_bitwarden/__init__.py
Normal file
22
src/rougail/structural_bitwarden/__init__.py
Normal file
|
@ -0,0 +1,22 @@
|
|||
"""
|
||||
Silique (https://www.silique.fr)
|
||||
Copyright (C) 2025
|
||||
|
||||
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 <http://www.gnu.org/licenses/>.
|
||||
"""
|
||||
from .object_model import Variable
|
||||
|
||||
|
||||
__all__ = ("Variable",)
|
||||
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
32
src/rougail/structural_bitwarden/config.py
Normal file
32
src/rougail/structural_bitwarden/config.py
Normal file
|
@ -0,0 +1,32 @@
|
|||
"""
|
||||
Silique (https://www.silique.fr)
|
||||
Copyright (C) 2025
|
||||
|
||||
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 <http://www.gnu.org/licenses/>.
|
||||
"""
|
||||
|
||||
|
||||
def get_rougail_config(
|
||||
*,
|
||||
backward_compatibility: bool = True, # pylint: disable=unused-argument
|
||||
) -> dict:
|
||||
return {
|
||||
"name": "bitwarden",
|
||||
"process": "structural",
|
||||
"level": 90,
|
||||
}
|
||||
|
||||
|
||||
__all__ = ("get_rougail_config",)
|
||||
|
31
src/rougail/structural_bitwarden/object_model.py
Normal file
31
src/rougail/structural_bitwarden/object_model.py
Normal file
|
@ -0,0 +1,31 @@
|
|||
"""
|
||||
Silique (https://www.silique.fr)
|
||||
Copyright (C) 2025
|
||||
|
||||
distribued with GPL-2 or later license
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 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 General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program; if not, write to the Free Software
|
||||
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
"""
|
||||
from typing import Optional
|
||||
from pydantic import BaseModel
|
||||
|
||||
|
||||
class Variable(BaseModel):
|
||||
bitwarden: bool=False
|
||||
|
||||
|
||||
__all__ = ('Variable',)
|
||||
|
||||
|
|
@ -1,3 +1,24 @@
|
|||
"""
|
||||
Silique (https://www.silique.fr)
|
||||
Copyright (C) 2025
|
||||
|
||||
distribued with GPL-2 or later license
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 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 General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program; if not, write to the Free Software
|
||||
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
"""
|
||||
|
||||
from .data import RougailUserDataBitwarden
|
||||
RougailUserData = RougailUserDataBitwarden
|
||||
__all__ = ('RougailUserDataBitwarden',)
|
||||
|
|
64
src/rougail/user_data_bitwarden/annotator.py
Normal file
64
src/rougail/user_data_bitwarden/annotator.py
Normal file
|
@ -0,0 +1,64 @@
|
|||
"""
|
||||
Silique (https://www.silique.fr)
|
||||
Copyright (C) 2025
|
||||
|
||||
distribued with GPL-2 or later license
|
||||
|
||||
This program is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 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 General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program; if not, write to the Free Software
|
||||
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
"""
|
||||
from rougail.error import DictConsistencyError
|
||||
from rougail.annotator.variable import Walk
|
||||
from .i18n import _
|
||||
|
||||
|
||||
class Annotator(Walk):
|
||||
"""Annotate for bitwarden"""
|
||||
|
||||
level = 95
|
||||
|
||||
def __init__(
|
||||
self,
|
||||
objectspace,
|
||||
*args, # pylint: disable=unused-argument
|
||||
) -> None:
|
||||
if not objectspace.paths:
|
||||
return
|
||||
self.objectspace = objectspace
|
||||
self.check_variable()
|
||||
|
||||
def check_variable(self):
|
||||
for variable in self.get_variables():
|
||||
if not variable.bitwarden:
|
||||
continue
|
||||
if variable.type not in ["unix_user", "secret"]:
|
||||
msg = _('only "unix_user" or "secret" variable type can have "bitwarden" attribute, but "{0}" has type "{1}"')
|
||||
raise DictConsistencyError(msg.format(variable.path, variable.type), 301, variable.xmlfiles)
|
||||
if variable.multi and variable.path not in self.objectspace.leaders:
|
||||
msg = _('the variable "{0}" has attribute "bitwarden" but is a multi variable')
|
||||
raise DictConsistencyError(msg.format(variable.path), 302, variable.xmlfiles)
|
||||
check_default_value = True
|
||||
if variable.path in self.objectspace.followers:
|
||||
leadership = variable.path.rsplit('.', 1)[0]
|
||||
leader_path = self.objectspace.parents[leadership][0]
|
||||
leader = self.objectspace.paths[leader_path]
|
||||
if leader.bitwarden:
|
||||
if variable.default:
|
||||
msg = _('the variable "{0}" is a follower and leader variable ("{1}") is also in Bitwarden so this variable could not have default value')
|
||||
raise DictConsistencyError(msg.format(variable.path, leader_path), 303, variable.xmlfiles)
|
||||
check_default_value = False
|
||||
if check_default_value and not variable.default:
|
||||
msg = _('the variable "{0}" is in Bitwarden so should have default value')
|
||||
raise DictConsistencyError(msg.format(variable.path), 304, variable.xmlfiles)
|
||||
self.objectspace.informations.add(variable.path, "bitwarden", True)
|
|
@ -23,8 +23,25 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|||
def get_rougail_config(*,
|
||||
backward_compatibility=True,
|
||||
) -> dict:
|
||||
options = """
|
||||
step:
|
||||
|
||||
structural:
|
||||
redefine: true
|
||||
default:
|
||||
jinja: |-
|
||||
{% if step.user_data == ['bitwarden'] %}
|
||||
bitwarden
|
||||
{% endif %}
|
||||
{% if step.user_data == ['risotto'] %}
|
||||
risotto
|
||||
{% else %}
|
||||
directory
|
||||
{% endif %}
|
||||
"""
|
||||
return {'name': 'bitwarden',
|
||||
'process': 'user data',
|
||||
"options": options,
|
||||
'level': 90,
|
||||
}
|
||||
|
||||
|
|
|
@ -21,6 +21,7 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
|||
|
||||
from subprocess import run
|
||||
from json import loads
|
||||
from os import environ
|
||||
|
||||
|
||||
from rougail.error import ExtentionError
|
||||
|
@ -50,6 +51,7 @@ class RougailUserDataBitwarden:
|
|||
raise ExtentionError(_('"bitwarden" is not set in step.user_data'))
|
||||
self.errors = []
|
||||
self.warnings = []
|
||||
self.leader_informations = {}
|
||||
|
||||
def run(self):
|
||||
self.set_passwords(self.config)
|
||||
|
@ -61,35 +63,79 @@ class RougailUserDataBitwarden:
|
|||
for option in optiondescription:
|
||||
if option.isoptiondescription():
|
||||
self.set_passwords(option)
|
||||
elif option.owner.isdefault() and option.type() == 'password':
|
||||
key_bitwarden = option.value.get()
|
||||
if not isinstance(key_bitwarden, str):
|
||||
self.errors.append(_('the default value for "{0}" must be the Bitwarden password name').format(option.path()))
|
||||
continue
|
||||
try:
|
||||
cpe = run(["bw", "list", "items", "--search", key_bitwarden, '--nointeraction'], capture_output=True)
|
||||
except Exception as exc:
|
||||
self.errors.append(_('cannot execute the "bw" commandline from Bitwarden for "{0}": {1}').format(option.path(), exc))
|
||||
continue
|
||||
out = cpe.stdout.decode('utf8')
|
||||
err = cpe.stderr.decode('utf8')
|
||||
if cpe.returncode != 0 or err:
|
||||
self.errors.append(_('cannot get password "{0}" from Bitwarden for "{1}": {2} ({3})').format(key_bitwarden, option.path(), err, cpe.returncode))
|
||||
continue
|
||||
try:
|
||||
data = loads(out)
|
||||
except Exception as exc:
|
||||
self.errors.append(_('cannot load password "{0}" from Bitwarden for "{1}": {2}').format(key_bitwarden, option.path(), exc))
|
||||
continue
|
||||
if not data:
|
||||
self.errors.append(_('cannot find password "{0}" from Bitwarden for "{1}"').format(key_bitwarden, option.path()))
|
||||
continue
|
||||
if len(data) != 1:
|
||||
names = [d["name"] for d in data]
|
||||
self.errors.append(_('several passwords found with name "{0}" from Bitwarden for "{1}": "{2}"').format(key_bitwarden, option.path(), "\", \"".join(names)))
|
||||
continue
|
||||
try:
|
||||
option.value.set(data[0]['login']['password'])
|
||||
except Exception as exc:
|
||||
self.errors.append(_('unexpected password "{0}" from Bitwarden for "{1}": {2}').format(key_bitwarden, option.path(), exc))
|
||||
elif option.information.get('bitwarden', False):
|
||||
path = option.path()
|
||||
if not option.owner.isdefault():
|
||||
if option.isfollower():
|
||||
self.errors.append(_('the value for "{0}" at index {1} is already set while it should be filled in by Bitwarden').format(path, option.index()))
|
||||
else:
|
||||
self.errors.append(_('the value for "{0}" is already set while it should be filled in by Bitwarden').format(path))
|
||||
continue
|
||||
type_ = option.information.get('type')
|
||||
if option.isleader():
|
||||
leader_values = []
|
||||
self.leader_informations[path] = []
|
||||
for val in option.value.get():
|
||||
names, values = self.get_values(path, type_, val, allow_multiple=True)
|
||||
print(names, values)
|
||||
if isinstance(values, list):
|
||||
leader_values.extend(values)
|
||||
self.leader_informations[path].extend(names)
|
||||
else:
|
||||
leader_values.append(values)
|
||||
self.leader_informations[path].append(names)
|
||||
option.value.set(leader_values)
|
||||
else:
|
||||
if option.isfollower():
|
||||
leader_path = optiondescription.leader().path()
|
||||
if leader_path in self.leader_informations:
|
||||
key_bitwarden = self.leader_informations[leader_path][option.index()]
|
||||
else:
|
||||
key_bitwarden = option.value.get()
|
||||
else:
|
||||
key_bitwarden = option.value.get()
|
||||
option.value.set(self.get_values(path, type_, key_bitwarden)[1])
|
||||
|
||||
def get_values(self, path, type_, key_bitwarden, *, allow_multiple=False):
|
||||
if not isinstance(key_bitwarden, str):
|
||||
self.errors.append(_('the default value for "{0}" must be the Bitwarden item name').format(path))
|
||||
return None, None
|
||||
if 'ROUGAIL_BITWARDEN_MOCK_ENABLE' in environ:
|
||||
if type_ == 'secret':
|
||||
return 'Ex4mpL3_P4ssw0rD'
|
||||
return 'example_login'
|
||||
try:
|
||||
cpe = run(["bw", "list", "items", "--search", key_bitwarden, '--nointeraction'], capture_output=True)
|
||||
except Exception as exc:
|
||||
self.errors.append(_('cannot execute the "bw" commandline from Bitwarden for "{0}": {1}').format(path, exc))
|
||||
return None, None
|
||||
out = cpe.stdout.decode('utf8')
|
||||
err = cpe.stderr.decode('utf8')
|
||||
if cpe.returncode != 0 or err:
|
||||
self.errors.append(_('cannot get {0} "{1}" from Bitwarden for "{2}": {3} ({4})').format(type_, key_bitwarden, path, err, cpe.returncode))
|
||||
return None, None
|
||||
try:
|
||||
data = loads(out)
|
||||
except Exception as exc:
|
||||
self.errors.append(_('cannot load {0} "{1}" from Bitwarden for "{2}": {3}').format(type_, key_bitwarden, path, exc))
|
||||
return None, None
|
||||
if not data:
|
||||
self.errors.append(_('cannot find {0} "{1}" from Bitwarden for "{2}"').format(type_, key_bitwarden, path))
|
||||
return None, None
|
||||
if len(data) != 1:
|
||||
names = [d["name"] for d in data]
|
||||
if allow_multiple:
|
||||
ret = []
|
||||
return names, [self.get_value(key_bitwarden, path, type_, d) for d in data]
|
||||
self.errors.append(_('several items found with name "{0}" from Bitwarden for "{1}": "{2}"').format(key_bitwarden, path, "\", \"".join(names)))
|
||||
return None, None
|
||||
return data[0]['name'], self.get_value(key_bitwarden, path, type_, data[0])
|
||||
|
||||
def get_value(self, key_bitwarden: str, path: str, type_: str, data: dict) -> str:
|
||||
try:
|
||||
if type_ == 'secret':
|
||||
return data['login']['password']
|
||||
return data['login']['username']
|
||||
except Exception as exc:
|
||||
self.errors.append(_('unexpected datas "{0}" from Bitwarden for "{1}": {2}').format(key_bitwarden, path, exc))
|
||||
return None
|
||||
|
|
Binary file not shown.
Binary file not shown.
4
tests/results/1_secret/errors/bitwarden.json
Normal file
4
tests/results/1_secret/errors/bitwarden.json
Normal file
|
@ -0,0 +1,4 @@
|
|||
{
|
||||
"errors": [],
|
||||
"warnings": []
|
||||
}
|
3
tests/results/1_secret/makedict/bitwarden.json
Normal file
3
tests/results/1_secret/makedict/bitwarden.json
Normal file
|
@ -0,0 +1,3 @@
|
|||
{
|
||||
"rougail.secret": "bitwarden_password"
|
||||
}
|
4
tests/results/2_username_secret/errors/bitwarden.json
Normal file
4
tests/results/2_username_secret/errors/bitwarden.json
Normal file
|
@ -0,0 +1,4 @@
|
|||
{
|
||||
"errors": [],
|
||||
"warnings": []
|
||||
}
|
4
tests/results/2_username_secret/makedict/bitwarden.json
Normal file
4
tests/results/2_username_secret/makedict/bitwarden.json
Normal file
|
@ -0,0 +1,4 @@
|
|||
{
|
||||
"rougail.username": "bitwarden_username",
|
||||
"rougail.secret": "bitwarden_password"
|
||||
}
|
4
tests/results/3_leadership_secret/errors/bitwarden.json
Normal file
4
tests/results/3_leadership_secret/errors/bitwarden.json
Normal file
|
@ -0,0 +1,4 @@
|
|||
{
|
||||
"errors": [],
|
||||
"warnings": []
|
||||
}
|
12
tests/results/3_leadership_secret/makedict/bitwarden.json
Normal file
12
tests/results/3_leadership_secret/makedict/bitwarden.json
Normal file
|
@ -0,0 +1,12 @@
|
|||
{
|
||||
"rougail.leader.username": [
|
||||
{
|
||||
"rougail.leader.username": "bitwarden_username",
|
||||
"rougail.leader.secret": "bitwarden_password"
|
||||
},
|
||||
{
|
||||
"rougail.leader.username": "bitwarden_username_2",
|
||||
"rougail.leader.secret": "bitwarden_password_2"
|
||||
}
|
||||
]
|
||||
}
|
|
@ -0,0 +1,4 @@
|
|||
{
|
||||
"errors": [],
|
||||
"warnings": []
|
||||
}
|
|
@ -0,0 +1,12 @@
|
|||
{
|
||||
"rougail.leader.username": [
|
||||
{
|
||||
"rougail.leader.username": "test_multi_username1",
|
||||
"rougail.leader.secret": "test_multi_password1"
|
||||
},
|
||||
{
|
||||
"rougail.leader.username": "test_multi_username2",
|
||||
"rougail.leader.secret": "test_multi_password2"
|
||||
}
|
||||
]
|
||||
}
|
6
tests/results/4_several_secrets/errors/bitwarden.json
Normal file
6
tests/results/4_several_secrets/errors/bitwarden.json
Normal file
|
@ -0,0 +1,6 @@
|
|||
{
|
||||
"errors": [
|
||||
"several items found with name \"test_secret_\" from Bitwarden for \"rougail.secret\": \"test_secret_1\", \"test_secret_2\""
|
||||
],
|
||||
"warnings": []
|
||||
}
|
3
tests/results/4_several_secrets/makedict/bitwarden.json
Normal file
3
tests/results/4_several_secrets/makedict/bitwarden.json
Normal file
|
@ -0,0 +1,3 @@
|
|||
{
|
||||
"rougail.secret": null
|
||||
}
|
|
@ -1,7 +0,0 @@
|
|||
{
|
||||
"errors": [
|
||||
"the default value for \"secret1\" must be the Bitwarden password name",
|
||||
"cannot get password \"value\" from Bitwarden for \"secret2\": Vault is locked. (1)"
|
||||
],
|
||||
"warnings": []
|
||||
}
|
|
@ -1,4 +0,0 @@
|
|||
{
|
||||
"secret1": null,
|
||||
"secret2": "value"
|
||||
}
|
|
@ -1,7 +0,0 @@
|
|||
{
|
||||
"errors": [
|
||||
"the default value for \"rougail.secret1\" must be the Bitwarden password name",
|
||||
"cannot get password \"value\" from Bitwarden for \"rougail.secret2\": Vault is locked. (1)"
|
||||
],
|
||||
"warnings": []
|
||||
}
|
|
@ -1,4 +0,0 @@
|
|||
{
|
||||
"rougail.secret1": null,
|
||||
"rougail.secret2": "value"
|
||||
}
|
8
tests/structures/1_secret/00-base.yml
Normal file
8
tests/structures/1_secret/00-base.yml
Normal file
|
@ -0,0 +1,8 @@
|
|||
---
|
||||
version: 1.1
|
||||
|
||||
secret:
|
||||
description: the second variable
|
||||
type: secret
|
||||
default: test_secret_1
|
||||
bitwarden: true
|
14
tests/structures/2_username_secret/00-base.yml
Normal file
14
tests/structures/2_username_secret/00-base.yml
Normal file
|
@ -0,0 +1,14 @@
|
|||
---
|
||||
version: 1.1
|
||||
|
||||
username:
|
||||
description: the username
|
||||
type: unix_user
|
||||
default: test_secret_1
|
||||
bitwarden: true
|
||||
|
||||
secret:
|
||||
description: the secret
|
||||
type: secret
|
||||
default: test_secret_1
|
||||
bitwarden: true
|
18
tests/structures/3_leadership_secret/00-base.yml
Normal file
18
tests/structures/3_leadership_secret/00-base.yml
Normal file
|
@ -0,0 +1,18 @@
|
|||
---
|
||||
version: 1.1
|
||||
|
||||
leader:
|
||||
type: leadership
|
||||
|
||||
username:
|
||||
description: the username
|
||||
type: unix_user
|
||||
default:
|
||||
- test_secret_1
|
||||
- test_secret_2
|
||||
bitwarden: true
|
||||
|
||||
secret:
|
||||
description: the secret
|
||||
type: secret
|
||||
bitwarden: true
|
17
tests/structures/3_leadership_secret_several/00-base.yml
Normal file
17
tests/structures/3_leadership_secret_several/00-base.yml
Normal file
|
@ -0,0 +1,17 @@
|
|||
---
|
||||
version: 1.1
|
||||
|
||||
leader:
|
||||
type: leadership
|
||||
|
||||
username:
|
||||
description: the username
|
||||
type: unix_user
|
||||
default:
|
||||
- test_multi_
|
||||
bitwarden: true
|
||||
|
||||
secret:
|
||||
description: the secret
|
||||
type: secret
|
||||
bitwarden: true
|
8
tests/structures/4_several_secrets/00-base.yml
Normal file
8
tests/structures/4_several_secrets/00-base.yml
Normal file
|
@ -0,0 +1,8 @@
|
|||
---
|
||||
version: 1.1
|
||||
|
||||
secret:
|
||||
description: the second variable
|
||||
type: secret
|
||||
default: test_secret_
|
||||
bitwarden: true
|
7
tests/structures/5_default_value/00-base.yml
Normal file
7
tests/structures/5_default_value/00-base.yml
Normal file
|
@ -0,0 +1,7 @@
|
|||
---
|
||||
version: 1.1
|
||||
|
||||
secret2:
|
||||
description: the variable
|
||||
type: secret
|
||||
bitwarden: true
|
|
@ -0,0 +1,15 @@
|
|||
---
|
||||
version: 1.1
|
||||
|
||||
leader:
|
||||
type: leadership
|
||||
|
||||
username:
|
||||
description: the username
|
||||
type: unix_user
|
||||
bitwarden: true
|
||||
|
||||
secret:
|
||||
description: the secret
|
||||
type: secret
|
||||
bitwarden: true
|
|
@ -0,0 +1,23 @@
|
|||
---
|
||||
version: 1.1
|
||||
|
||||
leader:
|
||||
type: leadership
|
||||
|
||||
username:
|
||||
description: the username
|
||||
type: unix_user
|
||||
default:
|
||||
- test_secret_1
|
||||
- test_secret_2
|
||||
bitwarden: true
|
||||
|
||||
secret:
|
||||
description: the secret
|
||||
type: secret
|
||||
default:
|
||||
jinja: test_secret_{{ index + 1 }}
|
||||
params:
|
||||
index:
|
||||
type: index
|
||||
bitwarden: true
|
9
tests/structures/8_multi_variable/00-base.yml
Normal file
9
tests/structures/8_multi_variable/00-base.yml
Normal file
|
@ -0,0 +1,9 @@
|
|||
---
|
||||
version: 1.1
|
||||
|
||||
secret:
|
||||
description: the secret variable
|
||||
type: secret
|
||||
default:
|
||||
- test_secret_1
|
||||
bitwarden: true
|
6
tests/structures/9_unknown_type/00-base.yml
Normal file
6
tests/structures/9_unknown_type/00-base.yml
Normal file
|
@ -0,0 +1,6 @@
|
|||
---
|
||||
version: 1.1
|
||||
|
||||
secret:
|
||||
description: the first variable
|
||||
bitwarden: true
|
|
@ -1,68 +1,39 @@
|
|||
import os
|
||||
from pytest import fixture # , raises
|
||||
from pathlib import Path
|
||||
from rougail import Rougail
|
||||
from rougail import Rougail, RougailConfig
|
||||
from rougail.error import DictConsistencyError
|
||||
#########################
|
||||
from dotenv import load_dotenv
|
||||
from rougail.user_data_bitwarden import RougailUserDataBitwarden as RougailUserData
|
||||
from json import load, dump
|
||||
#########################
|
||||
|
||||
from rougail_tests.utils import get_structures_list, get_rougail_config, get_values_for_config, config_to_dict
|
||||
|
||||
EXT = "env"
|
||||
|
||||
#########################
|
||||
#let's save the original environment
|
||||
save = os.environ.copy()
|
||||
#########################
|
||||
from pytest import raises
|
||||
|
||||
|
||||
excludes = []
|
||||
|
||||
test_ok = get_structures_list(excludes)
|
||||
test_ok = [Path('../rougail-tests/structures/00_6secret')]
|
||||
from rougail_tests.utils import config_to_dict
|
||||
|
||||
|
||||
def idfn(fixture_value):
|
||||
return fixture_value.name
|
||||
test_dir = Path(__file__).parent / 'structures'
|
||||
|
||||
|
||||
@fixture(scope="module", params=test_ok, ids=idfn)
|
||||
def test_dir(request):
|
||||
return request.param
|
||||
|
||||
|
||||
def _test_dictionaries(test_dir, namespace, ext):
|
||||
rougailconfig = get_rougail_config(test_dir, namespace)
|
||||
if not rougailconfig:
|
||||
return
|
||||
##################################
|
||||
def _test_dictionaries(test_dir):
|
||||
rougailconfig = RougailConfig.copy()
|
||||
rougailconfig['main_dictionaries'] = [str(test_dir)]
|
||||
# rougailconfig['tiramisu_cache'] = "cache.py"
|
||||
rougailconfig['step.user_data'] = ['bitwarden']
|
||||
##################################
|
||||
dir_name = 'test'
|
||||
if namespace:
|
||||
dir_name += '_namespace'
|
||||
elif (test_dir / 'force_namespace').is_file():
|
||||
return
|
||||
rougail = Rougail(rougailconfig)
|
||||
config = rougail.run()
|
||||
##################################
|
||||
if not has_secrets(config):
|
||||
return
|
||||
##################################
|
||||
# loads variables in the tiramisu config
|
||||
errors = RougailUserData(config, rougailconfig=rougailconfig).run()
|
||||
#expected output
|
||||
config_dict = dict(config_to_dict(config.value.get()))
|
||||
ok_file = Path('tests') / 'results' / dir_name / test_dir.name / 'makedict' / 'bitwarden.json'
|
||||
ok_file = Path('tests') / 'results' / test_dir.name / 'makedict' / 'bitwarden.json'
|
||||
if not ok_file.is_file():
|
||||
ok_file.parent.mkdir(parents=True, exist_ok=True)
|
||||
with open(ok_file, 'a') as json_file:
|
||||
dump(config_dict, json_file, indent=4)
|
||||
with open(ok_file) as json_file:
|
||||
expected = load(json_file)
|
||||
errors_file = Path('tests') / 'results' / dir_name / test_dir.name / 'errors' / 'bitwarden.json'
|
||||
errors_file = Path('tests') / 'results' / test_dir.name / 'errors' / 'bitwarden.json'
|
||||
if not errors_file.is_file():
|
||||
errors_file.parent.mkdir(parents=True, exist_ok=True)
|
||||
with open(errors_file, 'a') as json_file:
|
||||
|
@ -77,27 +48,63 @@ def _test_dictionaries(test_dir, namespace, ext):
|
|||
#
|
||||
config.property.read_only()
|
||||
assert expected == config_dict
|
||||
######################################
|
||||
#teardown: set the original environement again
|
||||
os.environ = save.copy()
|
||||
######################################
|
||||
|
||||
|
||||
def has_secrets(optiondescription):
|
||||
for option in optiondescription:
|
||||
if option.isoptiondescription():
|
||||
if has_secrets(option):
|
||||
return True
|
||||
elif option.information.get('type', None) == 'secret':
|
||||
return True
|
||||
return False
|
||||
|
||||
|
||||
def test_dictionaries_all(test_dir):
|
||||
def test_dictionaries_1_secret():
|
||||
"tests the output"
|
||||
_test_dictionaries(test_dir, False, EXT)
|
||||
_test_dictionaries(test_dir / '1_secret')
|
||||
|
||||
|
||||
def test_dictionaries_namespace_all(test_dir):
|
||||
def test_dictionaries_2_username_secret():
|
||||
"tests the output"
|
||||
_test_dictionaries(test_dir, True, EXT)
|
||||
_test_dictionaries(test_dir / '2_username_secret')
|
||||
|
||||
|
||||
def test_dictionaries_3_leadership_secret():
|
||||
"tests the output"
|
||||
_test_dictionaries(test_dir / '3_leadership_secret')
|
||||
|
||||
|
||||
def test_dictionaries_3_leadership_secret_several():
|
||||
"tests the output"
|
||||
_test_dictionaries(test_dir / '3_leadership_secret_several')
|
||||
|
||||
|
||||
def test_dictionaries_4_several_secrets():
|
||||
"tests the output"
|
||||
_test_dictionaries(test_dir / '4_several_secrets')
|
||||
|
||||
|
||||
def test_dictionaries_5_default_value():
|
||||
"tests the output"
|
||||
with raises(DictConsistencyError) as err:
|
||||
_test_dictionaries(test_dir / '5_default_value')
|
||||
assert err.errno == 304
|
||||
|
||||
|
||||
def test_dictionaries_6_leadership_secret_default_value():
|
||||
"tests the output"
|
||||
with raises(DictConsistencyError) as err:
|
||||
_test_dictionaries(test_dir / '6_leadership_secret_default_value')
|
||||
assert err.errno == 304
|
||||
|
||||
|
||||
def test_dictionaries_6_leadership_secret_follower_variable():
|
||||
"tests the output"
|
||||
with raises(DictConsistencyError) as err:
|
||||
_test_dictionaries(test_dir / '6_leadership_secret_follower_variable')
|
||||
assert err.errno == 303
|
||||
|
||||
|
||||
def test_dictionaries_8_multi_variable():
|
||||
"tests the output"
|
||||
with raises(DictConsistencyError) as err:
|
||||
_test_dictionaries(test_dir / '8_multi_variable')
|
||||
assert err.errno == 302
|
||||
|
||||
|
||||
def test_dictionaries_9_unknown_type():
|
||||
"tests the output"
|
||||
with raises(DictConsistencyError) as err:
|
||||
_test_dictionaries(test_dir / '9_unknown_type')
|
||||
assert err.errno == 301
|
||||
|
|
Loading…
Reference in a new issue