From f9beddaeffcea0e24f5132b5d8fe2758d48b88a0 Mon Sep 17 00:00:00 2001 From: MystyPy Date: Tue, 28 May 2024 12:10:51 +1000 Subject: [PATCH] Fix requested changes. --- core/scanners.py | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/core/scanners.py b/core/scanners.py index 9c2729d..5d31dc8 100644 --- a/core/scanners.py +++ b/core/scanners.py @@ -16,14 +16,18 @@ along with this program. If not, see . """ +from __future__ import annotations + import base64 import binascii import enum import logging import re -from typing import ClassVar +from typing import TYPE_CHECKING, ClassVar + -from types_.scanner import ScannerSecret +if TYPE_CHECKING: + from types_.scanner import ScannerSecret logger: logging.Logger = logging.getLogger(__name__) @@ -37,7 +41,7 @@ class Services(enum.Enum): class BaseScanner: REGEX: ClassVar[re.Pattern[str]] - SERVICE: Services + SERVICE: ClassVar[Services] @classmethod def match(cls, content: str) -> ScannerSecret: @@ -103,15 +107,17 @@ def scan_file( file: str, /, *, - allowed: list[Services] = [], - disallowed: list[Services] = [], + allowed: list[Services] | None = None, + disallowed: list[Services] | None = None, ) -> list[ScannerSecret]: """Scan for tokens in a given files content. You may pass a list of allowed or disallowed Services. If both lists are empty (Default) all available services will be scanned. """ - allowed = allowed if allowed else list(Services) + disallowed = disallowed or [] + allowed = allowed or list(Services) + services: list[Services] = [s for s in allowed if s not in disallowed] secrets: list[ScannerSecret] = []