Skip to content

Commit

Permalink
fix: Set Redis password in MessageBus.Optional when using redisstreams (
Browse files Browse the repository at this point in the history
#534)

closes #530

Signed-off-by: lenny <[email protected]>
  • Loading branch information
lenny-goodell authored Oct 9, 2020
1 parent 35ab7bc commit 7fa6067
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 8 deletions.
28 changes: 24 additions & 4 deletions appsdk/sdk.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
"context"
"errors"
"fmt"
"github.com/edgexfoundry/go-mod-messaging/messaging"
"github.com/edgexfoundry/go-mod-messaging/pkg/types"
nethttp "net/http"
"net/url"
Expand Down Expand Up @@ -71,6 +72,13 @@ const (
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"
bindingTypeMQTT = "EXTERNAL-MQTT"
bindingTypeHTTP = "HTTP"

OptionalPasswordKey = "Password"
)

// The key type is unexported to prevent collisions with context keys defined in
Expand Down Expand Up @@ -408,6 +416,18 @@ func (sdk *AppFunctionsSDK) Initialize() error {
sdk.EdgexClients.NotificationsClient = container.NotificationsClientFrom(dic.Get)
sdk.EdgexClients.CommandClient = container.CommandClientFrom(dic.Get)

// If using the RedisStreams MessageBus implementation then need to make sure the
// password for the Redis DB is set in the MessageBus Optional properties.
bindingType := strings.ToUpper(sdk.config.Binding.Type)
if (bindingType == bindingTypeMessageBus || bindingType == bindingTypeEdgeXMessageBus) &&
sdk.config.MessageBus.Type == messaging.RedisStreams {
credentials, err := sdk.secretProvider.GetDatabaseCredentials(sdk.config.Database)
if err != nil {
return fmt.Errorf("unable to set RedisStreams password from DB credentials")
}
sdk.config.MessageBus.Optional[OptionalPasswordKey] = credentials.Password
}

// We do special processing when the writeable section of the configuration changes, so have
// to wait to be signaled when the configuration has been updated and then process the changes
NewConfigUpdateProcessor(sdk).WaitForConfigUpdates(configUpdated)
Expand Down Expand Up @@ -444,16 +464,16 @@ func (sdk *AppFunctionsSDK) setupTrigger(configuration *common.ConfigurationStru
// Need to make dynamic, search for the binding that is input

switch strings.ToUpper(configuration.Binding.Type) {
case "HTTP":
case bindingTypeHTTP:
sdk.LoggingClient.Info("HTTP trigger selected")
t = &http.Trigger{Configuration: configuration, Runtime: runtime, Webserver: sdk.webserver, EdgeXClients: sdk.EdgexClients}

case "MESSAGEBUS",
"EDGEX-MESSAGEBUS": // Allows for more explicit name now that we have plain MQTT option also
case bindingTypeMessageBus,
bindingTypeEdgeXMessageBus: // Allows for more explicit name now that we have plain MQTT option also
sdk.LoggingClient.Info("EdgeX MessageBus trigger selected")
t = &messagebus.Trigger{Configuration: configuration, Runtime: runtime, EdgeXClients: sdk.EdgexClients}

case "EXTERNAL-MQTT":
case bindingTypeMQTT:
sdk.LoggingClient.Info("External MQTT trigger selected")
t = mqtt.NewTrigger(configuration, runtime, sdk.EdgexClients, sdk.secretProvider)

Expand Down
8 changes: 4 additions & 4 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@ require (
bitbucket.org/bertimus9/systemstat v0.0.0-20180207000608-0eeff89b0690
github.com/diegoholiveira/jsonlogic v1.0.1-0.20200220175622-ab7989be08b9
github.com/eclipse/paho.mqtt.golang v1.2.0
github.com/edgexfoundry/go-mod-bootstrap v0.0.46
github.com/edgexfoundry/go-mod-core-contracts v0.1.90
github.com/edgexfoundry/go-mod-messaging v0.1.23
github.com/edgexfoundry/go-mod-registry v0.1.23
github.com/edgexfoundry/go-mod-bootstrap v0.0.47
github.com/edgexfoundry/go-mod-core-contracts v0.1.94
github.com/edgexfoundry/go-mod-messaging v0.1.26
github.com/edgexfoundry/go-mod-registry v0.1.25
github.com/edgexfoundry/go-mod-secrets v0.0.23
github.com/fxamacker/cbor/v2 v2.2.0
github.com/golang/snappy v0.0.1 // indirect
Expand Down

0 comments on commit 7fa6067

Please sign in to comment.