mirror of
https://github.com/openkmip/pykmip
synced 2025-12-18 17:23:52 +00:00
Add SetAttribute support to the client
This change adds SetAttribute support to the ProxyKmipClient, leveraging the new generic request capability in the underlying KMIPProxy client. New unit tests have been added to cover the new client additions. Partially implements #547
This commit is contained in:
committed by
Peter Hamilton
parent
3be219144a
commit
2d283e128c
@@ -102,6 +102,7 @@ class ProxyKmipClient(object):
|
||||
self.logger = logging.getLogger(__name__)
|
||||
|
||||
self.attribute_factory = attributes.AttributeFactory()
|
||||
self.attribute_value_factory = self.attribute_factory.value_factory
|
||||
self.object_factory = factory.ObjectFactory()
|
||||
|
||||
# TODO (peter-hamilton) Consider adding validation checks for inputs.
|
||||
@@ -431,6 +432,46 @@ class ProxyKmipClient(object):
|
||||
|
||||
return response_payload.unique_identifier, response_payload.attribute
|
||||
|
||||
@is_connected
|
||||
def set_attribute(self, unique_identifier=None, **kwargs):
|
||||
"""
|
||||
Set an attribute on a KMIP managed object.
|
||||
|
||||
Args:
|
||||
unique_identifier (string): The ID of the managed object.
|
||||
**kwargs (various): A placeholder for attribute-related fields.
|
||||
Supported parameters include:
|
||||
attribute_name (string): The name of the attribute being
|
||||
set. Required.
|
||||
attribute_value (various): The value of the attribute
|
||||
being set. Required.
|
||||
|
||||
Here is an example. To set an object's 'sensitive' attribute
|
||||
to True, specify:
|
||||
attribute_name='Sensitive'
|
||||
attribute_value=True
|
||||
|
||||
For a list of all supported attributes, see the
|
||||
AttributeValueFactory.
|
||||
|
||||
Returns:
|
||||
string: The ID of the managed object the attribute was set on.
|
||||
"""
|
||||
a = self.attribute_value_factory.create_attribute_value_by_enum(
|
||||
enums.convert_attribute_name_to_tag(kwargs.get("attribute_name")),
|
||||
kwargs.get("attribute_value")
|
||||
)
|
||||
request_payload = payloads.SetAttributeRequestPayload(
|
||||
unique_identifier=unique_identifier,
|
||||
new_attribute=cobjects.NewAttribute(attribute=a)
|
||||
)
|
||||
response_payload = self.proxy.send_request_payload(
|
||||
enums.Operation.SET_ATTRIBUTE,
|
||||
request_payload
|
||||
)
|
||||
|
||||
return response_payload.unique_identifier
|
||||
|
||||
@is_connected
|
||||
def register(self, managed_object):
|
||||
"""
|
||||
|
||||
Reference in New Issue
Block a user