2024-11-12 13:51:09 +00:00
|
|
|
from collections.abc import Sequence
|
2024-12-24 10:38:51 +00:00
|
|
|
from typing import cast
|
2024-11-12 13:51:09 +00:00
|
|
|
from uuid import uuid4
|
|
|
|
|
|
2024-07-22 07:29:39 +00:00
|
|
|
from pydantic import Field
|
|
|
|
|
|
|
|
|
|
from core.helper import encrypter
|
|
|
|
|
|
2024-07-26 07:03:56 +00:00
|
|
|
from .segments import (
|
2024-07-27 06:43:51 +00:00
|
|
|
ArrayAnySegment,
|
2024-11-12 13:51:09 +00:00
|
|
|
ArrayFileSegment,
|
2024-07-27 06:43:51 +00:00
|
|
|
ArrayNumberSegment,
|
|
|
|
|
ArrayObjectSegment,
|
2024-12-23 07:52:50 +00:00
|
|
|
ArraySegment,
|
2024-07-27 06:43:51 +00:00
|
|
|
ArrayStringSegment,
|
2024-10-21 02:43:49 +00:00
|
|
|
FileSegment,
|
2024-07-26 07:03:56 +00:00
|
|
|
FloatSegment,
|
|
|
|
|
IntegerSegment,
|
|
|
|
|
NoneSegment,
|
|
|
|
|
ObjectSegment,
|
|
|
|
|
Segment,
|
|
|
|
|
StringSegment,
|
|
|
|
|
)
|
2024-07-22 07:29:39 +00:00
|
|
|
from .types import SegmentType
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class Variable(Segment):
|
|
|
|
|
"""
|
|
|
|
|
A variable is a segment that has a name.
|
|
|
|
|
"""
|
|
|
|
|
|
|
|
|
|
id: str = Field(
|
2024-11-12 13:51:09 +00:00
|
|
|
default=lambda _: str(uuid4()),
|
|
|
|
|
description="Unique identity for variable.",
|
2024-07-22 07:29:39 +00:00
|
|
|
)
|
|
|
|
|
name: str
|
2024-09-10 09:00:20 +00:00
|
|
|
description: str = Field(default="", description="Description of the variable.")
|
2024-11-12 13:51:09 +00:00
|
|
|
selector: Sequence[str] = Field(default_factory=list)
|
2024-07-22 07:29:39 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
class StringVariable(StringSegment, Variable):
|
|
|
|
|
pass
|
|
|
|
|
|
|
|
|
|
|
2024-07-26 07:03:56 +00:00
|
|
|
class FloatVariable(FloatSegment, Variable):
|
|
|
|
|
pass
|
2024-07-22 07:29:39 +00:00
|
|
|
|
2024-07-25 09:06:38 +00:00
|
|
|
|
2024-07-26 07:03:56 +00:00
|
|
|
class IntegerVariable(IntegerSegment, Variable):
|
|
|
|
|
pass
|
2024-07-22 07:29:39 +00:00
|
|
|
|
|
|
|
|
|
2024-07-26 07:03:56 +00:00
|
|
|
class ObjectVariable(ObjectSegment, Variable):
|
|
|
|
|
pass
|
2024-07-22 07:29:39 +00:00
|
|
|
|
2024-07-25 09:06:38 +00:00
|
|
|
|
2024-12-23 07:52:50 +00:00
|
|
|
class ArrayVariable(ArraySegment, Variable):
|
2024-07-26 07:03:56 +00:00
|
|
|
pass
|
2024-07-22 07:29:39 +00:00
|
|
|
|
|
|
|
|
|
2024-12-23 07:52:50 +00:00
|
|
|
class ArrayAnyVariable(ArrayAnySegment, ArrayVariable):
|
2024-07-27 06:43:51 +00:00
|
|
|
pass
|
|
|
|
|
|
|
|
|
|
|
2024-12-23 07:52:50 +00:00
|
|
|
class ArrayStringVariable(ArrayStringSegment, ArrayVariable):
|
2024-07-27 06:43:51 +00:00
|
|
|
pass
|
|
|
|
|
|
|
|
|
|
|
2024-12-23 07:52:50 +00:00
|
|
|
class ArrayNumberVariable(ArrayNumberSegment, ArrayVariable):
|
|
|
|
|
pass
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class ArrayObjectVariable(ArrayObjectSegment, ArrayVariable):
|
2024-07-27 06:43:51 +00:00
|
|
|
pass
|
|
|
|
|
|
|
|
|
|
|
2024-07-22 07:29:39 +00:00
|
|
|
class SecretVariable(StringVariable):
|
|
|
|
|
value_type: SegmentType = SegmentType.SECRET
|
|
|
|
|
|
|
|
|
|
@property
|
|
|
|
|
def log(self) -> str:
|
2024-12-24 10:38:51 +00:00
|
|
|
return cast(str, encrypter.obfuscated_token(self.value))
|
2024-07-23 09:59:32 +00:00
|
|
|
|
|
|
|
|
|
2024-07-23 13:46:08 +00:00
|
|
|
class NoneVariable(NoneSegment, Variable):
|
2024-07-23 09:59:32 +00:00
|
|
|
value_type: SegmentType = SegmentType.NONE
|
2024-07-23 13:46:08 +00:00
|
|
|
value: None = None
|
2024-10-21 02:43:49 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
class FileVariable(FileSegment, Variable):
|
|
|
|
|
pass
|
2024-11-12 13:51:09 +00:00
|
|
|
|
|
|
|
|
|
2024-12-24 07:56:59 +00:00
|
|
|
class ArrayFileVariable(ArrayFileSegment, ArrayVariable):
|
2024-11-12 13:51:09 +00:00
|
|
|
pass
|