identity.py 765 B

1234567891011121314151617181920212223
  1. """Request identity and scope used by all DataOps MCP tools."""
  2. from dataclasses import dataclass
  3. @dataclass(frozen=True)
  4. class AgentIdentity:
  5. subject: str
  6. roles: frozenset
  7. business_domains: frozenset
  8. environments: frozenset
  9. correlation_id: str
  10. def require_domain(self, domain):
  11. if "*" not in self.business_domains and domain not in self.business_domains:
  12. raise PermissionError("business domain is outside identity scope")
  13. def require_environment(self, environment):
  14. if "*" not in self.environments and environment not in self.environments:
  15. raise PermissionError("environment is outside identity scope")
  16. def has_any_role(self, roles):
  17. return bool(self.roles.intersection(roles))