From 9cda9759b05a4fde5385bbde3bc2c17157b6563e Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Marcin=20W=C4=85troba?= <markowanga@gmail.com>
Date: Mon, 16 Aug 2021 21:53:30 +0200
Subject: [PATCH] Add Base service improvement

---
 sziszapangma/integration/asr_processor.py              | 10 +++++++---
 .../integration/base_asr_service/asr_processor.py      |  4 ++++
 2 files changed, 11 insertions(+), 3 deletions(-)

diff --git a/sziszapangma/integration/asr_processor.py b/sziszapangma/integration/asr_processor.py
index bfc2685..f6df63a 100644
--- a/sziszapangma/integration/asr_processor.py
+++ b/sziszapangma/integration/asr_processor.py
@@ -1,5 +1,5 @@
 from abc import ABC, abstractmethod
-from typing import Any, Dict
+from typing import Any, Dict, Optional
 
 import requests
 
@@ -16,14 +16,18 @@ class AsrProcessor(ABC):
 
 class AsrWebClient(AsrProcessor):
     _url: str
+    _auth_token: Optional[str]
 
-    def __init__(self, url: str):
+    def __init__(self, url: str, auth_token: Optional[str]):
         super(AsrWebClient, self).__init__()
         self._url = url
+        self._auth_token = auth_token
 
     def call_recognise(self, file_path: str) -> Dict[str, Any]:
         files = {"file": open(file_path, "rb")}
-        res = requests.post(self._url, files=files)
+        headers = dict({'Authorization': f'Bearer {self._auth_token}'}) \
+            if self._auth_token is not None else dict()
+        res = requests.post(self._url, files=files, headers=headers)
         json_response = res.json()
         print(json_response)
         return json_response
diff --git a/sziszapangma/integration/base_asr_service/asr_processor.py b/sziszapangma/integration/base_asr_service/asr_processor.py
index a35df95..6cf478f 100644
--- a/sziszapangma/integration/base_asr_service/asr_processor.py
+++ b/sziszapangma/integration/base_asr_service/asr_processor.py
@@ -48,10 +48,14 @@ class AsrProcessor(ABC):
         else:
             return None
 
+    def health_check(self) -> Response:
+        return jsonify({'status': 'running'})
+
     def start_processor(self):
         app = Flask(__name__)
         auth = HTTPTokenAuth(scheme="Bearer")
         auth.verify_token(self.is_token_correct)
         Path(_TEMP_DIRECTORY).mkdir(parents=True, exist_ok=True)
         app.route("/process_asr", methods=["POST"])(auth.login_required(self.process_request))
+        app.route("/health_check", methods=["GET"])(self.health_check)
         app.run(debug=True, host="0.0.0.0")
-- 
GitLab