Skip to content

Commit

Permalink
bug fix
Browse files Browse the repository at this point in the history
matthewpeterkort committed Nov 15, 2024
1 parent c9f36fe commit 694ef9d
Showing 3 changed files with 49 additions and 5 deletions.
44 changes: 44 additions & 0 deletions accounts/bulk_write_filter.go
Original file line number Diff line number Diff line change
@@ -52,3 +52,47 @@ func (bw *BulkWriteFilter) RecvMsg(m interface{}) error {
}
}
}

type BulkWriteRawFilter struct {
SS grpc.ServerStream
User string
Access Access
}

func (bw *BulkWriteRawFilter) SetHeader(m metadata.MD) error {
return bw.SS.SendHeader(m)
}

func (bw *BulkWriteRawFilter) SendHeader(m metadata.MD) error {
return bw.SS.SendHeader(m)
}

func (bw *BulkWriteRawFilter) SetTrailer(m metadata.MD) {
bw.SS.SetTrailer(m)
}

func (bw *BulkWriteRawFilter) Context() context.Context {
return bw.SS.Context()
}

func (bw *BulkWriteRawFilter) SendMsg(m interface{}) error {
return bw.SS.SendMsg(m)
}

func (bw *BulkWriteRawFilter) RecvMsg(m interface{}) error {
for {
var ge gripql.RawJson
err := bw.SS.RecvMsg(&ge)
if err != nil {
return err
}
err = bw.Access.Enforce(bw.User, ge.Graph, Write)
if err == nil {
mPtr := m.(*gripql.RawJson)
*mPtr = ge
return nil
} else {
log.Infof("Graph write error: %s", ge.Graph)
}
}
}
2 changes: 1 addition & 1 deletion accounts/util.go
Original file line number Diff line number Diff line change
@@ -145,7 +145,7 @@ func streamAuthInterceptor(auth Authenticate, access Access) grpc.StreamServerIn
return handler(srv, &BulkWriteFilter{ss, user, access})
} else if info.FullMethod == "/gripql.Edit/BulkAddRaw" {
// Not sure if need to write custom filter for this, but existing BulkWriteFilter does not work
return handler(srv, ss)
return handler(srv, &BulkWriteRawFilter{ss, user, access})
} else {
log.Errorf("Unknown input streaming op %#v!!!", info)
return handler(srv, ss)
8 changes: 4 additions & 4 deletions server/api.go
Original file line number Diff line number Diff line change
@@ -293,23 +293,23 @@ func (server *GripServer) BulkAddRaw(stream gripql.Edit_BulkAddRawServer) error
for _, element := range result {
if element.Vertex != nil {
elementStream <- &gdbi.GraphElement{
Vertex: &gdbi.DataElement{
Vertex: &gdbi.Vertex{
ID: element.Vertex.Gid,
Data: element.Vertex.Data.AsMap(),
Label: element.Vertex.Label,
},
Graph: element.Graph,
Graph: class.Graph,
}
} else {
elementStream <- &gdbi.GraphElement{
Edge: &gdbi.DataElement{
Edge: &gdbi.Edge{
ID: element.Edge.Gid,
Label: element.Edge.Label,
From: element.Edge.From,
To: element.Edge.To,
Data: element.Edge.Data.AsMap(),
},
Graph: element.Graph,
Graph: class.Graph,
}
}
insertCount++

0 comments on commit 694ef9d

Please sign in to comment.