From a63106686f4a6fc2a407c94b19529a264b218f11 Mon Sep 17 00:00:00 2001 From: Alexander Myasoedov Date: Fri, 28 Feb 2025 19:32:40 +0200 Subject: [PATCH] feat(Add banner): --- agentic_security/__main__.py | 2 + agentic_security/banner.py | 88 ++++++++++++++++++++++++++++++++++++ poetry.lock | 13 +++++- pyproject.toml | 3 ++ 4 files changed, 105 insertions(+), 1 deletion(-) create mode 100644 agentic_security/banner.py diff --git a/agentic_security/__main__.py b/agentic_security/__main__.py index 1d35676..586b5ff 100644 --- a/agentic_security/__main__.py +++ b/agentic_security/__main__.py @@ -5,6 +5,7 @@ import fire import uvicorn from agentic_security.app import app +from agentic_security.banner import init_banner from agentic_security.lib import AgenticSecurity @@ -61,4 +62,5 @@ def main(): if __name__ == "__main__": + init_banner() main() diff --git a/agentic_security/banner.py b/agentic_security/banner.py new file mode 100644 index 0000000..23b2dd6 --- /dev/null +++ b/agentic_security/banner.py @@ -0,0 +1,88 @@ +from pyfiglet import Figlet, FontNotFound +from termcolor import colored + +try: + from importlib.metadata import version +except ImportError: + from importlib_metadata import version + + +def generate_banner( + title="Agentic Security", + font="slant", + version="v2.1.0", + tagline="Proactive Threat Detection & Automated Security Protocols", + author="Developed by: [Security Team]", + website="Website: https://github.com/msoedov/agentic_security", + warning="", +): + """Generate a visually enhanced banner with dynamic width and borders.""" + # Define the text elements + + # Initialize Figlet with the specified font, fallback to default if not found + try: + f = Figlet(font=font) + except FontNotFound: + f = Figlet() # Fallback to default font + + # Render the title text and calculate the maximum width of Figlet lines + banner_text = f.renderText(title) + banner_lines = banner_text.splitlines() + figlet_max_width = max(len(line) for line in banner_lines) if banner_lines else 0 + + # Create the details line and calculate its width + details_line = f"Version: {version} | {website}" + details_width = len(details_line) + + # Calculate widths of other text elements + warning_width = len(warning) + tagline_width = len(tagline) + + # Determine the overall maximum width for centering + overall_max_width = max( + figlet_max_width, warning_width, tagline_width, details_width + ) + + # Pad the Figlet lines to the overall maximum width + padded_banner_lines = [line.center(overall_max_width) for line in banner_lines] + + # Define decorative characters and colors + decor_chars = ["▄", "■", "►"] + decor_colors = ["blue", "red", "yellow"] + + # Create and color the content lines + content_lines = [] + for line in padded_banner_lines: + content_lines.append(colored(line, "blue")) + content_lines.append(colored(decor_chars[0] * overall_max_width, decor_colors[0])) + content_lines.append( + colored(warning.center(overall_max_width), "red", attrs=["blink", "bold"]) + ) + content_lines.append(colored(decor_chars[1] * overall_max_width, decor_colors[1])) + content_lines.append(colored(tagline.center(overall_max_width), "red")) + content_lines.append(colored(decor_chars[2] * overall_max_width, decor_colors[2])) + content_lines.append(colored(details_line.center(overall_max_width), "magenta")) + + # Define border color and create top and bottom borders + border_color = "blue" + top_border = colored("╔" + "═" * (overall_max_width + 2) + "╗", border_color) + bottom_border = colored("╚" + "═" * (overall_max_width + 2) + "╝", border_color) + + # Add side borders to each content line with padding + bordered_content = [ + colored("║ ", border_color) + line + colored(" ║", border_color) + for line in content_lines + ] + + # Assemble the full banner + banner = top_border + "\n" + "\n".join(bordered_content) + "\n" + bottom_border + return banner + + +def init_banner(): + ver = version("agentic_security") + print(generate_banner(version=ver)) + + +if __name__ == "__main__": + init_banner() diff --git a/poetry.lock b/poetry.lock index 2edf454..d4a3614 100644 --- a/poetry.lock +++ b/poetry.lock @@ -3102,6 +3102,17 @@ files = [ [package.dependencies] typing-extensions = ">=4.6.0,<4.7.0 || >4.7.0" +[[package]] +name = "pyfiglet" +version = "1.0.2" +description = "Pure-python FIGlet implementation" +optional = false +python-versions = ">=3.9" +files = [ + {file = "pyfiglet-1.0.2-py3-none-any.whl", hash = "sha256:889b351d79c99e50a3f619c8f8e6ffdb27fd8c939fc43ecbd7559bd57d5f93ea"}, + {file = "pyfiglet-1.0.2.tar.gz", hash = "sha256:758788018ab8faaddc0984e1ea05ff330d3c64be663c513cc1f105f6a3066dab"}, +] + [[package]] name = "pygments" version = "2.18.0" @@ -4527,4 +4538,4 @@ propcache = ">=0.2.0" [metadata] lock-version = "2.0" python-versions = "^3.11" -content-hash = "cfbaad4d4e8afd99604df03e4e374a8784f88d67cc370c604180c4f6b4070cba" +content-hash = "28a2b74bfafa9f93d14d2f8d1fcaffa340db212acce6469d6714d342203ad77f" diff --git a/pyproject.toml b/pyproject.toml index 5f8f599..f89571a 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -50,6 +50,9 @@ rich = "13.9.4" gTTS = "^2.5.4" sentry_sdk = "^2.22.0" orjson = "^3.10" +pyfiglet = "^1.0.2" +termcolor = "^2.4.0" + # garak = { version = "*", optional = true }