diff --git a/.env.example b/.env.example index 09ac4703..f7b153f3 100644 --- a/.env.example +++ b/.env.example @@ -44,8 +44,6 @@ ALIYUN_TEXT_EMBEDDING_API_KEY= # Extension: polly_tts AWS_ACCESS_KEY_ID= AWS_SECRET_ACCESS_KEY= -AWS_BEDROCK_MODEL= -AWS_REGION= # Extension: agora_rtc # Azure STT key and region @@ -84,11 +82,6 @@ LITELLM_MODEL=gpt-4o-mini # Extension: openai_chatgpt # OpenAI API key OPENAI_API_KEY= -# OpenAI base URL -# if using OpenAI, keep default. using other OpenAI-compatible providers, then set it to the other provider's address -OPENAI_BASE_URL= -# OpenAI Model -OPENAI_MODEL=gpt-4o-mini # OpenAI proxy URL OPENAI_PROXY_URL= diff --git a/agents/property.json b/agents/property.json index bf384a9c..f3ae5b2b 100644 --- a/agents/property.json +++ b/agents/property.json @@ -12,7 +12,7 @@ "addon": "agora_rtc", "name": "agora_rtc", "property": { - "app_id": "", + "app_id": "$AGORA_APP_ID", "token": "", "channel": "astra_agents_test", "stream_id": 1234, @@ -23,8 +23,8 @@ "enable_agora_asr": true, "agora_asr_vendor_name": "microsoft", "agora_asr_language": "en-US", - "agora_asr_vendor_key": "", - "agora_asr_vendor_region": "", + "agora_asr_vendor_key": "$AZURE_STT_KEY", + "agora_asr_vendor_region": "$AZURE_STT_REGION", "agora_asr_session_control_file_path": "session_control.conf" } }, @@ -41,12 +41,12 @@ "name": "openai_chatgpt", "property": { "base_url": "", - "api_key": "", + "api_key": "$OPENAI_API_KEY", "frequency_penalty": 0.9, "model": "gpt-3.5-turbo", "max_tokens": 512, "prompt": "", - "proxy_url": "", + "proxy_url": "$OPENAI_PROXY_URL", "greeting": "ASTRA agent connected. How can i help you today?", "max_memory_length": 10 } @@ -57,8 +57,8 @@ "addon": "azure_tts", "name": "azure_tts", "property": { - "azure_subscription_key": "", - "azure_subscription_region": "", + "azure_subscription_key": "$AZURE_TTS_KEY", + "azure_subscription_region": "$AZURE_TTS_REGION", "azure_synthesis_voice_name": "en-US-JaneNeural" } }, @@ -211,7 +211,7 @@ "addon": "agora_rtc", "name": "agora_rtc", "property": { - "app_id": "", + "app_id": "$AGORA_APP_ID", "token": "", "channel": "astra_agents_test", "stream_id": 1234, @@ -222,8 +222,8 @@ "enable_agora_asr": true, "agora_asr_vendor_name": "microsoft", "agora_asr_language": "en-US", - "agora_asr_vendor_key": "", - "agora_asr_vendor_region": "", + "agora_asr_vendor_key": "$AZURE_STT_KEY", + "agora_asr_vendor_region": "$AZURE_STT_REGION", "agora_asr_session_control_file_path": "session_control.conf" } }, @@ -240,12 +240,12 @@ "name": "openai_chatgpt", "property": { "base_url": "", - "api_key": "", + "api_key": "$OPENAI_API_KEY", "frequency_penalty": 0.9, "model": "gpt-3.5-turbo", "max_tokens": 512, "prompt": "", - "proxy_url": "", + "proxy_url": "$OPENAI_PROXY_URL", "greeting": "ASTRA agent connected. How can i help you today?", "max_memory_length": 10 } @@ -256,7 +256,7 @@ "addon": "elevenlabs_tts", "name": "elevenlabs_tts", "property": { - "api_key": "", + "api_key": "$ELEVENLABS_TTS_KEY", "model_id": "eleven_multilingual_v2", "optimize_streaming_latency": 0, "request_timeout_seconds": 30, @@ -416,7 +416,7 @@ "addon": "agora_rtc", "name": "agora_rtc", "property": { - "app_id": "", + "app_id": "$AGORA_APP_ID", "token": "", "channel": "astra_agents_test", "stream_id": 1234, @@ -427,8 +427,8 @@ "enable_agora_asr": true, "agora_asr_vendor_name": "microsoft", "agora_asr_language": "en-US", - "agora_asr_vendor_key": "", - "agora_asr_vendor_region": "", + "agora_asr_vendor_key": "$AZURE_STT_KEY", + "agora_asr_vendor_region": "$AZURE_STT_REGION", "agora_asr_session_control_file_path": "session_control.conf" } }, @@ -439,8 +439,8 @@ "name": "bedrock_llm", "property": { "region": "us-east-1", - "access_key": "", - "secret_key": "", + "access_key": "$AWS_ACCESS_KEY_ID", + "secret_key": "$AWS_SECRET_ACCESS_KEY", "model": "anthropic.claude-3-5-sonnet-20240620-v1:0", "max_tokens": 512, "prompt": "", @@ -454,8 +454,8 @@ "addon": "azure_tts", "name": "azure_tts", "property": { - "azure_subscription_key": "", - "azure_subscription_region": "", + "azure_subscription_key": "$AZURE_TTS_KEY", + "azure_subscription_region": "$AZURE_TTS_REGION", "azure_synthesis_voice_name": "en-US-JaneNeural" } }, @@ -580,7 +580,7 @@ "addon": "agora_rtc", "name": "agora_rtc", "property": { - "app_id": "", + "app_id": "$AGORA_APP_ID", "token": "", "channel": "astra_agents_test", "stream_id": 1234, @@ -591,8 +591,8 @@ "enable_agora_asr": true, "agora_asr_vendor_name": "microsoft", "agora_asr_language": "en-US", - "agora_asr_vendor_key": "", - "agora_asr_vendor_region": "", + "agora_asr_vendor_key": "$AZURE_STT_KEY", + "agora_asr_vendor_region": "$AZURE_STT_REGION", "agora_asr_session_control_file_path": "session_control.conf" } }, @@ -603,12 +603,12 @@ "name": "openai_chatgpt", "property": { "base_url": "", - "api_key": "", + "api_key": "$OPENAI_API_KEY", "frequency_penalty": 0.9, "model": "gpt-3.5-turbo", "max_tokens": 512, "prompt": "", - "proxy_url": "", + "proxy_url": "$OPENAI_PROXY_URL", "greeting": "ASTRA agent connected. How can i help you today?", "max_memory_length": 10 } @@ -619,7 +619,7 @@ "addon": "cosy_tts", "name": "cosy_tts", "property": { - "api_key": "", + "api_key": "$QWEN_API_KEY", "model": "cosyvoice-v1", "voice": "longxiaochun", "sample_rate": 16000 @@ -780,7 +780,7 @@ "addon": "agora_rtc", "name": "agora_rtc", "property": { - "app_id": "", + "app_id": "$AGORA_APP_ID", "token": "", "channel": "astra_agents_test", "stream_id": 1234, @@ -791,8 +791,8 @@ "enable_agora_asr": true, "agora_asr_vendor_name": "microsoft", "agora_asr_language": "en-US", - "agora_asr_vendor_key": "", - "agora_asr_vendor_region": "", + "agora_asr_vendor_key": "$AZURE_STT_KEY", + "agora_asr_vendor_region": "$AZURE_STT_REGION", "agora_asr_session_control_file_path": "session_control.conf" } }, @@ -802,7 +802,7 @@ "addon": "qwen_llm_python", "name": "qwen_llm", "property": { - "api_key": "", + "api_key": "$QWEN_API_KEY", "model": "qwen-max", "max_tokens": 512, "prompt": "", @@ -815,7 +815,7 @@ "addon": "cosy_tts", "name": "cosy_tts", "property": { - "api_key": "", + "api_key": "$QWEN_API_KEY", "model": "cosyvoice-v1", "voice": "longxiaochun", "sample_rate": 16000 @@ -983,7 +983,7 @@ "addon": "agora_rtc", "name": "agora_rtc", "property": { - "app_id": "", + "app_id": "$AGORA_APP_ID", "token": "", "channel": "astra_agents_test", "stream_id": 1234, @@ -994,8 +994,8 @@ "enable_agora_asr": true, "agora_asr_vendor_name": "microsoft", "agora_asr_language": "en-US", - "agora_asr_vendor_key": "", - "agora_asr_vendor_region": "", + "agora_asr_vendor_key": "$AZURE_STT_KEY", + "agora_asr_vendor_region": "$AZURE_STT_REGION", "agora_asr_session_control_file_path": "session_control.conf" } }, @@ -1006,8 +1006,8 @@ "name": "bedrock_llm", "property": { "region": "us-east-1", - "access_key": "", - "secret_key": "", + "access_key": "$AWS_ACCESS_KEY_ID", + "secret_key": "$AWS_SECRET_ACCESS_KEY", "model": "anthropic.claude-3-5-sonnet-20240620-v1:0", "max_tokens": 512, "prompt": "", @@ -1022,8 +1022,8 @@ "name": "polly_tts", "property": { "region": "us-east-1", - "access_key": "", - "secret_key": "", + "access_key": "$AWS_ACCESS_KEY_ID", + "secret_key": "$AWS_SECRET_ACCESS_KEY", "engine": "generative", "voice": "Ruth", "sample_rate": "16000", @@ -1151,7 +1151,7 @@ "addon": "agora_rtc", "name": "agora_rtc", "property": { - "app_id": "baf537f77ebc4187a06a1628a1827f14", + "app_id": "$AGORA_APP_ID", "token": "", "channel": "astra_agents_test", "stream_id": 1234, @@ -1162,8 +1162,8 @@ "enable_agora_asr": false, "agora_asr_vendor_name": "microsoft", "agora_asr_language": "en-US", - "agora_asr_vendor_key": "", - "agora_asr_vendor_region": "", + "agora_asr_vendor_key": "$AZURE_STT_KEY", + "agora_asr_vendor_region": "$AZURE_STT_REGION", "agora_asr_session_control_file_path": "session_control.conf" } }, @@ -1174,8 +1174,8 @@ "name": "transcribe_asr", "property": { "region": "us-east-1", - "access_key": "", - "secret_key": "", + "access_key": "$AWS_ACCESS_KEY_ID", + "secret_key": "$AWS_SECRET_ACCESS_KEY", "sample_rate": "16000", "lang_code": "en-US" } @@ -1187,8 +1187,8 @@ "name": "bedrock_llm", "property": { "region": "us-east-1", - "access_key": "", - "secret_key": "", + "access_key": "$AWS_ACCESS_KEY_ID", + "secret_key": "$AWS_SECRET_ACCESS_KEY", "model": "anthropic.claude-3-5-sonnet-20240620-v1:0", "max_tokens": 512, "prompt": "", @@ -1203,8 +1203,8 @@ "name": "polly_tts", "property": { "region": "us-east-1", - "access_key": "", - "secret_key": "", + "access_key": "$AWS_ACCESS_KEY_ID", + "secret_key": "$AWS_SECRET_ACCESS_KEY", "engine": "generative", "voice": "Ruth", "sample_rate": "16000", @@ -1381,7 +1381,7 @@ "addon": "agora_rtc", "name": "agora_rtc", "property": { - "app_id": "", + "app_id": "$AGORA_APP_ID", "token": "", "channel": "astra_agents_test", "stream_id": 1234, @@ -1393,8 +1393,8 @@ "enable_agora_asr": true, "agora_asr_vendor_name": "microsoft", "agora_asr_language": "zh-CN", - "agora_asr_vendor_key": "", - "agora_asr_vendor_region": "", + "agora_asr_vendor_key": "$AZURE_STT_KEY", + "agora_asr_vendor_region": "$AZURE_STT_REGION", "agora_asr_session_control_file_path": "session_control.conf", "subscribe_video_pix_fmt": 4 } @@ -1412,12 +1412,12 @@ "name": "openai_chatgpt", "property": { "base_url": "", - "api_key": "", + "api_key": "$OPENAI_API_KEY", "frequency_penalty": 0.9, "model": "gpt-4o", "max_tokens": 512, "prompt": "", - "proxy_url": "", + "proxy_url": "$OPENAI_PROXY_URL", "greeting": "Astra已连接,需要我为您提供什么帮助?", "checking_vision_text_items": "[\"让我看看你的摄像头...\",\"让我看一下...\",\"我看一下,请稍候...\"]", "max_memory_length": 10, @@ -1430,8 +1430,8 @@ "addon": "azure_tts", "name": "azure_tts", "property": { - "azure_subscription_key": "", - "azure_subscription_region": "", + "azure_subscription_key": "$AZURE_TTS_KEY", + "azure_subscription_region": "$AZURE_TTS_REGION", "azure_synthesis_voice_name": "en-US-JaneNeural" } }, @@ -1595,7 +1595,7 @@ "addon": "agora_rtc", "name": "agora_rtc", "property": { - "app_id": "", + "app_id": "$AGORA_APP_ID", "token": "", "channel": "astra_agents_test", "stream_id": 1234, @@ -1607,8 +1607,8 @@ "enable_agora_asr": true, "agora_asr_vendor_name": "microsoft", "agora_asr_language": "en-US", - "agora_asr_vendor_key": "", - "agora_asr_vendor_region": "", + "agora_asr_vendor_key": "$AZURE_STT_KEY", + "agora_asr_vendor_region": "$AZURE_STT_REGION", "agora_asr_session_control_file_path": "session_control.conf", "subscribe_video_pix_fmt": 4 } @@ -1626,12 +1626,12 @@ "name": "openai_chatgpt", "property": { "base_url": "", - "api_key": "", + "api_key": "$OPENAI_API_KEY", "frequency_penalty": 0.9, "model": "gpt-4o-mini", "max_tokens": 512, "prompt": "", - "proxy_url": "", + "proxy_url": "$OPENAI_PROXY_URL", "greeting": "ASTRA agent connected. How can i help you today?", "checking_vision_text_items": "[\"Let me take a look...\",\"Let me check your camera...\",\"Please wait for a second...\"]", "max_memory_length": 10, @@ -1644,8 +1644,8 @@ "addon": "azure_tts", "name": "azure_tts", "property": { - "azure_subscription_key": "", - "azure_subscription_region": "", + "azure_subscription_key": "$AZURE_TTS_KEY", + "azure_subscription_region": "$AZURE_TTS_REGION", "azure_synthesis_voice_name": "en-US-JaneNeural" } }, @@ -1809,7 +1809,7 @@ "addon": "agora_rtc", "name": "agora_rtc", "property": { - "app_id": "", + "app_id": "$AGORA_APP_ID", "token": "", "channel": "astra_agents_test", "stream_id": 1234, @@ -1820,8 +1820,8 @@ "enable_agora_asr": true, "agora_asr_vendor_name": "microsoft", "agora_asr_language": "en-US", - "agora_asr_vendor_key": "", - "agora_asr_vendor_region": "", + "agora_asr_vendor_key": "$AZURE_STT_KEY", + "agora_asr_vendor_region": "$AZURE_STT_REGION", "agora_asr_session_control_file_path": "session_control.conf" } }, @@ -1837,7 +1837,7 @@ "addon": "gemini_llm_python", "name": "gemini_llm", "property": { - "api_key": "", + "api_key": "$GEMINI_API_KEY", "greeting": "ASTRA agent connected. How can i help you today?", "max_memory_length": 10, "max_output_tokens": 512, @@ -1854,8 +1854,8 @@ "addon": "azure_tts", "name": "azure_tts", "property": { - "azure_subscription_key": "", - "azure_subscription_region": "", + "azure_subscription_key": "$AZURE_TTS_KEY", + "azure_subscription_region": "$AZURE_TTS_REGION", "azure_synthesis_voice_name": "en-US-JaneNeural" } }, @@ -2008,7 +2008,7 @@ "addon": "agora_rtc", "name": "agora_rtc", "property": { - "app_id": "", + "app_id": "$AGORA_APP_ID", "token": "", "channel": "astra_agents_test", "stream_id": 1234, @@ -2019,8 +2019,8 @@ "enable_agora_asr": true, "agora_asr_vendor_name": "microsoft", "agora_asr_language": "en-US", - "agora_asr_vendor_key": "", - "agora_asr_vendor_region": "", + "agora_asr_vendor_key": "$AZURE_STT_KEY", + "agora_asr_vendor_region": "$AZURE_STT_REGION", "agora_asr_session_control_file_path": "session_control.conf" } }, @@ -2030,7 +2030,7 @@ "addon": "qwen_llm_python", "name": "qwen_llm", "property": { - "api_key": "", + "api_key": "$QWEN_API_KEY", "model": "qwen-max", "max_tokens": 512, "prompt": "", @@ -2043,7 +2043,7 @@ "addon": "cosy_tts", "name": "cosy_tts", "property": { - "api_key": "", + "api_key": "$QWEN_API_KEY", "model": "cosyvoice-v1", "voice": "longxiaochun", "sample_rate": 16000 @@ -2055,8 +2055,8 @@ "addon": "azure_tts", "name": "azure_tts", "property": { - "azure_subscription_key": "", - "azure_subscription_region": "", + "azure_subscription_key": "$AZURE_TTS_KEY", + "azure_subscription_region": "$AZURE_TTS_REGION", "azure_synthesis_voice_name": "en-US-JaneNeural" } }, @@ -2088,7 +2088,7 @@ "addon": "aliyun_text_embedding", "name": "aliyun_text_embedding", "property": { - "api_key": "", + "api_key": "$ALIYUN_TEXT_EMBEDDING_API_KEY", "model": "text-embedding-v3" } }, @@ -2098,14 +2098,14 @@ "addon": "aliyun_analyticdb_vector_storage", "name": "aliyun_analyticdb_vector_storage", "property": { - "alibaba_cloud_access_key_id": "", - "alibaba_cloud_access_key_secret": "", - "adbpg_instance_id": "", - "adbpg_instance_region": "cn-shanghai", - "adbpg_account": "", - "adbpg_account_password": "", - "adbpg_namespace": "", - "adbpg_namespace_password": "" + "alibaba_cloud_access_key_id": "$ALIBABA_CLOUD_ACCESS_KEY_ID", + "alibaba_cloud_access_key_secret": "$ALIBABA_CLOUD_ACCESS_KEY_SECRET", + "adbpg_instance_id": "$ALIYUN_ANALYTICDB_INSTANCE_ID", + "adbpg_instance_region": "$ALIYUN_ANALYTICDB_INSTANCE_REGION", + "adbpg_account": "$ALIYUN_ANALYTICDB_ACCOUNT", + "adbpg_account_password": "$ALIYUN_ANALYTICDB_ACCOUNT_PASSWORD", + "adbpg_namespace": "$ALIYUN_ANALYTICDB_NAMESPACE", + "adbpg_namespace_password": "$ALIYUN_ANALYTICDB_NAMESPACE_PASSWORD" } }, { diff --git a/server/internal/config.go b/server/internal/config.go index a873e3d5..2701f212 100644 --- a/server/internal/config.go +++ b/server/internal/config.go @@ -38,102 +38,6 @@ const ( var ( logTag = slog.String("service", "HTTP_SERVER") - // Retrieve configuration information from environment variables and map it to the property.json file - EnvPropMap = map[string][]Prop{ - "AGORA_APP_ID": { - {ExtensionName: extensionNameAgoraRTC, Property: "app_id"}, - }, - "ALIBABA_CLOUD_ACCESS_KEY_ID": { - {ExtensionName: extensionNameAliyunAnalyticdbVectorStorage, Property: "alibaba_cloud_access_key_id"}, - }, - "ALIBABA_CLOUD_ACCESS_KEY_SECRET": { - {ExtensionName: extensionNameAliyunAnalyticdbVectorStorage, Property: "alibaba_cloud_access_key_secret"}, - }, - "ALIYUN_ANALYTICDB_ACCOUNT": { - {ExtensionName: extensionNameAliyunAnalyticdbVectorStorage, Property: "adbpg_account"}, - }, - "ALIYUN_ANALYTICDB_ACCOUNT_PASSWORD": { - {ExtensionName: extensionNameAliyunAnalyticdbVectorStorage, Property: "adbpg_account_password"}, - }, - "ALIYUN_ANALYTICDB_INSTANCE_ID": { - {ExtensionName: extensionNameAliyunAnalyticdbVectorStorage, Property: "adbpg_instance_id"}, - }, - "ALIYUN_ANALYTICDB_INSTANCE_REGION": { - {ExtensionName: extensionNameAliyunAnalyticdbVectorStorage, Property: "adbpg_instance_region"}, - }, - "ALIYUN_ANALYTICDB_NAMESPACE": { - {ExtensionName: extensionNameAliyunAnalyticdbVectorStorage, Property: "adbpg_namespace"}, - }, - "ALIYUN_ANALYTICDB_NAMESPACE_PASSWORD": { - {ExtensionName: extensionNameAliyunAnalyticdbVectorStorage, Property: "adbpg_namespace_password"}, - }, - "ALIYUN_TEXT_EMBEDDING_API_KEY": { - {ExtensionName: extensionNameAliyunTextEmbedding, Property: "api_key"}, - }, - "AWS_ACCESS_KEY_ID": { - {ExtensionName: extensionNameBedrockLLM, Property: "access_key"}, - {ExtensionName: extensionNamePollyTTS, Property: "access_key"}, - {ExtensionName: extensionNameTranscribeAsr, Property: "access_key"}, - }, - "AWS_SECRET_ACCESS_KEY": { - {ExtensionName: extensionNameBedrockLLM, Property: "secret_key"}, - {ExtensionName: extensionNamePollyTTS, Property: "secret_key"}, - {ExtensionName: extensionNameTranscribeAsr, Property: "secret_key"}, - }, - "AWS_BEDROCK_MODEL": { - {ExtensionName: extensionNameBedrockLLM, Property: "model"}, - }, - "AWS_REGION": { - {ExtensionName: extensionNameBedrockLLM, Property: "region"}, - {ExtensionName: extensionNamePollyTTS, Property: "region"}, - {ExtensionName: extensionNameTranscribeAsr, Property: "region"}, - }, - "AZURE_STT_KEY": { - {ExtensionName: extensionNameAgoraRTC, Property: "agora_asr_vendor_key"}, - }, - "AZURE_STT_REGION": { - {ExtensionName: extensionNameAgoraRTC, Property: "agora_asr_vendor_region"}, - }, - "AZURE_TTS_KEY": { - {ExtensionName: extensionNameAzureTTS, Property: "azure_subscription_key"}, - }, - "AZURE_TTS_REGION": { - {ExtensionName: extensionNameAzureTTS, Property: "azure_subscription_region"}}, - "COSY_TTS_KEY": { - {ExtensionName: extensionNameCosyTTS, Property: "api_key"}, - }, - "ELEVENLABS_TTS_KEY": { - {ExtensionName: extensionNameElevenlabsTTS, Property: "api_key"}, - }, - "GEMINI_API_KEY": { - {ExtensionName: extensionNameGeminiLLM, Property: "api_key"}, - }, - "OPENAI_API_KEY": { - {ExtensionName: extensionNameOpenaiChatgpt, Property: "api_key"}, - }, - "LITELLM_API_KEY": { - {ExtensionName: extensionNameLiteLLM, Property: "api_key"}, - }, - "LITELLM_MODEL": { - {ExtensionName: extensionNameLiteLLM, Property: "model"}, - }, - "LITELLM_PROVIDER": { - {ExtensionName: extensionNameLiteLLM, Property: "provider"}, - }, - "OPENAI_BASE_URL": { - {ExtensionName: extensionNameOpenaiChatgpt, Property: "base_url"}, - }, - "OPENAI_MODEL": { - {ExtensionName: extensionNameOpenaiChatgpt, Property: "model"}, - }, - "OPENAI_PROXY_URL": { - {ExtensionName: extensionNameOpenaiChatgpt, Property: "proxy_url"}, - }, - "QWEN_API_KEY": { - {ExtensionName: extensionNameQwenLLM, Property: "api_key"}, - }, - } - // Retrieve parameters from the request and map them to the property.json file startPropMap = map[string][]Prop{ "ChannelName": { diff --git a/server/internal/http_server.go b/server/internal/http_server.go index 827a362b..a7133ec2 100644 --- a/server/internal/http_server.go +++ b/server/internal/http_server.go @@ -15,6 +15,7 @@ import ( "net/http" "os" "path/filepath" + "regexp" "strings" "time" @@ -358,6 +359,23 @@ func (s *HttpServer) output(c *gin.Context, code *Code, data any, httpStatus ... c.JSON(httpStatus[0], gin.H{"code": code.code, "msg": code.msg, "data": data}) } +func replaceEnvVarsInJSON(jsonData string) string { + // Regex to find all occurrences of $VAR_NAME + re := regexp.MustCompile(`"\$(\w+)"`) + + // Function to replace the match with the environment variable value + result := re.ReplaceAllStringFunc(jsonData, func(match string) string { + // Extract the variable name (removing the leading $ and surrounding quotes) + envVar := strings.Trim(match, "\"$") + // Get the environment variable value + value := os.Getenv(envVar) + // Replace with the value (keeping it quoted) + return fmt.Sprintf("\"%s\"", value) + }) + + return result +} + func (s *HttpServer) processProperty(req *StartReq) (propertyJsonFile string, logFile string, err error) { content, err := os.ReadFile(PropertyJsonFile) if err != nil { @@ -410,13 +428,7 @@ func (s *HttpServer) processProperty(req *StartReq) (propertyJsonFile string, lo propertyJson, _ = sjson.Set(propertyJson, fmt.Sprintf(`%s.auto_start`, graph), true) // Set environment variable values to property.json - for envKey, envProps := range EnvPropMap { - if envVal := os.Getenv(envKey); envVal != "" { - for _, envProp := range envProps { - propertyJson, _ = sjson.Set(propertyJson, fmt.Sprintf(`%s.nodes.#(name=="%s").property.%s`, graph, envProp.ExtensionName, envProp.Property), envVal) - } - } - } + propertyJson = replaceEnvVarsInJSON(propertyJson) // Set additional properties to property.json for extensionName, props := range req.Properties {