Files
jiangchang-platform-kit/src/jiangchang_skill_core/guard.py
chendelian d2dbb5f61e
Some checks failed
Publish Python Package to Gitea / publish (push) Failing after 59s
重构项目路径
2026-05-06 17:16:09 +08:00

23 lines
634 B
Python

from .client import EntitlementClient
from .errors import EntitlementDeniedError
from .models import EntitlementResult
def enforce_entitlement(
user_id: str,
skill_slug: str,
trace_id: str = "",
context: dict | None = None,
client: EntitlementClient | None = None,
) -> EntitlementResult:
c = client or EntitlementClient()
result = c.check_entitlement(
user_id=user_id,
skill_slug=skill_slug,
trace_id=trace_id,
context=context or {},
)
if not result.allow:
raise EntitlementDeniedError(result.reason or "skill not purchased or expired")
return result