protoc-gen-validate icon indicating copy to clipboard operation
protoc-gen-validate copied to clipboard

Add CIDR validation for strings

Open ccakes opened this issue 2 years ago • 2 comments

This adds a new well known validation for strings which checks the input is a valid IP prefix in CIDR notation.

Example

message IPRoute {
  string prefix = 1 [(validate.rules).string.cidr = true];
  oneof egress {
    string interface = 2;
    string nexthop = 3 [(validate.rules).string.ip = true];
  };
}

I added the validation to the Java code as well but I'm not a Java dev so it could be fine, or could be terrible. Hoping unit tests will pick up whether its at least functional but feedback on that point very welcome.

ccakes avatar Apr 29 '22 02:04 ccakes

Ping @snowp is it possible to get this reviewed and hopefully merged?

ccakes avatar Jun 23 '22 01:06 ccakes

Hi @ccakes, thanks for your contribution and your continued patience in this.

To get this over the line, I'd like to see a test... there are places for declaring test cases, e.g. for string const constraint: https://github.com/envoyproxy/protoc-gen-validate/blob/dc51e59d2e463996ef24e45621cf61f95fa64b0f/tests/harness/cases/strings.proto#L8 https://github.com/envoyproxy/protoc-gen-validate/blob/dc51e59d2e463996ef24e45621cf61f95fa64b0f/tests/harness/executor/cases.go#L739

You should be able to fit this into the relevant string tests in these directories.

elliotmjackson avatar Sep 16 '22 15:09 elliotmjackson