-
Notifications
You must be signed in to change notification settings - Fork 38
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fixes #8228: Add constraints to ncf parameters #350
Fixes #8228: Add constraints to ncf parameters #350
Conversation
@@ -16,6 +16,8 @@ | |||
import sys | |||
import os | |||
import codecs | |||
import ncf_constraints | |||
from pprint import pprint |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can remove this now, I guess it was just used for debugging
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Up?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I never remove pprint, you always need it.
Having to add it each time you debug and removing it just after is very tiring. Moreover it costs almost nothing.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I clearly agree with peck, we always need it
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK, fine. It's nice to answer comments though, even if you don't agree with them :)
956884c
to
76b1c25
Compare
PR updated |
As a reminder: |
"list" : { | ||
"check" : from_list | ||
, "type" : list | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Re-reading the email discussion we had about specs makes me notice the name you've used here: "list". I don't think this is a good name, because it is not clear what "constraint" "list" is imposing.
I prefer "enum" (which, to me at least, makes it clear that this constraint in an enumeration of possible values), but I'm open to other terms. Maybe "values"?
Thoughts?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if it's an enumeration, in the web world we use "select", which is fairly easily understood.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like the 'select' ! second choice would be 'values'. I don't like 'enum', and agree that list is not a good choice
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
'select' works for me. It matches nicely with Rudder's Techniques metadata.xml terminology, too.
PR updated |
bb99c43
to
f4d062d
Compare
There should be an issue for documenting the constraint syntax |
This PR needs a rebase |
|
||
def match_regex(parameter, regex): | ||
match = re.search(regex, parameter) | ||
return match is not None |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
re.S and re.M should be considered
It means that a parameter should be considered as a whole and we are matching it as is, not with separate lines. A new line can still be matched with \n, which is expected. And we can match things that couldn't be matched without those flags.
Example:
- the regex r"^A.\nB.$" matches a line starting with A followed by a line starting with B. This is not possible without re.M
- with re.S r"A.B." could match 2 lines with A in the first one and B in the second one. This may be counter intuitive.
So I'd say, use re.MULTILINE only.
Anyway, whatever the final behavior, the multiline case must be carefully documented.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should use re.UNICODE too, because all our strings are unicode and i would expect '\w' to match 'é' in the general case.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think we should use re.M
I think we want to check the whole value with our regex, so with you first case you would match
A
A
B
If you use re.M and would not match with other cases, and i think we don't want to match
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You're right, I mixed up the definition of re.M, it is the opposite.
Everything else is ok for me |
@peckpeck I made a separate commit so you can look on the changes |
c006e07
to
2491551
Compare
|
||
def not_match_regex(parameter_value, regex): | ||
return not match_regex(parameter_value, regex) | ||
result = match_regex(parameter_value, regex) is not None |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There should be a re.U here
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is changed in next commit :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
and match_regexp is not re.match !
PR updated |
681c612
to
7efc3e6
Compare
PR updated |
7efc3e6
to
5abd7cb
Compare
@@ -114,11 +114,8 @@ def check_parameter(parameter_value, parameter_constraints): | |||
constraint_set = constraints | |||
|
|||
# Check that our value contains a variable or not | |||
value_without_variables = re.sub(r'[\$@][\{\(][a-zA-Z0-9\[\]_.-]+[\}\)]', "", parameter_value) | |||
if parameter_value != value_without_variables: | |||
if re.search(r'[$@][{(][$@{(a-zA-Z0-9[\]_.-]+[})]', parameter_value) is not None : |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just for information, ][ instead of [] works too
PR updated |
5abd7cb
to
a808aa9
Compare
This PR is not mergeable to upper versions. |
https://www.rudder-project.org/redmine/issues/8228