Skip to content
This repository has been archived by the owner on Jun 19, 2022. It is now read-only.

Commit

Permalink
Stop special-case unmarhalling json from pubsub. (#554)
Browse files Browse the repository at this point in the history
Instead, leave it in base64 like every other format.
  • Loading branch information
bskaplan authored Feb 14, 2020
1 parent 77812df commit 7075f74
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 13 deletions.
12 changes: 1 addition & 11 deletions pkg/pubsub/adapter/converters/pubsub.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ package converters

import (
"context"
"encoding/json"
"time"

cloudevents "github.com/cloudevents/sdk-go"
Expand Down Expand Up @@ -60,16 +59,7 @@ func convertPubSub(ctx context.Context, msg *cepubsub.Message, sendMode ModeType
ID: event.ID(),
Attributes: msg.Attributes,
PublishTime: event.Time(),
}

var raw json.RawMessage
if err := event.DataAs(&raw); err != nil {
logger.Desugar().Debug("Failed to get data as raw json, using as is.", zap.Error(err))
// Use data as a byte slice.
msg.Data = event.Data
} else {
// Use data as a raw message.
msg.Data = raw
Data: event.Data,
}

if err := event.SetData(&PushMessage{
Expand Down
4 changes: 2 additions & 2 deletions pkg/pubsub/adapter/converters/pubsub_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ func TestConvertCloudPubSub(t *testing.T) {
return pubSubPushCloudEvent(map[string]string{
"attribute1": "value1",
"Invalid-Attrib#$^": "value2",
}, "\"test data\"")
}, "\"InRlc3QgZGF0YSI=\"")
},
}, {
name: "Push mode with no attributes",
Expand All @@ -126,7 +126,7 @@ func TestConvertCloudPubSub(t *testing.T) {
},
sendMode: Push,
wantEventFn: func() *cloudevents.Event {
return pubSubPushCloudEvent(nil, "\"test data\"")
return pubSubPushCloudEvent(nil, "\"InRlc3QgZGF0YSI=\"")
},
}}

Expand Down

0 comments on commit 7075f74

Please sign in to comment.