rode / grafeas-elasticsearch

An implementation of the Grafeas storage backend based on Elasticsearch
Apache License 2.0
12 stars 5 forks source link

Updates to occurrence details require an invalid field mask #68

Open alexashley opened 3 years ago

alexashley commented 3 years ago

From this discussion: https://github.com/rode/collector-build/pull/4#discussion_r603450950

Occurrence details vary depending on the kind and so are implemented using a oneof field in the protobuf definition

Generally, oneof fields aren't treated as part of the message and instead the actual name of the set field is used. For instance, there's no details field when using protojson to serialize an occurrence. They also shouldn't appear in field masks.

However, the fieldmask-utils library used in occurrence updates requires that to be passed, see this issue for more details:

https://github.com/mennanov/fieldmask-utils/pull/15

This is easy to work around when calling Grafeas using gRPC; however, it's more of an issue with HTTP requests. Because of the design of the Grafeas protos, it's not possible to pass the field mask in the request; instead gRPC gateway fills in the mask automatically based on the request body.

As a result it doesn't seem possible to update the details of an occurrence using HTTP.

In terms of fixing it there doesn't seem to be an official method for merging that takes into account the field mask. See this issue:

https://github.com/golang/protobuf/issues/1296

There's a proto.Merge function; however it doesn't take a field mask. Its behavior is also such that arrays are concatenated, rather than replaced and that's not configurable.

It might be easiest to use something like mergo to handle the actual merge and then see what options are available for filtering the request body using the field mask.