mirror of
https://github.com/OpenBB-finance/OpenBB.git
synced 2026-10-27 12:40:35 +00:00
[Enhancement] - Sanitize sensitive data from .cli.his (#6361)
* Sanitize sensitive data from .cli.his * fix long command providers --------- Co-authored-by: Diogo Sousa <montezdesousa@gmail.com>
This commit is contained in:
@@ -16,6 +16,7 @@ from typing import (
|
||||
from prompt_toolkit.completion import CompleteEvent, Completer, Completion
|
||||
from prompt_toolkit.document import Document
|
||||
from prompt_toolkit.formatted_text import AnyFormattedText
|
||||
from prompt_toolkit.history import FileHistory
|
||||
|
||||
NestedDict = Mapping[str, Union[Any, Set[str], None, Completer]]
|
||||
|
||||
@@ -401,3 +402,26 @@ class NestedCompleter(Completer):
|
||||
|
||||
# This is a WordCompleter
|
||||
yield from completer.get_completions(document, complete_event)
|
||||
|
||||
|
||||
class CustomFileHistory(FileHistory):
|
||||
"""Filtered file history."""
|
||||
|
||||
def sanitize_input(self, string: str) -> str:
|
||||
"""Sanitize sensitive information from the input string by parsing arguments."""
|
||||
keywords = ["--password", "--email", "--pat"]
|
||||
string_list = string.split(" ")
|
||||
|
||||
for kw in keywords:
|
||||
if kw in string_list:
|
||||
index = string_list.index(kw)
|
||||
if len(string_list) > index + 1:
|
||||
string_list[index + 1] = "********"
|
||||
|
||||
result = " ".join(string_list)
|
||||
return result
|
||||
|
||||
def store_string(self, string: str) -> None:
|
||||
"""Store string in history."""
|
||||
string = self.sanitize_input(string)
|
||||
super().store_string(string)
|
||||
|
||||
@@ -204,7 +204,7 @@ class MenuText:
|
||||
"""
|
||||
formatted_name = self._format_cmd_name(name)
|
||||
name_padding = (self.CMD_NAME_LENGTH - len(formatted_name)) * " "
|
||||
providers = get_ordered_providers(f"{self.menu_path}{formatted_name}")
|
||||
providers = get_ordered_providers(f"{self.menu_path}{name}")
|
||||
formatted_description = self._format_cmd_description(
|
||||
formatted_name,
|
||||
description,
|
||||
|
||||
@@ -8,8 +8,8 @@ from openbb import obb
|
||||
from openbb_core.app.model.abstract.singleton import SingletonMeta
|
||||
from openbb_core.app.model.user_settings import UserSettings as User
|
||||
from prompt_toolkit import PromptSession
|
||||
from prompt_toolkit.history import FileHistory
|
||||
|
||||
from openbb_cli.config.completer import CustomFileHistory
|
||||
from openbb_cli.config.console import Console
|
||||
from openbb_cli.config.constants import HIST_FILE_PROMPT
|
||||
from openbb_cli.config.style import Style
|
||||
@@ -62,7 +62,7 @@ class Session(metaclass=SingletonMeta):
|
||||
try:
|
||||
if sys.stdin.isatty():
|
||||
prompt_session: Optional[PromptSession] = PromptSession(
|
||||
history=FileHistory(str(HIST_FILE_PROMPT))
|
||||
history=CustomFileHistory(str(HIST_FILE_PROMPT))
|
||||
)
|
||||
else:
|
||||
prompt_session = None
|
||||
|
||||
Reference in New Issue
Block a user