Create infrastructure_intents.py
Browse files
app/models/infrastructure_intents.py
ADDED
|
@@ -0,0 +1,61 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from pydantic import BaseModel, Field, field_validator
|
| 2 |
+
from typing import Optional, Literal, List, Any, Dict
|
| 3 |
+
|
| 4 |
+
from agentic_reliability_framework.core.governance.intents import (
|
| 5 |
+
ResourceType,
|
| 6 |
+
PermissionLevel,
|
| 7 |
+
Environment,
|
| 8 |
+
ChangeScope,
|
| 9 |
+
)
|
| 10 |
+
|
| 11 |
+
|
| 12 |
+
class BaseIntentRequest(BaseModel):
|
| 13 |
+
environment: Environment
|
| 14 |
+
estimated_cost: Optional[float] = Field(None, ge=0)
|
| 15 |
+
policy_violations: List[str] = Field(default_factory=list)
|
| 16 |
+
requester: str = Field(...)
|
| 17 |
+
provenance: Dict[str, Any] = Field(default_factory=dict)
|
| 18 |
+
|
| 19 |
+
|
| 20 |
+
class ProvisionResourceRequest(BaseIntentRequest):
|
| 21 |
+
intent_type: Literal["provision_resource"] = "provision_resource"
|
| 22 |
+
resource_type: ResourceType
|
| 23 |
+
region: str
|
| 24 |
+
size: str
|
| 25 |
+
configuration: Dict[str, Any] = Field(default_factory=dict)
|
| 26 |
+
|
| 27 |
+
@field_validator("region")
|
| 28 |
+
def validate_region(cls, v):
|
| 29 |
+
return v
|
| 30 |
+
|
| 31 |
+
|
| 32 |
+
class GrantAccessRequest(BaseIntentRequest):
|
| 33 |
+
intent_type: Literal["grant_access"] = "grant_access"
|
| 34 |
+
principal: str
|
| 35 |
+
permission_level: PermissionLevel
|
| 36 |
+
resource_scope: str
|
| 37 |
+
justification: Optional[str] = None
|
| 38 |
+
|
| 39 |
+
@field_validator("resource_scope")
|
| 40 |
+
def validate_resource_scope(cls, v):
|
| 41 |
+
if not v.startswith("/"):
|
| 42 |
+
raise ValueError("Resource scope must start with '/'")
|
| 43 |
+
return v
|
| 44 |
+
|
| 45 |
+
|
| 46 |
+
class DeployConfigurationRequest(BaseIntentRequest):
|
| 47 |
+
intent_type: Literal["deploy_config"] = "deploy_config"
|
| 48 |
+
service_name: str
|
| 49 |
+
change_scope: ChangeScope
|
| 50 |
+
deployment_target: Environment
|
| 51 |
+
risk_level_hint: Optional[float] = Field(None, ge=0, le=1)
|
| 52 |
+
configuration: Dict[str, Any] = Field(default_factory=dict)
|
| 53 |
+
|
| 54 |
+
@field_validator("service_name")
|
| 55 |
+
def validate_service_name(cls, v):
|
| 56 |
+
if len(v) < 3:
|
| 57 |
+
raise ValueError("Service name must be at least 3 characters")
|
| 58 |
+
return v
|
| 59 |
+
|
| 60 |
+
|
| 61 |
+
InfrastructureIntentRequest = ProvisionResourceRequest | GrantAccessRequest | DeployConfigurationRequest
|