From aa300b256cd4dfe7e717a5d8e424c986ab48ef12 Mon Sep 17 00:00:00 2001 From: Wyllys Date: Thu, 11 Sep 2014 18:04:22 -0400 Subject: [PATCH] Stub out server side locate operation. --- kmip/core/attributes.py | 19 +++++++++++++++++-- kmip/core/repo/mem_repo.py | 5 +---- kmip/core/server.py | 13 ++++++++++--- 3 files changed, 28 insertions(+), 9 deletions(-) diff --git a/kmip/core/attributes.py b/kmip/core/attributes.py index 41c067c..f73d4ff 100644 --- a/kmip/core/attributes.py +++ b/kmip/core/attributes.py @@ -85,8 +85,21 @@ class Name(Struct): self.__validate() def __validate(self): - # TODO (peter-hamilton) Finish implementation. - pass + name = self.__class__.__name__ + if self.name_value and \ + not isinstance(self.name_value, Name.NameValue) and \ + not isinstance(self.name_value, str): + member = 'name_value' + raise TypeError(msg.format('{}.{}'.format(name, member), + 'name_value', type(Name.NameValue), + type(name_type))) + if self.name_type and \ + not isinstance(self.name_type, Name.NameType) and \ + not isinstance(self.name_type, str): + member = 'name_type' + raise TypeError(msg.format('{}.{}'.format(name, member), + 'name_type', type(Name.NameType), + type(self.name_type))) @classmethod def create(cls, name_value, name_type): @@ -94,11 +107,13 @@ class Name(Struct): value = name_value elif isinstance(name_value, str): value = cls.NameValue(name_value) + # else: the __validate function will throw TypeError if isinstance(name_type, Name.NameType): n_type = name_type elif isinstance(name_type, Enum): n_type = cls.NameType(name_type) + # else: the __validate function will throw TypeError return Name(name_value=value, name_type=n_type) diff --git a/kmip/core/repo/mem_repo.py b/kmip/core/repo/mem_repo.py index 6d29e6a..1db2979 100644 --- a/kmip/core/repo/mem_repo.py +++ b/kmip/core/repo/mem_repo.py @@ -48,7 +48,4 @@ class MemRepo(ManagedObjectRepo): def locate(self, maximum_items, storage_status_mask, object_group_member, attributes): - # TODO - search objects, find one with matching attrs - if "1" in self.repo: - return [self.repo["1"]] - return None + raise NotImplementedError diff --git a/kmip/core/server.py b/kmip/core/server.py index 6e9478f..e297868 100644 --- a/kmip/core/server.py +++ b/kmip/core/server.py @@ -260,9 +260,16 @@ class KMIPImpl(KMIP): self.logger.debug('locate() called') msg = 'locating object(s) from repo' self.logger.debug(msg) - uuids = self.repo.locate(maximum_items, storage_status_mask, - object_group_member, attributes) - return LocateResult(ResultStatus(RS.SUCCESS), uuids=uuids) + try: + uuids = self.repo.locate(maximum_items, storage_status_mask, + object_group_member, attributes) + return LocateResult(ResultStatus(RS.SUCCESS), uuids=uuids) + except NotImplementedError: + msg = ResultMessage('Locate Operation Not Supported')) + reason = ResultReason(ResultReasonEnum.OPERATION_NOT_SUPPORTED) + return LocateResult(ResultStatus(RS.OPERATION_FAILED), + result_reason=reason, + result_message=msg) def _validate_req_field(self, attrs, name, expected, msg, required=True): self.logger.debug('Validating attribute %s' % name)