Skip to content

[Feature Request] Lint cel expression #28

Closed

Description

@toshi0607

Feature description:

I would be happy if cel expression validation is supported.

Problem it solves or use case:

When I buf lint the following proto, the second mistake is caught by buf lint proto/xxx/greeting/v1/greeting.proto:35:79:field xxx.greeting.v1.SayHelloResponse.request_time: option (buf.validate.field).timestamp.lt_nowwww: field lt_nowwww of buf.validate.TimestampRules does not exist, but the first one (cel expression) is not. I'd like to know if the expression is valid or not.

message SayHelloResponse {
  string message_id = 1;

  string message = 2 [(buf.validate.field).cel = {
    id: "sayHelloResponse.message",
    message: "message must start with 'Hello, ' and shorter than 1024",
    expression: "(this.startsWith('Hello, ') && this.string.max_lennnn "
  }];

  google.protobuf.Timestamp request_time = 3  [(buf.validate.field).timestamp.lt_nowwwwwww = true];
}

Proposed implementation or solution:

Is it possible to validate expression like other tools like linting IAM condition that checks cel validity?
https://cloud.google.com/iam/docs/linting-policies

Contribution:

Examples or references:

Additional context:

Activity

  1. elliotmjackson commented on Jun 13, 2023

    @elliotmjackson
    Contributor

    Hi @toshi0607,

    Thank you so much for taking the time to bring this issue to our attention! I understand how validating CEL (Common Expression Language) expressions would be beneficial for ensuring the correctness and integrity of the configurations.

    I'm excited to share that supporting CEL expression validation is actually on our roadmap. We understand the importance of catching these errors early on, and we plan to enhance our linter to include this feature. It will help streamline the development process by detecting and providing feedback on CEL syntax and semantic issues.

    Your input is invaluable in helping us to shape the development of our project. We will keep the community posted on our progress, and we will definitely appreciate further feedback or suggestions as we work on the implementation.

    Please feel free to add any more details or thoughts if you have them. Thanks again for your contribution!

  2. toshi0607 commented on Jun 14, 2023

    @toshi0607
    Author

    Hi @elliotmjackson, I'm really looking forward to using the feature!

    Currently are there any ways to know if the expression is valid or not regardless of whether the check is static or dynamic?

    And we would be glad to know the approximate delivery time on the roadmap because we are wondering when to start writing rules in PGV2. We have recently started using proto and made the decision not to start writing rules in PGV1 because of the articles about PGV2 being released and saving time in v1 -> v2 migration.

  3. added a commit that references this issue on Jul 18, 2023
  4. rodaine commented on Jan 3, 2024

    @rodaine
    Member

    Fixed in bufbuild/buf#2505. buf lint now supports linting protovalidate rules, including CEL expression. It's enabled by the DEFAULT ruleset or can be added explicitly as PROTOVALIDATE

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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