Skip to content

Commit

Permalink
feat(Update CLI):
Browse files Browse the repository at this point in the history
  • Loading branch information
msoedov committed Jan 4, 2025
1 parent 1138b66 commit 64f7f4b
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 13 deletions.
40 changes: 30 additions & 10 deletions agentic_security/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,28 +8,48 @@
from agentic_security.lib import AgenticSecurity


class T:
def server(self, port=8718, host="0.0.0.0"):
class CLI:
def server(self, port: int = 8718, host: str = "0.0.0.0"):
"""
Launch the Agentic Security server.
Args:
port (int): Port number for the server to listen on. Default is 8718.
host (str): Host address for the server. Default is "0.0.0.0".
"""
sys.path.append(os.path.dirname("."))
config = uvicorn.Config(
app, port=port, host=host, log_level="info", reload=True
)
server = uvicorn.Server(config)
server.run()
return

def headless(self):
s = server

def ci(self):
"""
Run Agentic Security in CI mode.
"""
sys.path.append(os.path.dirname("."))
AgenticSecurity().entrypoint()


def entrypoint():
fire.Fire(T().server)
def init(self):
"""
Generate the default CI configuration file.
"""
sys.path.append(os.path.dirname("."))
AgenticSecurity().generate_default_cfg()


def ci_entrypoint():
fire.Fire(T().headless)
def main():
"""
Entry point for the CLI. Default behavior launches the server,
while subcommands allow CI or configuration generation.
"""
fire.Fire(
CLI,
)


if __name__ == "__main__":
ci_entrypoint()
main()
4 changes: 4 additions & 0 deletions agentic_security/lib.py
Original file line number Diff line number Diff line change
Expand Up @@ -291,3 +291,7 @@ def generate_default_cfg(self):
"""
)

logger.info(
f"Default configuration generated successfully to {self.default_path}."
)
6 changes: 3 additions & 3 deletions agentic_security/test_lib.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,9 @@
import tempfile
import time

import agentic_security.test_spec_assets as test_spec_assets
import pytest

import agentic_security.test_spec_assets as test_spec_assets
from agentic_security.lib import AgenticSecurity


Expand Down Expand Up @@ -125,7 +126,6 @@ def test_backend(self, test_server):


class TestEntrypointCI:

def test_generate_default_cfg_to_tmp_path(self):
"""
Test that the `generate_default_cfg` method generates a valid default config file in a temporary path.
Expand All @@ -145,7 +145,7 @@ def test_generate_default_cfg_to_tmp_path(self):
assert os.path.exists(temp_path), f"{temp_path} file should be generated."

# Validate the contents of the generated config file
with open(temp_path, "r") as f:
with open(temp_path) as f:
generated_content = f.read()
assert (
"maxBudget = 1000000" in generated_content
Expand Down

0 comments on commit 64f7f4b

Please sign in to comment.