feat(request): add service accounts and unified authorization
This commit is contained in:
@@ -0,0 +1,34 @@
|
||||
"""ServiceAccountRole model — ServiceAccount → Role mapping.
|
||||
|
||||
This is the generic Principal → Role link for Service Accounts.
|
||||
Reuses existing Role model.
|
||||
"""
|
||||
|
||||
from sqlalchemy import Column, Integer, ForeignKey, UniqueConstraint
|
||||
from sqlalchemy.orm import relationship
|
||||
from request_app.models.base import Base, TimestampMixin
|
||||
|
||||
|
||||
class ServiceAccountRole(Base, TimestampMixin):
|
||||
"""ServiceAccountRole — links ServiceAccount to Role.
|
||||
|
||||
Reuses existing Role model for authorization.
|
||||
"""
|
||||
|
||||
__tablename__ = "service_account_roles"
|
||||
|
||||
id = Column(Integer, primary_key=True, index=True)
|
||||
service_account_id = Column(Integer, ForeignKey("service_accounts.id", ondelete="CASCADE"), nullable=False)
|
||||
role_id = Column(Integer, ForeignKey("roles.id", ondelete="CASCADE"), nullable=False)
|
||||
|
||||
# Unique constraint: one SA can have each role only once
|
||||
__table_args__ = (
|
||||
UniqueConstraint("service_account_id", "role_id", name="uq_service_account_role"),
|
||||
)
|
||||
|
||||
# Relationships
|
||||
service_account = relationship("ServiceAccount", back_populates="roles")
|
||||
role = relationship("Role")
|
||||
|
||||
def __repr__(self) -> str:
|
||||
return f"<ServiceAccountRole(sa_id={self.service_account_id}, role_id={self.role_id})>"
|
||||
Reference in New Issue
Block a user