class UserProjectGrant(sql.ModelBase, BaseGrant): __tablename__ = 'user_project_metadata' user_id = sql.Column(sql.String(64), sql.ForeignKey('user.id'), primary_key=True) project_id = sql.Column(sql.String(64), sql.ForeignKey('project.id'), primary_key=True) data = sql.Column(sql.JsonBlob())
class RolePermission(sql.ModelBase, sql.DictBase): """Role\'s permissions join table.""" __tablename__ = 'role_permission_fiware' role_id = sql.Column(sql.String(64), sql.ForeignKey('role_fiware.id'), primary_key=True) permission_id = sql.Column(sql.String(64), sql.ForeignKey('permission_fiware.id'), primary_key=True)
class Project(sql.ModelBase, sql.ModelDictMixinWithExtras): # NOTE(henry-nash): From the manager and above perspective, the domain_id # is nullable. However, to ensure uniqueness in multi-process # configurations, it is better to still use the sql uniqueness constraint. # Since the support for a nullable component of a uniqueness constraint # across different sql databases is mixed, we instead store a special value # to represent null, as defined in NULL_DOMAIN_ID above. def to_dict(self, include_extra_dict=False): d = super(Project, self).to_dict( include_extra_dict=include_extra_dict) if d['domain_id'] == base.NULL_DOMAIN_ID: d['domain_id'] = None return d __tablename__ = 'project' attributes = ['id', 'name', 'domain_id', 'description', 'enabled', 'parent_id', 'is_domain', 'tags'] id = sql.Column(sql.String(64), primary_key=True) name = sql.Column(sql.String(64), nullable=False) domain_id = sql.Column(sql.String(64), sql.ForeignKey('project.id'), nullable=False) description = sql.Column(sql.Text()) enabled = sql.Column(sql.Boolean) extra = sql.Column(sql.JsonBlob()) parent_id = sql.Column(sql.String(64), sql.ForeignKey('project.id')) is_domain = sql.Column(sql.Boolean, default=False, nullable=False, server_default='0') _tags = orm.relationship( 'ProjectTag', single_parent=True, lazy='subquery', cascade='all,delete-orphan', backref='project', primaryjoin='and_(ProjectTag.project_id==Project.id)' ) # Unique constraint across two columns to create the separation # rather than just only 'name' being unique __table_args__ = (sql.UniqueConstraint('domain_id', 'name'),) @property def tags(self): if self._tags: return [tag.name for tag in self._tags] return [] @tags.setter def tags(self, values): new_tags = [] for tag in values: tag_ref = ProjectTag() tag_ref.project_id = self.id tag_ref.name = text_type(tag) new_tags.append(tag_ref) self._tags = new_tags
class Credential(sql.ModelBase, sql.DictBase): __tablename__ = 'credential' attributes = ['id', 'user_id', 'project_id', 'blob', 'type'] id = sql.Column(sql.String(64), primary_key=True) user_id = sql.Column(sql.String(64), sql.ForeignKey('user.id'), nullable=False) project_id = sql.Column(sql.String(64), sql.ForeignKey('project.id')) blob = sql.Column(sql.JsonBlob(), nullable=False) type = sql.Column(sql.String(255), nullable=False) extra = sql.Column(sql.JsonBlob())
class RoleOrganization(sql.ModelBase, sql.ModelDictMixin): """Roles organizations join table.""" __tablename__ = 'role_organization_fiware' role_id = sql.Column(sql.String(64), sql.ForeignKey('role_fiware.id'), primary_key=True) organization_id = sql.Column(sql.String(64), sql.ForeignKey('project.id'), primary_key=True) application_id = sql.Column(sql.String(64), sql.ForeignKey('consumer_oauth2.id'), primary_key=True)
class ApplicationCredentialAccessRuleModel(sql.ModelBase, sql.ModelDictMixin): __tablename__ = 'application_credential_access_rule' attributes = ['application_credential_id', 'access_rule_id'] application_credential_id = sql.Column( sql.Integer, sql.ForeignKey('application_credential.internal_id', ondelete='cascade'), primary_key=True, nullable=False) access_rule_id = sql.Column(sql.Integer, sql.ForeignKey('access_rule.id'), primary_key=True, nullable=False)
class Project(sql.ModelBase, sql.DictBase): __tablename__ = 'project' attributes = ['id', 'name', 'domain_id', 'description', 'enabled', 'parent_id'] id = sql.Column(sql.String(64), primary_key=True) name = sql.Column(sql.String(64), nullable=False) domain_id = sql.Column(sql.String(64), sql.ForeignKey('domain.id'), nullable=False) description = sql.Column(sql.Text()) enabled = sql.Column(sql.Boolean) extra = sql.Column(sql.JsonBlob()) parent_id = sql.Column(sql.String(64), sql.ForeignKey('project.id')) # Unique constraint across two columns to create the separation # rather than just only 'name' being unique __table_args__ = (sql.UniqueConstraint('domain_id', 'name'), {})
class GroupDomainGrant(sql.ModelBase, BaseGrant): __tablename__ = 'group_domain_metadata' group_id = sql.Column(sql.String(64), primary_key=True) domain_id = sql.Column(sql.String(64), sql.ForeignKey('domain.id'), primary_key=True) data = sql.Column(sql.JsonBlob())
class RegisteredLimitModel(sql.ModelBase, sql.ModelDictMixin): __tablename__ = 'registered_limit' attributes = [ 'id', 'service_id', 'region_id', 'resource_name', 'default_limit' ] id = sql.Column(sql.String(length=64), primary_key=True) service_id = sql.Column(sql.String(255), sql.ForeignKey('service.id')) region_id = sql.Column(sql.String(64), sql.ForeignKey('region.id'), nullable=True) resource_name = sql.Column(sql.String(255)) default_limit = sql.Column(sql.Integer, nullable=False) __table_args__ = (sqlalchemy.UniqueConstraint('service_id', 'region_id', 'resource_name'), )
class LimitModel(sql.ModelBase, sql.ModelDictMixin): __tablename__ = 'limit' attributes = [ 'id', 'project_id', 'service_id', 'region_id', 'resource_name', 'resource_limit' ] id = sql.Column(sql.String(length=64), primary_key=True) project_id = sql.Column(sql.String(64), sql.ForeignKey('project.id')) service_id = sql.Column(sql.String(255)) region_id = sql.Column(sql.String(64), nullable=True) resource_name = sql.Column(sql.String(255)) resource_limit = sql.Column(sql.Integer, nullable=False) __table_args__ = ( sqlalchemy.ForeignKeyConstraint(['service_id', 'region_id', 'resource_name'], ['registered_limit.service_id', 'registered_limit.region_id', 'registered_limit.resource_name']), sqlalchemy.UniqueConstraint('project_id', 'service_id', 'region_id', 'resource_name'),)
class User(sql.ModelBase, sql.DictBase): __tablename__ = 'user' attributes = [ 'id', 'name', 'domain_id', 'password', 'enabled', 'default_project_id', 'username' ] id = sql.Column(sql.String(64), primary_key=True) name = sql.Column(sql.String(255), nullable=False) username = sql.Column(sql.String(255), nullable=True) domain_id = sql.Column(sql.String(64), sql.ForeignKey('domain.id'), nullable=False) password = sql.Column(sql.String(128)) enabled = sql.Column(sql.Boolean) extra = sql.Column(sql.JsonBlob()) default_project_id = sql.Column(sql.String(64)) # Unique constraint across two columns to create the separation # rather than just only 'name' being unique __table_args__ = (sql.UniqueConstraint('domain_id', 'name'), {}) def to_dict(self, include_extra_dict=False): d = super(User, self).to_dict(include_extra_dict=include_extra_dict) if 'default_project_id' in d and d['default_project_id'] is None: del d['default_project_id'] return d
class Password(sql.ModelBase, sql.DictBase): __tablename__ = 'password' attributes = ['id', 'local_user_id', 'password'] id = sql.Column(sql.Integer, primary_key=True) local_user_id = sql.Column( sql.Integer, sql.ForeignKey('local_user.id', ondelete='CASCADE')) password = sql.Column(sql.String(128))
class LimitModel(sql.ModelBase, sql.ModelDictMixin): __tablename__ = 'limit' attributes = [ 'internal_id', 'id', 'project_id', 'domain_id', 'service_id', 'region_id', 'resource_name', 'resource_limit', 'description', 'registered_limit_id' ] internal_id = sql.Column(sql.Integer, primary_key=True, nullable=False) id = sql.Column(sql.String(length=64), nullable=False, unique=True) project_id = sql.Column(sql.String(64)) domain_id = sql.Column(sql.String(64)) resource_limit = sql.Column(sql.Integer, nullable=False) description = sql.Column(sql.Text()) registered_limit_id = sql.Column(sql.String(64), sql.ForeignKey('registered_limit.id')) registered_limit = sqlalchemy.orm.relationship('RegisteredLimitModel') @hybrid_property def service_id(self): if self.registered_limit: return self.registered_limit.service_id return None @service_id.expression def service_id(self): return RegisteredLimitModel.service_id @hybrid_property def region_id(self): if self.registered_limit: return self.registered_limit.region_id return None @region_id.expression def region_id(self): return RegisteredLimitModel.region_id @hybrid_property def resource_name(self): if self.registered_limit: return self.registered_limit.resource_name return self._resource_name @resource_name.expression def resource_name(self): return RegisteredLimitModel.resource_name def to_dict(self): ref = super(LimitModel, self).to_dict() if self.registered_limit: ref['service_id'] = self.registered_limit.service_id ref['region_id'] = self.registered_limit.region_id ref['resource_name'] = self.registered_limit.resource_name ref.pop('internal_id') ref.pop('registered_limit_id') return ref
class FederatedUser(sql.ModelBase, sql.ModelDictMixin): __tablename__ = 'federated_user' attributes = ['id', 'user_id', 'idp_id', 'protocol_id', 'unique_id', 'display_name'] id = sql.Column(sql.Integer, primary_key=True) user_id = sql.Column(sql.String(64), sql.ForeignKey('user.id', ondelete='CASCADE')) idp_id = sql.Column(sql.String(64), sql.ForeignKey('identity_provider.id', ondelete='CASCADE')) protocol_id = sql.Column(sql.String(64), nullable=False) unique_id = sql.Column(sql.String(255), nullable=False) display_name = sql.Column(sql.String(255), nullable=True) __table_args__ = ( sql.UniqueConstraint('idp_id', 'protocol_id', 'unique_id'), sqlalchemy.ForeignKeyConstraint(['protocol_id', 'idp_id'], ['federation_protocol.id', 'federation_protocol.idp_id']) )
class AccessKey(sql.ModelBase, sql.DictBase): __tablename__ = 'access_key' attributes = ['id', 'user_id', 'password', 'enabled', 'default_project_id'] id = sql.Column(sql.String(64), primary_key=True) user_id = sql.Column(sql.String(64), sql.ForeignKey('user.id'), nullable=False) access_key_secret = sql.Column(sql.String(128)) extra = sql.Column(sql.JsonBlob())
class Endpoint(sql.ModelBase, sql.DictBase): __tablename__ = 'endpoint' attributes = ['id', 'region', 'service_id'] id = sql.Column(sql.String(64), primary_key=True) region = sql.Column('region', sql.String(255)) service_id = sql.Column(sql.String(64), sql.ForeignKey('service.id'), nullable=False) extra = sql.Column(sql.JsonBlob())
class Role(sql.ModelBase, sql.ModelDictMixin): __tablename__ = 'role_fiware' __table_args__ = (sql.UniqueConstraint('name', 'application_id'), {'extend_existing': True}) attributes = ['id', 'name', 'is_internal', 'application_id'] id = sql.Column(sql.String(64), primary_key=True, nullable=False) name = sql.Column(sql.String(64), nullable=False) is_internal = sql.Column(sql.Boolean(), default=False, nullable=False) application_id = sql.Column(sql.String(64), sql.ForeignKey('consumer_oauth2.id'), nullable=False, index=True)
class LocalUser(sql.ModelBase, sql.DictBase): __tablename__ = 'local_user' attributes = ['id', 'user_id', 'domain_id', 'name'] id = sql.Column(sql.Integer, primary_key=True) user_id = sql.Column(sql.String(64), sql.ForeignKey('user.id', ondelete='CASCADE'), unique=True) domain_id = sql.Column(sql.String(64), nullable=False) name = sql.Column(sql.String(255), nullable=False) passwords = orm.relationship('Password', single_parent=True, cascade='all,delete-orphan', backref='local_user') __table_args__ = (sql.UniqueConstraint('domain_id', 'name'), {})
class Password(sql.ModelBase, sql.DictBase): __tablename__ = 'password' attributes = ['id', 'local_user_id', 'password', 'created_at', 'expires_at'] id = sql.Column(sql.Integer, primary_key=True) local_user_id = sql.Column(sql.Integer, sql.ForeignKey('local_user.id', ondelete='CASCADE')) password = sql.Column(sql.String(128), nullable=True) # created_at default set here to safe guard in case it gets missed created_at = sql.Column(sql.DateTime, nullable=False, default=datetime.datetime.utcnow) expires_at = sql.Column(sql.DateTime, nullable=True)
class Password(sql.ModelBase, sql.ModelDictMixin): __tablename__ = 'password' attributes = [ 'id', 'local_user_id', 'password', 'password_hash', 'created_at', 'expires_at' ] id = sql.Column(sql.Integer, primary_key=True) local_user_id = sql.Column( sql.Integer, sql.ForeignKey('local_user.id', ondelete='CASCADE')) # TODO(notmorgan): in the Q release the "password" field can be dropped as # long as data migration exists to move the hashes over to the # password_hash column if no value is in the password_hash column. password = sql.Column(sql.String(128), nullable=True) password_hash = sql.Column(sql.String(255), nullable=True) # TODO(lbragstad): Once Rocky opens for development, the _created_at and # _expires_at attributes/columns can be removed from the schema. The # migration ensures all passwords are converted from datetime objects to # big integers. The old datetime columns and their corresponding attributes # in the model are no longer required. # created_at default set here to safe guard in case it gets missed _created_at = sql.Column('created_at', sql.DateTime, nullable=False, default=datetime.datetime.utcnow) _expires_at = sql.Column('expires_at', sql.DateTime, nullable=True) # set the default to 0, a 0 indicates it is unset. created_at_int = sql.Column(sql.DateTimeInt(), nullable=False, default=datetime.datetime.utcnow) expires_at_int = sql.Column(sql.DateTimeInt(), nullable=True) self_service = sql.Column(sql.Boolean, default=False, nullable=False, server_default='0') @hybrid_property def created_at(self): return self.created_at_int or self._created_at @created_at.setter def created_at(self, value): self._created_at = value self.created_at_int = value @hybrid_property def expires_at(self): return self.expires_at_int or self._expires_at @expires_at.setter def expires_at(self, value): self._expires_at = value self.expires_at_int = value
class UserOption(sql.ModelBase): __tablename__ = 'user_option' user_id = sql.Column(sql.String(64), sql.ForeignKey('user.id', ondelete='CASCADE'), nullable=False, primary_key=True) option_id = sql.Column(sql.String(4), nullable=False, primary_key=True) option_value = sql.Column(sql.JsonBlob, nullable=True) def __init__(self, option_id, option_value): self.option_id = option_id self.option_value = option_value
class Endpoint(sql.ModelBase, sql.DictBase): __tablename__ = 'endpoint' attributes = ['id', 'interface', 'region', 'service_id', 'url', 'legacy_endpoint_id'] id = sql.Column(sql.String(64), primary_key=True) legacy_endpoint_id = sql.Column(sql.String(64)) interface = sql.Column(sql.String(8), nullable=False) region = sql.Column(sql.String(255)) service_id = sql.Column(sql.String(64), sql.ForeignKey('service.id'), nullable=False) url = sql.Column(sql.Text(), nullable=False) extra = sql.Column(sql.JsonBlob())
class ProjectTag(sql.ModelBase, sql.ModelDictMixin): def to_dict(self): d = super(ProjectTag, self).to_dict() return d __tablename__ = 'project_tag' attributes = ['project_id', 'name'] project_id = sql.Column(sql.String(64), sql.ForeignKey('project.id', ondelete='CASCADE'), nullable=False, primary_key=True) name = sql.Column(sql.Unicode(255), nullable=False, primary_key=True) __table_args__ = (sql.UniqueConstraint('project_id', 'name'), )