Skip to content

Commit

Permalink
Added Class Type to Managed Object
Browse files Browse the repository at this point in the history
SQLAlchemy requires a unique identifier for classes when using the
join table inheritence strategy. Previous commits were reusing the
object_type attribute of ManagedObject, but this strategy does not
work for classes that are subclasses of an object. This will be the
case for the Certificate object type because one such subclass will be
X509Certificate.
  • Loading branch information
rellerreller committed Feb 19, 2016
1 parent e967bb0 commit 771aea7
Showing 1 changed file with 11 additions and 10 deletions.
21 changes: 11 additions & 10 deletions kmip/pie/objects.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
# under the License.

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.orm import relationship

Expand Down Expand Up @@ -46,15 +46,16 @@ class ManagedObject(sql.Base):
__tablename__ = 'managed_objects'
unique_identifier = Column('uid', Integer, primary_key=True)
_object_type = Column('object_type', sql.EnumType(enums.ObjectType))
_class_type = Column('class_type', String(50))
value = Column('value', VARBINARY(1024))
name_index = Column(Integer, default=0)
_names = relationship('ManagedObjectName', back_populates='mo',
cascade='all, delete-orphan')
names = association_proxy('_names', 'name')

__mapper_args__ = {
'polymorphic_identity': 0x00000000,
'polymorphic_on': _object_type
'polymorphic_identity': 'ManagedObject',
'polymorphic_on': _class_type
}

@abstractmethod
Expand Down Expand Up @@ -149,7 +150,7 @@ class CryptographicObject(ManagedObject):
cryptographic_usage_masks = Column('cryptographic_usage_mask',
sql.UsageMaskType)
__mapper_args__ = {
'polymorphic_identity': 0x80000001
'polymorphic_identity': 'CryptographicObject'
}

@abstractmethod
Expand Down Expand Up @@ -209,7 +210,7 @@ class Key(CryptographicObject):
'key_format_type', sql.EnumType(enums.KeyFormatType))

__mapper_args__ = {
'polymorphic_identity': 0x80000002
'polymorphic_identity': 'Key'
}

@abstractmethod
Expand Down Expand Up @@ -256,7 +257,7 @@ class SymmetricKey(Key):
primary_key=True)

__mapper_args__ = {
'polymorphic_identity': enums.ObjectType.SYMMETRIC_KEY
'polymorphic_identity': 'SymmetricKey'
}

def __init__(self, algorithm, length, value, masks=None,
Expand Down Expand Up @@ -394,7 +395,7 @@ class PublicKey(Key):
primary_key=True)

__mapper_args__ = {
'polymorphic_identity': enums.ObjectType.PUBLIC_KEY
'polymorphic_identity': 'PublicKey'
}

def __init__(self, algorithm, length, value,
Expand Down Expand Up @@ -545,7 +546,7 @@ class PrivateKey(Key):
primary_key=True)

__mapper_args__ = {
'polymorphic_identity': enums.ObjectType.PRIVATE_KEY
'polymorphic_identity': 'PrivateKey'
}

def __init__(self, algorithm, length, value, format_type, masks=None,
Expand Down Expand Up @@ -839,7 +840,7 @@ class SecretData(CryptographicObject):
primary_key=True)
data_type = Column('data_type', sql.EnumType(enums.SecretDataType))
__mapper_args__ = {
'polymorphic_identity': enums.ObjectType.SECRET_DATA
'polymorphic_identity': 'SecretData'
}

def __init__(self, value, data_type, masks=None, name='Secret Data'):
Expand Down Expand Up @@ -952,7 +953,7 @@ class OpaqueObject(ManagedObject):
primary_key=True)
opaque_type = Column('opaque_type', sql.EnumType(enums.OpaqueDataType))
__mapper_args__ = {
'polymorphic_identity': enums.ObjectType.OPAQUE_DATA
'polymorphic_identity': 'OpaqueData'
}

def __init__(self, value, opaque_type, name='Opaque Object'):
Expand Down

0 comments on commit 771aea7

Please sign in to comment.