mirror of
https://github.com/YunoHost/yunohost.git
synced 2024-09-03 20:06:10 +02:00
config/question: broadcast data to redact to all OperationLogger instances
This commit is contained in:
parent
155942a92c
commit
12bc94f76e
3 changed files with 12 additions and 51 deletions
|
@ -1723,8 +1723,6 @@ def app_config_set(
|
||||||
|
|
||||||
config_ = AppConfigPanel(app)
|
config_ = AppConfigPanel(app)
|
||||||
|
|
||||||
Question.operation_logger = operation_logger
|
|
||||||
|
|
||||||
return config_.set(key, value, args, args_file, operation_logger=operation_logger)
|
return config_.set(key, value, args, args_file, operation_logger=operation_logger)
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -348,9 +348,7 @@ def test_question_password():
|
||||||
]
|
]
|
||||||
answers = {"some_password": "some_value"}
|
answers = {"some_password": "some_value"}
|
||||||
expected_result = OrderedDict({"some_password": ("some_value", "password")})
|
expected_result = OrderedDict({"some_password": ("some_value", "password")})
|
||||||
Question.operation_logger = MagicMock()
|
assert parse_args_in_yunohost_format(answers, questions) == expected_result
|
||||||
with patch.object(Question.operation_logger, "data_to_redact", create=True):
|
|
||||||
assert parse_args_in_yunohost_format(answers, questions) == expected_result
|
|
||||||
|
|
||||||
|
|
||||||
def test_question_password_no_input():
|
def test_question_password_no_input():
|
||||||
|
@ -375,13 +373,9 @@ def test_question_password_input():
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
answers = {}
|
answers = {}
|
||||||
Question.operation_logger = {"data_to_redact": []}
|
|
||||||
expected_result = OrderedDict({"some_password": ("some_value", "password")})
|
expected_result = OrderedDict({"some_password": ("some_value", "password")})
|
||||||
|
|
||||||
Question.operation_logger = MagicMock()
|
with patch.object(Moulinette, "prompt", return_value="some_value"), patch.object(
|
||||||
with patch.object(
|
|
||||||
Question.operation_logger, "data_to_redact", create=True
|
|
||||||
), patch.object(Moulinette, "prompt", return_value="some_value"), patch.object(
|
|
||||||
os, "isatty", return_value=True
|
os, "isatty", return_value=True
|
||||||
):
|
):
|
||||||
assert parse_args_in_yunohost_format(answers, questions) == expected_result
|
assert parse_args_in_yunohost_format(answers, questions) == expected_result
|
||||||
|
@ -397,10 +391,7 @@ def test_question_password_input_no_ask():
|
||||||
answers = {}
|
answers = {}
|
||||||
expected_result = OrderedDict({"some_password": ("some_value", "password")})
|
expected_result = OrderedDict({"some_password": ("some_value", "password")})
|
||||||
|
|
||||||
Question.operation_logger = MagicMock()
|
with patch.object(Moulinette, "prompt", return_value="some_value"), patch.object(
|
||||||
with patch.object(
|
|
||||||
Question.operation_logger, "data_to_redact", create=True
|
|
||||||
), patch.object(Moulinette, "prompt", return_value="some_value"), patch.object(
|
|
||||||
os, "isatty", return_value=True
|
os, "isatty", return_value=True
|
||||||
):
|
):
|
||||||
assert parse_args_in_yunohost_format(answers, questions) == expected_result
|
assert parse_args_in_yunohost_format(answers, questions) == expected_result
|
||||||
|
@ -417,20 +408,14 @@ def test_question_password_no_input_optional():
|
||||||
answers = {}
|
answers = {}
|
||||||
expected_result = OrderedDict({"some_password": ("", "password")})
|
expected_result = OrderedDict({"some_password": ("", "password")})
|
||||||
|
|
||||||
Question.operation_logger = MagicMock()
|
with patch.object(os, "isatty", return_value=False):
|
||||||
with patch.object(
|
|
||||||
Question.operation_logger, "data_to_redact", create=True
|
|
||||||
), patch.object(os, "isatty", return_value=False):
|
|
||||||
assert parse_args_in_yunohost_format(answers, questions) == expected_result
|
assert parse_args_in_yunohost_format(answers, questions) == expected_result
|
||||||
|
|
||||||
questions = [
|
questions = [
|
||||||
{"name": "some_password", "type": "password", "optional": True, "default": ""}
|
{"name": "some_password", "type": "password", "optional": True, "default": ""}
|
||||||
]
|
]
|
||||||
|
|
||||||
Question.operation_logger = MagicMock()
|
with patch.object(os, "isatty", return_value=False):
|
||||||
with patch.object(
|
|
||||||
Question.operation_logger, "data_to_redact", create=True
|
|
||||||
), patch.object(os, "isatty", return_value=False):
|
|
||||||
assert parse_args_in_yunohost_format(answers, questions) == expected_result
|
assert parse_args_in_yunohost_format(answers, questions) == expected_result
|
||||||
|
|
||||||
|
|
||||||
|
@ -446,10 +431,7 @@ def test_question_password_optional_with_input():
|
||||||
answers = {}
|
answers = {}
|
||||||
expected_result = OrderedDict({"some_password": ("some_value", "password")})
|
expected_result = OrderedDict({"some_password": ("some_value", "password")})
|
||||||
|
|
||||||
Question.operation_logger = MagicMock()
|
with patch.object(Moulinette, "prompt", return_value="some_value"), patch.object(
|
||||||
with patch.object(
|
|
||||||
Question.operation_logger, "data_to_redact", create=True
|
|
||||||
), patch.object(Moulinette, "prompt", return_value="some_value"), patch.object(
|
|
||||||
os, "isatty", return_value=True
|
os, "isatty", return_value=True
|
||||||
):
|
):
|
||||||
assert parse_args_in_yunohost_format(answers, questions) == expected_result
|
assert parse_args_in_yunohost_format(answers, questions) == expected_result
|
||||||
|
@ -467,10 +449,7 @@ def test_question_password_optional_with_empty_input():
|
||||||
answers = {}
|
answers = {}
|
||||||
expected_result = OrderedDict({"some_password": ("", "password")})
|
expected_result = OrderedDict({"some_password": ("", "password")})
|
||||||
|
|
||||||
Question.operation_logger = MagicMock()
|
with patch.object(Moulinette, "prompt", return_value=""), patch.object(
|
||||||
with patch.object(
|
|
||||||
Question.operation_logger, "data_to_redact", create=True
|
|
||||||
), patch.object(Moulinette, "prompt", return_value=""), patch.object(
|
|
||||||
os, "isatty", return_value=True
|
os, "isatty", return_value=True
|
||||||
):
|
):
|
||||||
assert parse_args_in_yunohost_format(answers, questions) == expected_result
|
assert parse_args_in_yunohost_format(answers, questions) == expected_result
|
||||||
|
@ -487,10 +466,7 @@ def test_question_password_optional_with_input_without_ask():
|
||||||
answers = {}
|
answers = {}
|
||||||
expected_result = OrderedDict({"some_password": ("some_value", "password")})
|
expected_result = OrderedDict({"some_password": ("some_value", "password")})
|
||||||
|
|
||||||
Question.operation_logger = MagicMock()
|
with patch.object(Moulinette, "prompt", return_value="some_value"), patch.object(
|
||||||
with patch.object(
|
|
||||||
Question.operation_logger, "data_to_redact", create=True
|
|
||||||
), patch.object(Moulinette, "prompt", return_value="some_value"), patch.object(
|
|
||||||
os, "isatty", return_value=True
|
os, "isatty", return_value=True
|
||||||
):
|
):
|
||||||
assert parse_args_in_yunohost_format(answers, questions) == expected_result
|
assert parse_args_in_yunohost_format(answers, questions) == expected_result
|
||||||
|
@ -540,10 +516,7 @@ def test_question_password_input_test_ask():
|
||||||
]
|
]
|
||||||
answers = {}
|
answers = {}
|
||||||
|
|
||||||
Question.operation_logger = MagicMock()
|
|
||||||
with patch.object(
|
with patch.object(
|
||||||
Question.operation_logger, "data_to_redact", create=True
|
|
||||||
), patch.object(
|
|
||||||
Moulinette, "prompt", return_value="some_value"
|
Moulinette, "prompt", return_value="some_value"
|
||||||
) as prompt, patch.object(
|
) as prompt, patch.object(
|
||||||
os, "isatty", return_value=True
|
os, "isatty", return_value=True
|
||||||
|
@ -572,10 +545,7 @@ def test_question_password_input_test_ask_with_example():
|
||||||
]
|
]
|
||||||
answers = {}
|
answers = {}
|
||||||
|
|
||||||
Question.operation_logger = MagicMock()
|
|
||||||
with patch.object(
|
with patch.object(
|
||||||
Question.operation_logger, "data_to_redact", create=True
|
|
||||||
), patch.object(
|
|
||||||
Moulinette, "prompt", return_value="some_value"
|
Moulinette, "prompt", return_value="some_value"
|
||||||
) as prompt, patch.object(
|
) as prompt, patch.object(
|
||||||
os, "isatty", return_value=True
|
os, "isatty", return_value=True
|
||||||
|
@ -599,10 +569,7 @@ def test_question_password_input_test_ask_with_help():
|
||||||
]
|
]
|
||||||
answers = {}
|
answers = {}
|
||||||
|
|
||||||
Question.operation_logger = MagicMock()
|
|
||||||
with patch.object(
|
with patch.object(
|
||||||
Question.operation_logger, "data_to_redact", create=True
|
|
||||||
), patch.object(
|
|
||||||
Moulinette, "prompt", return_value="some_value"
|
Moulinette, "prompt", return_value="some_value"
|
||||||
) as prompt, patch.object(
|
) as prompt, patch.object(
|
||||||
os, "isatty", return_value=True
|
os, "isatty", return_value=True
|
||||||
|
|
|
@ -39,6 +39,7 @@ from moulinette.utils.filesystem import (
|
||||||
|
|
||||||
from yunohost.utils.i18n import _value_for_locale
|
from yunohost.utils.i18n import _value_for_locale
|
||||||
from yunohost.utils.error import YunohostError, YunohostValidationError
|
from yunohost.utils.error import YunohostError, YunohostValidationError
|
||||||
|
from yunohost.log import OperationLogger
|
||||||
|
|
||||||
logger = getActionLogger("yunohost.config")
|
logger = getActionLogger("yunohost.config")
|
||||||
CONFIG_PANEL_VERSION_SUPPORTED = 1.0
|
CONFIG_PANEL_VERSION_SUPPORTED = 1.0
|
||||||
|
@ -441,7 +442,6 @@ class ConfigPanel:
|
||||||
|
|
||||||
class Question(object):
|
class Question(object):
|
||||||
hide_user_input_in_prompt = False
|
hide_user_input_in_prompt = False
|
||||||
operation_logger = None
|
|
||||||
pattern = None
|
pattern = None
|
||||||
|
|
||||||
def __init__(self, question, user_answers):
|
def __init__(self, question, user_answers):
|
||||||
|
@ -575,13 +575,9 @@ class Question(object):
|
||||||
for data in data_to_redact
|
for data in data_to_redact
|
||||||
if urllib.parse.quote(data) != data
|
if urllib.parse.quote(data) != data
|
||||||
]
|
]
|
||||||
if self.operation_logger:
|
|
||||||
self.operation_logger.data_to_redact.extend(data_to_redact)
|
for operation_logger in OperationLogger._instances:
|
||||||
elif data_to_redact:
|
operation_logger.data_to_redact.extend(data_to_redact)
|
||||||
raise YunohostError(
|
|
||||||
f"Can't redact {self.name} because no operation logger available in the context",
|
|
||||||
raw_msg=True,
|
|
||||||
)
|
|
||||||
|
|
||||||
return self.value
|
return self.value
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue