variables.py 1.8 KB

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