Reorganizing message payload code

This change is primarily a reorganization of the message payload code
originally found in kmip/core/messages/operations.py. The code from that
module has been moved to a new package, kmip.core.messages.payloads, and
split into separate modules according to each supported KMIP operation.

The surrounding KMIP codebase has been updated to use the new package
structure and a placeholder test suite has been put in place for future
tests. This change does NOT include test cases as these would primarily
be a refactoring from the current test suite found in
kmip/tests/core/messages/test_messages.py and that work has not been
done yet.
This commit is contained in:
Peter Hamilton 2014-11-06 10:59:33 -05:00
parent 6a11dacfc3
commit b99bf8cbf4
18 changed files with 820 additions and 613 deletions

View File

@ -13,4 +13,4 @@
# License for the specific language governing permissions and limitations # License for the specific language governing permissions and limitations
# under the License. # under the License.
__all__ = ['contents', 'messages', 'operations'] __all__ = ['contents', 'messages', 'payloads']

View File

@ -19,7 +19,7 @@ from kmip.core.messages import contents
from kmip.core.messages.contents import AsynchronousCorrelationValue from kmip.core.messages.contents import AsynchronousCorrelationValue
from kmip.core.messages.contents import BatchErrorContinuationOption from kmip.core.messages.contents import BatchErrorContinuationOption
from kmip.core.messages import operations from kmip.core.messages import payloads
from kmip.core.primitives import Struct from kmip.core.primitives import Struct
@ -194,7 +194,7 @@ class RequestBatchItem(Struct):
self.unique_batch_item_id.read(tstream) self.unique_batch_item_id.read(tstream)
# Lookup the response payload class that belongs to the operation # Lookup the response payload class that belongs to the operation
cls = operations.REQUEST_MAP.get(self.operation.enum) cls = payloads.REQUEST_MAP.get(self.operation.enum)
self.request_payload = cls() self.request_payload = cls()
self.request_payload.read(tstream) self.request_payload.read(tstream)
@ -281,7 +281,7 @@ class ResponseBatchItem(Struct):
self.async_correlation_value.read(tstream) self.async_correlation_value.read(tstream)
# Lookup the response payload class that belongs to the operation # Lookup the response payload class that belongs to the operation
cls = operations.RESPONSE_MAP.get(self.operation.enum) cls = payloads.RESPONSE_MAP.get(self.operation.enum)
expected = cls() expected = cls()
if self.is_tag_next(expected.tag, tstream): if self.is_tag_next(expected.tag, tstream):
self.response_payload = cls() self.response_payload = cls()

View File

@ -1,555 +0,0 @@
# Copyright (c) 2014 The Johns Hopkins University/Applied Physics Laboratory
# All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
from kmip.core.factories.secrets import SecretFactory
from kmip.core import attributes
from kmip.core import enums
from kmip.core.enums import Tags
from kmip.core.objects import KeyWrappingSpecification
from kmip.core.objects import TemplateAttribute
from kmip.core.objects import Attribute
from kmip.core.primitives import Struct
from kmip.core.primitives import Enumeration
from kmip.core.primitives import Integer
from kmip.core.utils import BytearrayStream
# 4.1
class CreateRequestPayload(Struct):
def __init__(self,
object_type=None,
template_attribute=None):
super(self.__class__, self).__init__(tag=enums.Tags.REQUEST_PAYLOAD)
self.object_type = object_type
self.template_attribute = template_attribute
self.validate()
def read(self, istream):
super(self.__class__, self).read(istream)
tstream = BytearrayStream(istream.read(self.length))
self.object_type = attributes.ObjectType()
self.template_attribute = TemplateAttribute()
self.object_type.read(tstream)
self.template_attribute.read(tstream)
self.is_oversized(tstream)
self.validate()
def write(self, ostream):
tstream = BytearrayStream()
# Write the object type and template attribute of the request payload
self.object_type.write(tstream)
self.template_attribute.write(tstream)
# Write the length and value of the request payload
self.length = tstream.length()
super(self.__class__, self).write(ostream)
ostream.write(tstream.buffer)
def validate(self):
# TODO (peter-hamilton) Finish implementation.
pass
class CreateResponsePayload(Struct):
def __init__(self,
object_type=None,
unique_identifier=None,
template_attribute=None):
super(self.__class__, self).__init__(tag=enums.Tags.RESPONSE_PAYLOAD)
self.object_type = object_type
self.unique_identifier = unique_identifier
self.template_attribute = template_attribute
self.validate()
def read(self, istream):
super(self.__class__, self).read(istream)
tstream = BytearrayStream(istream.read(self.length))
self.object_type = attributes.ObjectType()
self.unique_identifier = attributes.UniqueIdentifier()
self.object_type.read(tstream)
self.unique_identifier.read(tstream)
if self.is_tag_next(Tags.TEMPLATE_ATTRIBUTE, tstream):
self.template_attribute = TemplateAttribute()
self.template_attribute.read(tstream)
self.is_oversized(tstream)
self.validate()
def write(self, ostream):
tstream = BytearrayStream()
# Write the contents of the request payload
self.object_type.write(tstream)
self.unique_identifier.write(tstream)
if self.template_attribute is not None:
self.template_attribute.write(tstream)
# Write the length and value of the request payload
self.length = tstream.length()
super(self.__class__, self).write(ostream)
ostream.write(tstream.buffer)
def validate(self):
# TODO (peter-hamilton) Finish implementation.
pass
# 4.3
class RegisterRequestPayload(Struct):
def __init__(self,
object_type=None,
template_attribute=None,
secret=None):
super(self.__class__, self).__init__(Tags.REQUEST_PAYLOAD)
self.secret_factory = SecretFactory()
self.object_type = object_type
self.template_attribute = template_attribute
self.secret = secret
self.validate()
def read(self, istream):
super(self.__class__, self).read(istream)
tstream = BytearrayStream(istream.read(self.length))
self.object_type = attributes.ObjectType()
self.template_attribute = TemplateAttribute()
self.object_type.read(tstream)
self.template_attribute.read(tstream)
secret_type = self.object_type.enum
secret = self.secret_factory.create_secret(secret_type)
if self.is_tag_next(secret.tag, tstream):
self.secret = secret
self.secret.read(tstream)
self.is_oversized(tstream)
self.validate()
def write(self, ostream):
tstream = BytearrayStream()
# Write the contents of the request payload
self.object_type.write(tstream)
self.template_attribute.write(tstream)
if self.secret is not None:
self.secret.write(tstream)
# Write the length and value of the request payload
self.length = tstream.length()
super(self.__class__, self).write(ostream)
ostream.write(tstream.buffer)
def validate(self):
self.__validate()
def __validate(self):
# TODO (peter-hamilton) Finish implementation.
pass
class RegisterResponsePayload(Struct):
def __init__(self,
unique_identifier=None,
template_attribute=None):
super(self.__class__, self).__init__(Tags.RESPONSE_PAYLOAD)
self.unique_identifier = unique_identifier
self.template_attribute = template_attribute
self.validate()
def read(self, istream):
super(self.__class__, self).read(istream)
tstream = BytearrayStream(istream.read(self.length))
self.unique_identifier = attributes.UniqueIdentifier()
self.unique_identifier.read(tstream)
if self.is_tag_next(Tags.TEMPLATE_ATTRIBUTE, tstream):
self.template_attribute = TemplateAttribute()
self.template_attribute.read(tstream)
self.is_oversized(tstream)
self.validate()
def write(self, ostream):
tstream = BytearrayStream()
# Write the contents of the request payload
self.unique_identifier.write(tstream)
if self.template_attribute is not None:
self.template_attribute.write(tstream)
# Write the length and value of the request payload
self.length = tstream.length()
super(self.__class__, self).write(ostream)
ostream.write(tstream.buffer)
def validate(self):
self.__validate()
def __validate(self):
# TODO (peter-hamilton) Finish implementation.
pass
# 4.11
class GetRequestPayload(Struct):
# 9.1.3.2.2
class KeyCompressionType(Enumeration):
ENUM_TYPE = enums.KeyCompressionType
def __init__(self, value=None):
super(self.__class__, self).__init__(value,
Tags.KEY_COMPRESSION_TYPE)
# 9.1.3.2.3
class KeyFormatType(Enumeration):
ENUM_TYPE = enums.KeyFormatType
def __init__(self, value=None):
super(self.__class__, self).__init__(value, Tags.KEY_FORMAT_TYPE)
def __init__(self,
unique_identifier=None,
key_format_type=None,
key_compression_type=None,
key_wrapping_specification=None):
super(self.__class__, self).__init__(tag=enums.Tags.REQUEST_PAYLOAD)
self.unique_identifier = unique_identifier
self.key_format_type = key_format_type
self.key_compression_type = key_compression_type
self.key_wrapping_specification = key_wrapping_specification
self.validate()
def read(self, istream):
super(self.__class__, self).read(istream)
tstream = BytearrayStream(istream.read(self.length))
if self.is_tag_next(Tags.UNIQUE_IDENTIFIER, tstream):
self.unique_identifier = attributes.UniqueIdentifier()
self.unique_identifier.read(tstream)
if self.is_tag_next(Tags.KEY_FORMAT_TYPE, tstream):
self.key_format_type = GetRequestPayload.KeyFormatType()
self.key_format_type.read(tstream)
if self.is_tag_next(Tags.KEY_COMPRESSION_TYPE, tstream):
self.key_compression_type = GetRequestPayload.KeyCompressionType()
self.key_compression_type.read(tstream)
if self.is_tag_next(Tags.KEY_WRAPPING_SPECIFICATION, tstream):
self.key_wrapping_specification = KeyWrappingSpecification()
self.key_wrapping_specification.read(tstream)
self.is_oversized(tstream)
self.validate()
def write(self, ostream):
tstream = BytearrayStream()
# Write the contents of the request payload
if self.unique_identifier is not None:
self.unique_identifier.write(tstream)
if self.key_format_type is not None:
self.key_format_type.write(tstream)
if self.key_compression_type is not None:
self.key_compression_type.write(tstream)
if self.key_wrapping_specification is not None:
self.key_wrapping_specification.write(tstream)
# Write the length and value of the request payload
self.length = tstream.length()
super(self.__class__, self).write(ostream)
ostream.write(tstream.buffer)
def validate(self):
self.__validate()
def __validate(self):
# TODO (peter-hamilton) Finish implementation
pass
class GetResponsePayload(Struct):
def __init__(self,
object_type=None,
unique_identifier=None,
secret=None):
super(self.__class__, self).__init__(tag=Tags.RESPONSE_PAYLOAD)
self.object_type = object_type
self.unique_identifier = unique_identifier
self.secret = secret
self.secret_factory = SecretFactory()
self.validate()
def read(self, istream):
super(self.__class__, self).read(istream)
tstream = BytearrayStream(istream.read(self.length))
self.object_type = attributes.ObjectType()
self.unique_identifier = attributes.UniqueIdentifier()
self.object_type.read(tstream)
self.unique_identifier.read(tstream)
secret_type = self.object_type.enum
self.secret = self.secret_factory.create_secret(secret_type)
self.secret.read(tstream)
self.is_oversized(tstream)
self.validate()
def write(self, ostream):
tstream = BytearrayStream()
self.object_type.write(tstream)
self.unique_identifier.write(tstream)
self.secret.write(tstream)
# Write the length and value of the request payload
self.length = tstream.length()
super(self.__class__, self).write(ostream)
ostream.write(tstream.buffer)
def validate(self):
self.__validate()
def __validate(self):
# TODO (peter-hamilton) Finish implementation.
pass
# 4.21
class DestroyRequestPayload(Struct):
def __init__(self,
unique_identifier=None):
super(self.__class__, self).__init__(enums.Tags.REQUEST_PAYLOAD)
self.unique_identifier = unique_identifier
self.validate()
def read(self, istream):
super(self.__class__, self).read(istream)
tstream = BytearrayStream(istream.read(self.length))
if self.is_tag_next(Tags.UNIQUE_IDENTIFIER, tstream):
self.unique_identifier = attributes.UniqueIdentifier()
self.unique_identifier.read(tstream)
self.is_oversized(tstream)
self.validate()
def write(self, ostream):
tstream = BytearrayStream()
if self.unique_identifier is not None:
self.unique_identifier.write(tstream)
# Write the length and value of the request payload
self.length = tstream.length()
super(self.__class__, self).write(ostream)
ostream.write(tstream.buffer)
def validate(self):
self.__validate()
def __validate(self):
# TODO (peter-hamilton) Finish implementation.
pass
class DestroyResponsePayload(Struct):
def __init__(self,
unique_identifier=None):
super(self.__class__, self).__init__(enums.Tags.RESPONSE_PAYLOAD)
self.unique_identifier = unique_identifier
self.validate()
def read(self, istream):
super(self.__class__, self).read(istream)
tstream = BytearrayStream(istream.read(self.length))
self.unique_identifier = attributes.UniqueIdentifier()
self.unique_identifier.read(tstream)
self.is_oversized(tstream)
self.validate()
def write(self, ostream):
tstream = BytearrayStream()
self.unique_identifier.write(tstream)
# Write the length and value of the request payload
self.length = tstream.length()
super(self.__class__, self).write(ostream)
ostream.write(tstream.buffer)
def validate(self):
self.__validate()
def __validate(self):
# TODO (peter-hamilton) Finish implementation.
pass
class LocateRequestPayload(Struct):
# 9.1.3.2.33
class ObjectGroupMember(Enumeration):
ENUM_TYPE = enums.ObjectGroupMember
def __init__(self, value=None):
super(self.__class__, self).__init__(value,
Tags.OBJECT_GROUP_MEMBER)
class MaximumItems(Integer):
def __init__(self, value=None):
super(self.__class__, self).__init__(value,
Tags.MAXIMUM_ITEMS)
# 9.1.3.3.2
class StorageStatusMask(Enumeration):
ENUM_TYPE = enums.StorageStatusMask
def __init__(self, value=None):
super(self.__class__, self).__init__(value,
Tags.STORAGE_STATUS_MASK)
def __init__(self, maximum_items=None, storage_status_mask=None,
object_group_member=None, attributes=None):
super(self.__class__, self).__init__(enums.Tags.REQUEST_PAYLOAD)
self.maximum_items = maximum_items
self.storage_status_mask = storage_status_mask
self.object_group_member = object_group_member
self.attributes = attributes or []
self.validate()
def read(self, istream):
super(self.__class__, self).read(istream)
tstream = BytearrayStream(istream.read(self.length))
if self.is_tag_next(Tags.MAXIMUM_ITEMS, tstream):
self.maximum_items = LocateRequestPayload.MaximumItems()
self.maximum_items.read()
if self.is_tag_next(Tags.STORAGE_STATUS_MASK, tstream):
self.storage_status_mask = LocateRequestPayload.StorageStatusMask()
self.storage_status_mask.read()
if self.is_tag_next(Tags.OBJECT_GROUP_MEMBER, tstream):
self.object_group_member = LocateRequestPayload.ObjectGroupMember()
self.object_group_member.read(tstream)
while self.is_tag_next(Tags.ATTRIBUTE, tstream):
attr = Attribute()
attr.read(tstream)
self.attributes.append(attr)
self.validate()
def write(self, ostream):
tstream = BytearrayStream()
if self.maximum_items is not None:
self.maximum_items.write(tstream)
if self.storage_status_mask is not None:
self.storage_status_mask.write(tstream)
if self.attributes is not None:
for a in self.attributes:
a.write(tstream)
# Write the length and value of the request payload
self.length = tstream.length()
super(self.__class__, self).write(ostream)
ostream.write(tstream.buffer)
def validate(self):
self._validate()
def _validate(self):
# TODO Finish implementation.
pass
class LocateResponsePayload(Struct):
def __init__(self, unique_identifiers=[]):
super(self.__class__, self).__init__(enums.Tags.RESPONSE_PAYLOAD)
self.unique_identifiers = unique_identifiers or []
self.validate()
def read(self, istream):
super(self.__class__, self).read(istream)
tstream = BytearrayStream(istream.read(self.length))
while self.is_tag_next(Tags.UNIQUE_IDENTIFIER, tstream):
ui = attributes.UniqueIdentifier()
ui.read(tstream)
self.unique_identifiers.append(ui)
self.is_oversized(tstream)
self.validate()
def write(self, ostream):
tstream = BytearrayStream()
for ui in self.unique_identifiers:
ui.write(tstream)
# Write the length and value of the request payload
self.length = tstream.length()
super(self.__class__, self).write(ostream)
ostream.write(tstream.buffer)
def validate(self):
self.__validate()
def __validate(self):
# TODO Finish implementation.
pass
REQUEST_MAP = {enums.Operation.CREATE: CreateRequestPayload,
enums.Operation.GET: GetRequestPayload,
enums.Operation.DESTROY: DestroyRequestPayload,
enums.Operation.REGISTER: RegisterRequestPayload,
enums.Operation.LOCATE: LocateRequestPayload}
RESPONSE_MAP = {enums.Operation.CREATE: CreateResponsePayload,
enums.Operation.GET: GetResponsePayload,
enums.Operation.REGISTER: RegisterResponsePayload,
enums.Operation.DESTROY: DestroyResponsePayload,
enums.Operation.LOCATE: LocateResponsePayload}

View File

@ -0,0 +1,37 @@
# Copyright (c) 2014 The Johns Hopkins University/Applied Physics Laboratory
# All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
__all__ = ['create', 'destroy', 'get', 'locate', 'register']
from kmip.core import enums
from kmip.core.messages.payloads import create
from kmip.core.messages.payloads import get
from kmip.core.messages.payloads import destroy
from kmip.core.messages.payloads import register
from kmip.core.messages.payloads import locate
# TODO (peter-hamilton) Replace with PayloadFactories
REQUEST_MAP = {enums.Operation.CREATE: create.CreateRequestPayload,
enums.Operation.GET: get.GetRequestPayload,
enums.Operation.DESTROY: destroy.DestroyRequestPayload,
enums.Operation.REGISTER: register.RegisterRequestPayload,
enums.Operation.LOCATE: locate.LocateRequestPayload}
RESPONSE_MAP = {enums.Operation.CREATE: create.CreateResponsePayload,
enums.Operation.GET: get.GetResponsePayload,
enums.Operation.REGISTER: register.RegisterResponsePayload,
enums.Operation.DESTROY: destroy.DestroyResponsePayload,
enums.Operation.LOCATE: locate.LocateResponsePayload}

View File

@ -0,0 +1,113 @@
# Copyright (c) 2014 The Johns Hopkins University/Applied Physics Laboratory
# All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
from kmip.core import attributes
from kmip.core import enums
from kmip.core.enums import Tags
from kmip.core.objects import TemplateAttribute
from kmip.core.primitives import Struct
from kmip.core.utils import BytearrayStream
class CreateRequestPayload(Struct):
def __init__(self,
object_type=None,
template_attribute=None):
super(self.__class__, self).__init__(tag=enums.Tags.REQUEST_PAYLOAD)
self.object_type = object_type
self.template_attribute = template_attribute
self.validate()
def read(self, istream):
super(self.__class__, self).read(istream)
tstream = BytearrayStream(istream.read(self.length))
self.object_type = attributes.ObjectType()
self.template_attribute = TemplateAttribute()
self.object_type.read(tstream)
self.template_attribute.read(tstream)
self.is_oversized(tstream)
self.validate()
def write(self, ostream):
tstream = BytearrayStream()
# Write the object type and template attribute of the request payload
self.object_type.write(tstream)
self.template_attribute.write(tstream)
# Write the length and value of the request payload
self.length = tstream.length()
super(self.__class__, self).write(ostream)
ostream.write(tstream.buffer)
def validate(self):
# TODO (peter-hamilton) Finish implementation.
pass
class CreateResponsePayload(Struct):
def __init__(self,
object_type=None,
unique_identifier=None,
template_attribute=None):
super(self.__class__, self).__init__(tag=enums.Tags.RESPONSE_PAYLOAD)
self.object_type = object_type
self.unique_identifier = unique_identifier
self.template_attribute = template_attribute
self.validate()
def read(self, istream):
super(self.__class__, self).read(istream)
tstream = BytearrayStream(istream.read(self.length))
self.object_type = attributes.ObjectType()
self.unique_identifier = attributes.UniqueIdentifier()
self.object_type.read(tstream)
self.unique_identifier.read(tstream)
if self.is_tag_next(Tags.TEMPLATE_ATTRIBUTE, tstream):
self.template_attribute = TemplateAttribute()
self.template_attribute.read(tstream)
self.is_oversized(tstream)
self.validate()
def write(self, ostream):
tstream = BytearrayStream()
# Write the contents of the request payload
self.object_type.write(tstream)
self.unique_identifier.write(tstream)
if self.template_attribute is not None:
self.template_attribute.write(tstream)
# Write the length and value of the request payload
self.length = tstream.length()
super(self.__class__, self).write(ostream)
ostream.write(tstream.buffer)
def validate(self):
# TODO (peter-hamilton) Finish implementation.
pass

View File

@ -0,0 +1,97 @@
# Copyright (c) 2014 The Johns Hopkins University/Applied Physics Laboratory
# All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
from kmip.core import attributes
from kmip.core import enums
from kmip.core.enums import Tags
from kmip.core.primitives import Struct
from kmip.core.utils import BytearrayStream
# 4.21
class DestroyRequestPayload(Struct):
def __init__(self,
unique_identifier=None):
super(self.__class__, self).__init__(enums.Tags.REQUEST_PAYLOAD)
self.unique_identifier = unique_identifier
self.validate()
def read(self, istream):
super(self.__class__, self).read(istream)
tstream = BytearrayStream(istream.read(self.length))
if self.is_tag_next(Tags.UNIQUE_IDENTIFIER, tstream):
self.unique_identifier = attributes.UniqueIdentifier()
self.unique_identifier.read(tstream)
self.is_oversized(tstream)
self.validate()
def write(self, ostream):
tstream = BytearrayStream()
if self.unique_identifier is not None:
self.unique_identifier.write(tstream)
# Write the length and value of the request payload
self.length = tstream.length()
super(self.__class__, self).write(ostream)
ostream.write(tstream.buffer)
def validate(self):
self.__validate()
def __validate(self):
# TODO (peter-hamilton) Finish implementation.
pass
class DestroyResponsePayload(Struct):
def __init__(self,
unique_identifier=None):
super(self.__class__, self).__init__(enums.Tags.RESPONSE_PAYLOAD)
self.unique_identifier = unique_identifier
self.validate()
def read(self, istream):
super(self.__class__, self).read(istream)
tstream = BytearrayStream(istream.read(self.length))
self.unique_identifier = attributes.UniqueIdentifier()
self.unique_identifier.read(tstream)
self.is_oversized(tstream)
self.validate()
def write(self, ostream):
tstream = BytearrayStream()
self.unique_identifier.write(tstream)
# Write the length and value of the request payload
self.length = tstream.length()
super(self.__class__, self).write(ostream)
ostream.write(tstream.buffer)
def validate(self):
self.__validate()
def __validate(self):
# TODO (peter-hamilton) Finish implementation.
pass

View File

@ -0,0 +1,156 @@
# Copyright (c) 2014 The Johns Hopkins University/Applied Physics Laboratory
# All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
from kmip.core.factories.secrets import SecretFactory
from kmip.core import attributes
from kmip.core import enums
from kmip.core.enums import Tags
from kmip.core.objects import KeyWrappingSpecification
from kmip.core.primitives import Struct
from kmip.core.primitives import Enumeration
from kmip.core.utils import BytearrayStream
# 4.11
class GetRequestPayload(Struct):
# 9.1.3.2.2
class KeyCompressionType(Enumeration):
ENUM_TYPE = enums.KeyCompressionType
def __init__(self, value=None):
super(self.__class__, self).__init__(value,
Tags.KEY_COMPRESSION_TYPE)
# 9.1.3.2.3
class KeyFormatType(Enumeration):
ENUM_TYPE = enums.KeyFormatType
def __init__(self, value=None):
super(self.__class__, self).__init__(value, Tags.KEY_FORMAT_TYPE)
def __init__(self,
unique_identifier=None,
key_format_type=None,
key_compression_type=None,
key_wrapping_specification=None):
super(self.__class__, self).__init__(tag=enums.Tags.REQUEST_PAYLOAD)
self.unique_identifier = unique_identifier
self.key_format_type = key_format_type
self.key_compression_type = key_compression_type
self.key_wrapping_specification = key_wrapping_specification
self.validate()
def read(self, istream):
super(self.__class__, self).read(istream)
tstream = BytearrayStream(istream.read(self.length))
if self.is_tag_next(Tags.UNIQUE_IDENTIFIER, tstream):
self.unique_identifier = attributes.UniqueIdentifier()
self.unique_identifier.read(tstream)
if self.is_tag_next(Tags.KEY_FORMAT_TYPE, tstream):
self.key_format_type = GetRequestPayload.KeyFormatType()
self.key_format_type.read(tstream)
if self.is_tag_next(Tags.KEY_COMPRESSION_TYPE, tstream):
self.key_compression_type = GetRequestPayload.KeyCompressionType()
self.key_compression_type.read(tstream)
if self.is_tag_next(Tags.KEY_WRAPPING_SPECIFICATION, tstream):
self.key_wrapping_specification = KeyWrappingSpecification()
self.key_wrapping_specification.read(tstream)
self.is_oversized(tstream)
self.validate()
def write(self, ostream):
tstream = BytearrayStream()
# Write the contents of the request payload
if self.unique_identifier is not None:
self.unique_identifier.write(tstream)
if self.key_format_type is not None:
self.key_format_type.write(tstream)
if self.key_compression_type is not None:
self.key_compression_type.write(tstream)
if self.key_wrapping_specification is not None:
self.key_wrapping_specification.write(tstream)
# Write the length and value of the request payload
self.length = tstream.length()
super(self.__class__, self).write(ostream)
ostream.write(tstream.buffer)
def validate(self):
self.__validate()
def __validate(self):
# TODO (peter-hamilton) Finish implementation
pass
class GetResponsePayload(Struct):
def __init__(self,
object_type=None,
unique_identifier=None,
secret=None):
super(self.__class__, self).__init__(tag=Tags.RESPONSE_PAYLOAD)
self.object_type = object_type
self.unique_identifier = unique_identifier
self.secret = secret
self.secret_factory = SecretFactory()
self.validate()
def read(self, istream):
super(self.__class__, self).read(istream)
tstream = BytearrayStream(istream.read(self.length))
self.object_type = attributes.ObjectType()
self.unique_identifier = attributes.UniqueIdentifier()
self.object_type.read(tstream)
self.unique_identifier.read(tstream)
secret_type = self.object_type.enum
self.secret = self.secret_factory.create_secret(secret_type)
self.secret.read(tstream)
self.is_oversized(tstream)
self.validate()
def write(self, ostream):
tstream = BytearrayStream()
self.object_type.write(tstream)
self.unique_identifier.write(tstream)
self.secret.write(tstream)
# Write the length and value of the request payload
self.length = tstream.length()
super(self.__class__, self).write(ostream)
ostream.write(tstream.buffer)
def validate(self):
self.__validate()
def __validate(self):
# TODO (peter-hamilton) Finish implementation.
pass

View File

@ -0,0 +1,138 @@
# Copyright (c) 2014 The Johns Hopkins University/Applied Physics Laboratory
# All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
from kmip.core import attributes
from kmip.core import enums
from kmip.core.enums import Tags
from kmip.core.objects import Attribute
from kmip.core.primitives import Struct
from kmip.core.primitives import Enumeration
from kmip.core.primitives import Integer
from kmip.core.utils import BytearrayStream
class LocateRequestPayload(Struct):
# 9.1.3.2.33
class ObjectGroupMember(Enumeration):
ENUM_TYPE = enums.ObjectGroupMember
def __init__(self, value=None):
super(self.__class__, self).__init__(value,
Tags.OBJECT_GROUP_MEMBER)
class MaximumItems(Integer):
def __init__(self, value=None):
super(self.__class__, self).__init__(value,
Tags.MAXIMUM_ITEMS)
# 9.1.3.3.2
class StorageStatusMask(Enumeration):
ENUM_TYPE = enums.StorageStatusMask
def __init__(self, value=None):
super(self.__class__, self).__init__(value,
Tags.STORAGE_STATUS_MASK)
def __init__(self, maximum_items=None, storage_status_mask=None,
object_group_member=None, attributes=None):
super(self.__class__, self).__init__(enums.Tags.REQUEST_PAYLOAD)
self.maximum_items = maximum_items
self.storage_status_mask = storage_status_mask
self.object_group_member = object_group_member
self.attributes = attributes or []
self.validate()
def read(self, istream):
super(self.__class__, self).read(istream)
tstream = BytearrayStream(istream.read(self.length))
if self.is_tag_next(Tags.MAXIMUM_ITEMS, tstream):
self.maximum_items = LocateRequestPayload.MaximumItems()
self.maximum_items.read()
if self.is_tag_next(Tags.STORAGE_STATUS_MASK, tstream):
self.storage_status_mask = LocateRequestPayload.StorageStatusMask()
self.storage_status_mask.read()
if self.is_tag_next(Tags.OBJECT_GROUP_MEMBER, tstream):
self.object_group_member = LocateRequestPayload.ObjectGroupMember()
self.object_group_member.read(tstream)
while self.is_tag_next(Tags.ATTRIBUTE, tstream):
attr = Attribute()
attr.read(tstream)
self.attributes.append(attr)
self.validate()
def write(self, ostream):
tstream = BytearrayStream()
if self.maximum_items is not None:
self.maximum_items.write(tstream)
if self.storage_status_mask is not None:
self.storage_status_mask.write(tstream)
if self.attributes is not None:
for a in self.attributes:
a.write(tstream)
# Write the length and value of the request payload
self.length = tstream.length()
super(self.__class__, self).write(ostream)
ostream.write(tstream.buffer)
def validate(self):
self._validate()
def _validate(self):
# TODO Finish implementation.
pass
class LocateResponsePayload(Struct):
def __init__(self, unique_identifiers=[]):
super(self.__class__, self).__init__(enums.Tags.RESPONSE_PAYLOAD)
self.unique_identifiers = unique_identifiers or []
self.validate()
def read(self, istream):
super(self.__class__, self).read(istream)
tstream = BytearrayStream(istream.read(self.length))
while self.is_tag_next(Tags.UNIQUE_IDENTIFIER, tstream):
ui = attributes.UniqueIdentifier()
ui.read(tstream)
self.unique_identifiers.append(ui)
self.is_oversized(tstream)
self.validate()
def write(self, ostream):
tstream = BytearrayStream()
for ui in self.unique_identifiers:
ui.write(tstream)
# Write the length and value of the request payload
self.length = tstream.length()
super(self.__class__, self).write(ostream)
ostream.write(tstream.buffer)
def validate(self):
self.__validate()
def __validate(self):
# TODO Finish implementation.
pass

View File

@ -0,0 +1,132 @@
# Copyright (c) 2014 The Johns Hopkins University/Applied Physics Laboratory
# All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.
from kmip.core.factories.secrets import SecretFactory
from kmip.core import attributes
from kmip.core.enums import Tags
from kmip.core.objects import TemplateAttribute
from kmip.core.primitives import Struct
from kmip.core.utils import BytearrayStream
# 4.3
class RegisterRequestPayload(Struct):
def __init__(self,
object_type=None,
template_attribute=None,
secret=None):
super(self.__class__, self).__init__(Tags.REQUEST_PAYLOAD)
self.secret_factory = SecretFactory()
self.object_type = object_type
self.template_attribute = template_attribute
self.secret = secret
self.validate()
def read(self, istream):
super(self.__class__, self).read(istream)
tstream = BytearrayStream(istream.read(self.length))
self.object_type = attributes.ObjectType()
self.template_attribute = TemplateAttribute()
self.object_type.read(tstream)
self.template_attribute.read(tstream)
secret_type = self.object_type.enum
secret = self.secret_factory.create_secret(secret_type)
if self.is_tag_next(secret.tag, tstream):
self.secret = secret
self.secret.read(tstream)
self.is_oversized(tstream)
self.validate()
def write(self, ostream):
tstream = BytearrayStream()
# Write the contents of the request payload
self.object_type.write(tstream)
self.template_attribute.write(tstream)
if self.secret is not None:
self.secret.write(tstream)
# Write the length and value of the request payload
self.length = tstream.length()
super(self.__class__, self).write(ostream)
ostream.write(tstream.buffer)
def validate(self):
self.__validate()
def __validate(self):
# TODO (peter-hamilton) Finish implementation.
pass
class RegisterResponsePayload(Struct):
def __init__(self,
unique_identifier=None,
template_attribute=None):
super(self.__class__, self).__init__(Tags.RESPONSE_PAYLOAD)
self.unique_identifier = unique_identifier
self.template_attribute = template_attribute
self.validate()
def read(self, istream):
super(self.__class__, self).read(istream)
tstream = BytearrayStream(istream.read(self.length))
self.unique_identifier = attributes.UniqueIdentifier()
self.unique_identifier.read(tstream)
if self.is_tag_next(Tags.TEMPLATE_ATTRIBUTE, tstream):
self.template_attribute = TemplateAttribute()
self.template_attribute.read(tstream)
self.is_oversized(tstream)
self.validate()
def write(self, ostream):
tstream = BytearrayStream()
# Write the contents of the request payload
self.unique_identifier.write(tstream)
if self.template_attribute is not None:
self.template_attribute.write(tstream)
# Write the length and value of the request payload
self.length = tstream.length()
super(self.__class__, self).write(ostream)
ostream.write(tstream.buffer)
def validate(self):
self.__validate()
def __validate(self):
# TODO (peter-hamilton) Finish implementation.
pass

View File

@ -35,7 +35,12 @@ from kmip.core.messages.contents import ProtocolVersion
from kmip.core.messages.contents import Operation from kmip.core.messages.contents import Operation
from kmip.core.messages import messages from kmip.core.messages import messages
from kmip.core.messages import operations
from kmip.core.messages.payloads import create
from kmip.core.messages.payloads import get
from kmip.core.messages.payloads import register
from kmip.core.messages.payloads import locate
from kmip.core.messages.payloads import destroy
from kmip.services.kmip_protocol import KMIPProtocol from kmip.services.kmip_protocol import KMIPProtocol
@ -126,7 +131,7 @@ class KMIPProxy(KMIP):
if object_type is None: if object_type is None:
raise ValueError('object_type cannot be None') raise ValueError('object_type cannot be None')
req_pl = operations.CreateRequestPayload( req_pl = create.CreateRequestPayload(
object_type=object_type, object_type=object_type,
template_attribute=template_attribute) template_attribute=template_attribute)
batch_item = messages.RequestBatchItem(operation=operation, batch_item = messages.RequestBatchItem(operation=operation,
@ -174,14 +179,14 @@ class KMIPProxy(KMIP):
if unique_identifier is not None: if unique_identifier is not None:
uuid = attr.UniqueIdentifier(unique_identifier) uuid = attr.UniqueIdentifier(unique_identifier)
if key_format_type is not None: if key_format_type is not None:
kft = operations.GetRequestPayload.KeyFormatType(key_format_type) kft = get.GetRequestPayload.KeyFormatType(key_format_type)
if key_compression_type is not None: if key_compression_type is not None:
kct = key_compression_type kct = key_compression_type
kct = operations.GetRequestPayload.KeyCompressionType(kct) kct = get.GetRequestPayload.KeyCompressionType(kct)
if key_wrapping_specification is not None: if key_wrapping_specification is not None:
kws = objects.KeyWrappingSpecification(key_wrapping_specification) kws = objects.KeyWrappingSpecification(key_wrapping_specification)
req_pl = operations.GetRequestPayload(unique_identifier=uuid, req_pl = get.GetRequestPayload(unique_identifier=uuid,
key_format_type=kft, key_format_type=kft,
key_compression_type=kct, key_compression_type=kct,
key_wrapping_specification=kws) key_wrapping_specification=kws)
@ -223,7 +228,7 @@ class KMIPProxy(KMIP):
if unique_identifier is not None: if unique_identifier is not None:
uuid = attr.UniqueIdentifier(unique_identifier) uuid = attr.UniqueIdentifier(unique_identifier)
payload = operations.DestroyRequestPayload(unique_identifier=uuid) payload = destroy.DestroyRequestPayload(unique_identifier=uuid)
batch_item = messages.RequestBatchItem(operation=operation, batch_item = messages.RequestBatchItem(operation=operation,
request_payload=payload) request_payload=payload)
@ -257,7 +262,7 @@ class KMIPProxy(KMIP):
if object_type is None: if object_type is None:
raise ValueError('object_type cannot be None') raise ValueError('object_type cannot be None')
req_pl = operations.RegisterRequestPayload( req_pl = register.RegisterRequestPayload(
object_type=object_type, object_type=object_type,
template_attribute=template_attribute, template_attribute=template_attribute,
secret=secret) secret=secret)
@ -297,15 +302,15 @@ class KMIPProxy(KMIP):
objgrp = None objgrp = None
if maximum_items is not None: if maximum_items is not None:
mxi = operations.LocateRequestPayload.MaximumItems(maximum_items) mxi = locate.LocateRequestPayload.MaximumItems(maximum_items)
if storage_status_mask is not None: if storage_status_mask is not None:
m = storage_status_mask m = storage_status_mask
ssmask = operations.LocateRequestPayload.StorageStatusMask(m) ssmask = locate.LocateRequestPayload.StorageStatusMask(m)
if object_group_member is not None: if object_group_member is not None:
o = object_group_member o = object_group_member
objgrp = operations.LocateRequestPayload.ObjectGroupMember(o) objgrp = locate.LocateRequestPayload.ObjectGroupMember(o)
payload = operations.LocateRequestPayload(maximum_items=mxi, payload = locate.LocateRequestPayload(maximum_items=mxi,
storage_status_mask=ssmask, storage_status_mask=ssmask,
object_group_member=objgrp, object_group_member=objgrp,
attributes=attributes) attributes=attributes)

View File

@ -27,11 +27,11 @@ from kmip.core.messages.contents import TimeStamp
from kmip.core.primitives import Base from kmip.core.primitives import Base
from kmip.core.messages.operations import CreateResponsePayload from kmip.core.messages.payloads.create import CreateResponsePayload
from kmip.core.messages.operations import GetResponsePayload from kmip.core.messages.payloads.get import GetResponsePayload
from kmip.core.messages.operations import DestroyResponsePayload from kmip.core.messages.payloads.destroy import DestroyResponsePayload
from kmip.core.messages.operations import RegisterResponsePayload from kmip.core.messages.payloads.register import RegisterResponsePayload
from kmip.core.messages.operations import LocateResponsePayload from kmip.core.messages.payloads.locate import LocateResponsePayload
from kmip.core.enums import Operation from kmip.core.enums import Operation
from kmip.core.enums import ResultStatus as RS from kmip.core.enums import ResultStatus as RS

View File

@ -0,0 +1,14 @@
# Copyright (c) 2014 The Johns Hopkins University/Applied Physics Laboratory
# All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.

View File

@ -0,0 +1,14 @@
# Copyright (c) 2014 The Johns Hopkins University/Applied Physics Laboratory
# All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.

View File

@ -0,0 +1,14 @@
# Copyright (c) 2014 The Johns Hopkins University/Applied Physics Laboratory
# All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.

View File

@ -0,0 +1,14 @@
# Copyright (c) 2014 The Johns Hopkins University/Applied Physics Laboratory
# All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.

View File

@ -0,0 +1,14 @@
# Copyright (c) 2014 The Johns Hopkins University/Applied Physics Laboratory
# All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.

View File

@ -0,0 +1,14 @@
# Copyright (c) 2014 The Johns Hopkins University/Applied Physics Laboratory
# All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License"); you may
# not use this file except in compliance with the License. You may obtain
# a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
# License for the specific language governing permissions and limitations
# under the License.

View File

@ -41,13 +41,12 @@ from kmip.core.keys import RawKey
from kmip.core.messages import contents from kmip.core.messages import contents
from kmip.core.messages import messages from kmip.core.messages import messages
from kmip.core.messages import operations
from kmip.core.messages.operations import DestroyRequestPayload from kmip.core.messages.payloads import create
from kmip.core.messages.operations import RegisterRequestPayload from kmip.core.messages.payloads import get
from kmip.core.messages.operations import DestroyResponsePayload from kmip.core.messages.payloads import register
from kmip.core.messages.operations import RegisterResponsePayload from kmip.core.messages.payloads import locate
from kmip.core.messages.operations import LocateResponsePayload from kmip.core.messages.payloads import destroy
from kmip.core.primitives import TextString from kmip.core.primitives import TextString
@ -233,8 +232,8 @@ class TestRequestMessage(TestCase):
request_payload = batch_item.request_payload request_payload = batch_item.request_payload
msg = "Bad request payload type: expected {0}, received {1}" msg = "Bad request payload type: expected {0}, received {1}"
self.assertIsInstance(request_payload, self.assertIsInstance(request_payload,
operations.CreateRequestPayload, create.CreateRequestPayload,
msg.format(operations.CreateRequestPayload, msg.format(create.CreateRequestPayload,
type(request_payload))) type(request_payload)))
object_type = request_payload.object_type object_type = request_payload.object_type
@ -370,7 +369,7 @@ class TestRequestMessage(TestCase):
temp_attr = objects.TemplateAttribute(attributes=[attr_a, attr_b, temp_attr = objects.TemplateAttribute(attributes=[attr_a, attr_b,
attr_c]) attr_c])
req_pl = operations.CreateRequestPayload(object_type=object_type, req_pl = create.CreateRequestPayload(object_type=object_type,
template_attribute=temp_attr) template_attribute=temp_attr)
batch_item = messages.RequestBatchItem(operation=operation, batch_item = messages.RequestBatchItem(operation=operation,
request_payload=req_pl) request_payload=req_pl)
@ -462,8 +461,8 @@ class TestRequestMessage(TestCase):
request_payload = batch_item.request_payload request_payload = batch_item.request_payload
msg = "Bad request payload type: expected {0}, received {1}" msg = "Bad request payload type: expected {0}, received {1}"
self.assertIsInstance(request_payload, self.assertIsInstance(request_payload,
operations.GetRequestPayload, get.GetRequestPayload,
msg.format(operations.GetRequestPayload, msg.format(get.GetRequestPayload,
type(request_payload))) type(request_payload)))
unique_identifier = request_payload.unique_identifier unique_identifier = request_payload.unique_identifier
@ -487,7 +486,7 @@ class TestRequestMessage(TestCase):
operation = contents.Operation(enums.Operation.GET) operation = contents.Operation(enums.Operation.GET)
uuid = attr.UniqueIdentifier('49a1ca88-6bea-4fb2-b450-7e58802c3038') uuid = attr.UniqueIdentifier('49a1ca88-6bea-4fb2-b450-7e58802c3038')
request_payload = operations.GetRequestPayload(unique_identifier=uuid) request_payload = get.GetRequestPayload(unique_identifier=uuid)
batch_item = messages.RequestBatchItem(operation=operation, batch_item = messages.RequestBatchItem(operation=operation,
request_payload=request_payload) request_payload=request_payload)
request_message = messages.RequestMessage(request_header=req_header, request_message = messages.RequestMessage(request_header=req_header,
@ -578,7 +577,7 @@ class TestRequestMessage(TestCase):
request_payload = batch_item.request_payload request_payload = batch_item.request_payload
msg = "Bad request payload type: expected {0}, received {1}" msg = "Bad request payload type: expected {0}, received {1}"
exp_type = operations.DestroyRequestPayload exp_type = destroy.DestroyRequestPayload
rcv_type = type(request_payload) rcv_type = type(request_payload)
self.assertIsInstance(request_payload, exp_type, self.assertIsInstance(request_payload, exp_type,
msg.format(exp_type, rcv_type)) msg.format(exp_type, rcv_type))
@ -604,7 +603,7 @@ class TestRequestMessage(TestCase):
operation = contents.Operation(enums.Operation.DESTROY) operation = contents.Operation(enums.Operation.DESTROY)
uuid = attr.UniqueIdentifier('fb4b5b9c-6188-4c63-8142-fe9c328129fc') uuid = attr.UniqueIdentifier('fb4b5b9c-6188-4c63-8142-fe9c328129fc')
request_payload = DestroyRequestPayload(unique_identifier=uuid) request_payload = destroy.DestroyRequestPayload(unique_identifier=uuid)
batch_item = messages.RequestBatchItem(operation=operation, batch_item = messages.RequestBatchItem(operation=operation,
request_payload=request_payload) request_payload=request_payload)
request_message = messages.RequestMessage(request_header=req_header, request_message = messages.RequestMessage(request_header=req_header,
@ -695,7 +694,7 @@ class TestRequestMessage(TestCase):
request_payload = batch_item.request_payload request_payload = batch_item.request_payload
msg = "Bad request payload type: expected {0}, received {1}" msg = "Bad request payload type: expected {0}, received {1}"
exp_type = operations.RegisterRequestPayload exp_type = register.RegisterRequestPayload
rcv_type = type(request_payload) rcv_type = type(request_payload)
self.assertIsInstance(request_payload, exp_type, self.assertIsInstance(request_payload, exp_type,
msg.format(exp_type, rcv_type)) msg.format(exp_type, rcv_type))
@ -801,7 +800,8 @@ class TestRequestMessage(TestCase):
template = Template(attributes=attributes) template = Template(attributes=attributes)
request_payload = RegisterRequestPayload(object_type=object_type, request_payload = register.RegisterRequestPayload(
object_type=object_type,
template_attribute=tmpl_attr, template_attribute=tmpl_attr,
secret=template) secret=template)
batch_item = messages.RequestBatchItem(operation=operation, batch_item = messages.RequestBatchItem(operation=operation,
@ -893,7 +893,7 @@ class TestRequestMessage(TestCase):
request_payload = batch_item.request_payload request_payload = batch_item.request_payload
msg = "Bad request payload type: expected {0}, received {1}" msg = "Bad request payload type: expected {0}, received {1}"
exp_type = operations.LocateRequestPayload exp_type = locate.LocateRequestPayload
rcv_type = type(request_payload) rcv_type = type(request_payload)
self.assertIsInstance(request_payload, exp_type, self.assertIsInstance(request_payload, exp_type,
msg.format(exp_type, rcv_type)) msg.format(exp_type, rcv_type))
@ -1140,7 +1140,7 @@ class TestResponseMessage(TestCase):
result_status.enum)) result_status.enum))
response_payload = batch_item.response_payload response_payload = batch_item.response_payload
exp_type = operations.CreateResponsePayload exp_type = create.CreateResponsePayload
rcv_type = type(response_payload) rcv_type = type(response_payload)
self.assertIsInstance(response_payload, exp_type, self.assertIsInstance(response_payload, exp_type,
self.msg.format('response payload', 'type', self.msg.format('response payload', 'type',
@ -1182,7 +1182,7 @@ class TestResponseMessage(TestCase):
uuid = 'fb4b5b9c-6188-4c63-8142-fe9c328129fc' uuid = 'fb4b5b9c-6188-4c63-8142-fe9c328129fc'
uniq_id = attr.UniqueIdentifier(uuid) uniq_id = attr.UniqueIdentifier(uuid)
resp_pl = operations.CreateResponsePayload(object_type=object_type, resp_pl = create.CreateResponsePayload(object_type=object_type,
unique_identifier=uniq_id) unique_identifier=uniq_id)
batch_item = messages.ResponseBatchItem(operation=operation, batch_item = messages.ResponseBatchItem(operation=operation,
result_status=result_status, result_status=result_status,
@ -1289,7 +1289,7 @@ class TestResponseMessage(TestCase):
result_status.enum)) result_status.enum))
response_payload = batch_item.response_payload response_payload = batch_item.response_payload
exp_type = operations.GetResponsePayload exp_type = get.GetResponsePayload
rcv_type = type(response_payload) rcv_type = type(response_payload)
self.assertIsInstance(response_payload, exp_type, self.assertIsInstance(response_payload, exp_type,
self.msg.format('response payload', 'type', self.msg.format('response payload', 'type',
@ -1405,7 +1405,7 @@ class TestResponseMessage(TestCase):
'cryptographic_length': cryptographic_length} 'cryptographic_length': cryptographic_length}
secret = self.secret_factory.create_secret(ObjectType.SYMMETRIC_KEY, secret = self.secret_factory.create_secret(ObjectType.SYMMETRIC_KEY,
value) value)
resp_pl = operations.GetResponsePayload(object_type=object_type, resp_pl = get.GetResponsePayload(object_type=object_type,
unique_identifier=uniq_id, unique_identifier=uniq_id,
secret=secret) secret=secret)
batch_item = messages.ResponseBatchItem(operation=operation, batch_item = messages.ResponseBatchItem(operation=operation,
@ -1521,7 +1521,7 @@ class TestResponseMessage(TestCase):
response_payload = batch_item.response_payload response_payload = batch_item.response_payload
msg = "Bad response payload type: expected {0}, received {1}" msg = "Bad response payload type: expected {0}, received {1}"
exp_type = operations.DestroyResponsePayload exp_type = destroy.DestroyResponsePayload
rcv_type = type(response_payload) rcv_type = type(response_payload)
self.assertIsInstance(response_payload, exp_type, self.assertIsInstance(response_payload, exp_type,
msg.format(exp_type, rcv_type)) msg.format(exp_type, rcv_type))
@ -1552,7 +1552,7 @@ class TestResponseMessage(TestCase):
result_status = contents.ResultStatus(enums.ResultStatus.SUCCESS) result_status = contents.ResultStatus(enums.ResultStatus.SUCCESS)
uuid = attr.UniqueIdentifier('fb4b5b9c-6188-4c63-8142-fe9c328129fc') uuid = attr.UniqueIdentifier('fb4b5b9c-6188-4c63-8142-fe9c328129fc')
resp_pl = DestroyResponsePayload(unique_identifier=uuid) resp_pl = destroy.DestroyResponsePayload(unique_identifier=uuid)
batch_item = messages.ResponseBatchItem(operation=operation, batch_item = messages.ResponseBatchItem(operation=operation,
result_status=result_status, result_status=result_status,
response_payload=resp_pl) response_payload=resp_pl)
@ -1664,7 +1664,7 @@ class TestResponseMessage(TestCase):
response_payload = batch_item.response_payload response_payload = batch_item.response_payload
msg = "Bad response payload type: expected {0}, received {1}" msg = "Bad response payload type: expected {0}, received {1}"
exp_type = operations.RegisterResponsePayload exp_type = register.RegisterResponsePayload
rcv_type = type(response_payload) rcv_type = type(response_payload)
self.assertIsInstance(response_payload, exp_type, self.assertIsInstance(response_payload, exp_type,
msg.format(exp_type, rcv_type)) msg.format(exp_type, rcv_type))
@ -1695,7 +1695,7 @@ class TestResponseMessage(TestCase):
result_status = contents.ResultStatus(enums.ResultStatus.SUCCESS) result_status = contents.ResultStatus(enums.ResultStatus.SUCCESS)
uuid = attr.UniqueIdentifier('5c9b81ef-4ee5-42cd-ba2d-c002fdd0c7b3') uuid = attr.UniqueIdentifier('5c9b81ef-4ee5-42cd-ba2d-c002fdd0c7b3')
resp_pl = RegisterResponsePayload(unique_identifier=uuid) resp_pl = register.RegisterResponsePayload(unique_identifier=uuid)
batch_item = messages.ResponseBatchItem(operation=operation, batch_item = messages.ResponseBatchItem(operation=operation,
result_status=result_status, result_status=result_status,
response_payload=resp_pl) response_payload=resp_pl)
@ -1728,7 +1728,7 @@ class TestResponseMessage(TestCase):
result_status = contents.ResultStatus(enums.ResultStatus.SUCCESS) result_status = contents.ResultStatus(enums.ResultStatus.SUCCESS)
uuid = attr.UniqueIdentifier('49a1ca88-6bea-4fb2-b450-7e58802c3038') uuid = attr.UniqueIdentifier('49a1ca88-6bea-4fb2-b450-7e58802c3038')
resp_pl = LocateResponsePayload(unique_identifiers=[uuid]) resp_pl = locate.LocateResponsePayload(unique_identifiers=[uuid])
batch_item = messages.ResponseBatchItem(operation=operation, batch_item = messages.ResponseBatchItem(operation=operation,
result_status=result_status, result_status=result_status,