11import logging
2- import os
3- from dotenv import load_dotenv
4- from .models .config import CoreConfig
52from .core .logger .logger import Logger
63from .core .logger .local_logger import LocalLogger
7- from .core .queue .topic import Topic
8- from .core .storage .providers .azure import azure_storage_client , azure_file_entity
9- from .core .storage .providers .azure .azure_storage_config import AzureStorageConfig
4+ from .core .topic .topic import Topic
5+ from .core .topic .local_topic import LocalTopic
6+ from .core .storage .providers .azure .azure_storage_client import AzureStorageClient
7+ from .core .storage .providers .local .local_storage_client import LocalStorageClient
8+ from .core .config .config import CoreConfig , LocalConfig
109
11- load_dotenv ()
10+ LOCAL_ENV = 'LOCAL'
11+ AZURE_ENV = 'AZURE'
1212
1313
1414class Core :
15-
16- # FIXME: Fix the configuration
1715 def __init__ (self , config = None ):
18-
19- if config is not None :
20- self .config = config
16+ if config is not None and config .upper () == LOCAL_ENV :
17+ self .config = LocalConfig ()
2118 else :
22- self .config = CoreConfig .default ()
23-
24- # FIXME: remove local from here and accept only Azure for now
25- if self .config .provider == 'Local' :
26- logging .error (f'Unimplemented initialization for core { self .config .provider } ' )
27-
28- @staticmethod
29- def initialize ():
30- return Core ().__check_health ()
31-
32- @staticmethod
33- def get_logger (provider = None ):
34- if provider and provider .lower () == 'local' :
35- return LocalLogger (provider_config = provider )
19+ self .config = CoreConfig ()
20+ self .__check_health ()
21+
22+ def get_logger (self ):
23+ logger_config = self .config .logger ()
24+ if logger_config .provider .upper () == LOCAL_ENV :
25+ return LocalLogger (config = logger_config )
26+ elif logger_config .provider .upper () == AZURE_ENV :
27+ return Logger (config = logger_config )
3628 else :
37- return Logger ()
38-
39- # @staticmethod
40- # def get_custom_queue():
41-
42- @staticmethod
43- def get_topic (topic_name : str ):
44- if topic_name is not None :
45- return Topic (config = CoreConfig .default (), topic_name = topic_name )
29+ logging .error (f'Unimplemented initialization for core { logger_config .provider } ' )
30+
31+ def get_topic (self , topic_name : str ):
32+ topic_config = self .config .topic ()
33+ if topic_config .provider .upper () == LOCAL_ENV :
34+ return LocalTopic (config = topic_config , topic_name = topic_name )
35+ elif topic_config .provider .upper () == AZURE_ENV :
36+ return Topic (config = topic_config , topic_name = topic_name )
4637 else :
47- logging .error (f'Error: Topic name is required as function parameter' )
48- return
49-
50- @staticmethod
51- def get_storage_client ():
52- return azure_storage_client .AzureStorageClient (AzureStorageConfig ())
38+ logging .error (f'Unimplemented initialization for core { topic_config .provider } ' )
39+
40+ def get_storage_client (self ):
41+ storage_config = self .config .storage ()
42+ if storage_config .provider .upper () == LOCAL_ENV :
43+ return LocalStorageClient (storage_config )
44+ elif storage_config .provider .upper () == AZURE_ENV :
45+ return AzureStorageClient (storage_config )
46+ else :
47+ logging .error (f'Unimplemented initialization for core { storage_config .provider } ' )
5348
5449 def __check_health (self ):
5550 print ('\x1b [32m ------------------------- \x1b [0m' )
@@ -63,34 +58,34 @@ def __check_health(self):
6358
6459 print (f'Configured for \x1b [32m { self .config .provider } \x1b [0m \n ' )
6560
66- if self .config .provider == 'Azure' :
67- logger_queue_name = os .environ .get ('LOGGERQUEUE' , None )
68- queue_connection = os .environ .get ('QUEUECONNECTION' , None )
69- storage_connection = os .environ .get ('STORAGECONNECTION' , None )
70-
71- print ('\x1b [31m > Checking Queue Connections\x1b [0m' )
72- if queue_connection is None :
73- print ('\x1b [33m Queue connection not available by default \x1b [0m' )
74- print ('\x1b [33m Please configure QUEUECONNECTION in .env file to ensure queue communication \x1b [0m' )
75- print ('\x1b [33m Note: All the logger functionality will be restricted to console \x1b [0m' )
76- else :
77- print ('\x1b [32m\x1b [40m Connected to Queues \x1b [0m' )
61+ logger_config = self .config .logger ()
62+ queue_config = self .config .queue ()
63+ storage_config = self .config .storage ()
64+ logger_queue_name = logger_config .queue_name
65+ queue_connection = queue_config .connection_string
66+ storage_connection = storage_config .connection_string
67+ print ('\x1b [31m > Checking Queue Connections\x1b [0m' )
68+ if queue_connection is None :
69+ print ('\x1b [33m Queue connection not available by default \x1b [0m' )
70+ print ('\x1b [33m Please configure QUEUECONNECTION in .env file to ensure queue communication \x1b [0m' )
71+ print ('\x1b [33m Note: All the logger functionality will be restricted to console \x1b [0m' )
72+ else :
73+ print ('\x1b [32m\x1b [40m Connected to Queues \x1b [0m' )
7874
79- print ('\x1b [31m\n > Checking Storage Connections\x1b [0m' )
75+ print ('\x1b [31m\n > Checking Storage Connections\x1b [0m' )
8076
81- if storage_connection is None :
82- print ('\x1b [31m Storage connection not available \x1b [0m' )
83- print ('\x1b [31m Storage related functionalities will be unavailable \x1b [0m' )
84- print ('\x1b [31m Please configure STORAGECONNECTION in .env for storage functions \x1b [0m' )
85- else :
86- print ('\x1b [32m\x1b [40m Connected to Storage \x1b [0m' )
77+ if storage_connection is None :
78+ print ('\x1b [31m Storage connection not available \x1b [0m' )
79+ print ('\x1b [31m Storage related functionalities will be unavailable \x1b [0m' )
80+ print ('\x1b [31m Please configure STORAGECONNECTION in .env for storage functions \x1b [0m' )
81+ else :
82+ print ('\x1b [32m\x1b [40m Connected to Storage \x1b [0m' )
8783
88- print ('\x1b [31m\n > Checking Logger Queue \x1b [0m' )
89- if logger_queue_name is None :
90- print ('\x1b [33m Logger queue is not configured. App will write to \x1b [0m' )
91- print ('\x1b [32m tdei-ms-log queue \x1b [0m' )
92- else :
93- print ('\x1b [32m Logger configured \x1b [0m' )
94- print ('\x1b [32m ------------------------- \x1b [0m' )
95- return True
84+ print ('\x1b [31m\n > Checking Logger Queue \x1b [0m' )
85+ if logger_queue_name is None :
86+ print ('\x1b [33m Logger queue is not configured. App will write to \x1b [0m' )
87+ print ('\x1b [32m tdei-ms-log queue \x1b [0m' )
88+ else :
89+ print ('\x1b [32m Logger configured \x1b [0m' )
90+ print ('\x1b [32m ------------------------- \x1b [0m' )
9691 return True
0 commit comments