generated from coulomb/repo-seed
Governed asset registry slice with asset creation, representations, metadata, lifecycle transitions, policy authorization, fail-closed denial, audit events, and version records
This commit is contained in:
@@ -76,6 +76,22 @@ class AssetRepresentation:
|
||||
}
|
||||
)
|
||||
|
||||
@classmethod
|
||||
def from_dict(cls, data: dict[str, Any]) -> "AssetRepresentation":
|
||||
return cls(
|
||||
representation_id=data["representation_id"],
|
||||
asset_id=data["asset_id"],
|
||||
kind=RepresentationKind(data["kind"]),
|
||||
media_type=data["media_type"],
|
||||
digest=data["digest"],
|
||||
size_bytes=int(data["size_bytes"]),
|
||||
storage_ref=data.get("storage_ref"),
|
||||
producer=data.get("producer"),
|
||||
source_ref_id=data.get("source_ref_id"),
|
||||
metadata=dict(data.get("metadata", {})),
|
||||
created_at=data["created_at"],
|
||||
)
|
||||
|
||||
|
||||
@dataclass(frozen=True)
|
||||
class KnowledgeAsset:
|
||||
@@ -119,6 +135,9 @@ class KnowledgeAsset:
|
||||
return self
|
||||
return replace(self, aliases=self.aliases + (alias,), updated_at=utc_now().isoformat())
|
||||
|
||||
def with_current_version(self, version_id: str) -> "KnowledgeAsset":
|
||||
return replace(self, current_version_id=version_id, updated_at=utc_now().isoformat())
|
||||
|
||||
def transition_lifecycle(self, lifecycle: LifecycleState | str) -> "KnowledgeAsset":
|
||||
lifecycle_state = LifecycleState(lifecycle)
|
||||
classification = replace(self.classification, lifecycle=lifecycle_state)
|
||||
@@ -145,3 +164,17 @@ class KnowledgeAsset:
|
||||
}
|
||||
)
|
||||
|
||||
@classmethod
|
||||
def from_dict(cls, data: dict[str, Any]) -> "KnowledgeAsset":
|
||||
return cls(
|
||||
id=data["id"],
|
||||
title=data["title"],
|
||||
classification=Classification.from_dict(data["classification"]),
|
||||
source_refs=tuple(SourceReference.from_dict(item) for item in data.get("source_refs", [])),
|
||||
aliases=tuple(data.get("aliases", [])),
|
||||
current_version_id=data.get("current_version_id"),
|
||||
lifecycle=LifecycleState(data.get("lifecycle", LifecycleState.ACTIVE.value)),
|
||||
metadata=dict(data.get("metadata", {})),
|
||||
created_at=data["created_at"],
|
||||
updated_at=data["updated_at"],
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user