diff options
-rw-r--r-- | lib/chef_zero/chef_data/acl_path.rb | 20 | ||||
-rw-r--r-- | lib/chef_zero/chef_data/default_creator.rb | 11 |
2 files changed, 16 insertions, 15 deletions
diff --git a/lib/chef_zero/chef_data/acl_path.rb b/lib/chef_zero/chef_data/acl_path.rb index 4592342..c783a1a 100644 --- a/lib/chef_zero/chef_data/acl_path.rb +++ b/lib/chef_zero/chef_data/acl_path.rb @@ -51,30 +51,28 @@ module ChefZero end end + # # Reverse transform from acl_data_path to path. # /acls/root -> / - # /acls/containers/TYPE -> /TYPE - # /acls/TYPE/NAME -> /TYPE/NAME - # /organizations/ORG/acls/root -> / - # /organizations/ORG/acls/containers/TYPE -> /organizations/ORG/TYPE - # /organizations/ORG/acls/TYPE/NAME -> /organizations/ORG/TYPE/NAME + # /acls/** -> /** + # /organizations/ORG/acls/root -> /organizations/ORG + # /organizations/ORG/acls/** -> /organizations/ORG/** + # + # This means that /acls/containers/nodes maps to + # /containers/nodes, not /nodes. # def self.get_object_path(acl_data_path) if acl_data_path[0] == 'acls' if acl_data_path[1] == 'root' [] - elsif acl_data_path[1] == 'containers' - [acl_data_path[2]] else - acl_data_path[1..2] + acl_data_path[1..-1] end elsif acl_data_path[0] == 'organizations' && acl_data_path[2] == 'acls' if acl_data_path[3] == 'root' acl_data_path[0..1] - elsif acl_data_path[3] == 'containers' - acl_data_path[0..1] + [ acl_data_path[4] ] else - acl_data_path[0..1] + acl_data_path[3..4] + acl_data_path[0..1] + acl_data_path[3..-1] end end end diff --git a/lib/chef_zero/chef_data/default_creator.rb b/lib/chef_zero/chef_data/default_creator.rb index f0403ab..b649cf1 100644 --- a/lib/chef_zero/chef_data/default_creator.rb +++ b/lib/chef_zero/chef_data/default_creator.rb @@ -62,7 +62,7 @@ module ChefZero def get(path) return nil if deleted?(path) - case path[0] + result = case path[0] when 'acls' # /acls/* object_path = AclPath.get_object_path(path) @@ -89,6 +89,8 @@ module ChefZero end end end + + result end def list(path) @@ -101,13 +103,13 @@ module ChefZero case path[0] when 'acls' if path.size == 1 - [ 'root' ] + data.list(path + [ 'containers' ]) + [ 'root' ] + (data.list(path + [ 'containers' ]) - [ 'organizations' ]) else data.list(AclPath.get_object_path(path)) end when 'containers' - [ 'containers', 'users' ] + [ 'containers', 'users', 'organizations' ] when 'users' superusers @@ -256,7 +258,8 @@ module ChefZero def get_org_acl_default(path) object_path = AclPath.get_object_path(path) - return nil if !data_exists?(object_path) + # The actual things containers correspond to don't have to exist, as long as the container does + return nil if object_path[2] != 'containers' && !data_exists?(object_path) basic_acl = case path[3..-1].join('/') when 'root', 'containers/containers', 'containers/groups' |