Skip to content

[Feature Request] Allow complex types for value of rule CEL variable. #446

@jmmills

Description

@jmmills

Feature description:

Currently the value of the rule variable seems to only work with primitive types rather than custom messages

Works:

extend buf.validate.StringRules {
  optional string allow = 536870909 [(buf.validate.predefined).cel = {
    id: "string.identifier"
    message: "field must be a valid identifier"
    expression: "this == rule"
  }];

Does not work:

extend buf.validate.StringRules {
  optional ComplexRule allow = 536870909 [(buf.validate.predefined).cel = {
    id: "string.identifier"
    message: "field must be a valid identifier"
    expression: "rule.enabled && this == rule.value"
  }];

message ComplexRule {
    optional bool enabled = 1;
    optional string value = 2;
}

Problem it solves or use case:
This would allow more complex rules to be written in a cleaner fashion.

Proposed implementation or solution:
When the value of the predefined rule type is a proto message supply it as the value for rule.

Contribution:
I'm willing to attempt a PR if the maintainers don't have any deeper reason why this should not be allowed.

Metadata

Metadata

Assignees

No one assigned

    Labels

    FeatureNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions