Merge pull request #137 from OpenKMIP/feat/sqlalchemy-cert

Added Class Type to Managed Object
This commit is contained in:
Peter Hamilton 2016-02-19 13:58:14 -05:00
commit 3a4de2121d

View File

@ -14,7 +14,7 @@
# under the License. # under the License.
from abc import abstractmethod from abc import abstractmethod
from sqlalchemy import Column, event, ForeignKey, Integer, VARBINARY from sqlalchemy import Column, event, ForeignKey, Integer, String, VARBINARY
from sqlalchemy.ext.associationproxy import association_proxy from sqlalchemy.ext.associationproxy import association_proxy
from sqlalchemy.orm import relationship from sqlalchemy.orm import relationship
@ -46,6 +46,7 @@ class ManagedObject(sql.Base):
__tablename__ = 'managed_objects' __tablename__ = 'managed_objects'
unique_identifier = Column('uid', Integer, primary_key=True) unique_identifier = Column('uid', Integer, primary_key=True)
_object_type = Column('object_type', sql.EnumType(enums.ObjectType)) _object_type = Column('object_type', sql.EnumType(enums.ObjectType))
_class_type = Column('class_type', String(50))
value = Column('value', VARBINARY(1024)) value = Column('value', VARBINARY(1024))
name_index = Column(Integer, default=0) name_index = Column(Integer, default=0)
_names = relationship('ManagedObjectName', back_populates='mo', _names = relationship('ManagedObjectName', back_populates='mo',
@ -53,8 +54,8 @@ class ManagedObject(sql.Base):
names = association_proxy('_names', 'name') names = association_proxy('_names', 'name')
__mapper_args__ = { __mapper_args__ = {
'polymorphic_identity': 0x00000000, 'polymorphic_identity': 'ManagedObject',
'polymorphic_on': _object_type 'polymorphic_on': _class_type
} }
@abstractmethod @abstractmethod
@ -149,7 +150,7 @@ class CryptographicObject(ManagedObject):
cryptographic_usage_masks = Column('cryptographic_usage_mask', cryptographic_usage_masks = Column('cryptographic_usage_mask',
sql.UsageMaskType) sql.UsageMaskType)
__mapper_args__ = { __mapper_args__ = {
'polymorphic_identity': 0x80000001 'polymorphic_identity': 'CryptographicObject'
} }
@abstractmethod @abstractmethod
@ -209,7 +210,7 @@ class Key(CryptographicObject):
'key_format_type', sql.EnumType(enums.KeyFormatType)) 'key_format_type', sql.EnumType(enums.KeyFormatType))
__mapper_args__ = { __mapper_args__ = {
'polymorphic_identity': 0x80000002 'polymorphic_identity': 'Key'
} }
@abstractmethod @abstractmethod
@ -256,7 +257,7 @@ class SymmetricKey(Key):
primary_key=True) primary_key=True)
__mapper_args__ = { __mapper_args__ = {
'polymorphic_identity': enums.ObjectType.SYMMETRIC_KEY 'polymorphic_identity': 'SymmetricKey'
} }
def __init__(self, algorithm, length, value, masks=None, def __init__(self, algorithm, length, value, masks=None,
@ -394,7 +395,7 @@ class PublicKey(Key):
primary_key=True) primary_key=True)
__mapper_args__ = { __mapper_args__ = {
'polymorphic_identity': enums.ObjectType.PUBLIC_KEY 'polymorphic_identity': 'PublicKey'
} }
def __init__(self, algorithm, length, value, def __init__(self, algorithm, length, value,
@ -545,7 +546,7 @@ class PrivateKey(Key):
primary_key=True) primary_key=True)
__mapper_args__ = { __mapper_args__ = {
'polymorphic_identity': enums.ObjectType.PRIVATE_KEY 'polymorphic_identity': 'PrivateKey'
} }
def __init__(self, algorithm, length, value, format_type, masks=None, def __init__(self, algorithm, length, value, format_type, masks=None,
@ -839,7 +840,7 @@ class SecretData(CryptographicObject):
primary_key=True) primary_key=True)
data_type = Column('data_type', sql.EnumType(enums.SecretDataType)) data_type = Column('data_type', sql.EnumType(enums.SecretDataType))
__mapper_args__ = { __mapper_args__ = {
'polymorphic_identity': enums.ObjectType.SECRET_DATA 'polymorphic_identity': 'SecretData'
} }
def __init__(self, value, data_type, masks=None, name='Secret Data'): def __init__(self, value, data_type, masks=None, name='Secret Data'):
@ -952,7 +953,7 @@ class OpaqueObject(ManagedObject):
primary_key=True) primary_key=True)
opaque_type = Column('opaque_type', sql.EnumType(enums.OpaqueDataType)) opaque_type = Column('opaque_type', sql.EnumType(enums.OpaqueDataType))
__mapper_args__ = { __mapper_args__ = {
'polymorphic_identity': enums.ObjectType.OPAQUE_DATA 'polymorphic_identity': 'OpaqueData'
} }
def __init__(self, value, opaque_type, name='Opaque Object'): def __init__(self, value, opaque_type, name='Opaque Object'):