瀏覽代碼

Automatically insert the ven_id and request_id into outgoing messages from the VTN.

Stan Janssen 4 年之前
父節點
當前提交
b5bdf064ca
共有 1 個文件被更改,包括 7 次插入0 次删除
  1. 7 0
      openleadr/service/vtn_service.py

+ 7 - 0
openleadr/service/vtn_service.py

@@ -23,6 +23,7 @@ from jinja2 import Environment, PackageLoader, select_autoescape
 
 from .. import errors
 from ..messaging import create_message, parse_message
+from ..utils import generate_id
 
 class VTNService:
 
@@ -49,11 +50,15 @@ class VTNService:
                 response_type, response_payload = result
             else:
                 response_type, response_payload = 'oadrResponse', {}
+
             response_payload['vtn_id'] = self.vtn_id
+            if 'ven_id' in message_payload:
+                response_payload['ven_id'] = message_payload['ven_id']
 
             response_payload['response'] = {'request_id': message_payload.get('request_id', None),
                                             'response_code': 200,
                                             'response_description': 'OK'}
+            response_payload['request_id'] = generate_id()
 
             # Create the XML response
             msg = self._create_message(response_type, **response_payload)
@@ -63,8 +68,10 @@ class VTNService:
 
         else:
             msg = self._create_message('oadrResponse',
+                                       ven_id=message_payload.get('ven_id'),
                                        status_code=errorcodes.COMPLIANCE_ERROR,
                                        status_description=f"A message of type {message_type} should not be sent to this endpoint")
+
             response = web.Response(
                 text=msg,
                 status=HTTPStatus.BAD_REQUEST,