-
Notifications
You must be signed in to change notification settings - Fork 54
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
Update YAML permissions in configuration #1564
Conversation
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.
Looks like this basically works, and I like the documentation updates.
I would just suggest that we can improve the error checking and the decimal number conversion. See in-code comments.
ldms/python/ldmsd/parser_util.py
Outdated
if type(perm_str) is not str: | ||
raise TypeError(f'Error: YAML "perms" value must be a string') | ||
nperm = '0' | ||
if len(perm_str.split('-')) > 1: |
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 see what you are going for here: differentiating between the unix-line string case, and the case where it is all digits (a octal permsion). I think we can make this a step more pythonic, and clearer to read if we use:
if not perm_str.isdecimal()
ldms/python/ldmsd/parser_util.py
Outdated
f'Allowed format: (r|-)(w|-)-(r|-)(w|-)-(r|-)(w|-)-') | ||
i = 0 | ||
x = 0 | ||
for ch in perm_str: |
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 there isn't checking to see if the letters are correctly "r" or "w, or that the "x" positions are "-". So this would be accepted right now
Qf-ltoxep
No bits set, of course, but I think that needs to raise an error.:)
I think I would probably just use a regex something like below. The regex takes care of all the correctness checking, and we just need to sum up the bit values.
perms_pattern = re.compile('(?:(r)|-)(?:(w)|-)-(?:(r)|-)(?:(w)|-)-(?:(r)|-)(?:(w)|-)-')
m = perms_pattern.fullmatch(sys.argv[1])
if not m:
raise ValueError("whatever")
perms = 0
if m.group(1):
perms += 0o400
if m.group(2):
perms += 0o200
if m.group(3):
perms += 0o040
if m.group(4):
perms += 0o020
if m.group(5):
perms += 0o004
if m.group(6):
perms += 0o002
perm_str = '0'+oct(perms)[2:]
ldms/python/ldmsd/parser_util.py
Outdated
try: | ||
z = int(perm_str[0]) | ||
return perm_str[0] | ||
z = int(perm_str) |
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 would suggest that we always treat the decimal string as octal:
z = int(perm_str, base=8)
perm_str = '0'+oct(z)[:2]
Then the user doesn't have to be as careful with octal. All of these would work from a string:
perm: "640"
perm: "0640"
perm: "0o640"
I don't think we need to support non-octal decimals for this.
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 think this would be staggeringly confusing for the user. No need to be clever. Support something we can document. Let's support what strtoul(x, NULL, 0) would do and then refer to this in our doc.
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 think this would be staggeringly confusing for the user. No need to be clever. Support something we can document. Let's support what strtoul(x, NULL, 0) would do and then refer to this in our doc.
I can't see how interpreting "640" as rw-r-----, what basically every user would expect for permissions bits, is "staggeringly confusing" or even particularly clever. Could you elaborate on why that would be? Do you know any people that regularly do permission bits in base 10?
I think using base 8 translation for things that are octal like this is pretty ordinary. I don't claim to have thought that up.
I think most users would be rather confused to put in "640" and get, at best, "r--------". (Is there even any error checking for numbers with bits out of the expected range?)
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'll point out too, that "chmod" doesn't accept base-10 numbers, only base-8. Decimals digits are assumed to be base-8 as I have proposed.
Likewise, when dealing with file permissions in the "find" command, it only interprets digits as base-8.
The more that I look around, the only staggeringly confusing thing seems to be that ldmsd has ever accepted perms that were not in octal form.
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.
Yes @morrone, there is a third parameter to strtoul, which is the base. I was talking about the python format "0o123".isdecimal() which is what you proposed and returns false. This is a $1 problem on which OGC has spent $1000. Nick is working on adding the checking for any character other than 'r', 'w', and '-'...which is 1 line of code. I agree with you that specifying permissions in base 10 doesn't make much sense....which leaves...exactly what was suggested.
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, you didn't say that. I'm just fine with "0o123".isdecimal() not working. That wasn't at all the driving issue. The main issue was making it octal-only rather than base 10. I supplied most of the code to make the changes that I suggested, and if it is a monetary issue to integrate them further, you could say that as well, and I'll supply the full patch.
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.
or the regex:
(0o)?\d+
instead of .decimal()
@morrone, @nick-enoent, @emdonat happy with this? I need to merge it very soon. |
@nick-enoent could you please fix the conflicts and force push the result. |
112a261
to
2e621e1
Compare
Updated. |
Add cache_ip option to aggregators->peers
Update documentation