generated from TrueCloudLab/basic
[#60] chain: Support numeric conditions #60
No reviewers
Labels
No labels
Infrastructure
blocked
bug
config
discussion
documentation
duplicate
enhancement
go
help wanted
internal
invalid
kludge
observability
perfomance
question
refactoring
wontfix
No milestone
No project
No assignees
6 participants
Notifications
Due date
No due date set.
Dependencies
No dependencies set.
Reference: TrueCloudLab/policy-engine#60
Loading…
Reference in a new issue
No description provided.
Delete branch "mbiryukova/policy-engine:feature/numeric_conditions"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Signed-off-by: Marina Biryukova m.biryukova@yadro.com
80571b9c1f
tocc3259379f
[#xx] chain: Support numeric conditionsto [#60] chain: Support numeric conditionscc3259379f
toe5b7e1f763
@ -385,6 +385,12 @@ func TestConvertToChainCondition(t *testing.T) {
CondArnLike: {condKeyAWSPrincipalARN: {principal}},
CondArnNotEquals: {"key18": {"val18"}},
CondArnNotLike: {"key19": {"val19"}},
CondNumericEquals: {"key20": {"20"}},
negative, zero, hex, binary values tests should be added.
also values with spaces, with '+' sign.
AWS supports only integer and decimals. So here (in
converter_test.go
) I wouldn't add hex/binary values.If this is required we can support such values in native condition types and add tests there.
Tests should not be only positive. I was expecting to see a negative binary and hex test. Also we need to support decimals)
@ -191,2 +195,3 @@
func (r *Rule) Match(req resource.Request) (status Status, matched bool) {
func (c *Condition) matchNumeric(val string) (bool, error) {
valInt, err := strconv.ParseInt(val, 10, 64)
Probably we should try parse float if parsing integer failed because spec says
Numeric condition operators let you construct Condition elements that restrict access based on comparing a key to an integer or decimal value.
Can we parse only float in this case?
No. In general we cannot do this because equals for float can have some error:
Or we have to write custom equal function and not use
==
What is the length of a decimal?
neo-go has a fixed decimal package https://github.com/nspcc-dev/neo-go/blob/master/pkg/encoding/fixedn/decimal.go (and we already depend on neo-go)
Do we have any compatibility tests here? The description at the link you have provided is vague.
I couldn't find more precise description of this conditions. So we decided to use
1e-8
precision. We can use decimal from neo-go I thinke5b7e1f763
to18aa3a3442
18aa3a3442
tod06de615ad
@ -192,0 +215,4 @@
case CondNumericLessThan:
return valFloat < condVal
case CondNumericLessThanEquals:
return valFloat <= condVal
I suppose the correct way is to compare them like this
LGTM, but see comment
d06de615ad
to8af1392faf
@ -276,2 +294,4 @@
}
func numericConvertFunction(val string) (string, error) {
if _, err := strconv.ParseFloat(val, 64); err == nil {
+Inf
,inf
,NaN
,nan
are valid float strings, see https://pkg.go.dev/strconv#example-ParseFloatDoes IAM supports it?
No. But now we use Fixed8 and it doesn't support it.
Probably we should include this
+Inf, inf, NaN, nan
in test cases8af1392faf
todf6b80cd2a
df6b80cd2a
to4bdc8d679a
4bdc8d679a
to84c6be01de