Skip to content

NBI validation for entity attributes

Andre Sterba requested to merge nbi-grpc-validation into master

Description

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.

Related Issue

Motivation and Context

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.

Screenshots (if appropriate):

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:

Screenshot_from_2023-06-29_07-50-58

Edited by Andre Sterba

Merge request reports

Loading