From 0a0159ba161b80bc3275f26aeb5e1bd0be86c0ec Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=B9=BF=E9=91=AB?= Date: Wed, 9 Mar 2022 17:04:10 +0800 Subject: [PATCH 1/2] support edgegallery http protocol. --- src/config/address.go | 32 ++++++++++++++------------------ 1 file changed, 14 insertions(+), 18 deletions(-) diff --git a/src/config/address.go b/src/config/address.go index a780157..ddcade5 100644 --- a/src/config/address.go +++ b/src/config/address.go @@ -19,6 +19,7 @@ package config import ( "errors" + "fmt" "mep-agent/src/util" "os" "strings" @@ -33,12 +34,10 @@ type ServerURL struct { } const ( - mepAuthApigwURL string = "https://${MEP_IP}:${MEP_APIGW_PORT}/mep/token" - mepSerRegisterApigwURL string = "https://${MEP_IP}:${MEP_APIGW_PORT}/mep/mec_service_mgmt/v1/applications/${appInstanceId}/services" - mepSerQueryByNameApigwURL string = "https://${MEP_IP}:${MEP_APIGW_PORT}/mep/mec_service_mgmt/v1/services?ser_name=" - mepHeartBeatApigwURL string = "https://${MEP_IP}:${MEP_APIGW_PORT}" - mepIP string = "${MEP_IP}" - mepApigwPort string = "${MEP_APIGW_PORT}" + mepAuthApigwURL string = "%s://%s:%s/mep/token" + mepSerRegisterApigwURL string = "%s://%s:%s/mep/mec_service_mgmt/v1/applications/${appInstanceId}/services" + mepSerQueryByNameApigwURL string = "%s://%s:%s/mep/mec_service_mgmt/v1/services?ser_name=" + mepHeartBeatApigwURL string = "%s://%s:%s" ) // ServerURLConfig server Url Configuration. @@ -57,21 +56,18 @@ func GetServerURL() (ServerURL, error) { return serverURL, errors.New("validate mep api gw failed") } - serverURL.MepServerRegisterURL = strings.Replace( - strings.Replace(mepSerRegisterApigwURL, mepIP, mepIPVal, 1), - mepApigwPort, mepAPIGwPort, 1) + egProtocol := "https" + if strings.EqualFold(os.Getenv("EG_PROTOCOL"), "http") { + egProtocol = "http" + } + + serverURL.MepServerRegisterURL = fmt.Sprintf(mepSerRegisterApigwURL, egProtocol, mepIPVal, mepAPIGwPort) - serverURL.MepAuthURL = strings.Replace( - strings.Replace(mepAuthApigwURL, mepIP, mepIPVal, 1), - mepApigwPort, mepAPIGwPort, 1) + serverURL.MepServerRegisterURL = fmt.Sprintf(mepAuthApigwURL, egProtocol, mepIPVal, mepAPIGwPort) - serverURL.MepHeartBeatURL = strings.Replace( - strings.Replace(mepHeartBeatApigwURL, mepIP, mepIPVal, 1), - mepApigwPort, mepAPIGwPort, 1) + serverURL.MepHeartBeatURL = fmt.Sprintf(mepHeartBeatApigwURL, egProtocol, mepIPVal, mepAPIGwPort) - serverURL.MepServiceDiscoveryURL = strings.Replace( - strings.Replace(mepSerQueryByNameApigwURL, mepIP, mepIPVal, 1), - mepApigwPort, mepAPIGwPort, 1) + serverURL.MepServiceDiscoveryURL = fmt.Sprintf(mepSerQueryByNameApigwURL, egProtocol, mepIPVal, mepAPIGwPort) return serverURL, nil } -- Gitee From 58fa82a59bea6cd562ff1bdf9c65fee7270fba63 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=B9=BF=E9=91=AB?= Date: Wed, 9 Mar 2022 17:05:20 +0800 Subject: [PATCH 2/2] support edgegallery http protocol. --- src/config/address.go | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/config/address.go b/src/config/address.go index ddcade5..c4e6789 100644 --- a/src/config/address.go +++ b/src/config/address.go @@ -20,6 +20,7 @@ package config import ( "errors" "fmt" + log "github.com/sirupsen/logrus" "mep-agent/src/util" "os" "strings" @@ -60,6 +61,7 @@ func GetServerURL() (ServerURL, error) { if strings.EqualFold(os.Getenv("EG_PROTOCOL"), "http") { egProtocol = "http" } + log.Info("egProtocol: " + egProtocol) serverURL.MepServerRegisterURL = fmt.Sprintf(mepSerRegisterApigwURL, egProtocol, mepIPVal, mepAPIGwPort) -- Gitee