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