mirror of
https://github.com/openkmip/pykmip
synced 2026-01-04 09:33:37 +00:00
Update object hierarchy read/write to support the KMIP version
This change updates the PyKMIP object hierarchy's read/write method signatures to support propagation of the KMIP version. The introduction of KMIP 2.0 introduces future KMIP message encodings that break backwards compatibility; to support this, PyKMIP must know what KMIP version is being used when encoding or decoding an object; the KMIP version residing in the client or server alone is now insufficient. Prior versions of KMIP, namely 1.0 - 1.4, have been backwards compatible, obviating the need for the KMIP version at encode/decode time. Going forward, this is no longer true. The PyKMIP client and server have been updated to include the KMIP version when making calls to read/write, as have the associated test cases covering this functionality.
This commit is contained in:
committed by
Peter Hamilton
parent
c012a430aa
commit
dcade2a264
@@ -62,7 +62,7 @@ class ArchiveRequestPayload(primitives.Struct):
|
||||
else:
|
||||
raise TypeError("Unique identifier must be a string.")
|
||||
|
||||
def read(self, input_stream):
|
||||
def read(self, input_stream, kmip_version=enums.KMIPVersion.KMIP_1_0):
|
||||
"""
|
||||
Read the data encoding the Archive request payload and decode it into
|
||||
its constituent parts.
|
||||
@@ -71,23 +71,32 @@ class ArchiveRequestPayload(primitives.Struct):
|
||||
input_stream (stream): A data stream containing encoded object
|
||||
data, supporting a read method; usually a BytearrayStream
|
||||
object.
|
||||
kmip_version (KMIPVersion): An enumeration defining the KMIP
|
||||
version with which the object will be decoded. Optional,
|
||||
defaults to KMIP 1.0.
|
||||
|
||||
Raises:
|
||||
ValueError: Raised if the data attribute is missing from the
|
||||
encoded payload.
|
||||
"""
|
||||
super(ArchiveRequestPayload, self).read(input_stream)
|
||||
super(ArchiveRequestPayload, self).read(
|
||||
input_stream,
|
||||
kmip_version=kmip_version
|
||||
)
|
||||
local_stream = utils.BytearrayStream(input_stream.read(self.length))
|
||||
|
||||
if self.is_tag_next(enums.Tags.UNIQUE_IDENTIFIER, local_stream):
|
||||
self._unique_identifier = primitives.TextString(
|
||||
tag=enums.Tags.UNIQUE_IDENTIFIER
|
||||
)
|
||||
self._unique_identifier.read(local_stream)
|
||||
self._unique_identifier.read(
|
||||
local_stream,
|
||||
kmip_version=kmip_version
|
||||
)
|
||||
|
||||
self.is_oversized(local_stream)
|
||||
|
||||
def write(self, output_stream):
|
||||
def write(self, output_stream, kmip_version=enums.KMIPVersion.KMIP_1_0):
|
||||
"""
|
||||
Write the data encoding the Archive request payload to a stream.
|
||||
|
||||
@@ -95,6 +104,9 @@ class ArchiveRequestPayload(primitives.Struct):
|
||||
output_stream (stream): A data stream in which to encode object
|
||||
data, supporting a write method; usually a BytearrayStream
|
||||
object.
|
||||
kmip_version (KMIPVersion): An enumeration defining the KMIP
|
||||
version with which the object will be encoded. Optional,
|
||||
defaults to KMIP 1.0.
|
||||
|
||||
Raises:
|
||||
ValueError: Raised if the data attribute is not defined.
|
||||
@@ -102,10 +114,16 @@ class ArchiveRequestPayload(primitives.Struct):
|
||||
local_stream = utils.BytearrayStream()
|
||||
|
||||
if self._unique_identifier:
|
||||
self._unique_identifier.write(local_stream)
|
||||
self._unique_identifier.write(
|
||||
local_stream,
|
||||
kmip_version=kmip_version
|
||||
)
|
||||
|
||||
self.length = local_stream.length()
|
||||
super(ArchiveRequestPayload, self).write(output_stream)
|
||||
super(ArchiveRequestPayload, self).write(
|
||||
output_stream,
|
||||
kmip_version=kmip_version
|
||||
)
|
||||
output_stream.write(local_stream.buffer)
|
||||
|
||||
def __eq__(self, other):
|
||||
@@ -175,7 +193,7 @@ class ArchiveResponsePayload(primitives.Struct):
|
||||
else:
|
||||
raise TypeError("Unique identifier must be a string.")
|
||||
|
||||
def read(self, input_stream):
|
||||
def read(self, input_stream, kmip_version=enums.KMIPVersion.KMIP_1_0):
|
||||
"""
|
||||
Read the data encoding the Archive response payload and decode it
|
||||
into its constituent parts.
|
||||
@@ -184,23 +202,32 @@ class ArchiveResponsePayload(primitives.Struct):
|
||||
input_stream (stream): A data stream containing encoded object
|
||||
data, supporting a read method; usually a BytearrayStream
|
||||
object.
|
||||
kmip_version (KMIPVersion): An enumeration defining the KMIP
|
||||
version with which the object will be decoded. Optional,
|
||||
defaults to KMIP 1.0.
|
||||
|
||||
Raises:
|
||||
ValueError: Raised if the data attribute is missing from the
|
||||
encoded payload.
|
||||
"""
|
||||
super(ArchiveResponsePayload, self).read(input_stream)
|
||||
super(ArchiveResponsePayload, self).read(
|
||||
input_stream,
|
||||
kmip_version=kmip_version
|
||||
)
|
||||
local_stream = utils.BytearrayStream(input_stream.read(self.length))
|
||||
|
||||
if self.is_tag_next(enums.Tags.UNIQUE_IDENTIFIER, local_stream):
|
||||
self._unique_identifier = primitives.TextString(
|
||||
tag=enums.Tags.UNIQUE_IDENTIFIER
|
||||
)
|
||||
self._unique_identifier.read(local_stream)
|
||||
self._unique_identifier.read(
|
||||
local_stream,
|
||||
kmip_version=kmip_version
|
||||
)
|
||||
|
||||
self.is_oversized(local_stream)
|
||||
|
||||
def write(self, output_stream):
|
||||
def write(self, output_stream, kmip_version=enums.KMIPVersion.KMIP_1_0):
|
||||
"""
|
||||
Write the data encoding the Archive response payload to a stream.
|
||||
|
||||
@@ -208,6 +235,9 @@ class ArchiveResponsePayload(primitives.Struct):
|
||||
output_stream (stream): A data stream in which to encode object
|
||||
data, supporting a write method; usually a BytearrayStream
|
||||
object.
|
||||
kmip_version (KMIPVersion): An enumeration defining the KMIP
|
||||
version with which the object will be decoded. Optional,
|
||||
defaults to KMIP 1.0.
|
||||
|
||||
Raises:
|
||||
ValueError: Raised if the data attribute is not defined.
|
||||
@@ -215,10 +245,16 @@ class ArchiveResponsePayload(primitives.Struct):
|
||||
local_stream = utils.BytearrayStream()
|
||||
|
||||
if self._unique_identifier:
|
||||
self._unique_identifier.write(local_stream)
|
||||
self._unique_identifier.write(
|
||||
local_stream,
|
||||
kmip_version=kmip_version
|
||||
)
|
||||
|
||||
self.length = local_stream.length()
|
||||
super(ArchiveResponsePayload, self).write(output_stream)
|
||||
super(ArchiveResponsePayload, self).write(
|
||||
output_stream,
|
||||
kmip_version=kmip_version
|
||||
)
|
||||
output_stream.write(local_stream.buffer)
|
||||
|
||||
def __eq__(self, other):
|
||||
|
||||
Reference in New Issue
Block a user