diff options
author | John Keiser <jkeiser@opscode.com> | 2014-07-24 20:12:22 -0600 |
---|---|---|
committer | John Keiser <jkeiser@opscode.com> | 2014-08-22 09:20:48 -0700 |
commit | 512267cdd9efd90095db8c70874727d489852e70 (patch) | |
tree | 4aab41b3771417a317c14597171fd132c5552053 | |
parent | c5a81a1d9c2d04c0c3997b1ff75ba231a1ab01d1 (diff) | |
download | chef-zero-512267cdd9efd90095db8c70874727d489852e70.tar.gz |
Move owners_of to AclBase
-rw-r--r-- | lib/chef_zero/data_store/default_facade.rb | 38 | ||||
-rw-r--r-- | lib/chef_zero/endpoints/acl_base.rb | 42 |
2 files changed, 41 insertions, 39 deletions
diff --git a/lib/chef_zero/data_store/default_facade.rb b/lib/chef_zero/data_store/default_facade.rb index 6f69a82..49439b9 100644 --- a/lib/chef_zero/data_store/default_facade.rb +++ b/lib/chef_zero/data_store/default_facade.rb @@ -218,44 +218,6 @@ module ChefZero real_store.exists_dir?(path) || default(path) end - def self.is_created_with_org?(path, osc_compat = false) - return false if path.size == 0 || path[0] != 'organizations' - value = org_defaults(path[1], 'pivotal', [], osc_compat) - for part in path[2..-1] - break if !value - value = value[part] - end - return !!value - end - - # Used by owners_of to find all owners of a thing by looking up - # the trail of directories - def self.list_metadata(data, path, metadata_type, *options) - begin - result = data.list([ 'metadata', metadata_type, path.join('/') ]) - rescue DataNotFoundError - result = [] - end - if options.include?(:recurse_up) && path.size >= 1 - result = list_metadata(data, path[0..-2], metadata_type, *options) | result - end - return result - end - - def self.owners_of(data, path) - # The objects that were created with the org itself, and containers for - # some reason, have the peculiar property of missing pivotal from their acls. - if is_created_with_org?(path, false) || path[0] == 'organizations' && path[2] == 'containers' - list_metadata(data, path[0..1], 'owners') - else - result = list_metadata(data, path, 'owners', :recurse_up) - if path.size == 4 && path[0] == 'organizations' && path[2] == 'clients' - result |= [ path[3] ] - end - result - end - end - def self.org_defaults(name, creator, superusers, osc_compat) result = { 'clients' => { diff --git a/lib/chef_zero/endpoints/acl_base.rb b/lib/chef_zero/endpoints/acl_base.rb index ea2ad81..ca51420 100644 --- a/lib/chef_zero/endpoints/acl_base.rb +++ b/lib/chef_zero/endpoints/acl_base.rb @@ -26,7 +26,7 @@ module ChefZero end # We merge owners into every acl, because we're awesome like that. - owners = DataStore::DefaultFacade.owners_of(data_store, path) + owners = owners_of(path) %w(create read update delete grant).each do |perm| acls[perm] ||= {} @@ -37,6 +37,8 @@ module ChefZero acls end + private + def get_container_acls(request, path) if path[0] == 'organizations' if %w(clients containers cookbooks data environments groups nodes roles sandboxes).include?(path[2]) @@ -47,6 +49,44 @@ module ChefZero end return nil end + + def owners_of(path) + # The objects that were created with the org itself, and containers for + # some reason, have the peculiar property of missing pivotal from their acls. + if is_created_with_org?(path, false) || path[0] == 'organizations' && path[2] == 'containers' + list_metadata(path[0..1], 'owners') + else + result = list_metadata(path, 'owners', :recurse_up) + if path.size == 4 && path[0] == 'organizations' && path[2] == 'clients' + result |= [ path[3] ] + end + result + end + end + + def is_created_with_org?(path, osc_compat = false) + return false if path.size == 0 || path[0] != 'organizations' + value = DataStore::DefaultFacade.org_defaults(path[1], 'pivotal', [], osc_compat) + for part in path[2..-1] + break if !value + value = value[part] + end + return !!value + end + + # Used by owners_of to find all owners of a thing by looking up + # the trail of directories + def list_metadata(path, metadata_type, *options) + begin + result = data_store.list([ 'metadata', metadata_type, path.join('/') ]) + rescue DataStore::DataNotFoundError + result = [] + end + if options.include?(:recurse_up) && path.size >= 1 + result = list_metadata(path[0..-2], metadata_type, *options) | result + end + return result + end end end end |