mirror of
https://github.com/hoshikawa2/agent_framework_oci_evaluator.git
synced 2026-07-09 18:34:20 +00:00
first commit
This commit is contained in:
BIN
evaluator/identity/__pycache__/resolver.cpython-313.pyc
Normal file
BIN
evaluator/identity/__pycache__/resolver.cpython-313.pyc
Normal file
Binary file not shown.
41
evaluator/identity/resolver.py
Normal file
41
evaluator/identity/resolver.py
Normal file
@@ -0,0 +1,41 @@
|
||||
from __future__ import annotations
|
||||
|
||||
from pathlib import Path
|
||||
from typing import Any
|
||||
|
||||
import yaml
|
||||
|
||||
|
||||
def _deep_get(data: dict, path: str):
|
||||
cur = data
|
||||
for part in path.split("."):
|
||||
if not isinstance(cur, dict):
|
||||
return None
|
||||
cur = cur.get(part)
|
||||
return cur
|
||||
|
||||
|
||||
class IdentityResolver:
|
||||
def __init__(self, path: str = "configs/identity.yaml"):
|
||||
self.path = Path(path)
|
||||
self.config = yaml.safe_load(self.path.read_text(encoding="utf-8")) or {}
|
||||
self.identity = self.config.get("identity", {})
|
||||
self.keys = self.identity.get("keys", {})
|
||||
|
||||
def resolve(self, payload: dict[str, Any]) -> dict[str, Any]:
|
||||
out = {}
|
||||
|
||||
for key, spec in self.keys.items():
|
||||
value = None
|
||||
for source in spec.get("sources", []):
|
||||
value = _deep_get(payload, source)
|
||||
if value not in (None, ""):
|
||||
break
|
||||
out[key] = str(value) if value not in (None, "") else None
|
||||
|
||||
out["metadata"] = {
|
||||
"identity_version": self.identity.get("version"),
|
||||
"identity_source": str(self.path),
|
||||
}
|
||||
|
||||
return out
|
||||
Reference in New Issue
Block a user