56 lines
2.4 KiB
Python
56 lines
2.4 KiB
Python
from pydantic import BaseModel, Field
|
|
from typing import Dict, Any, Optional
|
|
|
|
|
|
class ConfigBase(BaseModel):
|
|
"""Base class for configuration schemas."""
|
|
repository: str = Field(..., description="Repository URL or identifier")
|
|
job_id: str = Field(..., description="Nomad job ID")
|
|
description: Optional[str] = Field(None, description="Description of this configuration")
|
|
repository_alias: Optional[str] = Field(None, description="Short name or alias for the repository")
|
|
|
|
# Additional metadata can be stored in the meta field
|
|
meta: Optional[Dict[str, Any]] = Field(None, description="Additional metadata")
|
|
|
|
|
|
class ConfigCreate(ConfigBase):
|
|
"""Schema for creating a new configuration."""
|
|
name: str = Field(..., description="Configuration name (used as the file name)")
|
|
|
|
|
|
class ConfigUpdate(BaseModel):
|
|
"""Schema for updating an existing configuration."""
|
|
repository: Optional[str] = Field(None, description="Repository URL or identifier")
|
|
job_id: Optional[str] = Field(None, description="Nomad job ID")
|
|
description: Optional[str] = Field(None, description="Description of this configuration")
|
|
repository_alias: Optional[str] = Field(None, description="Short name or alias for the repository")
|
|
meta: Optional[Dict[str, Any]] = Field(None, description="Additional metadata")
|
|
|
|
|
|
class ConfigResponse(ConfigBase):
|
|
"""Schema for configuration response."""
|
|
name: str = Field(..., description="Configuration name")
|
|
repository_info: Optional[Dict[str, Any]] = Field(None, description="Repository information from Gitea if available")
|
|
|
|
class Config:
|
|
schema_extra = {
|
|
"example": {
|
|
"name": "my-web-app",
|
|
"repository": "http://gitea.internal.example.com/username/repo-name",
|
|
"repository_alias": "web-app",
|
|
"job_id": "web-app",
|
|
"description": "Web application running in Nomad",
|
|
"meta": {
|
|
"owner": "devops-team",
|
|
"environment": "production"
|
|
},
|
|
"repository_info": {
|
|
"description": "A web application",
|
|
"default_branch": "main",
|
|
"stars": 5,
|
|
"forks": 2,
|
|
"owner": "username",
|
|
"html_url": "http://gitea.internal.example.com/username/repo-name"
|
|
}
|
|
}
|
|
} |