Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(data): update validateEvent topic check #4345

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions internal/core/data/controller/messaging/subscriber.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//
// Copyright (C) 2021-2022 IOTech Ltd
// Copyright (C) 2021-2023 IOTech Ltd
//
// SPDX-License-Identifier: Apache-2.0

Expand All @@ -12,7 +12,7 @@ import (
"strings"

"github.com/edgexfoundry/go-mod-bootstrap/v3/config"
cbor "github.com/fxamacker/cbor/v2"
"github.com/fxamacker/cbor/v2"

"github.com/edgexfoundry/edgex-go/internal/core/data/application"
dataContainer "github.com/edgexfoundry/edgex-go/internal/core/data/container"
Expand Down Expand Up @@ -68,7 +68,7 @@ func SubscribeEvents(ctx context.Context, dic *di.Container) errors.EdgeX {
case e := <-messageErrors:
lc.Error(e.Error())
case msgEnvelope := <-messages:
lc.Debugf("Event received from MessageBus. Topic: %s, Correlation-id: %s ", subscribeTopic, msgEnvelope.CorrelationID)
lc.Debugf("Event received from MessageBus. Topic: %s, Correlation-id: %s", msgEnvelope.ReceivedTopic, msgEnvelope.CorrelationID)
event := &requests.AddEventRequest{}
// decoding the large payload may cause memory issues so checking before decoding
maxEventSize := dataContainer.ConfigurationFrom(dic.Get).MaxEventSize
Expand Down Expand Up @@ -114,11 +114,11 @@ func unmarshalPayload(envelope types.MessageEnvelope, target interface{}) error
}

func validateEvent(messageTopic string, e dtos.Event) errors.EdgeX {
// Parse messageTopic by the pattern `edgex/events/<device-profile-name>/<device-name>/<source-name>`
// Parse messageTopic by the pattern `edgex/events/device/<device-service-name>/<device-profile-name>/<device-name>/<source-name>`
fields := strings.Split(messageTopic, "/")

// assumes a non-empty base topic with /profileName/deviceName/sourceName appended by publisher
if len(fields) < 4 {
if len(fields) < 5 {
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@lenny-intel Do you think we still need to check this ? I didn't see the change in #4348

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe we need this check, and update the comment in line 120
however, why doesn't it if len(fields) < 6?

return errors.NewCommonEdgeX(errors.KindContractInvalid, fmt.Sprintf("invalid message topic %s", messageTopic), nil)
}

Expand Down