Skip to content

Commit a48d639

Browse files
authored
feat: allow sending notifications to authenticated EdgeX endpoints (#4763)
* feat: allow sending notifications to authenticated EdgeX endpoints Signed-off-by: Jeff Titus <[email protected]> * refactor: remove extraneous else Signed-off-by: Jeff Titus <[email protected]> * build(deps): bump github.com/edgexfoundry/go-mod-core-contracts/v3 to v3.2.0-dev.9 Signed-off-by: Jeff Titus <[email protected]> * docs: update support-notifications openapi spec Signed-off-by: Jeff Titus <[email protected]> --------- Signed-off-by: Jeff Titus <[email protected]>
1 parent 2395694 commit a48d639

File tree

5 files changed

+21
-10
lines changed

5 files changed

+21
-10
lines changed

go.mod

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ require (
66
github.com/eclipse/paho.mqtt.golang v1.4.3
77
github.com/edgexfoundry/go-mod-bootstrap/v3 v3.2.0-dev.18
88
github.com/edgexfoundry/go-mod-configuration/v3 v3.2.0-dev.2
9-
github.com/edgexfoundry/go-mod-core-contracts/v3 v3.2.0-dev.8
9+
github.com/edgexfoundry/go-mod-core-contracts/v3 v3.2.0-dev.9
1010
github.com/edgexfoundry/go-mod-messaging/v3 v3.2.0-dev.12
1111
github.com/edgexfoundry/go-mod-secrets/v3 v3.2.0-dev.5
1212
github.com/fxamacker/cbor/v2 v2.6.0

go.sum

+2-2
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,8 @@ github.com/edgexfoundry/go-mod-bootstrap/v3 v3.2.0-dev.18 h1:h59Vx7wpVVjkbxvs62+
3030
github.com/edgexfoundry/go-mod-bootstrap/v3 v3.2.0-dev.18/go.mod h1:M3/344c8Zq4Bna/nR2WD2SWZ5tD5gLU8ukYus4dTb6s=
3131
github.com/edgexfoundry/go-mod-configuration/v3 v3.2.0-dev.2 h1:71C39GPP7nbxa5GTOqoc1eAXbogoie1DCYCLBQo71t0=
3232
github.com/edgexfoundry/go-mod-configuration/v3 v3.2.0-dev.2/go.mod h1:+RykcMAHe6rluqJSKOAy+EwtzaeSc/qbxRYdtY2vA0g=
33-
github.com/edgexfoundry/go-mod-core-contracts/v3 v3.2.0-dev.8 h1:la7SU8i0TwgJ1tnbgUacHtuCKmUEnb7R3VVgvJ2EiPY=
34-
github.com/edgexfoundry/go-mod-core-contracts/v3 v3.2.0-dev.8/go.mod h1:mXa4zgfgECdC/8WLULwCWmI5ZZNG7pzXeGGh4SH0FC0=
33+
github.com/edgexfoundry/go-mod-core-contracts/v3 v3.2.0-dev.9 h1:JzwiVf/r+hBNweRFOrMWL8BiHqD5cAidrRZ6Socuz+w=
34+
github.com/edgexfoundry/go-mod-core-contracts/v3 v3.2.0-dev.9/go.mod h1:mXa4zgfgECdC/8WLULwCWmI5ZZNG7pzXeGGh4SH0FC0=
3535
github.com/edgexfoundry/go-mod-messaging/v3 v3.2.0-dev.12 h1:/Z9Uxttg8ofl4Vv55ZPBz2tHkTyZTPIQiYENNnPeAPU=
3636
github.com/edgexfoundry/go-mod-messaging/v3 v3.2.0-dev.12/go.mod h1:/oGknon5z25PsBFnPHa74i54XM5xxwZ0AXCQLvk0qWw=
3737
github.com/edgexfoundry/go-mod-registry/v3 v3.2.0-dev.2 h1:Fj2CLjWB8I0KSjysV5oITrFlPI82K5aJXMt0/ZPC+/4=

internal/support/notifications/application/channel/sender.go

+14-6
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,11 @@ import (
1010
notificationContainer "github.com/edgexfoundry/edgex-go/internal/support/notifications/container"
1111

1212
"github.com/edgexfoundry/go-mod-bootstrap/v3/bootstrap/container"
13+
bootstrapInterfaces "github.com/edgexfoundry/go-mod-bootstrap/v3/bootstrap/interfaces"
14+
"github.com/edgexfoundry/go-mod-bootstrap/v3/bootstrap/secret"
1315
"github.com/edgexfoundry/go-mod-bootstrap/v3/di"
1416

17+
"github.com/edgexfoundry/go-mod-core-contracts/v3/clients/interfaces"
1518
"github.com/edgexfoundry/go-mod-core-contracts/v3/errors"
1619
"github.com/edgexfoundry/go-mod-core-contracts/v3/models"
1720
)
@@ -23,12 +26,13 @@ type Sender interface {
2326

2427
// RESTSender is the implementation of the interfaces.ChannelSender, which is used to send the notifications via REST
2528
type RESTSender struct {
26-
dic *di.Container
29+
dic *di.Container
30+
secretProvider bootstrapInterfaces.SecretProviderExt
2731
}
2832

2933
// NewRESTSender creates the RESTSender instance
30-
func NewRESTSender(dic *di.Container) Sender {
31-
return &RESTSender{dic: dic}
34+
func NewRESTSender(dic *di.Container, secretProvider bootstrapInterfaces.SecretProviderExt) Sender {
35+
return &RESTSender{dic: dic, secretProvider: secretProvider}
3236
}
3337

3438
// Send sends the REST request to the specified address
@@ -39,9 +43,13 @@ func (sender *RESTSender) Send(notification models.Notification, address models.
3943
if !ok {
4044
return "", errors.NewCommonEdgeX(errors.KindContractInvalid, "fail to cast Address to RESTAddress", nil)
4145
}
42-
// NOTE: Not currently passing an AuthenticationInjector here;
43-
// no current notifications are calling EdgeX services
44-
return utils.SendRequestWithRESTAddress(lc, notification.Content, notification.ContentType, restAddress, nil)
46+
47+
var injector interfaces.AuthenticationInjector
48+
if restAddress.InjectEdgeXAuth {
49+
injector = secret.NewJWTSecretProvider(sender.secretProvider)
50+
}
51+
52+
return utils.SendRequestWithRESTAddress(lc, notification.Content, notification.ContentType, restAddress, injector)
4553
}
4654

4755
// EmailSender is the implementation of the interfaces.ChannelSender, which is used to send the notifications via email

internal/support/notifications/init.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ func NewBootstrap(router *echo.Echo, serviceName string) *Bootstrap {
5050
func (b *Bootstrap) BootstrapHandler(ctx context.Context, _ *sync.WaitGroup, _ startup.Timer, dic *di.Container) bool {
5151
LoadRestRoutes(b.router, dic, b.serviceName)
5252

53-
restSender := channel.NewRESTSender(dic)
53+
restSender := channel.NewRESTSender(dic, bootstrapContainer.SecretProviderExtFrom(dic.Get))
5454
emailSender := channel.NewEmailSender(dic)
5555
dic.Update(di.ServiceConstructorMap{
5656
channel.RESTSenderName: func(get di.Get) interface{} {

openapi/v3/support-notifications.yaml

+3
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,9 @@ components:
102102
httpMethod:
103103
description: "Indicates which Http verb should be used for the REST endpoint."
104104
type: string
105+
injectEdgeXAuth:
106+
description: "Specifies whether or not to inject the EdgeX services JWT into the request."
107+
type: boolean
105108
required:
106109
- type
107110
- host

0 commit comments

Comments
 (0)