mirror of
https://github.com/pomerium/pomerium.git
synced 2025-05-28 16:37:24 +02:00
databroker: add support for field masks on Put (#3210)
* databroker: add support for field masks on Put * return errors * clean up go.mod
This commit is contained in:
parent
8fc5dbf4c5
commit
2dc778035d
15 changed files with 381 additions and 134 deletions
31
pkg/protoutil/mask.go
Normal file
31
pkg/protoutil/mask.go
Normal file
|
@ -0,0 +1,31 @@
|
|||
package protoutil
|
||||
|
||||
import (
|
||||
"github.com/mennanov/fmutils"
|
||||
"google.golang.org/protobuf/proto"
|
||||
"google.golang.org/protobuf/types/known/anypb"
|
||||
"google.golang.org/protobuf/types/known/fieldmaskpb"
|
||||
)
|
||||
|
||||
// MergeAnyWithFieldMask merges the data in src with the data in dst,
|
||||
// but only the fields identified by the given mask.
|
||||
func MergeAnyWithFieldMask(dst, src *anypb.Any, mask *fieldmaskpb.FieldMask) (*anypb.Any, error) {
|
||||
if mask == nil {
|
||||
return src, nil
|
||||
}
|
||||
|
||||
srcMsg, err := src.UnmarshalNew()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
dstMsg, err := dst.UnmarshalNew()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
fmutils.Filter(srcMsg, mask.GetPaths())
|
||||
proto.Merge(dstMsg, srcMsg)
|
||||
|
||||
return anypb.New(dstMsg)
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue