This MR provides basic validation (e.g. name of an entity must be provided) on the NBI gRPC layer.
It is based on protovalidate by buf, which uses protovalidate-go underneath.
Currently it is very easy to crash the controller by simply not providing a needed field via a NBI request. For example create a new entity and don't provide some configuration field.
Example for link.proto
with validation rule:
message Link {
string id = 1 [(buf.validate.field).string.min_len = 1];
...
}
The validator can the can be called in the respective NBI server implementation via:
v, err := protovalidate.New()
if err != nil {
return nil, status.Errorf(codes.Aborted, "%v", err)
}
if err = v.Validate(request); err != nil {
return nil, status.Errorf(codes.Aborted, "%v", err)
} else {
logrus.Info("validation succeeded")
}
If the request is not valid, the caller will get this message: