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"],
|
||||
)
|
||||
|
||||
@@ -70,3 +70,18 @@ class AuditEvent:
|
||||
}
|
||||
)
|
||||
|
||||
@classmethod
|
||||
def from_dict(cls, data: dict[str, Any]) -> "AuditEvent":
|
||||
return cls(
|
||||
event_id=data["event_id"],
|
||||
operation=data["operation"],
|
||||
target=data["target"],
|
||||
outcome=AuditOutcome(data["outcome"]),
|
||||
actor_id=data["actor_id"],
|
||||
correlation_id=data["correlation_id"],
|
||||
policy_decision=PolicyDecision.from_dict(data["policy_decision"])
|
||||
if data.get("policy_decision")
|
||||
else None,
|
||||
details=dict(data.get("details", {})),
|
||||
occurred_at=data["occurred_at"],
|
||||
)
|
||||
|
||||
@@ -48,6 +48,18 @@ class Classification:
|
||||
}
|
||||
)
|
||||
|
||||
@classmethod
|
||||
def from_dict(cls, data: dict[str, Any]) -> "Classification":
|
||||
return cls(
|
||||
asset_type=data["asset_type"],
|
||||
sensitivity=Sensitivity(data.get("sensitivity", Sensitivity.INTERNAL.value)),
|
||||
lifecycle=LifecycleState(data.get("lifecycle", LifecycleState.ACTIVE.value)),
|
||||
topics=tuple(data.get("topics", [])),
|
||||
owner=data.get("owner"),
|
||||
review_state=data.get("review_state"),
|
||||
metadata=dict(data.get("metadata", {})),
|
||||
)
|
||||
|
||||
|
||||
@dataclass(frozen=True)
|
||||
class MetadataRecord:
|
||||
@@ -72,3 +84,14 @@ class MetadataRecord:
|
||||
}
|
||||
)
|
||||
|
||||
@classmethod
|
||||
def from_dict(cls, data: dict[str, Any]) -> "MetadataRecord":
|
||||
return cls(
|
||||
record_id=data["record_id"],
|
||||
key=data["key"],
|
||||
value=data.get("value"),
|
||||
provenance=dict(data.get("provenance", {})),
|
||||
confidence=data.get("confidence"),
|
||||
confirmed=bool(data.get("confirmed", False)),
|
||||
created_at=data["created_at"],
|
||||
)
|
||||
|
||||
@@ -77,3 +77,16 @@ class PolicyDecision:
|
||||
}
|
||||
)
|
||||
|
||||
@classmethod
|
||||
def from_dict(cls, data: dict[str, Any]) -> "PolicyDecision":
|
||||
return cls(
|
||||
decision_id=data["decision_id"],
|
||||
effect=PolicyEffect(data["effect"]),
|
||||
subject_id=data["subject_id"],
|
||||
action=data["action"],
|
||||
resource=data["resource"],
|
||||
reason=data.get("reason", ""),
|
||||
obligations=dict(data.get("obligations", {})),
|
||||
context=dict(data.get("context", {})),
|
||||
decided_at=data["decided_at"],
|
||||
)
|
||||
|
||||
@@ -48,6 +48,19 @@ class SourceReference:
|
||||
}
|
||||
)
|
||||
|
||||
@classmethod
|
||||
def from_dict(cls, data: dict[str, Any]) -> "SourceReference":
|
||||
return cls(
|
||||
id=data["id"],
|
||||
source_system=data["source_system"],
|
||||
path=data.get("path"),
|
||||
uri=data.get("uri"),
|
||||
external_id=data.get("external_id"),
|
||||
checksum=data.get("checksum"),
|
||||
connector_ref=data.get("connector_ref"),
|
||||
metadata=dict(data.get("metadata", {})),
|
||||
)
|
||||
|
||||
|
||||
class VersionChangeType(str, Enum):
|
||||
CREATED = "created"
|
||||
@@ -93,6 +106,23 @@ class AssetVersion:
|
||||
}
|
||||
)
|
||||
|
||||
@classmethod
|
||||
def from_dict(cls, data: dict[str, Any]) -> "AssetVersion":
|
||||
return cls(
|
||||
version_id=data["version_id"],
|
||||
asset_id=data["asset_id"],
|
||||
sequence=int(data["sequence"]),
|
||||
change_type=VersionChangeType(data["change_type"]),
|
||||
representation_ids=tuple(data.get("representation_ids", [])),
|
||||
actor_id=data.get("actor_id"),
|
||||
operation_id=data.get("operation_id"),
|
||||
parent_version_id=data.get("parent_version_id"),
|
||||
metadata_delta=dict(data.get("metadata_delta", {})),
|
||||
relationship_delta=dict(data.get("relationship_delta", {})),
|
||||
lifecycle=data.get("lifecycle"),
|
||||
created_at=data["created_at"],
|
||||
)
|
||||
|
||||
|
||||
@dataclass(frozen=True)
|
||||
class DerivedArtifactLineage:
|
||||
@@ -129,4 +159,3 @@ class DerivedArtifactLineage:
|
||||
if include_hash:
|
||||
data["lineage_hash"] = self.lineage_hash
|
||||
return data
|
||||
|
||||
|
||||
Reference in New Issue
Block a user