Commit bf693ab9 by Oleksandr Barabash

small fixes, health check added

parent 932acc60
...@@ -19,7 +19,7 @@ from marshmallow import ValidationError, EXCLUDE ...@@ -19,7 +19,7 @@ from marshmallow import ValidationError, EXCLUDE
from bots import TeamsMessagingExtensionsActionPreviewBot from bots import TeamsMessagingExtensionsActionPreviewBot
from bots.exceptions import ConversationNotFound, DataParsingError from bots.exceptions import ConversationNotFound, DataParsingError
from config import AppConfig, COSMOS_CLIENT, CosmosDBConfig from config import AppConfig, COSMOS_CLIENT, CosmosDBConfig, KEY_VAULT_CLIENT
from entities.json.notification import Notification, NotificationCosmos from entities.json.notification import Notification, NotificationCosmos
from utils.cosmos_client import ItemNotFound from utils.cosmos_client import ItemNotFound
from utils.json_func import json_loads from utils.json_func import json_loads
...@@ -157,6 +157,23 @@ async def v1_health_check(_request: Request) -> Response: ...@@ -157,6 +157,23 @@ async def v1_health_check(_request: Request) -> Response:
""" Health check """ """ Health check """
# TODO(s1z): Add checks here. DB, etc. # TODO(s1z): Add checks here. DB, etc.
Log.i(TAG, "v1_health_check::ok") Log.i(TAG, "v1_health_check::ok")
key = None
container = None
try:
container = await COSMOS_CLIENT.get_conversations_container()
key = await KEY_VAULT_CLIENT.get_random_key()
except Exception as e:
Log.e(TAG, "v1_health_check::error", e)
if key is None:
return Response(
status=HTTPStatus.INTERNAL_SERVER_ERROR,
body=json.dumps({"error": "Can't connect to KeyVault"})
)
if container is None:
return Response(
status=HTTPStatus.INTERNAL_SERVER_ERROR,
body=json.dumps({"error": "Can't connect to CosmosDB"})
)
return Response(status=HTTPStatus.OK) return Response(status=HTTPStatus.OK)
......
...@@ -71,4 +71,5 @@ class CosmosDBConfig: ...@@ -71,4 +71,5 @@ class CosmosDBConfig:
COSMOS_CLIENT = CosmosClient(CosmosDBConfig.HOST, CosmosDBConfig.KEY) COSMOS_CLIENT = CosmosClient(CosmosDBConfig.HOST, CosmosDBConfig.KEY)
KEYVAULT_CLIENT = AzureKeyVaultClient(AppConfig.CLIENT_ID, AppConfig.KEY_VAULT) KEY_VAULT_CLIENT = AzureKeyVaultClient(AppConfig.CLIENT_ID,
AppConfig.KEY_VAULT)
...@@ -40,8 +40,9 @@ class AzureKeyVaultClient: ...@@ -40,8 +40,9 @@ class AzureKeyVaultClient:
async def get_random_key_bl(self) -> KeyVaultKey: async def get_random_key_bl(self) -> KeyVaultKey:
""" Blocking get random key """ """ Blocking get random key """
keys = self.key_client.list_properties_of_keys() keys = await self.execute_blocking(
await self.execute_blocking(self.key_client.list_properties_of_keys) self.key_client.list_properties_of_keys
)
all_keys = [] all_keys = []
for key in keys: for key in keys:
all_keys.append(key) all_keys.append(key)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment