forked from flipt-io/flipt
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Empty string constraint fixes (flipt-io#193)
* Fix issue where != would evaluate to true if constraint value was not present * Require value for constraints unless operator is one of [empty, not empty, present, not present] * Move validation into middleware * Move errors into own package
- Loading branch information
1 parent
df73704
commit 434a58b
Showing
30 changed files
with
2,029 additions
and
1,719 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
ignore: | ||
- "rpc/flipt.pb.*" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
package errors | ||
|
||
import ( | ||
"errors" | ||
"fmt" | ||
) | ||
|
||
// New creates a new error with errors.New | ||
func New(s string) error { | ||
return errors.New(s) | ||
} | ||
|
||
// ErrNotFound represents a not found error | ||
type ErrNotFound string | ||
|
||
// ErrNotFoundf creates an ErrNotFound using a custom format | ||
func ErrNotFoundf(format string, args ...interface{}) error { | ||
return ErrNotFound(fmt.Sprintf(format, args...)) | ||
} | ||
|
||
func (e ErrNotFound) Error() string { | ||
return fmt.Sprintf("%s not found", string(e)) | ||
} | ||
|
||
// ErrInvalid represents an invalid error | ||
type ErrInvalid string | ||
|
||
// ErrInvalidf creates an ErrInvalid using a custom format | ||
func ErrInvalidf(format string, args ...interface{}) error { | ||
return ErrInvalid(fmt.Sprintf(format, args...)) | ||
} | ||
|
||
func (e ErrInvalid) Error() string { | ||
return string(e) | ||
} | ||
|
||
// ErrValidation is a validation error for a specific field and reason | ||
type ErrValidation struct { | ||
field string | ||
reason string | ||
} | ||
|
||
func (e ErrValidation) Error() string { | ||
return fmt.Sprintf("invalid field %s: %s", e.field, e.reason) | ||
} | ||
|
||
// InvalidFieldError creates an ErrInvalidField for a specific field and reason | ||
func InvalidFieldError(field, reason string) error { | ||
return ErrValidation{field, reason} | ||
} | ||
|
||
// EmptyFieldError creates an ErrInvalidField for an empty field | ||
func EmptyFieldError(field string) error { | ||
return InvalidFieldError(field, "must not be empty") | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
package flipt | ||
|
||
const ( | ||
OpEQ = "eq" | ||
OpNEQ = "neq" | ||
OpLT = "lt" | ||
OpLTE = "lte" | ||
OpGT = "gt" | ||
OpGTE = "gte" | ||
OpEmpty = "empty" | ||
OpNotEmpty = "notempty" | ||
OpTrue = "true" | ||
OpFalse = "false" | ||
OpPresent = "present" | ||
OpNotPresent = "notpresent" | ||
OpPrefix = "prefix" | ||
OpSuffix = "suffix" | ||
) | ||
|
||
var ( | ||
ValidOperators = map[string]struct{}{ | ||
OpEQ: {}, | ||
OpNEQ: {}, | ||
OpLT: {}, | ||
OpLTE: {}, | ||
OpGT: {}, | ||
OpGTE: {}, | ||
OpEmpty: {}, | ||
OpNotEmpty: {}, | ||
OpTrue: {}, | ||
OpFalse: {}, | ||
OpPresent: {}, | ||
OpNotPresent: {}, | ||
OpPrefix: {}, | ||
OpSuffix: {}, | ||
} | ||
NoValueOperators = map[string]struct{}{ | ||
OpEmpty: {}, | ||
OpNotEmpty: {}, | ||
OpPresent: {}, | ||
OpNotPresent: {}, | ||
} | ||
StringOperators = map[string]struct{}{ | ||
OpEQ: {}, | ||
OpNEQ: {}, | ||
OpEmpty: {}, | ||
OpNotEmpty: {}, | ||
OpPrefix: {}, | ||
OpSuffix: {}, | ||
} | ||
NumberOperators = map[string]struct{}{ | ||
OpEQ: {}, | ||
OpNEQ: {}, | ||
OpLT: {}, | ||
OpLTE: {}, | ||
OpGT: {}, | ||
OpGTE: {}, | ||
OpPresent: {}, | ||
OpNotPresent: {}, | ||
} | ||
BooleanOperators = map[string]struct{}{ | ||
OpTrue: {}, | ||
OpFalse: {}, | ||
OpPresent: {}, | ||
OpNotPresent: {}, | ||
} | ||
) |
Oops, something went wrong.