You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Originally this problem was reported by one of OpenStack operators : when he used TripleO to tune API policies for one of the services, he ended up having valid JSON file, which looked invalid from operator's perspective. After taking a second look at this issue we have figured out that this is cause by Json.lns. I want to kindly ask you to take a look at the following steps to reproduce and let us know if this is a cosmetic issue that could be fixed or a feature.
root@ubuntu:~# cat /tmp/policy.json
{
"context_is_admin": "role:admin or role:load-balancer_admin",
"admin_or_owner": "is_admin:True or project_id:%(project_id)s",
"load-balancer:read": "rule:admin_or_owner",
"load-balancer:read-global": "is_admin:True",
"load-balancer:write": "rule:admin_or_owner",
"load-balancer:read-quota": "rule:admin_or_owner",
"load-balancer:read-quota-global": "is_admin:True",
"load-balancer:write-quota": "is_admin:True"
}
root@ubuntu:~# augtool --version
augtool 1.14.1 <http://augeas.net/>
Copyright (C) 2007-2016 David Lutterkort
License LGPLv2+: GNU LGPL version 2.1 or later
<http://www.gnu.org/licenses/lgpl-2.1.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.
Written by David Lutterkort
root@ubuntu:~# augtool
augtool> set /augeas/load/Json/lens Json.lns
augtool> set /augeas/load/Json/incl /tmp/policy.json
augtool> load
augtool> set /files/tmp/policy.json/dict/entry[last()+1] 'groups'
augtool> touch /files/tmp/policy.json/dict/entry[last()]/array
augtool> save
Saved 1 file(s)
augtool> quit
root@ubuntu:~# cat /tmp/policy.json
{
"context_is_admin": "role:admin or role:load-balancer_admin",
"admin_or_owner": "is_admin:True or project_id:%(project_id)s",
"load-balancer:read": "rule:admin_or_owner",
"load-balancer:read-global": "is_admin:True",
"load-balancer:write": "rule:admin_or_owner",
"load-balancer:read-quota": "rule:admin_or_owner",
"load-balancer:read-quota-global": "is_admin:True",
"load-balancer:write-quota": "is_admin:True"
,
"groups":[]}
The text was updated successfully, but these errors were encountered:
In general, Augeas lenses create files which are syntactically correct for a given syntax (such as Json), they do not necessarily make them "pretty".
Part of the problem is that for many languages such as JSON, spaces are not significant. So when a new entry is created, the amount of space that can or should be inserted becomes arbitrary.
In this case, it may be possible to update the lens to produce a more readable output, though I expect the indentation would remain messy.
I find it odd that appending another entry after "groups" inserts the new entry directly between previous one and the }
> augtool --noload --noautoload
augtool> set /augeas/load/Json/lens Json.lns
augtool> set /augeas/load/Json/incl /tmp/policy.json
augtool> load-file /tmp/policy.json
augtool> set /files/tmp/policy.json/dict/entry[last()+1] 'extra1'
augtool> set /files/tmp/policy.json/dict/entry[.='extra1']/string 'hello'
augtool> set /files/tmp/policy.json/dict/entry[last()+1] 'extra2'
augtool> set /files/tmp/policy.json/dict/entry[.='extra2']/string 'world'
augtool> preview /files/tmp/policy.json/
{
"context_is_admin": "role:admin or role:load-balancer_admin",
"admin_or_owner": "is_admin:True or project_id:%(project_id)s",
"load-balancer:read": "rule:admin_or_owner",
"load-balancer:read-global": "is_admin:True",
"load-balancer:write": "rule:admin_or_owner",
"load-balancer:read-quota": "rule:admin_or_owner",
"load-balancer:read-quota-global": "is_admin:True",
"load-balancer:write-quota": "is_admin:True"
,
"extra1":"hello","extra2":"world"}augtool>
Originally this problem was reported by one of OpenStack operators : when he used TripleO to tune API policies for one of the services, he ended up having valid JSON file, which looked invalid from operator's perspective. After taking a second look at this issue we have figured out that this is cause by Json.lns. I want to kindly ask you to take a look at the following steps to reproduce and let us know if this is a cosmetic issue that could be fixed or a feature.
The text was updated successfully, but these errors were encountered: