Compare commits
27 commits
Author | SHA1 | Date | |
---|---|---|---|
3b72988cb5 | |||
d3c0f94f86 | |||
80b1155d2a | |||
65e318e883 | |||
e9ef79e80b | |||
a12cf396fd | |||
4c72346aa6 | |||
80ddd65206 | |||
d96f888e48 | |||
82e0c371a0 | |||
5d8dd6881f | |||
4fd27de57e | |||
76b43846ed | |||
510b97d7cf | |||
b332195ef3 | |||
8b180e131e | |||
52a56476d3 | |||
7925cdcc6a | |||
01feb985fb | |||
c16fcdb7fe | |||
b16e71846b | |||
eea2badb64 | |||
b6e4744085 | |||
653790b9af | |||
971311e0f5 | |||
abb4b87924 | |||
5682ac96b6 |
36 changed files with 911 additions and 0 deletions
77
CHANGELOG.md
Normal file
77
CHANGELOG.md
Normal file
|
@ -0,0 +1,77 @@
|
||||||
|
## 0.1.0a13 (2025-02-19)
|
||||||
|
|
||||||
|
### Fix
|
||||||
|
|
||||||
|
- MOCK
|
||||||
|
|
||||||
|
## 0.1.0a12 (2025-02-19)
|
||||||
|
|
||||||
|
### Fix
|
||||||
|
|
||||||
|
- MOCK
|
||||||
|
|
||||||
|
## 0.1.0a11 (2025-02-19)
|
||||||
|
|
||||||
|
### Fix
|
||||||
|
|
||||||
|
- if mock is active, do not search rbw or bw
|
||||||
|
|
||||||
|
## 0.1.0a10 (2025-02-17)
|
||||||
|
|
||||||
|
### Fix
|
||||||
|
|
||||||
|
- support hidden attribut
|
||||||
|
|
||||||
|
## 0.1.0a9 (2025-02-17)
|
||||||
|
|
||||||
|
### Fix
|
||||||
|
|
||||||
|
- support hidden attribut
|
||||||
|
|
||||||
|
## 0.1.0a8 (2025-02-17)
|
||||||
|
|
||||||
|
### Fix
|
||||||
|
|
||||||
|
- update structural plugin version
|
||||||
|
|
||||||
|
## 0.1.0a7 (2025-02-17)
|
||||||
|
|
||||||
|
### Feat
|
||||||
|
|
||||||
|
- support rbw and bw command line
|
||||||
|
|
||||||
|
## 0.1.0a6 (2025-02-13)
|
||||||
|
|
||||||
|
### Fix
|
||||||
|
|
||||||
|
- bitwarden key could be an invalid username/secret
|
||||||
|
|
||||||
|
## 0.1.0a5 (2025-02-13)
|
||||||
|
|
||||||
|
### Fix
|
||||||
|
|
||||||
|
- structural load
|
||||||
|
|
||||||
|
## 0.1.0a4 (2025-02-13)
|
||||||
|
|
||||||
|
### Fix
|
||||||
|
|
||||||
|
- structural version
|
||||||
|
|
||||||
|
## 0.1.0a2 (2025-02-13)
|
||||||
|
|
||||||
|
### Fix
|
||||||
|
|
||||||
|
- separate user-data and structural
|
||||||
|
|
||||||
|
## 0.1.0a1 (2025-02-12)
|
||||||
|
|
||||||
|
### Fix
|
||||||
|
|
||||||
|
- many improvment
|
||||||
|
|
||||||
|
## 0.1.0a0 (2025-02-05)
|
||||||
|
|
||||||
|
### Feat
|
||||||
|
|
||||||
|
- first version
|
104
locale/fr/LC_MESSAGES/rougail_user_data_bitwarden.po
Normal file
104
locale/fr/LC_MESSAGES/rougail_user_data_bitwarden.po
Normal file
|
@ -0,0 +1,104 @@
|
||||||
|
# SOME DESCRIPTIVE TITLE.
|
||||||
|
# Copyright (C) YEAR ORGANIZATION
|
||||||
|
# FIRST AUTHOR <EMAIL@ADDRESS>, YEAR.
|
||||||
|
#
|
||||||
|
msgid ""
|
||||||
|
msgstr ""
|
||||||
|
"Project-Id-Version: \n"
|
||||||
|
"POT-Creation-Date: 2025-02-17 09:25+0100\n"
|
||||||
|
"PO-Revision-Date: 2025-02-17 09:28+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:52
|
||||||
|
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:83
|
||||||
|
msgid "please unlock Bitwarden password database"
|
||||||
|
msgstr "veuillez déverrouiller la base de donnée de mot de passe Bitwarden"
|
||||||
|
|
||||||
|
#: src/rougail/user_data_bitwarden/data.py:84
|
||||||
|
msgid "cannot find Bitwarden command (rbw or bw) please install it"
|
||||||
|
msgstr "ne peut trouver la commande Bitwarden (rbw ou bw) veuillez l'installer"
|
||||||
|
|
||||||
|
#: src/rougail/user_data_bitwarden/data.py:126
|
||||||
|
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:128
|
||||||
|
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ée alors que celle doit devrait être "
|
||||||
|
"renseignée par Bitwarden"
|
||||||
|
|
||||||
|
#: src/rougail/user_data_bitwarden/data.py:157
|
||||||
|
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:166
|
||||||
|
msgid "cannot execute the \"{0}\" commandline from Bitwarden for \"{1}\": {2}"
|
||||||
|
msgstr ""
|
||||||
|
"ne peut exécuter la ligne de commande \"{0}\" pour Bitwarden pour \"{1}\": "
|
||||||
|
"{2}"
|
||||||
|
|
||||||
|
#: src/rougail/user_data_bitwarden/data.py:169
|
||||||
|
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:176
|
||||||
|
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:186
|
||||||
|
msgid "unexpected datas \"{0}\" from Bitwarden for \"{1}\": {2}"
|
||||||
|
msgstr "données inattendues \"{0}\" pour Bitwarden pour \"{1}\": {2}"
|
||||||
|
|
||||||
|
#~ 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}\""
|
||||||
|
|
||||||
|
#~ 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"
|
||||||
|
|
||||||
|
#~ 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"
|
||||||
|
|
||||||
|
#~ 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"
|
||||||
|
|
||||||
|
#~ 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})"
|
||||||
|
|
||||||
|
#~ msgid "cannot load {0} \"{1}\" from Bitwarden for \"{2}\": {3}"
|
||||||
|
#~ msgstr "ne peut charger {0} \"{1}\" pour Bitwarden pour \"{2}\": {3}"
|
57
locale/rougail_user_data_bitwarden.pot
Normal file
57
locale/rougail_user_data_bitwarden.pot
Normal file
|
@ -0,0 +1,57 @@
|
||||||
|
# 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-17 09:28+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:52
|
||||||
|
msgid "\"bitwarden\" is not set in step.user_data"
|
||||||
|
msgstr ""
|
||||||
|
|
||||||
|
#: src/rougail/user_data_bitwarden/data.py:83
|
||||||
|
msgid "please unlock Bitwarden password database"
|
||||||
|
msgstr ""
|
||||||
|
|
||||||
|
#: src/rougail/user_data_bitwarden/data.py:84
|
||||||
|
msgid "cannot find Bitwarden command (rbw or bw) please install it"
|
||||||
|
msgstr ""
|
||||||
|
|
||||||
|
#: src/rougail/user_data_bitwarden/data.py:126
|
||||||
|
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:128
|
||||||
|
msgid "the value for \"{0}\" is already set while it should be filled in by Bitwarden"
|
||||||
|
msgstr ""
|
||||||
|
|
||||||
|
#: src/rougail/user_data_bitwarden/data.py:157
|
||||||
|
msgid "the default value for \"{0}\" must be the Bitwarden item name"
|
||||||
|
msgstr ""
|
||||||
|
|
||||||
|
#: src/rougail/user_data_bitwarden/data.py:166
|
||||||
|
msgid "cannot execute the \"{0}\" commandline from Bitwarden for \"{1}\": {2}"
|
||||||
|
msgstr ""
|
||||||
|
|
||||||
|
#: src/rougail/user_data_bitwarden/data.py:169
|
||||||
|
msgid "cannot find {0} \"{1}\" from Bitwarden for \"{2}\""
|
||||||
|
msgstr ""
|
||||||
|
|
||||||
|
#: src/rougail/user_data_bitwarden/data.py:176
|
||||||
|
msgid "several items found with name \"{0}\" from Bitwarden for \"{1}\": \"{2}\""
|
||||||
|
msgstr ""
|
||||||
|
|
||||||
|
#: src/rougail/user_data_bitwarden/data.py:186
|
||||||
|
msgid "unexpected datas \"{0}\" from Bitwarden for \"{1}\": {2}"
|
||||||
|
msgstr ""
|
||||||
|
|
41
pyproject.toml
Normal file
41
pyproject.toml
Normal file
|
@ -0,0 +1,41 @@
|
||||||
|
[build-system]
|
||||||
|
build-backend = "flit_core.buildapi"
|
||||||
|
requires = ["flit_core >=3.8.0,<4"]
|
||||||
|
|
||||||
|
[project]
|
||||||
|
name = "rougail.user_data_bitwarden"
|
||||||
|
version = "0.1.0a13"
|
||||||
|
authors = [{name = "Emmanuel Garette", email = "gnunux@gnunux.info"}]
|
||||||
|
readme = "README.md"
|
||||||
|
description = "Rougail user_data Bitwarden"
|
||||||
|
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 >= 1.1,<2",
|
||||||
|
"rougail-structural-bitwarden == 0.1.0a2",
|
||||||
|
]
|
||||||
|
|
||||||
|
[project.urls]
|
||||||
|
Home = "https://forge.cloud.silique.fr/stove/rougail-user-data-bitwarden"
|
||||||
|
|
||||||
|
[tool.commitizen]
|
||||||
|
name = "cz_conventional_commits"
|
||||||
|
tag_format = "$version"
|
||||||
|
version_scheme = "pep440"
|
||||||
|
version_provider = "pep621"
|
||||||
|
update_changelog_on_bump = true
|
||||||
|
changelog_merge_prerelease = true
|
24
src/rougail/user_data_bitwarden/__init__.py
Normal file
24
src/rougail/user_data_bitwarden/__init__.py
Normal file
|
@ -0,0 +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',)
|
49
src/rougail/user_data_bitwarden/config.py
Normal file
49
src/rougail/user_data_bitwarden/config.py
Normal file
|
@ -0,0 +1,49 @@
|
||||||
|
"""
|
||||||
|
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
|
||||||
|
"""
|
||||||
|
|
||||||
|
|
||||||
|
def get_rougail_config(*,
|
||||||
|
backward_compatibility=True,
|
||||||
|
) -> dict:
|
||||||
|
options = """
|
||||||
|
step:
|
||||||
|
|
||||||
|
structural:
|
||||||
|
redefine: true
|
||||||
|
default:
|
||||||
|
jinja: |-
|
||||||
|
{% if 'bitwarden' in step.user_data %}
|
||||||
|
bitwarden
|
||||||
|
{% endif %}
|
||||||
|
{% if 'risotto' in step.user_data %}
|
||||||
|
risotto
|
||||||
|
{% else %}
|
||||||
|
directory
|
||||||
|
{% endif %}
|
||||||
|
"""
|
||||||
|
return {'name': 'bitwarden',
|
||||||
|
'process': 'user data',
|
||||||
|
"options": options,
|
||||||
|
'level': 90,
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
__all__ = ('get_rougail_config',)
|
188
src/rougail/user_data_bitwarden/data.py
Normal file
188
src/rougail/user_data_bitwarden/data.py
Normal file
|
@ -0,0 +1,188 @@
|
||||||
|
"""
|
||||||
|
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 subprocess import run
|
||||||
|
from json import loads
|
||||||
|
from os import environ
|
||||||
|
from shutil import which
|
||||||
|
|
||||||
|
|
||||||
|
from rougail.error import ExtentionError
|
||||||
|
from .i18n import _
|
||||||
|
|
||||||
|
|
||||||
|
class RougailUserDataBitwarden:
|
||||||
|
force_apply_user_data = True
|
||||||
|
|
||||||
|
def __init__(self,
|
||||||
|
config: 'Config',
|
||||||
|
*,
|
||||||
|
rougailconfig: "RougailConfig"=None,
|
||||||
|
):
|
||||||
|
# this is the tiramisu config object
|
||||||
|
self.config = config
|
||||||
|
if rougailconfig is None:
|
||||||
|
from rougail.config import RougailConfig
|
||||||
|
rougailconfig = RougailConfig
|
||||||
|
user_data = rougailconfig['step.user_data']
|
||||||
|
if 'bitwarden' not in user_data:
|
||||||
|
user_data.append('bitwarden')
|
||||||
|
rougailconfig['step.user_data'] = user_data
|
||||||
|
user_data = rougailconfig['step.user_data']
|
||||||
|
self.rougailconfig = rougailconfig
|
||||||
|
if 'bitwarden' not in user_data:
|
||||||
|
raise ExtentionError(_('"bitwarden" is not set in step.user_data'))
|
||||||
|
self.errors = []
|
||||||
|
self.warnings = []
|
||||||
|
self.leader_informations = {}
|
||||||
|
bitwarden_command_line = None
|
||||||
|
one_is_find = False
|
||||||
|
if 'ROUGAIL_BITWARDEN_MOCK_ENABLE' not in environ:
|
||||||
|
if which('rbw'):
|
||||||
|
one_is_find = True
|
||||||
|
try:
|
||||||
|
cpe = run(['rbw', 'unlocked'], capture_output=True)
|
||||||
|
except Exception as exc:
|
||||||
|
pass
|
||||||
|
else:
|
||||||
|
if cpe.returncode == 0:
|
||||||
|
bitwarden_command_line = 'rbw'
|
||||||
|
if bitwarden_command_line is None and which('bw'):
|
||||||
|
one_is_find = True
|
||||||
|
try:
|
||||||
|
cpe = run(['bw', 'status'], capture_output=True)
|
||||||
|
except Exception as exc:
|
||||||
|
pass
|
||||||
|
else:
|
||||||
|
if cpe.returncode == 0:
|
||||||
|
try:
|
||||||
|
data = loads(cpe.stdout.decode('utf8'))
|
||||||
|
if data["status"] == "unlocked":
|
||||||
|
bitwarden_command_line = 'bw'
|
||||||
|
except:
|
||||||
|
pass
|
||||||
|
if bitwarden_command_line is None:
|
||||||
|
if one_is_find:
|
||||||
|
raise ExtentionError(_('please unlock Bitwarden password database'))
|
||||||
|
raise ExtentionError(_('cannot find Bitwarden command (rbw or bw) please install it'))
|
||||||
|
self.bitwarden_command_line = bitwarden_command_line
|
||||||
|
|
||||||
|
def run(self):
|
||||||
|
self.set_passwords(self.config.forcepermissive)
|
||||||
|
return {'errors': self.errors,
|
||||||
|
'warnings': self.warnings,
|
||||||
|
}
|
||||||
|
|
||||||
|
def run_commandline(self, cmd) -> str:
|
||||||
|
cpe = run(cmd, capture_output=True)
|
||||||
|
err = cpe.stderr.decode('utf8')
|
||||||
|
if cpe.returncode != 0 or err:
|
||||||
|
raise Exception('{0} ({1})'.format(err, cpe.returncode))
|
||||||
|
return cpe.stdout.decode('utf8')
|
||||||
|
|
||||||
|
def get_key_from_commandline(self, key_bitwarden: str, allow_multiple: bool) -> list[str]:
|
||||||
|
if self.bitwarden_command_line == 'rbw':
|
||||||
|
if allow_multiple:
|
||||||
|
keys = []
|
||||||
|
items = self.run_commandline(["rbw", "search", key_bitwarden]).strip()
|
||||||
|
for item in items.split('\n'):
|
||||||
|
if item.count('@') != 1:
|
||||||
|
continue
|
||||||
|
keys.append(item.split('@', 1)[-1])
|
||||||
|
else:
|
||||||
|
keys = [key_bitwarden]
|
||||||
|
datas = []
|
||||||
|
for key in keys:
|
||||||
|
data = loads(self.run_commandline(["rbw", "get", key, '--raw']).strip())
|
||||||
|
datas.append({'name': key, 'login': data["data"]})
|
||||||
|
return datas
|
||||||
|
return loads(self.run_commandline(["bw", "list", "items", "--search", key_bitwarden, '--nointeraction']))
|
||||||
|
|
||||||
|
def set_passwords(self, optiondescription):
|
||||||
|
for option in optiondescription:
|
||||||
|
if option.isoptiondescription():
|
||||||
|
self.set_passwords(option)
|
||||||
|
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] = []
|
||||||
|
values = option.value.get()
|
||||||
|
for val in values:
|
||||||
|
names, values = self.get_values(path, type_, val, allow_multiple=True)
|
||||||
|
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 allow_multiple:
|
||||||
|
return ['example_login'], ['Ex4mpL3_P4ssw0rD']
|
||||||
|
return 'example_login', 'Ex4mpL3_P4ssw0rD'
|
||||||
|
try:
|
||||||
|
data = self.get_key_from_commandline(key_bitwarden, allow_multiple)
|
||||||
|
except Exception as exc:
|
||||||
|
self.errors.append(_('cannot execute the "{0}" commandline from Bitwarden for "{1}": {2}').format(self.bitwarden_command_line, 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
|
26
src/rougail/user_data_bitwarden/i18n.py
Normal file
26
src/rougail/user_data_bitwarden/i18n.py
Normal file
|
@ -0,0 +1,26 @@
|
||||||
|
"""
|
||||||
|
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 gettext import translation
|
||||||
|
from pathlib import Path
|
||||||
|
|
||||||
|
t = translation(
|
||||||
|
"rougail_user_data_bitwarden", str(Path(__file__).parent / "locale"), fallback=True
|
||||||
|
)
|
||||||
|
|
||||||
|
_ = t.gettext
|
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"
|
||||||
|
}
|
|
@ -0,0 +1,4 @@
|
||||||
|
{
|
||||||
|
"errors": [],
|
||||||
|
"warnings": []
|
||||||
|
}
|
|
@ -0,0 +1,4 @@
|
||||||
|
{
|
||||||
|
"rougail.username": "bitwarden_username",
|
||||||
|
"rougail.secret": "bitwarden_password"
|
||||||
|
}
|
|
@ -0,0 +1,4 @@
|
||||||
|
{
|
||||||
|
"errors": [],
|
||||||
|
"warnings": []
|
||||||
|
}
|
|
@ -0,0 +1,4 @@
|
||||||
|
{
|
||||||
|
"rougail.username": "up_secret_error_1",
|
||||||
|
"rougail.secret": "up_secret_error_pass_1"
|
||||||
|
}
|
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_username2",
|
||||||
|
"rougail.leader.secret": "test_multi_password2"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"rougail.leader.username": "test_multi_username1",
|
||||||
|
"rougail.leader.secret": "test_multi_password1"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
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": [
|
||||||
|
"cannot execute the \"rbw\" commandline from Bitwarden for \"rougail.secret\": rbw get: couldn't find entry for 'test_secret_': multiple entries found: bitwarden_username_2@test_secret_2, bitwarden_username@test_secret_1\n (1)"
|
||||||
|
],
|
||||||
|
"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
|
||||||
|
}
|
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
|
15
tests/structures/2_username_secret_hidden/00-base.yml
Normal file
15
tests/structures/2_username_secret_hidden/00-base.yml
Normal file
|
@ -0,0 +1,15 @@
|
||||||
|
---
|
||||||
|
version: 1.1
|
||||||
|
|
||||||
|
username:
|
||||||
|
description: the username
|
||||||
|
type: unix_user
|
||||||
|
default: test_secret_1
|
||||||
|
bitwarden: true
|
||||||
|
|
||||||
|
secret:
|
||||||
|
description: the secret
|
||||||
|
type: secret
|
||||||
|
hidden: true
|
||||||
|
default: test_secret_1
|
||||||
|
bitwarden: true
|
14
tests/structures/2_username_secret_invalid/00-base.yml
Normal file
14
tests/structures/2_username_secret_invalid/00-base.yml
Normal file
|
@ -0,0 +1,14 @@
|
||||||
|
---
|
||||||
|
version: 1.1
|
||||||
|
|
||||||
|
username:
|
||||||
|
description: the username
|
||||||
|
type: unix_user
|
||||||
|
default: UP SECRET 1
|
||||||
|
bitwarden: true
|
||||||
|
|
||||||
|
secret:
|
||||||
|
description: the secret
|
||||||
|
type: secret
|
||||||
|
default: UP 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
|
119
tests/test_load.py
Normal file
119
tests/test_load.py
Normal file
|
@ -0,0 +1,119 @@
|
||||||
|
import os
|
||||||
|
from pathlib import Path
|
||||||
|
from rougail import Rougail, RougailConfig
|
||||||
|
from rougail.error import DictConsistencyError
|
||||||
|
#########################
|
||||||
|
from rougail.user_data_bitwarden import RougailUserDataBitwarden as RougailUserData
|
||||||
|
from json import load, dump
|
||||||
|
#########################
|
||||||
|
from pytest import raises
|
||||||
|
|
||||||
|
|
||||||
|
from rougail_tests.utils import config_to_dict
|
||||||
|
|
||||||
|
|
||||||
|
test_dir = Path(__file__).parent / 'structures'
|
||||||
|
|
||||||
|
|
||||||
|
def _test_dictionaries(test_dir):
|
||||||
|
rougailconfig = RougailConfig.copy()
|
||||||
|
rougailconfig['main_dictionaries'] = [str(test_dir)]
|
||||||
|
# rougailconfig['tiramisu_cache'] = "cache.py"
|
||||||
|
rougailconfig['step.user_data'] = ['bitwarden']
|
||||||
|
rougail = Rougail(rougailconfig)
|
||||||
|
config = rougail.run()
|
||||||
|
# loads variables in the tiramisu config
|
||||||
|
errors = RougailUserData(config, rougailconfig=rougailconfig).run()
|
||||||
|
#expected output
|
||||||
|
config_dict = dict(config_to_dict(config.forcepermissive.value.get()))
|
||||||
|
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' / 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:
|
||||||
|
dump(errors, json_file, indent=4)
|
||||||
|
with open(errors_file) as json_file:
|
||||||
|
expected_errors = load(json_file)
|
||||||
|
# expected_errors = {
|
||||||
|
# 'errors': [],
|
||||||
|
# 'warnings': [],
|
||||||
|
# }
|
||||||
|
assert expected_errors == errors
|
||||||
|
#
|
||||||
|
assert expected == config_dict
|
||||||
|
|
||||||
|
|
||||||
|
def test_dictionaries_1_secret():
|
||||||
|
"tests the output"
|
||||||
|
_test_dictionaries(test_dir / '1_secret')
|
||||||
|
|
||||||
|
|
||||||
|
def test_dictionaries_2_username_secret():
|
||||||
|
"tests the output"
|
||||||
|
_test_dictionaries(test_dir / '2_username_secret')
|
||||||
|
|
||||||
|
|
||||||
|
def test_dictionaries_2_username_secret_invalid():
|
||||||
|
"tests the output"
|
||||||
|
_test_dictionaries(test_dir / '2_username_secret_invalid')
|
||||||
|
|
||||||
|
|
||||||
|
def test_dictionaries_2_username_secret_hidden():
|
||||||
|
"tests the output"
|
||||||
|
_test_dictionaries(test_dir / '2_username_secret_hidden')
|
||||||
|
|
||||||
|
|
||||||
|
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