kmip/services/server/engine.py
def _set_attribute_on_managed_object(self, managed_object, attribute):
        """
        Set the attribute value on the kmip.pie managed object.
        """
        attribute_name = attribute[0]
        attribute_value = attribute[1]

        if self._attribute_policy.is_attribute_multivalued(attribute_name):
            if attribute_name == 'Name':
                managed_object.names.extend(
                    [x.name_value.value for x in attribute_value]
                )
                for name in managed_object.names:
                    if managed_object.names.count(name) > 1:
                        raise exceptions.InvalidField(
                            "Cannot set duplicate name values."
                        )
            else:
                # TODO (peterhamilton) Remove when all attributes are supported
                raise exceptions.InvalidField(
                    "The {0} attribute is unsupported.".format(attribute_name)
                )
        else:
            field = None
            value = attribute_value.value

            if attribute_name == 'Cryptographic Algorithm':
                field = 'cryptographic_algorithm'
            elif attribute_name == 'Cryptographic Length':
                field = 'cryptographic_length'
            elif attribute_name == 'Cryptographic Usage Mask':
                field = 'cryptographic_usage_masks'
                value = list()
                for e in enums.CryptographicUsageMask:
                    if e.value & attribute_value.value:
                        value.append(e)
            elif attribute_name == 'Operation Policy Name':
                field = 'operation_policy_name'

            if field:
                existing_value = getattr(managed_object, field)
                if existing_value:
                    if existing_value != value:
                        raise exceptions.InvalidField(
                            "Cannot overwrite the {0} attribute.".format(
                                attribute_name
                            )
                        )
                else:
                    setattr(managed_object, field, value)
            else:
                # TODO (peterhamilton) Remove when all attributes are supported
                raise exceptions.InvalidField(
                    "The {0} attribute is unsupported.".format(attribute_name)
                )
def _set_attribute_on_managed_object(self, managed_object, attribute):
        attribute_name = attribute[0]
        attribute_value = attribute[1]

        if self._attribute_policy.is_attribute_multivalued(attribute_name):
            if attribute_name == 'Name':
                managed_object.names.extend(
                    [x.name_value.value for x in attribute_value]
                )
                for name in managed_object.names:
                    if managed_object.names.count(name) > 1:
                        raise exceptions.InvalidField(
                            "Cannot set duplicate name values."
                        )
            else:
                # TODO (peterhamilton) Remove when all attributes are supported
                raise exceptions.InvalidField(
                    "The {0} attribute is unsupported.".format(attribute_name)
                )
        else:
            field = None
            value = attribute_value.value

            if attribute_name == 'Cryptographic Algorithm':
                field = 'cryptographic_algorithm'
            elif attribute_name == 'Cryptographic Length':
                field = 'cryptographic_length'
            elif attribute_name == 'Cryptographic Usage Mask':
                field = 'cryptographic_usage_masks'
                value = list()
                for e in enums.CryptographicUsageMask:
                    if e.value & attribute_value.value:
                        value.append(e)
            elif attribute_name == 'Operation Policy Name':
                field = 'operation_policy_name'

            if field:
                existing_value = getattr(managed_object, field)
                if existing_value:
                    if existing_value != value:
                        raise exceptions.InvalidField(
                            "Cannot overwrite the {0} attribute.".format(
                                attribute_name
                            )
                        )
                else:
                    setattr(managed_object, field, value)
            else:
                # TODO (peterhamilton) Remove when all attributes are supported
                raise exceptions.InvalidField(
                    "The {0} attribute is unsupported.".format(attribute_name)
                )
def _set_attribute_on_managed_object ( self , managed_object , attribute ) : attribute_name = attribute [ 0 ] attribute_value = attribute [ 1 ] if self . _attribute_policy . is_attribute_multivalued ( attribute_name ) : if attribute_name == 'Name' : managed_object . names . extend ( [ x . name_value . value for x in attribute_value ] ) for name in managed_object . names : if managed_object . names . count ( name ) > 1 : raise exceptions . InvalidField ( "Cannot set duplicate name values." ) else : # TODO (peterhamilton) Remove when all attributes are supported raise exceptions . InvalidField ( "The {0} attribute is unsupported." . format ( attribute_name ) ) else : field = None value = attribute_value . value if attribute_name == 'Cryptographic Algorithm' : field = 'cryptographic_algorithm' elif attribute_name == 'Cryptographic Length' : field = 'cryptographic_length' elif attribute_name == 'Cryptographic Usage Mask' : field = 'cryptographic_usage_masks' value = list ( ) for e in enums . CryptographicUsageMask : if e . value & attribute_value . value : value . append ( e ) elif attribute_name == 'Operation Policy Name' : field = 'operation_policy_name' if field : existing_value = getattr ( managed_object , field ) if existing_value : if existing_value != value : raise exceptions . InvalidField ( "Cannot overwrite the {0} attribute." . format ( attribute_name ) ) else : setattr ( managed_object , field , value ) else : # TODO (peterhamilton) Remove when all attributes are supported raise exceptions . InvalidField ( "The {0} attribute is unsupported." . format ( attribute_name ) )
Set the attribute value on the kmip.pie managed object.
Set the attribute value on the kmip . pie managed object .