Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove colorama depedency #747

Merged
merged 14 commits into from
Jan 29, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@

### Features
### Improvements
* removes `colorama` dependency

### Bugfix
* fixes a bug with lucene regex and parentheses
* fixes a conflict between lucene filter and the Crypto module
Expand Down
2 changes: 1 addition & 1 deletion logprep/abc/component.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
""" abstract module for components"""
"""abstract module for components"""

import functools
import inspect
Expand Down
2 changes: 1 addition & 1 deletion logprep/abc/connector.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
""" abstract module for connectors"""
"""abstract module for connectors"""

from attrs import define, field

Expand Down
2 changes: 1 addition & 1 deletion logprep/abc/exceptions.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
""" abstract module for exceptions"""
"""abstract module for exceptions"""


class LogprepException(Exception):
Expand Down
2 changes: 1 addition & 1 deletion logprep/configuration.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
"""module for component configuration """
"""module for component configuration"""

from typing import TYPE_CHECKING, Any, Mapping

Expand Down
2 changes: 1 addition & 1 deletion logprep/framework/rule_tree/rule_tagger.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
""" This module implements functionality to add tags to filter expressions. """
"""This module implements functionality to add tags to filter expressions."""

from typing import Union, List

Expand Down
2 changes: 1 addition & 1 deletion logprep/generator/kafka/configuration.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
""" Contains configuration class with configuration validation """
"""Contains configuration class with configuration validation"""

# pylint: disable=too-few-public-methods
import sys
Expand Down
4 changes: 2 additions & 2 deletions logprep/processor/pre_detector/rule.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@
ip_fields:
- some_ip_field
The pre_detector also has the option to normalize the timestamp.
The pre_detector also has the option to normalize the timestamp.
To configure this the following parameters can be set in the rule configuration.
.. code-block:: yaml
Expand All @@ -110,7 +110,7 @@
target_timezone: <the timezone after normalization>
description: Some malicious event.
All of these new parameters are configurable and default to
All of these new parameters are configurable and default to
standard values if not explicitly set.
.. autoclass:: logprep.processor.pre_detector.rule.PreDetectorRule.Config
Expand Down
2 changes: 1 addition & 1 deletion logprep/processor/timestamper/rule.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
:caption: Given timestamper rule
filter: "winlog.event_id: 123456789"
timestamper:
timestamper:
source_fields: ["winlog.event_data.some_timestamp_utc"]
target_field: "@timestamp"
source_format: UNIX
Expand Down
4 changes: 2 additions & 2 deletions logprep/registry.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
"""module for processor registry
it is used to check if a processor is known to the system.
you have to register new processors here by import them and add to `ProcessorRegistry.mapping`
it is used to check if a processor is known to the system.
you have to register new processors here by import them and add to `ProcessorRegistry.mapping`
"""

from logprep.connector.confluent_kafka.input import ConfluentKafkaInput
Expand Down
2 changes: 1 addition & 1 deletion logprep/run_logprep.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import warnings

import click
from colorama import Fore
from logprep.util.ansi import Fore

from logprep.generator.http.controller import Controller
from logprep.generator.kafka.run_load_tester import LoadTester
Expand Down
78 changes: 78 additions & 0 deletions logprep/util/ansi.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
# Copyright (c) 2010 Jonathan Hartley
# All rights reserved.

# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions are met:

# * Redistributions of source code must retain the above copyright notice, this
# list of conditions and the following disclaimer.

# * Redistributions in binary form must reproduce the above copyright notice,
# this list of conditions and the following disclaimer in the documentation
# and/or other materials provided with the distribution.

# * Neither the name of the copyright holders, nor those of its contributors
# may be used to endorse or promote products derived from this software without
# specific prior written permission.

# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
# SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
# CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
# OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

"""
This module generates ANSI character codes to printing colors to terminals.
See: http://en.wikipedia.org/wiki/ANSI_escape_code
This module contains only a subset of the original colorama library. Additional codes can be added in this module from
https://github.com/tartley/colorama/blob/master/colorama/ansi.py.
"""

CSI = "\033["
OSC = "\033]"
BEL = "\a"


def code_to_chars(code):
return CSI + str(code) + "m"


class AnsiCodes(object):
def __init__(self):
# the subclasses declare class attributes which are numbers.
# Upon instantiation we define instance attributes, which are the same
# as the class attributes but wrapped with the ANSI escape sequence
for name in dir(self):
if not name.startswith("_"):
value = getattr(self, name)
setattr(self, name, code_to_chars(value))


class AnsiFore(AnsiCodes):
BLACK = 30
RED = 31
GREEN = 32
YELLOW = 33
BLUE = 34
MAGENTA = 35
CYAN = 36
WHITE = 37
RESET = 39


class AnsiBack(AnsiCodes):
BLACK = 40
YELLOW = 43
MAGENTA = 45
CYAN = 46
WHITE = 47
RESET = 49


Fore = AnsiFore()
Back = AnsiBack()
2 changes: 1 addition & 1 deletion logprep/util/auto_rule_tester/auto_rule_tester.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@
from pprint import pprint
from typing import TYPE_CHECKING, Union

from colorama import Fore
from logprep.util.ansi import Fore
from more_itertools import nth
from ruamel.yaml import YAML, YAMLError

Expand Down
10 changes: 5 additions & 5 deletions logprep/util/credentials.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
filled with the correct values that correspond to the method you want to use.
.. code-block:: yaml
:caption: Example for credentials file
:caption: Example for credentials file
getter:
"http://target.url":
# example for token given directly via file
Expand Down Expand Up @@ -71,11 +71,11 @@
/second*:
username: <username>
password: <password>
Options for the credentials file are:
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
.. autoclass:: logprep.util.credentials.BasicAuthCredentials
:members: username, password
:no-index:
Expand All @@ -88,7 +88,7 @@
.. autoclass:: logprep.util.credentials.MTLSCredentials
:members: client_key, cert, ca_cert
:no-index:
Authentication Process:
^^^^^^^^^^^^^^^^^^^^^^^
.. figure:: ../_images/Credentials.svg
Expand Down
2 changes: 1 addition & 1 deletion logprep/util/grok/grok.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
original code from https://github.com/garyelephant/pygrok released under MIT Licence
The MIT License (MIT)
Copyright (c) 2014
Copyright (c) 2014
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
3 changes: 1 addition & 2 deletions logprep/util/helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@
from os import remove
from typing import TYPE_CHECKING, Optional, Union

from colorama import Back, Fore
from colorama.ansi import AnsiBack, AnsiFore
from logprep.util.ansi import Back, Fore, AnsiBack, AnsiFore

from logprep.processor.base.exceptions import FieldExistsWarning
from logprep.util.defaults import DEFAULT_CONFIG_LOCATION
Expand Down
2 changes: 1 addition & 1 deletion logprep/util/json_handling.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
""" module for json handling helper methods"""
"""module for json handling helper methods"""

import json
import os
Expand Down
2 changes: 1 addition & 1 deletion logprep/util/rule_dry_runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,13 @@
from functools import cached_property
from typing import Dict, List

from colorama import Back, Fore
from ruamel.yaml import YAML

from logprep.framework.pipeline import Pipeline, PipelineResult
from logprep.util.configuration import Configuration
from logprep.util.getter import GetterFactory
from logprep.util.helper import color_print_line, color_print_title, recursive_compare
from logprep.util.ansi import Back, Fore

yaml = YAML(typ="safe", pure=True)

Expand Down
2 changes: 1 addition & 1 deletion logprep/util/url/url.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
""" helper functions for URL extraction and validation.
"""helper functions for URL extraction and validation.
Code is inspired by django url validation:
https://docs.djangoproject.com/en/4.1/_modules/django/core/validators/
"""
Expand Down
2 changes: 1 addition & 1 deletion logprep/util/validators.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
""" validators to use with `attrs` fields"""
"""validators to use with `attrs` fields"""

import os
import typing
Expand Down
1 change: 0 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,6 @@ dependencies = [
"aiohttp>=3.9.2", # CVE-2024-23334
"attrs",
"certifi>=2023.7.22", # CVE-2023-37920
"colorama",
"confluent-kafka>2",
"filelock",
"geoip2",
Expand Down
20 changes: 20 additions & 0 deletions tests/unit/util/test_ansi_code.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
from logprep.util.ansi import Fore, Back


class TestAnsiCodes:
def test_basic_color_codes(self):
assert Fore.BLACK == "\033[30m"
assert Fore.RED == "\033[31m"
assert Fore.GREEN == "\033[32m"
assert Fore.YELLOW == "\033[33m"
assert Fore.BLUE == "\033[34m"
assert Fore.MAGENTA == "\033[35m"
assert Fore.CYAN == "\033[36m"
assert Fore.WHITE == "\033[37m"
assert Fore.RESET == "\033[39m"
assert Back.BLACK == "\033[40m"
assert Back.YELLOW == "\033[43m"
assert Back.MAGENTA == "\033[45m"
assert Back.CYAN == "\033[46m"
assert Back.WHITE == "\033[47m"
assert Back.RESET == "\033[49m"
Loading