Schemas
This page documents the schema classes used in Eunomia Core for data validation and serialization.
Attribute Schemas
eunomia_core.schemas.Attribute
Bases: BaseModel
Source code in pkgs/core/src/eunomia_core/schemas/entity.py
| class Attribute(BaseModel):
key: str = Field(..., description="Attribute key")
value: str = Field(..., description="Attribute value")
|
eunomia_core.schemas.AttributeInDb
Bases: Attribute
Source code in pkgs/core/src/eunomia_core/schemas/entity.py
| class AttributeInDb(Attribute):
updated_at: datetime = Field(
description="Time when this attribute was last updated"
)
registered_at: datetime = Field(
description="Time when this attribute was first registered"
)
model_config = ConfigDict(from_attributes=True)
|
Entity Schemas
eunomia_core.schemas.EntityCreate
Bases: EntityBase
Source code in pkgs/core/src/eunomia_core/schemas/entity.py
| class EntityCreate(EntityBase):
uri: Optional[str] = Field(
default_factory=lambda: generate_uri(),
description="Unique identifier for the entity, generated if not provided",
)
@field_validator("attributes", mode="before")
@classmethod
def at_least_one_attribute(cls, v: list[Attribute]) -> list[Attribute]:
if not v:
raise ValueError("At least one attribute must be provided")
return v
@field_validator("uri", mode="after")
@classmethod
def enforce_uri(cls, v: str | None) -> str:
if v is None:
return generate_uri()
return v
|
eunomia_core.schemas.EntityUpdate
Bases: EntityBase
Source code in pkgs/core/src/eunomia_core/schemas/entity.py
| class EntityUpdate(EntityBase):
type: Optional[EntityType] = None # type is not required for the attributes update
@field_validator("attributes", mode="before")
@classmethod
def at_least_one_attribute(cls, v: list[Attribute]) -> list[Attribute]:
if not v:
raise ValueError("At least one attribute must be provided")
return v
|
eunomia_core.schemas.EntityCheck
Bases: BaseModel
Source code in pkgs/core/src/eunomia_core/schemas/check.py
| class EntityCheck(BaseModel):
uri: Optional[str] = Field(
default=None, description="Unique identifier for the entity"
)
attributes: Optional[dict[str, str]] = Field(
default_factory=dict, description="Entity attributes"
)
type: EntityType = Field(..., description="Type of entity")
@field_validator("attributes", mode="before")
@classmethod
def from_list(cls, v: list[Attribute] | dict) -> dict[str, str]:
if isinstance(v, list) and all(isinstance(attr, Attribute) for attr in v):
return {attr.key: attr.value for attr in v}
elif isinstance(v, list):
return {attr["key"]: attr["value"] for attr in v}
return v
@model_validator(mode="after")
def either_uri_or_attributes(self) -> "EntityCheck":
if not self.uri and not self.attributes:
raise ValueError("Either 'uri' or non-empty 'attributes' must be provided")
return self
|
eunomia_core.schemas.EntityInDb
Bases: EntityBase
Source code in pkgs/core/src/eunomia_core/schemas/entity.py
| class EntityInDb(EntityBase):
attributes: list[AttributeInDb] = Field(..., description="Entity attributes")
registered_at: datetime = Field(description="Time when this entity was registered")
model_config = ConfigDict(from_attributes=True)
|
Check Schemas
eunomia_core.schemas.ResourceCheck
Bases: EntityCheck
Source code in pkgs/core/src/eunomia_core/schemas/check.py
| class ResourceCheck(EntityCheck):
type: Literal[EntityType.resource] = EntityType.resource
|
eunomia_core.schemas.PrincipalCheck
Bases: EntityCheck
Source code in pkgs/core/src/eunomia_core/schemas/check.py
| class PrincipalCheck(EntityCheck):
type: Literal[EntityType.principal] = EntityType.principal
|
eunomia_core.schemas.CheckRequest
Bases: BaseModel
Source code in pkgs/core/src/eunomia_core/schemas/check.py
| class CheckRequest(BaseModel):
principal: PrincipalCheck = Field(
..., description="The principal performing the action"
)
resource: ResourceCheck = Field(..., description="The resource being acted on")
action: str = Field(
default="access", description="The action being performed on the resource"
)
|
eunomia_core.schemas.Policy
Bases: BaseModel
Source code in pkgs/core/src/eunomia_core/schemas/policy.py
| class Policy(BaseModel):
name: str = Field(..., description="Name of the policy")
description: Optional[str] = Field(
None, description="Human-readable description of the policy"
)
rules: list[Rule] = Field(..., description="list of rules to evaluate")
default_effect: PolicyEffect = Field(
PolicyEffect.DENY, description="Default effect if no rules match"
)
model_config = ConfigDict(from_attributes=True)
|