variables.py 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. from collections.abc import Sequence
  2. from uuid import uuid4
  3. from pydantic import Field
  4. from core.helper import encrypter
  5. from .segments import (
  6. ArrayAnySegment,
  7. ArrayFileSegment,
  8. ArrayNumberSegment,
  9. ArrayObjectSegment,
  10. ArrayStringSegment,
  11. FileSegment,
  12. FloatSegment,
  13. IntegerSegment,
  14. NoneSegment,
  15. ObjectSegment,
  16. Segment,
  17. StringSegment,
  18. )
  19. from .types import SegmentType
  20. class Variable(Segment):
  21. """
  22. A variable is a segment that has a name.
  23. """
  24. id: str = Field(
  25. default=lambda _: str(uuid4()),
  26. description="Unique identity for variable.",
  27. )
  28. name: str
  29. description: str = Field(default="", description="Description of the variable.")
  30. selector: Sequence[str] = Field(default_factory=list)
  31. class StringVariable(StringSegment, Variable):
  32. pass
  33. class FloatVariable(FloatSegment, Variable):
  34. pass
  35. class IntegerVariable(IntegerSegment, Variable):
  36. pass
  37. class ObjectVariable(ObjectSegment, Variable):
  38. pass
  39. class ArrayAnyVariable(ArrayAnySegment, Variable):
  40. pass
  41. class ArrayStringVariable(ArrayStringSegment, Variable):
  42. pass
  43. class ArrayNumberVariable(ArrayNumberSegment, Variable):
  44. pass
  45. class ArrayObjectVariable(ArrayObjectSegment, Variable):
  46. pass
  47. class SecretVariable(StringVariable):
  48. value_type: SegmentType = SegmentType.SECRET
  49. @property
  50. def log(self) -> str:
  51. return encrypter.obfuscated_token(self.value)
  52. class NoneVariable(NoneSegment, Variable):
  53. value_type: SegmentType = SegmentType.NONE
  54. value: None = None
  55. class FileVariable(FileSegment, Variable):
  56. pass
  57. class ArrayFileVariable(ArrayFileSegment, Variable):
  58. pass