File size: 3,890 Bytes
6440b1f
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
"""
Configuration module for VAPT Agent.

This module handles all configuration loading from environment variables
and provides a centralized config object.
"""

import os
from typing import Optional
from dotenv import load_dotenv

load_dotenv(override=True)


class VAPTConfig:
    """Configuration class for VAPT Agent."""

    def __init__(self):
        """Initialize configuration from environment variables."""

        # ====================================================================
        # AWS Configuration
        # ====================================================================
        self.use_bedrock = os.getenv("CLAUDE_CODE_USE_BEDROCK", "0") == "1"
        self.aws_access_key_id = os.getenv("AWS_ACCESS_KEY_ID", "")
        self.aws_secret_access_key = os.getenv("AWS_SECRET_ACCESS_KEY", "")
        self.aws_region = os.getenv("AWS_REGION", "us-east-1")

        # ====================================================================
        # Model Configuration
        # ====================================================================
        if self.use_bedrock:
            # Default to Bedrock model identifier
            default_model = "global.anthropic.claude-haiku-4-5-20251001-v1:0"
        else:
            # Default to Anthropic API model
            default_model = "claude-sonnet-4-20250514"

        self.model_name = os.getenv("ANTHROPIC_MODEL", default_model)

        # ====================================================================
        # Postman Configuration
        # ====================================================================
        self.postman_api_key = os.getenv("POSTMAN_API_KEY", "")

        # ====================================================================
        # Test API Configuration
        # ====================================================================
        self.test_api_endpoint = os.getenv(
            "TEST_API_ENDPOINT", "https://sandbox.api.sap.com/SAPCALM/calm-tasks/v1/tasks?projectId=111"
        )
        self.test_api_method = os.getenv("TEST_API_METHOD", "GET")
        self.test_api_key = os.getenv("TEST_API_KEY", "")

        # ====================================================================
        # Agent Configuration
        # ====================================================================
        self.max_turns = int(os.getenv("MAX_TURNS", "100"))
        self.timeout_seconds = int(os.getenv("TIMEOUT_SECONDS", "600"))
        self.max_retries = int(os.getenv("MAX_RETRIES", "3"))

        # Validate required configuration
        self._validate()

    def _validate(self):
        """Validate required configuration values."""
        errors = []

        if not self.postman_api_key:
            errors.append("POSTMAN_API_KEY is required")

        if self.use_bedrock:
            if not self.aws_access_key_id:
                errors.append("AWS_ACCESS_KEY_ID is required when using Bedrock")
            if not self.aws_secret_access_key:
                errors.append("AWS_SECRET_ACCESS_KEY is required when using Bedrock")

        if errors:
            raise ValueError(
                "Configuration validation failed:\n"
                + "\n".join(f"  - {e}" for e in errors)
            )

    def to_dict(self):
        """Return configuration as dictionary (excluding sensitive data)."""
        return {
            "use_bedrock": self.use_bedrock,
            "aws_region": self.aws_region,
            "model_name": self.model_name,
            "test_api_endpoint": self.test_api_endpoint,
            "test_api_method": self.test_api_method,
            "max_turns": self.max_turns,
            "timeout_seconds": self.timeout_seconds,
            "max_retries": self.max_retries,
        }

    def __repr__(self):
        """String representation of configuration."""
        return f"VAPTConfig({self.to_dict()})"