thomaspoignant / go-feature-flag

GO Feature Flag is a simple, complete and lightweight self-hosted feature flag solution 100% Open Source. 🎛️
https://gofeatureflag.org/
MIT License
1.26k stars 123 forks source link

(question) Rule query syntax validation #2201

Open niccolocast opened 1 month ago

niccolocast commented 1 month ago

Your question

Is query syntax validation without evaluation possible? For example calling a function that returns an error if a user tries to add a malformed rule query like ((env eq "pro") and (company eq "go-feature-flag")

thomaspoignant commented 1 month ago

Hi @niccolocast, I have looked at your question and checked in the nikunjy/rules what was possible to do to validate a rule.

I came to this simple solution that works partially:

func eval(rule string) error {
    ev, err := parser.NewEvaluator(rule)
    if err != nil {
        return err
    }
    _, err = ev.Process(map[string]interface{}{})
    return err
}

If the eval function error it means that the rule is invalid. That being said it does not catch all the use-cases, your example is considered valid while it should not.

To have a bit more info, I have opened this issue https://github.com/nikunjy/rules/issues/41 on the nikunjy/rules repository. If I know more about it I will let you know.