예제 #1
0
파일: engine.py 프로젝트: jseadragon/PyKMIP
    def _process_register(self, payload):
        self._logger.info("Processing operation: Register")

        object_type = payload.object_type.value
        template_attribute = payload.template_attribute

        if self._object_map.get(object_type) is None:
            name = object_type.name
            raise exceptions.InvalidField(
                "The {0} object type is not supported.".format(''.join(
                    [x.capitalize() for x in name.split('_')])))

        if payload.secret:
            secret = payload.secret
        else:
            # TODO (peterhamilton) It is possible to register 'empty' secrets
            # like Private Keys. For now, that feature is not supported.
            raise exceptions.InvalidField(
                "Cannot register a secret in absentia.")

        object_attributes = {}
        if template_attribute:
            object_attributes = self._process_template_attribute(
                template_attribute)

        managed_object_factory = factory.ObjectFactory()
        managed_object = managed_object_factory.convert(secret)
        managed_object.names = []

        self._set_attributes_on_managed_object(managed_object,
                                               object_attributes)

        # TODO (peterhamilton) Set additional server-only attributes.
        managed_object._owner = self._client_identity

        self._data_session.add(managed_object)

        # NOTE (peterhamilton) SQLAlchemy will *not* assign an ID until
        # commit is called. This makes future support for UNDO problematic.
        self._data_session.commit()

        self._logger.info("Registered a {0} with ID: {1}".format(
            ''.join([x.capitalize() for x in object_type.name.split('_')]),
            managed_object.unique_identifier))

        response_payload = register.RegisterResponsePayload(
            unique_identifier=attributes.UniqueIdentifier(
                str(managed_object.unique_identifier)))

        self._id_placeholder = str(managed_object.unique_identifier)

        return response_payload
예제 #2
0
 def _create_register_payload(self):
     return register.RegisterResponsePayload()