variables.py 1.6 KB

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