config.py 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. """
  2. Configuration Command Classes
  3. This module implements commands for configuration management.
  4. """
  5. from typing import Optional, Dict, Any
  6. from dataclasses import dataclass, field
  7. from .base import TrixyCommand, CommandResponse, ValidationError
  8. @dataclass
  9. class ConfigUpdateCommand(TrixyCommand):
  10. """Command to update configuration settings."""
  11. config_section: str = field(default="")
  12. config_changes: Dict[str, Any] = field(default_factory=dict)
  13. def validate(self) -> bool:
  14. if not self.config_section:
  15. raise ValidationError("ConfigUpdateCommand must have a config_section")
  16. return True
  17. def get_command_name(self) -> str:
  18. return "ConfigUpdateCommand"
  19. @dataclass
  20. class ConfigRequestCommand(TrixyCommand):
  21. """Command to request configuration data."""
  22. config_section: str = field(default="all")
  23. def validate(self) -> bool:
  24. return True
  25. def get_command_name(self) -> str:
  26. return "ConfigRequestCommand"
  27. @dataclass
  28. class ConfigValidateCommand(TrixyCommand):
  29. """Command to validate configuration."""
  30. config_data: Dict[str, Any] = field(default_factory=dict)
  31. def validate(self) -> bool:
  32. return True
  33. def get_command_name(self) -> str:
  34. return "ConfigValidateCommand"
  35. @dataclass
  36. class ConfigUpdateResponse(CommandResponse):
  37. """Response to config update command."""
  38. update_applied: bool = field(default=False)
  39. def validate(self) -> bool:
  40. return True
  41. def get_response_name(self) -> str:
  42. return "ConfigUpdateResponse"
  43. @dataclass
  44. class ConfigRequestResponse(CommandResponse):
  45. """Response to config request command."""
  46. config_data: Dict[str, Any] = field(default_factory=dict)
  47. def validate(self) -> bool:
  48. return True
  49. def get_response_name(self) -> str:
  50. return "ConfigRequestResponse"
  51. @dataclass
  52. class ConfigValidateResponse(CommandResponse):
  53. """Response to config validate command."""
  54. is_valid: bool = field(default=False)
  55. def validate(self) -> bool:
  56. return True
  57. def get_response_name(self) -> str:
  58. return "ConfigValidateResponse"
  59. __all__ = [
  60. "ConfigUpdateCommand", "ConfigRequestCommand", "ConfigValidateCommand",
  61. "ConfigUpdateResponse", "ConfigRequestResponse", "ConfigValidateResponse"
  62. ]