initializer.py
1 import logging 2 import os 3 import json 4 from solace_ai_connector.main import load_config 5 6 log = logging.getLogger(__name__) 7 8 _has_initialized_system = False 9 10 def initialize(): 11 global _has_initialized_system 12 if not _has_initialized_system: 13 _has_initialized_system = True 14 else: 15 return 16 17 try: 18 from solace_agent_mesh_enterprise.init_enterprise import initialize_enterprise_features 19 except ImportError: 20 # Community edition 21 # Contact Solace support for enterprise features 22 return 23 24 enterprise_config = os.getenv("SAM_AUTHORIZATION_CONFIG") 25 if enterprise_config and isinstance(enterprise_config, str): 26 if enterprise_config.endswith('.yaml') or enterprise_config.endswith('.yml'): 27 try: 28 enterprise_config = load_config(enterprise_config) 29 except Exception as e: 30 log.error("Failed to load YAML config from SAM_AUTHORIZATION_CONFIG: %s", e, exc_info=True) 31 raise 32 elif enterprise_config.endswith('.json'): 33 try: 34 with open(enterprise_config, 'r', encoding='utf-8') as file: 35 enterprise_config = json.load(file) 36 except Exception as e: 37 log.error("Failed to load JSON config from SAM_AUTHORIZATION_CONFIG: %s", e, exc_info=True) 38 raise 39 else: 40 try: 41 enterprise_config = json.loads(enterprise_config) 42 except json.JSONDecodeError as e: 43 log.error("Invalid JSON in SAM_AUTHORIZATION_CONFIG: %s", e, exc_info=True) 44 raise 45 else: 46 enterprise_config = {} 47 48 try: 49 initialize_enterprise_features(enterprise_config) 50 except Exception as e: 51 log.error("Failed to initialize enterprise features: %s", e, exc_info=True) 52 raise