first commit
This commit is contained in:
55
microservices/token-service/models.py
Normal file
55
microservices/token-service/models.py
Normal file
@@ -0,0 +1,55 @@
|
||||
"""
|
||||
Pydantic models for Token Management Service
|
||||
"""
|
||||
|
||||
from pydantic import BaseModel, Field
|
||||
from typing import List, Optional, Dict, Any
|
||||
from datetime import datetime
|
||||
|
||||
class TokenGenerateRequest(BaseModel):
|
||||
"""Request model for token generation"""
|
||||
name: str = Field(..., description="Token owner name")
|
||||
list_of_resources: List[str] = Field(..., description="List of accessible resources")
|
||||
data_aggregation: bool = Field(default=False, description="Allow data aggregation")
|
||||
time_aggregation: bool = Field(default=False, description="Allow time aggregation")
|
||||
embargo: int = Field(default=0, description="Embargo period in seconds")
|
||||
exp_hours: int = Field(default=24, description="Token expiration in hours")
|
||||
|
||||
class TokenResponse(BaseModel):
|
||||
"""Response model for token operations"""
|
||||
token: str = Field(..., description="JWT token")
|
||||
|
||||
class TokenValidationResponse(BaseModel):
|
||||
"""Response model for token validation"""
|
||||
valid: bool = Field(..., description="Whether token is valid")
|
||||
token: str = Field(..., description="Original token")
|
||||
decoded: Optional[Dict[str, Any]] = Field(None, description="Decoded token payload")
|
||||
error: Optional[str] = Field(None, description="Error message if invalid")
|
||||
|
||||
class TokenRecord(BaseModel):
|
||||
"""Token database record model"""
|
||||
token: str
|
||||
datetime: str
|
||||
active: bool
|
||||
name: str
|
||||
resources: List[str]
|
||||
expires_at: str
|
||||
created_at: str
|
||||
updated_at: str
|
||||
|
||||
class TokenListResponse(BaseModel):
|
||||
"""Response model for token list"""
|
||||
tokens: List[Dict[str, Any]]
|
||||
count: int
|
||||
|
||||
class HealthResponse(BaseModel):
|
||||
"""Health check response"""
|
||||
service: str
|
||||
status: str
|
||||
timestamp: datetime
|
||||
version: str
|
||||
|
||||
class Config:
|
||||
json_encoders = {
|
||||
datetime: lambda v: v.isoformat()
|
||||
}
|
||||
Reference in New Issue
Block a user