This commit is contained in:
@@ -60,6 +60,8 @@ addLoggingLevel("TRACE", logging.DEBUG - 5)
|
||||
|
||||
|
||||
class ColoredFormatter(logging.Formatter):
|
||||
sensetive = set() # TODO: chain formatters?
|
||||
|
||||
def __init__(self, fmt):
|
||||
super().__init__()
|
||||
self.fmt = fmt
|
||||
@@ -72,7 +74,12 @@ class ColoredFormatter(logging.Formatter):
|
||||
logging.CRITICAL: colored(self.fmt, "red", attrs=["bold"]),
|
||||
}
|
||||
|
||||
def _mask_sensetive_data(self, message: str) -> str:
|
||||
for value in self.sensetive:
|
||||
message = message.replace(value, "*****")
|
||||
return message
|
||||
|
||||
def format(self, record: logging.LogRecord):
|
||||
log_fmt = self.FORMATS.get(record.levelno)
|
||||
formatter = logging.Formatter(log_fmt)
|
||||
return formatter.format(record)
|
||||
return self._mask_sensetive_data(formatter.format(record))
|
||||
|
||||
@@ -5,7 +5,7 @@ from .entry import Entry
|
||||
|
||||
class EmptyEntry(Entry):
|
||||
def __init__(self):
|
||||
super().__init__([], Path(), Path())
|
||||
super().__init__([], {}, Path(), Path())
|
||||
|
||||
def __bool__(self):
|
||||
return False
|
||||
|
||||
@@ -3,6 +3,7 @@ from pathlib import Path
|
||||
from typing import NamedTuple, Self
|
||||
|
||||
from ..common.command import CommandExecutor
|
||||
from ..preset.model import Variables
|
||||
|
||||
logger = logging.getLogger("entry")
|
||||
|
||||
@@ -57,13 +58,21 @@ class Entry:
|
||||
def __init__(
|
||||
self,
|
||||
tasks: list[Task],
|
||||
variables: Variables,
|
||||
basepath: Path,
|
||||
rootpath: Path,
|
||||
):
|
||||
self._tasks = tasks
|
||||
self._variables = variables
|
||||
self._basepath = basepath
|
||||
self._roopath = rootpath
|
||||
|
||||
@property
|
||||
def sensentive_data(self):
|
||||
for k, v in self._variables.items():
|
||||
if "pass" in k.lower():
|
||||
yield v
|
||||
|
||||
def show(self):
|
||||
self._logger.info("🔵 %s", self)
|
||||
level = logging.root.level
|
||||
|
||||
@@ -6,6 +6,7 @@ from typing import Iterable
|
||||
|
||||
from .common.command import CommandError
|
||||
from .common.ignore import create_ignore
|
||||
from .common.logging_colored import ColoredFormatter
|
||||
from .entry.entry import Entry, PartialTaskKey
|
||||
from .entry.resolver import EntryResolver
|
||||
from .preset.detector import PresetEntryDetector
|
||||
@@ -38,7 +39,10 @@ class ProjectManager:
|
||||
|
||||
def run_task(self, key: PartialTaskKey) -> dict[str, int]:
|
||||
counter = Counter()
|
||||
sensetive = set()
|
||||
ColoredFormatter.sensetive = sensetive
|
||||
for entry in self._iter_entries():
|
||||
sensetive.update(set(entry.sensentive_data))
|
||||
try:
|
||||
if count := entry.run_task(key):
|
||||
counter[ResultType.SUCCESS] += count
|
||||
@@ -51,4 +55,5 @@ class ProjectManager:
|
||||
self._logger.info(
|
||||
"%s", "\n".join(f"{RESULT_ICONS[k]} {v}" for k, v in counter.items())
|
||||
)
|
||||
ColoredFormatter.sensetive = set()
|
||||
return counter
|
||||
|
||||
@@ -27,6 +27,7 @@ class PresetEntryDetector(EntryDetector):
|
||||
return ENTRY_SKIP
|
||||
tasks = []
|
||||
global_variables = {f"env_{k.lower()}": v for k, v in environ.items()}
|
||||
entry_variables = {}
|
||||
presets = sorted(
|
||||
preset.presets.items(), key=lambda item: item[1].priority, reverse=True
|
||||
)
|
||||
@@ -39,6 +40,7 @@ class PresetEntryDetector(EntryDetector):
|
||||
if tag == "*":
|
||||
template.update_variables(preset.variables, global_variables)
|
||||
template.update_variables(preset.variables, preset_variables)
|
||||
entry_variables.update(preset_variables)
|
||||
if preset.conditions and not template.check_conditions(
|
||||
preset.conditions, preset_variables
|
||||
):
|
||||
@@ -73,5 +75,5 @@ class PresetEntryDetector(EntryDetector):
|
||||
tasks.append(task)
|
||||
if tasks:
|
||||
tasks = sorted(tasks, key=operator.attrgetter("priority"), reverse=True)
|
||||
return Entry(tasks, basepath, rootpath)
|
||||
return Entry(tasks, entry_variables, basepath, rootpath)
|
||||
return ENTRY_NONE
|
||||
|
||||
Reference in New Issue
Block a user