1+ import jsonschema
2+
3+ from beanie import Document , Indexed , before_event , Replace , Save , Link
4+ from datetime import datetime
5+ from pydantic import Field , Any , field_validator
6+ from .access_types import AccessTypeEnum
7+
8+ from app .project .models .project_database_model import Project
9+
10+
11+ class Satellite (Document ):
12+
13+ name : Indexed (str , unique = True ) = Field (..., description = "Name of the satellite" )
14+
15+ friendly_name : str = Field (..., description = "Friendly name of the satellite" )
16+
17+ description : str = Field (..., description = "Description of the satellite" )
18+
19+ access_type : AccessTypeEnum = Field (..., description = "Access type of the satellite" )
20+
21+ configs : dict [str , Any ] = Field (..., description = "Configurations of the satellite, a valid jsonschema object for the configs" )
22+ inputs : dict [str , Any ] = Field (..., description = "Input data fothe satellite, a valid jsonschema object for the inputs" )
23+ metrics : dict [str , Any ] = Field (..., description = "Metrics of the satellite, a valid jsonschema object for the metrics" )
24+ outputs : dict [str , Any ] = Field (..., description = "Outputs of the satellite, a valid jsonschema object for the outputs" )
25+
26+ project : Link [Project ] = Field (..., description = "Project of the satellite" )
27+
28+ created_at : datetime = Field (default_factory = datetime .now , description = "Date and time when the satellite was created" )
29+
30+ updated_at : datetime = Field (default_factory = datetime .now , description = "Date and time when the satellite was last updated" )
31+
32+
33+ @field_validator ("configs" , "inputs" , "metrics" , "outputs" )
34+ def validate_jsonschema (cls , v : dict [str , Any ]) -> dict [str , Any ]:
35+ validator = jsonschema .validators .validator_for (v )
36+
37+ try :
38+ validator .check_schema (v )
39+ except jsonschema .exceptions .SchemaError as e :
40+ raise ValueError (f"Invalid JSON schema: { e .message } " )
41+
42+ return v
43+
44+
45+ @before_event ([Save , Replace ])
46+ def update_updated_at (self ):
47+ self .updated_at = datetime .now ()
0 commit comments