53 lines
1.6 KiB
Python
53 lines
1.6 KiB
Python
from typing import Optional, Dict
|
|
from datetime import date, datetime
|
|
import json
|
|
|
|
from pydantic import BaseModel, Field, field_validator
|
|
|
|
from app.core.refdata import ReconJobStatus
|
|
# from app.models.recon_auth import UserResponse
|
|
|
|
|
|
class ReconJobRequest(BaseModel):
|
|
""" Contains all user settable attributes.
|
|
I.e. User cannot change id, user or status as this is updated internally.
|
|
"""
|
|
name: str
|
|
as_at_date: date = Field(description="The date of the data - not a filename date. Each source and dest system in the config will use it's offset for filters and filenames.")
|
|
recon_config_reference: str = Field(description="User supplied reference of the config")
|
|
due_datetime: Optional[datetime] = None
|
|
|
|
|
|
class ReconJobResponse(ReconJobRequest):
|
|
""" Returns all recon job attributes including id and status fields.
|
|
"""
|
|
id: int
|
|
status: ReconJobStatus
|
|
status_reason: str
|
|
username: str
|
|
start_datetime: Optional[datetime] = None
|
|
finish_datetime: Optional[datetime] = None
|
|
results: Optional[Dict] = Field(default=None)
|
|
|
|
model_config = {
|
|
"from_attributes": True # Ability to load from ORM model
|
|
}
|
|
|
|
@field_validator("results", mode="before")
|
|
def parse_json(cls, v):
|
|
if isinstance(v, str) and len(v) > 0:
|
|
try:
|
|
return json.loads(v)
|
|
except json.JSONDecodeError:
|
|
raise ValueError("Invalid JSON string")
|
|
return None
|
|
|
|
class ReconJob(ReconJobResponse):
|
|
"""
|
|
Internal representation of a recon job
|
|
"""
|
|
|
|
model_config = {
|
|
"from_attributes": True # Ability to load from ORM model
|
|
}
|