security_config.py 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. from dataclasses import dataclass, fields
  2. from openhands.core.config.config_utils import get_field_info
  3. @dataclass
  4. class SecurityConfig:
  5. """Configuration for security related functionalities.
  6. Attributes:
  7. confirmation_mode: Whether to enable confirmation mode.
  8. security_analyzer: The security analyzer to use.
  9. """
  10. confirmation_mode: bool = False
  11. security_analyzer: str | None = None
  12. def defaults_to_dict(self) -> dict:
  13. """Serialize fields to a dict for the frontend, including type hints, defaults, and whether it's optional."""
  14. dict = {}
  15. for f in fields(self):
  16. dict[f.name] = get_field_info(f)
  17. return dict
  18. def __str__(self):
  19. attr_str = []
  20. for f in fields(self):
  21. attr_name = f.name
  22. attr_value = getattr(self, f.name)
  23. attr_str.append(f'{attr_name}={repr(attr_value)}')
  24. return f"SecurityConfig({', '.join(attr_str)})"
  25. @classmethod
  26. def from_dict(cls, security_config_dict: dict) -> 'SecurityConfig':
  27. return cls(**security_config_dict)
  28. def __repr__(self):
  29. return self.__str__()