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

Send events only if StatusCode is OK #2621

Merged
merged 1 commit into from
Mar 8, 2022
Merged
Show file tree
Hide file tree
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
5 changes: 5 additions & 0 deletions changelog/unreleased/send-events-only-if-ok.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Bugfix: send events only if response code is `OK`

Before events middleware was sending events also when the resulting status code was not `OK`. This is clearly a bug.

https://github.com/cs3org/reva/pull/2621
5 changes: 4 additions & 1 deletion internal/grpc/interceptors/eventsmiddleware/events.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import (
"google.golang.org/grpc"

"github.com/asim/go-micro/plugins/events/nats/v4"
rpc "github.com/cs3org/go-cs3apis/cs3/rpc/v1beta1"
collaboration "github.com/cs3org/go-cs3apis/cs3/sharing/collaboration/v1beta1"
"github.com/cs3org/reva/v2/pkg/events"
"github.com/cs3org/reva/v2/pkg/events/server"
Expand Down Expand Up @@ -58,7 +59,9 @@ func NewUnary(m map[string]interface{}) (grpc.UnaryServerInterceptor, int, error
var ev interface{}
switch v := res.(type) {
case *collaboration.CreateShareResponse:
ev = ShareCreated(v)
if v.Status.Code == rpc.Code_CODE_OK {
ev = ShareCreated(v)
}
}

if ev != nil {
Expand Down
2 changes: 1 addition & 1 deletion pkg/events/example/example.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ func Server() {

// Client builds a nats client
func Client() events.Stream {
c, err := server.NewNatsStream(nats.Address("127.0.0.1:4222"), nats.ClusterID("test-cluster"))
c, err := server.NewNatsStream(nats.Address("127.0.0.1:9233"), nats.ClusterID("test-cluster"))
if err != nil {
log.Fatal(err)
}
Expand Down