2015-06-22 22:47:27 +02:00
|
|
|
"""
|
2015-08-09 01:12:29 +02:00
|
|
|
.. module: lemur.roles.models
|
2015-06-22 22:47:27 +02:00
|
|
|
:platform: unix
|
|
|
|
:synopsis: This module contains all of the models need to create a role within Lemur
|
|
|
|
|
2018-05-29 19:18:16 +02:00
|
|
|
:copyright: (c) 2018 by Netflix Inc., see AUTHORS for more
|
2015-06-22 22:47:27 +02:00
|
|
|
:license: Apache, see LICENSE for more details.
|
|
|
|
|
|
|
|
.. moduleauthor:: Kevin Glisson <kglisson@netflix.com>
|
|
|
|
|
|
|
|
"""
|
|
|
|
from sqlalchemy.orm import relationship
|
2017-12-11 22:51:45 +01:00
|
|
|
from sqlalchemy import Boolean, Column, Integer, String, Text, ForeignKey
|
2015-06-22 22:47:27 +02:00
|
|
|
|
|
|
|
from lemur.database import db
|
2015-10-10 02:17:05 +02:00
|
|
|
from lemur.utils import Vault
|
2019-05-16 16:57:02 +02:00
|
|
|
from lemur.models import (
|
|
|
|
roles_users,
|
|
|
|
roles_authorities,
|
|
|
|
roles_certificates,
|
|
|
|
pending_cert_role_associations,
|
|
|
|
)
|
2015-06-22 22:47:27 +02:00
|
|
|
|
|
|
|
|
|
|
|
class Role(db.Model):
|
2019-05-16 16:57:02 +02:00
|
|
|
__tablename__ = "roles"
|
2015-06-22 22:47:27 +02:00
|
|
|
id = Column(Integer, primary_key=True)
|
|
|
|
name = Column(String(128), unique=True)
|
|
|
|
username = Column(String(128))
|
2015-10-10 02:17:05 +02:00
|
|
|
password = Column(Vault)
|
2015-06-22 22:47:27 +02:00
|
|
|
description = Column(Text)
|
2019-05-16 16:57:02 +02:00
|
|
|
authority_id = Column(Integer, ForeignKey("authorities.id"))
|
|
|
|
authorities = relationship(
|
|
|
|
"Authority",
|
|
|
|
secondary=roles_authorities,
|
|
|
|
passive_deletes=True,
|
|
|
|
backref="role",
|
|
|
|
cascade="all,delete",
|
|
|
|
)
|
|
|
|
user_id = Column(Integer, ForeignKey("users.id"))
|
2017-12-11 22:51:45 +01:00
|
|
|
third_party = Column(Boolean)
|
2019-05-16 16:57:02 +02:00
|
|
|
users = relationship(
|
|
|
|
"User", secondary=roles_users, passive_deletes=True, backref="role"
|
|
|
|
)
|
|
|
|
certificates = relationship(
|
|
|
|
"Certificate", secondary=roles_certificates, backref="role"
|
|
|
|
)
|
|
|
|
pending_certificates = relationship(
|
|
|
|
"PendingCertificate", secondary=pending_cert_role_associations, backref="role"
|
|
|
|
)
|
|
|
|
|
|
|
|
sensitive_fields = ("password",)
|
2017-08-16 18:38:42 +02:00
|
|
|
|
2016-11-16 18:30:54 +01:00
|
|
|
def __repr__(self):
|
|
|
|
return "Role(name={name})".format(name=self.name)
|