From 866257ffcfaa1493c6f36db43f391099b44c29ec Mon Sep 17 00:00:00 2001 From: Lenny Goodell <44779287+lenny-intel@users.noreply.github.com> Date: Thu, 25 Feb 2021 16:00:27 -0700 Subject: [PATCH] refactor: Remove deprecated environment variables and related code (#718) * refactor: Remove deprecated environment variables and related code closes #337 BREAKING CHANGE: The following environment variables no longer supported: - `edgex_profile` (replaced by uppercase version) - `edgex_service` Signed-off-by: lenny --- appsdk/sdk.go | 49 ---------------------------------------------- appsdk/sdk_test.go | 32 ++++++++++-------------------- 2 files changed, 10 insertions(+), 71 deletions(-) diff --git a/appsdk/sdk.go b/appsdk/sdk.go index f0904099e..829fc7905 100644 --- a/appsdk/sdk.go +++ b/appsdk/sdk.go @@ -21,11 +21,9 @@ import ( "errors" "fmt" nethttp "net/http" - "net/url" "os" "os/signal" "reflect" - "strconv" "strings" "sync" "syscall" @@ -63,13 +61,8 @@ import ( const ( // ProfileSuffixPlaceholder is used to create unique names for profiles ProfileSuffixPlaceholder = "" - envV1Profile = "edgex_profile" // TODO: Remove for release v2.0.0 envProfile = "EDGEX_PROFILE" envServiceKey = "EDGEX_SERVICE_KEY" - envV1Service = "edgex_service" // deprecated TODO: Remove for release v2.0.0 - envServiceProtocol = "Service_Protocol" // Used for envV1Service processing TODO: Remove for release v2.0.0 - envServiceHost = "Service_Host" // Used for envV1Service processing TODO: Remove for release v2.0.0 - envServicePort = "Service_Port" // Used for envV1Service processing TODO: Remove for release v2.0.0 bindingTypeMessageBus = "MESSAGEBUS" bindingTypeEdgeXMessageBus = "EDGEX-MESSAGEBUS" @@ -377,14 +370,6 @@ func (sdk *AppFunctionsSDK) Initialize() error { sdk.LoggingClient.Info(fmt.Sprintf("Starting %s %s ", sdk.ServiceKey, internal.ApplicationVersion)) - // The use of the edgex_service environment variable (only used for App Services) has been deprecated - // and not included in the common bootstrap. Have to be handle here before calling into the common bootstrap - // so proper overrides are set. - // TODO: Remove for release v2.0.0 - if err := sdk.handleEdgexService(); err != nil { - return err - } - sdk.config = &common.ConfigurationStruct{} dic := di.NewContainer(di.ServiceConstructorMap{ container.ConfigurationName: func(get di.Get) interface{} { @@ -516,11 +501,6 @@ func (sdk *AppFunctionsSDK) setServiceKey(profile string) { // Have to handle environment override here before common bootstrap is used so it is passed the proper service key profileOverride := os.Getenv(envProfile) - if len(profileOverride) == 0 { - // V2 not set so try V1 - profileOverride = os.Getenv(envV1Profile) // TODO: Remove for release v2.0.0: - } - if len(profileOverride) > 0 { profile = profileOverride } @@ -533,32 +513,3 @@ func (sdk *AppFunctionsSDK) setServiceKey(profile string) { // No profile specified so remove the placeholder text sdk.ServiceKey = strings.Replace(sdk.ServiceKey, ProfileSuffixPlaceholder, "", 1) } - -// handleEdgexService checks to see if the "edgex_service" environment variable is set and if so creates appropriate config -// overrides from the URL parts. -// TODO: Remove for release v2.0.0 -func (sdk *AppFunctionsSDK) handleEdgexService() error { - if envValue := os.Getenv(envV1Service); envValue != "" { - u, err := url.Parse(envValue) - if err != nil { - return fmt.Errorf( - "failed to parse 'edgex_service' environment value '%s' as a URL: %s", - envValue, - err.Error()) - } - - _, err = strconv.ParseInt(u.Port(), 10, 0) - if err != nil { - return fmt.Errorf( - "failed to parse port from 'edgex_service' environment value '%s' as an integer: %s", - envValue, - err.Error()) - } - - os.Setenv(envServiceProtocol, u.Scheme) - os.Setenv(envServiceHost, u.Hostname()) - os.Setenv(envServicePort, u.Port()) - } - - return nil -} diff --git a/appsdk/sdk_test.go b/appsdk/sdk_test.go index a78fd729a..f03c2a28d 100644 --- a/appsdk/sdk_test.go +++ b/appsdk/sdk_test.go @@ -23,17 +23,18 @@ import ( "reflect" "testing" - "github.com/gorilla/mux" - "github.com/stretchr/testify/assert" - "github.com/stretchr/testify/require" - "github.com/edgexfoundry/app-functions-sdk-go/v2/appcontext" "github.com/edgexfoundry/app-functions-sdk-go/v2/internal/common" "github.com/edgexfoundry/app-functions-sdk-go/v2/internal/runtime" triggerHttp "github.com/edgexfoundry/app-functions-sdk-go/v2/internal/trigger/http" "github.com/edgexfoundry/app-functions-sdk-go/v2/internal/trigger/messagebus" "github.com/edgexfoundry/app-functions-sdk-go/v2/internal/webserver" + "github.com/edgexfoundry/go-mod-core-contracts/v2/clients/logger" + + "github.com/gorilla/mux" + "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" ) var lc logger.LoggingClient @@ -76,7 +77,7 @@ func TestAddBackgroundPublisher(t *testing.T) { } require.NotNil(t, pub.output, "publisher should have an output channel set") - require.NotNil(t, sdk.backgroundChannel, "sdk should have a background channel set for passing to trigger intitialization") + require.NotNil(t, sdk.backgroundChannel, "sdk should have a background channel set for passing to trigger initialization") // compare addresses since types will not match assert.Equal(t, fmt.Sprintf("%p", sdk.backgroundChannel), fmt.Sprintf("%p", pub.output), @@ -367,14 +368,6 @@ func TestSetServiceKey(t *testing.T) { originalServiceKey: "MyAppService-" + ProfileSuffixPlaceholder, expectedServiceKey: "MyAppService-mqtt-export", }, - { - name: "Profile specified with V1 override", - profile: "rules-engine", - profileEnvVar: envV1Profile, - profileEnvValue: "rules-engine-mqtt", - originalServiceKey: "MyAppService-" + ProfileSuffixPlaceholder, - expectedServiceKey: "MyAppService-rules-engine-mqtt", - }, { name: "Profile specified with V2 override", profile: "rules-engine", @@ -383,13 +376,6 @@ func TestSetServiceKey(t *testing.T) { originalServiceKey: "MyAppService-" + ProfileSuffixPlaceholder, expectedServiceKey: "MyAppService-rules-engine-redis", }, - { - name: "No profile specified with V1 override", - profileEnvVar: envV1Profile, - profileEnvValue: "sample", - originalServiceKey: "MyAppService-" + ProfileSuffixPlaceholder, - expectedServiceKey: "MyAppService-sample", - }, { name: "No profile specified with V2 override", profileEnvVar: envProfile, @@ -444,10 +430,12 @@ func TestSetServiceKey(t *testing.T) { for _, test := range tests { t.Run(test.name, func(t *testing.T) { if len(test.profileEnvVar) > 0 && len(test.profileEnvValue) > 0 { - os.Setenv(test.profileEnvVar, test.profileEnvValue) + err := os.Setenv(test.profileEnvVar, test.profileEnvValue) + require.NoError(t, err) } if len(test.serviceKeyEnvValue) > 0 { - os.Setenv(envServiceKey, test.serviceKeyEnvValue) + err := os.Setenv(envServiceKey, test.serviceKeyEnvValue) + require.NoError(t, err) } defer os.Clearenv()