diff options
51 files changed, 229 insertions, 133 deletions
diff --git a/.travis.yml b/.travis.yml index 4fdfc7f..415a0e3 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,6 +1,3 @@ -rvm: 2.1 -gemfile: Gemfile - # This prevents testing branches that are created just for PRs branches: only: @@ -12,30 +9,41 @@ before_install: - gem install bundler sudo: false +language: ruby +cache: bundler + script: - bundle update - bundle exec rake pedant matrix: include: - - rvm: 2.1 + - rvm: 2.3.1 env: PEDANT_KNIFE_TESTS=true PEDANT_ALLOW_RVM=1 - - rvm: 2.1 + - rvm: 2.3.1 env: SINGLE_ORG=true - - rvm: 2.1 + - rvm: 2.3.1 env: CHEF_FS=true - - rvm: 2.1 - env: - - CHEF_FS=true - - "GEMFILE_MOD=\"gem 'chef', github: 'chef/chef'\"" - - rvm: 2.1 +# Commented out until we work with a released version again +# - rvm: 2.2.5 +# env: +# - CHEF_FS=true +# - "GEMFILE_MOD=\"gem 'chef', github: 'chef/chef'\"" +# - rvm: 2.3.1 +# env: +# - CHEF_FS=true +# - "GEMFILE_MOD=\"gem 'chef', github: 'chef/chef'\"" + - rvm: 2.3.1 env: FILE_STORE=true - - rvm: 2.1 + - rvm: 2.3.1 script: bundle exec rake chef_spec env: TEST=chef_spec - - rvm: 2.1 + - rvm: 2.2.5 + script: bundle exec rake spec + env: TEST=rake_spec + - rvm: 2.3.1 script: bundle exec rake spec env: TEST=rake_spec - - rvm: 2.1 + - rvm: 2.3.1 script: bundle exec rake style env: TEST=chefstyle diff --git a/CHANGELOG.md b/CHANGELOG.md index dfcc589..c043d68 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,7 +1,40 @@ # Change Log -## [4.8.0](https://github.com/chef/chef-zero/tree/4.8.0) (2016-07-25) -[Full Changelog](https://github.com/chef/chef-zero/compare/v4.7.1...4.8.0) +## [v5.1.1](https://github.com/chef/chef-zero/tree/v5.1.1) (2016-12-13) +[Full Changelog](https://github.com/chef/chef-zero/compare/v5.1.0...v5.1.1) + +**Implemented enhancements:** +- Add link to contributing docs and fix chefstyle warnings [\#245](https://github.com/chef/chef-zero/pull/245) ([tas50](https://github.com/tas50)) + +**Fixed bugs:** +- Fix pagination with start parameters [\#248](https://github.com/chef/chef-zero/pull/248) ([smith](https://github.com/smith)) +- Handle the start and rows parameters correctly [\#247](https://github.com/chef/chef-zero/pull/247) ([smith](https://github.com/smith)) + +## [v5.1.0](https://github.com/chef/chef-zero/tree/v5.1.0) (2016-09-07) +[Full Changelog](https://github.com/chef/chef-zero/compare/v5.0.0...v5.1.0) + +**Implemented enhancements:** + +- store ACEs by client/user [\#240](https://github.com/chef/chef-zero/pull/240) ([marcparadise](https://github.com/marcparadise)) + +## [v5.0.0](https://github.com/chef/chef-zero/tree/v5.0.0) (2016-08-24) +[Full Changelog](https://github.com/chef/chef-zero/compare/v4.9.0...v5.0.0) + +**Implemented enhancements:** + +- Support clients and users fields in ACL PUT requests [\#239](https://github.com/chef/chef-zero/pull/239) ([marcparadise](https://github.com/marcparadise)) +- Remove support for Ruby 2.1 [\#237](https://github.com/chef/chef-zero/pull/237) ([jkeiser](https://github.com/jkeiser)) + +## [v4.9.0](https://github.com/chef/chef-zero/tree/v4.9.0) (2016-08-11) +[Full Changelog](https://github.com/chef/chef-zero/compare/v4.8.0...v4.9.0) + +**Fixed bugs:** + +- Connect to chef zero default port in the playground [\#229](https://github.com/chef/chef-zero/pull/229) ([thommay](https://github.com/thommay)) +- Correct ruby syntax error to make script usable [\#228](https://github.com/chef/chef-zero/pull/228) ([AntonOfTheWoods](https://github.com/AntonOfTheWoods)) + +## [v4.8.0](https://github.com/chef/chef-zero/tree/v4.8.0) (2016-07-25) +[Full Changelog](https://github.com/chef/chef-zero/compare/v4.7.1...v4.8.0) **Implemented enhancements:** @@ -592,4 +625,4 @@ ## [v0.9](https://github.com/chef/chef-zero/tree/v0.9) (2012-12-24) -\* *This Change Log was automatically generated by [github_changelog_generator](https://github.com/skywinder/Github-Changelog-Generator)*
\ No newline at end of file +\* *This Change Log was automatically generated by [github_changelog_generator](https://github.com/skywinder/Github-Changelog-Generator)* @@ -1,9 +1,9 @@ source "https://rubygems.org" gemspec -# gem 'rest-client', :github => 'chef/rest-client' +# gem 'rest-client', :git => 'https://github.com/chef/rest-client.git' -gem "oc-chef-pedant", :github => "chef/chef-server" +gem "oc-chef-pedant", :git => "https://github.com/chef/chef-server.git" group :changelog do gem "github_changelog_generator" @@ -13,10 +13,7 @@ group :development, :test do gem "chefstyle", "= 0.3.1" end -# bundler resolve failure on "rspec_junit_formatter" -# gem 'chef-pedant', :github => 'opscode/chef-pedant', :ref => "server-cli-option" - -# gem 'chef', :github => 'chef/chef', :branch => 'jk/policies-acls' +gem "chef" if ENV["GEMFILE_MOD"] puts "GEMFILE_MOD: #{ENV['GEMFILE_MOD']}" @@ -145,6 +145,10 @@ Usage: chef-zero [ARGS] --version Show version ``` +## Contributing + +For information on contributing to this project see <https://github.com/chef/chef/blob/master/CONTRIBUTING.md> + ## License Copyright 2012-2016, Chef Software, Inc. diff --git a/chef-zero.gemspec b/chef-zero.gemspec index fd131a7..5152af2 100644 --- a/chef-zero.gemspec +++ b/chef-zero.gemspec @@ -12,20 +12,19 @@ Gem::Specification.new do |s| s.homepage = "http://www.chef.io" s.license = "Apache 2.0" - s.required_ruby_version = ">= 2.1.0" + s.required_ruby_version = ">= 2.2.2" s.add_dependency "mixlib-log", "~> 1.3" s.add_dependency "hashie", ">= 2.0", "< 4.0" s.add_dependency "uuidtools", "~> 2.1" s.add_dependency "ffi-yajl", "~> 2.2" - s.add_dependency "rack", "< 2" # 2.0 requires Ruby 2.2+ + s.add_dependency "rack", "~> 2.0" s.add_development_dependency "pry" s.add_development_dependency "pry-byebug" s.add_development_dependency "pry-stack_explorer" s.add_development_dependency "rake" s.add_development_dependency "rspec" - s.add_development_dependency "chef" s.bindir = "bin" s.executables = ["chef-zero"] diff --git a/lib/chef_zero/chef_data/data_normalizer.rb b/lib/chef_zero/chef_data/data_normalizer.rb index a762581..939acc5 100644 --- a/lib/chef_zero/chef_data/data_normalizer.rb +++ b/lib/chef_zero/chef_data/data_normalizer.rb @@ -8,8 +8,18 @@ module ChefZero def self.normalize_acls(acls) ChefData::DefaultCreator::PERMISSIONS.each do |perm| acls[perm] ||= {} - (acls[perm]["actors"] ||= []).uniq! # this gets doubled sometimes, for reasons. acls[perm]["groups"] ||= [] + if acls[perm].has_key? "users" + # When clients and users are split, their combined list + # is the final list of actors that a subsequent GET will + # provide. Each list is guaranteed to be unique, but the + # combined list is not. + acls[perm]["actors"] = acls[perm]["clients"].uniq + + acls[perm]["users"].uniq + else + # this gets doubled sometimes, for reasons. + (acls[perm]["actors"] ||= []).uniq! + end end acls end @@ -211,7 +221,7 @@ module ChefZero end def self.normalize_run_list(run_list) - run_list.map {|item| + run_list.map do |item| case item when /^recipe\[.*\]$/ item # explicit recipe @@ -220,7 +230,7 @@ module ChefZero else "recipe[#{item}]" end - }.uniq + end.uniq end end end diff --git a/lib/chef_zero/chef_data/default_creator.rb b/lib/chef_zero/chef_data/default_creator.rb index 1ce6253..51872d5 100644 --- a/lib/chef_zero/chef_data/default_creator.rb +++ b/lib/chef_zero/chef_data/default_creator.rb @@ -240,11 +240,11 @@ module ChefZero when "groups/admins" admins = data.list(path[0..1] + [ "users" ]).select do |name| - user = FFI_Yajl::Parser.parse(data.get(path[0..1] + [ "users", name ]), :create_additions => false) + user = FFI_Yajl::Parser.parse(data.get(path[0..1] + [ "users", name ])) user["admin"] end admins += data.list(path[0..1] + [ "clients" ]).select do |name| - client = FFI_Yajl::Parser.parse(data.get(path[0..1] + [ "clients", name ]), :create_additions => false) + client = FFI_Yajl::Parser.parse(data.get(path[0..1] + [ "clients", name ])) client["admin"] end admins += @creators[path[0..1]] if @creators[path[0..1]] @@ -346,57 +346,83 @@ module ChefZero end def get_owners(acl_path) - owners = [] - + unknown_owners = [] path = AclPath.get_object_path(acl_path) if path # Non-validator clients own themselves. if path.size == 4 && path[0] == "organizations" && path[2] == "clients" begin - client = FFI_Yajl::Parser.parse(data.get(path), :create_additions => false) + client = FFI_Yajl::Parser.parse(data.get(path)) if !client["validator"] - owners |= [ path[3] ] + unknown_owners |= [ path[3] ] end rescue - owners |= [ path[3] ] + unknown_owners |= [ path[3] ] end # Add creators as owners (except any validator clients). if @creators[path] @creators[path].each do |creator| begin - client = FFI_Yajl::Parser.parse(data.get(path[0..2] + [ creator ]), :create_additions => false) + client = FFI_Yajl::Parser.parse(data.get(path[0..2] + [ creator ])) next if client["validator"] rescue end - owners |= [ creator ] + unknown_owners |= [ creator ] end end else - owners |= @creators[path] if @creators[path] + unknown_owners |= @creators[path] if @creators[path] end + owners = filter_owners(path, unknown_owners) #ANGRY # Non-default containers do not get superusers added to them, # because reasons. unless path.size == 4 && path[0] == "organizations" && path[2] == "containers" && !exists?(path) - owners += superusers + owners[:users] += superusers end + else + owners = { clients: [], users: [] } end - # we don't de-dup this list, because pedant expects to see ["pivotal", "pivotal"] in some cases. + owners[:users].uniq! + owners[:clients].uniq! + owners + end + + # Figures out if an object was created by a user or client. + # If the object does not exist in the context + # of an organization, it can only be a user + # + # This isn't perfect, because we are never explicitly told + # if a requestor creating an object is a user or client - + # but it gets us reasonably close + def filter_owners(path, unknown_owners) + owners = { clients: [], users: [] } + unknown_owners.each do |entity| + if path[0] == "organizations" && path.length > 2 + begin + data.get(["organizations", path[1], "clients", entity]) + owners[:clients] |= [ entity ] + rescue + owners[:users] |= [ entity ] + end + else + owners[:users] |= [ entity ] + end + end owners end def default_acl(acl_path, acl = {}) - owners = nil + owners = get_owners(acl_path) container_acl = nil PERMISSIONS.each do |perm| acl[perm] ||= {} - acl[perm]["actors"] ||= begin - owners ||= get_owners(acl_path) - end + acl[perm]["users"] = owners[:users] + acl[perm]["clients"] = owners[:clients] acl[perm]["groups"] ||= begin # When we create containers, we don't merge groups (not sure why). if acl_path[0] == "organizations" && acl_path[3] == "containers" @@ -406,6 +432,7 @@ module ChefZero (container_acl[perm] ? container_acl[perm]["groups"] : []) || [] end end + acl[perm]["actors"] = acl[perm]["clients"] + acl[perm]["users"] end acl end @@ -413,7 +440,7 @@ module ChefZero def get_container_acl(acl_path) parent_path = AclPath.parent_acl_data_path(acl_path) if parent_path - FFI_Yajl::Parser.parse(data.get(parent_path), :create_additions => false) + FFI_Yajl::Parser.parse(data.get(parent_path)) else nil end diff --git a/lib/chef_zero/endpoints/acl_endpoint.rb b/lib/chef_zero/endpoints/acl_endpoint.rb index 366bb89..527ba17 100644 --- a/lib/chef_zero/endpoints/acl_endpoint.rb +++ b/lib/chef_zero/endpoints/acl_endpoint.rb @@ -28,8 +28,8 @@ module ChefZero def put(request) path, perm = validate_request(request) - acls = FFI_Yajl::Parser.parse(get_data(request, path), :create_additions => false) - acls[perm] = FFI_Yajl::Parser.parse(request.body, :create_additions => false)[perm] + acls = FFI_Yajl::Parser.parse(get_data(request, path)) + acls[perm] = FFI_Yajl::Parser.parse(request.body)[perm] set_data(request, path, FFI_Yajl::Encoder.encode(acls, :pretty => true)) json_response(200, { "uri" => "#{build_uri(request.base_uri, request.rest_path)}" }) end diff --git a/lib/chef_zero/endpoints/acls_endpoint.rb b/lib/chef_zero/endpoints/acls_endpoint.rb index 8565eea..64840cd 100644 --- a/lib/chef_zero/endpoints/acls_endpoint.rb +++ b/lib/chef_zero/endpoints/acls_endpoint.rb @@ -20,8 +20,19 @@ module ChefZero if !acl_path raise RestErrorResponse.new(404, "Object not found: #{build_uri(request.base_uri, request.rest_path)}") end - acls = FFI_Yajl::Parser.parse(get_data(request, acl_path), :create_additions => false) + acls = FFI_Yajl::Parser.parse(get_data(request, acl_path)) acls = ChefData::DataNormalizer.normalize_acls(acls) + if request.query_params["detail"] == "granular" + acls.each do |perm, ace| + acls[perm]["actors"] = [] + end + else + acls.each do |perm, ace| + acls[perm].delete("clients") + acls[perm].delete("users") + end + end + json_response(200, acls) end end diff --git a/lib/chef_zero/endpoints/actor_endpoint.rb b/lib/chef_zero/endpoints/actor_endpoint.rb index ea5284e..8d90c13 100644 --- a/lib/chef_zero/endpoints/actor_endpoint.rb +++ b/lib/chef_zero/endpoints/actor_endpoint.rb @@ -36,7 +36,7 @@ module ChefZero def put(request) # Find out if we're updating the public key. - request_body = FFI_Yajl::Parser.parse(request.body, :create_additions => false) + request_body = FFI_Yajl::Parser.parse(request.body) if request_body["public_key"].nil? # If public_key is null, then don't overwrite it. Weird patchiness. diff --git a/lib/chef_zero/endpoints/authenticate_user_endpoint.rb b/lib/chef_zero/endpoints/authenticate_user_endpoint.rb index fd26798..e54b8f1 100644 --- a/lib/chef_zero/endpoints/authenticate_user_endpoint.rb +++ b/lib/chef_zero/endpoints/authenticate_user_endpoint.rb @@ -6,7 +6,7 @@ module ChefZero # /authenticate_user class AuthenticateUserEndpoint < RestBase def post(request) - request_json = FFI_Yajl::Parser.parse(request.body, :create_additions => false) + request_json = FFI_Yajl::Parser.parse(request.body) name = request_json["username"] password = request_json["password"] begin @@ -14,7 +14,7 @@ module ChefZero rescue ChefZero::DataStore::DataNotFoundError raise RestErrorResponse.new(401, "Bad username or password") end - user = FFI_Yajl::Parser.parse(user, :create_additions => false) + user = FFI_Yajl::Parser.parse(user) user = ChefData::DataNormalizer.normalize_user(user, name, [ "username" ], server.options[:osc_compat]) if user["password"] != password raise RestErrorResponse.new(401, "Bad username or password") diff --git a/lib/chef_zero/endpoints/container_endpoint.rb b/lib/chef_zero/endpoints/container_endpoint.rb index 588d787..098f9a4 100644 --- a/lib/chef_zero/endpoints/container_endpoint.rb +++ b/lib/chef_zero/endpoints/container_endpoint.rb @@ -13,7 +13,7 @@ module ChefZero undef_method(:put) def populate_defaults(request, response_json) - container = FFI_Yajl::Parser.parse(response_json, :create_additions => false) + container = FFI_Yajl::Parser.parse(response_json) container = ChefData::DataNormalizer.normalize_container(container, request.rest_path[3]) FFI_Yajl::Encoder.encode(container, :pretty => true) end diff --git a/lib/chef_zero/endpoints/cookbook_endpoint.rb b/lib/chef_zero/endpoints/cookbook_endpoint.rb index 7dce172..8c4d49d 100644 --- a/lib/chef_zero/endpoints/cookbook_endpoint.rb +++ b/lib/chef_zero/endpoints/cookbook_endpoint.rb @@ -19,7 +19,7 @@ module ChefZero result = [] filter_cookbooks(all_cookbooks_list(request), {}, 1) do |name, versions| if versions.size > 0 - cookbook = FFI_Yajl::Parser.parse(get_data(request, request.rest_path[0..1] + ["cookbooks", name, versions[0]]), :create_additions => false) + cookbook = FFI_Yajl::Parser.parse(get_data(request, request.rest_path[0..1] + ["cookbooks", name, versions[0]])) result += recipe_names(name, cookbook) end end diff --git a/lib/chef_zero/endpoints/cookbook_version_endpoint.rb b/lib/chef_zero/endpoints/cookbook_version_endpoint.rb index 55acd1a..d22e5d9 100644 --- a/lib/chef_zero/endpoints/cookbook_version_endpoint.rb +++ b/lib/chef_zero/endpoints/cookbook_version_endpoint.rb @@ -22,13 +22,13 @@ module ChefZero # Honor frozen if existing_cookbook - existing_cookbook_json = FFI_Yajl::Parser.parse(existing_cookbook, :create_additions => false) + existing_cookbook_json = FFI_Yajl::Parser.parse(existing_cookbook) if existing_cookbook_json["frozen?"] if request.query_params["force"] != "true" raise RestErrorResponse.new(409, "The cookbook #{name} at version #{version} is frozen. Use the 'force' option to override.") end # For some reason, you are forever unable to modify "frozen?" on a frozen cookbook. - request_body = FFI_Yajl::Parser.parse(request.body, :create_additions => false) + request_body = FFI_Yajl::Parser.parse(request.body) if !request_body["frozen?"] request_body["frozen?"] = true request.body = FFI_Yajl::Encoder.encode(request_body, :pretty => true) @@ -71,7 +71,7 @@ module ChefZero def get_checksums(cookbook) result = [] - FFI_Yajl::Parser.parse(cookbook, :create_additions => false).each_pair do |key, value| + FFI_Yajl::Parser.parse(cookbook).each_pair do |key, value| if value.is_a?(Array) value.each do |file| if file.is_a?(Hash) && file.has_key?("checksum") @@ -95,9 +95,13 @@ module ChefZero cookbooks = [] end cookbooks.each do |cookbook_name| - data_store.list(request.rest_path[0..1] + [cookbook_type, cookbook_name]).each do |version| - cookbook = data_store.get(request.rest_path[0..1] + [cookbook_type, cookbook_name, version], request) - deleted_checksums = deleted_checksums - get_checksums(cookbook) + # as below, this can be racy. + begin + data_store.list(request.rest_path[0..1] + [cookbook_type, cookbook_name]).each do |version| + cookbook = data_store.get(request.rest_path[0..1] + [cookbook_type, cookbook_name, version], request) + deleted_checksums = deleted_checksums - get_checksums(cookbook) + end + rescue ChefZero::DataStore::DataNotFoundError end end end @@ -114,7 +118,7 @@ module ChefZero def populate_defaults(request, response_json) # Inject URIs into each cookbook file - cookbook = FFI_Yajl::Parser.parse(response_json, :create_additions => false) + cookbook = FFI_Yajl::Parser.parse(response_json) cookbook = ChefData::DataNormalizer.normalize_cookbook(self, request.rest_path[0..1], cookbook, request.rest_path[3], request.rest_path[4], request.base_uri, request.method) FFI_Yajl::Encoder.encode(cookbook, :pretty => true) end diff --git a/lib/chef_zero/endpoints/data_bag_endpoint.rb b/lib/chef_zero/endpoints/data_bag_endpoint.rb index 2f754cf..8d1a96f 100644 --- a/lib/chef_zero/endpoints/data_bag_endpoint.rb +++ b/lib/chef_zero/endpoints/data_bag_endpoint.rb @@ -12,7 +12,7 @@ module ChefZero end def post(request) - json = FFI_Yajl::Parser.parse(request.body, :create_additions => false) + json = FFI_Yajl::Parser.parse(request.body) key = identity_keys.map { |k| json[k] }.select { |v| v }.first response = super(request) if response[0] == 201 @@ -23,7 +23,7 @@ module ChefZero end def get_key(contents) - data_bag_item = FFI_Yajl::Parser.parse(contents, :create_additions => false) + data_bag_item = FFI_Yajl::Parser.parse(contents) if data_bag_item["json_class"] == "Chef::DataBagItem" && data_bag_item["raw_data"] data_bag_item["raw_data"]["id"] else diff --git a/lib/chef_zero/endpoints/data_bag_item_endpoint.rb b/lib/chef_zero/endpoints/data_bag_item_endpoint.rb index 79bfedd..915e9ad 100644 --- a/lib/chef_zero/endpoints/data_bag_item_endpoint.rb +++ b/lib/chef_zero/endpoints/data_bag_item_endpoint.rb @@ -16,7 +16,7 @@ module ChefZero end def self.populate_defaults(request, response_json, data_bag, data_bag_item) - response = FFI_Yajl::Parser.parse(response_json, :create_additions => false) + response = FFI_Yajl::Parser.parse(response_json) response = ChefData::DataNormalizer.normalize_data_bag_item(response, data_bag, data_bag_item, request.method) FFI_Yajl::Encoder.encode(response, :pretty => true) end diff --git a/lib/chef_zero/endpoints/data_bags_endpoint.rb b/lib/chef_zero/endpoints/data_bags_endpoint.rb index 03791b0..0ddb34e 100644 --- a/lib/chef_zero/endpoints/data_bags_endpoint.rb +++ b/lib/chef_zero/endpoints/data_bags_endpoint.rb @@ -7,7 +7,7 @@ module ChefZero class DataBagsEndpoint < RestListEndpoint def post(request) contents = request.body - json = FFI_Yajl::Parser.parse(contents, :create_additions => false) + json = FFI_Yajl::Parser.parse(contents) name = identity_keys.map { |k| json[k] }.select { |v| v }.first if name.nil? error(400, "Must specify #{identity_keys.map { |k| k.inspect }.join(' or ')} in JSON") diff --git a/lib/chef_zero/endpoints/environment_cookbook_endpoint.rb b/lib/chef_zero/endpoints/environment_cookbook_endpoint.rb index 692244d..3e4bb61 100644 --- a/lib/chef_zero/endpoints/environment_cookbook_endpoint.rb +++ b/lib/chef_zero/endpoints/environment_cookbook_endpoint.rb @@ -7,7 +7,7 @@ module ChefZero class EnvironmentCookbookEndpoint < CookbooksBase def get(request) cookbook_name = request.rest_path[5] - environment = FFI_Yajl::Parser.parse(get_data(request, request.rest_path[0..3]), :create_additions => false) + environment = FFI_Yajl::Parser.parse(get_data(request, request.rest_path[0..3])) constraints = environment["cookbook_versions"] || {} cookbook_versions = list_data(request, request.rest_path[0..1] + request.rest_path[4..5]) if request.query_params["num_versions"] == "all" diff --git a/lib/chef_zero/endpoints/environment_cookbook_versions_endpoint.rb b/lib/chef_zero/endpoints/environment_cookbook_versions_endpoint.rb index 8e693b5..f1f38fe 100644 --- a/lib/chef_zero/endpoints/environment_cookbook_versions_endpoint.rb +++ b/lib/chef_zero/endpoints/environment_cookbook_versions_endpoint.rb @@ -12,7 +12,7 @@ module ChefZero # Get the list of cookbooks and versions desired by the runlist desired_versions = {} - run_list = FFI_Yajl::Parser.parse(request.body, :create_additions => false)["run_list"] + run_list = FFI_Yajl::Parser.parse(request.body)["run_list"] run_list.each do |run_list_entry| if run_list_entry =~ /(.+)::.+\@(.+)/ || run_list_entry =~ /(.+)\@(.+)/ raise RestErrorResponse.new(412, "No such cookbook: #{$1}") if !cookbook_names.include?($1) @@ -26,7 +26,7 @@ module ChefZero end # Filter by environment constraints - environment = FFI_Yajl::Parser.parse(get_data(request, request.rest_path[0..3]), :create_additions => false) + environment = FFI_Yajl::Parser.parse(get_data(request, request.rest_path[0..3])) environment_constraints = environment["cookbook_versions"] || {} desired_versions.each_key do |name| @@ -48,7 +48,7 @@ module ChefZero result = {} solved.each_pair do |name, versions| - cookbook = FFI_Yajl::Parser.parse(get_data(request, request.rest_path[0..1] + ["cookbooks", name, versions[0]]), :create_additions => false) + cookbook = FFI_Yajl::Parser.parse(get_data(request, request.rest_path[0..1] + ["cookbooks", name, versions[0]])) result[name] = ChefData::DataNormalizer.normalize_cookbook(self, request.rest_path[0..1], cookbook, name, versions[0], request.base_uri, "MIN") end json_response(200, result) @@ -74,7 +74,7 @@ module ChefZero new_unsolved = unsolved[1..-1] # Pick this cookbook, and add dependencies - cookbook_obj = FFI_Yajl::Parser.parse(get_data(request, request.rest_path[0..1] + ["cookbooks", solve_for, desired_version]), :create_additions => false) + cookbook_obj = FFI_Yajl::Parser.parse(get_data(request, request.rest_path[0..1] + ["cookbooks", solve_for, desired_version])) cookbook_metadata = cookbook_obj["metadata"] || {} cookbook_dependencies = cookbook_metadata["dependencies"] || {} dep_not_found = false diff --git a/lib/chef_zero/endpoints/environment_cookbooks_endpoint.rb b/lib/chef_zero/endpoints/environment_cookbooks_endpoint.rb index c243bd0..ced6345 100644 --- a/lib/chef_zero/endpoints/environment_cookbooks_endpoint.rb +++ b/lib/chef_zero/endpoints/environment_cookbooks_endpoint.rb @@ -6,7 +6,7 @@ module ChefZero # /environments/NAME/cookbooks class EnvironmentCookbooksEndpoint < CookbooksBase def get(request) - environment = FFI_Yajl::Parser.parse(get_data(request, request.rest_path[0..3]), :create_additions => false) + environment = FFI_Yajl::Parser.parse(get_data(request, request.rest_path[0..3])) constraints = environment["cookbook_versions"] || {} if request.query_params["num_versions"] == "all" num_versions = nil diff --git a/lib/chef_zero/endpoints/environment_endpoint.rb b/lib/chef_zero/endpoints/environment_endpoint.rb index 6d256e8..4f07a72 100644 --- a/lib/chef_zero/endpoints/environment_endpoint.rb +++ b/lib/chef_zero/endpoints/environment_endpoint.rb @@ -24,7 +24,7 @@ module ChefZero end def populate_defaults(request, response_json) - response = FFI_Yajl::Parser.parse(response_json, :create_additions => false) + response = FFI_Yajl::Parser.parse(response_json) response = ChefData::DataNormalizer.normalize_environment(response, request.rest_path[3]) FFI_Yajl::Encoder.encode(response, :pretty => true) end diff --git a/lib/chef_zero/endpoints/environment_nodes_endpoint.rb b/lib/chef_zero/endpoints/environment_nodes_endpoint.rb index cffe596..55e1877 100644 --- a/lib/chef_zero/endpoints/environment_nodes_endpoint.rb +++ b/lib/chef_zero/endpoints/environment_nodes_endpoint.rb @@ -11,7 +11,7 @@ module ChefZero result = {} list_data(request, request.rest_path[0..1] + ["nodes"]).each do |name| - node = FFI_Yajl::Parser.parse(get_data(request, request.rest_path[0..1] + ["nodes", name]), :create_additions => false) + node = FFI_Yajl::Parser.parse(get_data(request, request.rest_path[0..1] + ["nodes", name])) if node["chef_environment"] == request.rest_path[3] result[name] = build_uri(request.base_uri, request.rest_path[0..1] + ["nodes", name]) end diff --git a/lib/chef_zero/endpoints/environment_recipes_endpoint.rb b/lib/chef_zero/endpoints/environment_recipes_endpoint.rb index 8165a68..d79660e 100644 --- a/lib/chef_zero/endpoints/environment_recipes_endpoint.rb +++ b/lib/chef_zero/endpoints/environment_recipes_endpoint.rb @@ -6,12 +6,12 @@ module ChefZero # /environment/NAME/recipes class EnvironmentRecipesEndpoint < CookbooksBase def get(request) - environment = FFI_Yajl::Parser.parse(get_data(request, request.rest_path[0..3]), :create_additions => false) + environment = FFI_Yajl::Parser.parse(get_data(request, request.rest_path[0..3])) constraints = environment["cookbook_versions"] || {} result = [] filter_cookbooks(all_cookbooks_list(request), constraints, 1) do |name, versions| if versions.size > 0 - cookbook = FFI_Yajl::Parser.parse(get_data(request, request.rest_path[0..1] + ["cookbooks", name, versions[0]]), :create_additions => false) + cookbook = FFI_Yajl::Parser.parse(get_data(request, request.rest_path[0..1] + ["cookbooks", name, versions[0]])) result += recipe_names(name, cookbook) end end diff --git a/lib/chef_zero/endpoints/environment_role_endpoint.rb b/lib/chef_zero/endpoints/environment_role_endpoint.rb index b05f28a..9d3ce3e 100644 --- a/lib/chef_zero/endpoints/environment_role_endpoint.rb +++ b/lib/chef_zero/endpoints/environment_role_endpoint.rb @@ -18,7 +18,7 @@ module ChefZero # Verify that the environment exists get_data(request, environment_path) - role = FFI_Yajl::Parser.parse(get_data(request, role_path), :create_additions => false) + role = FFI_Yajl::Parser.parse(get_data(request, role_path)) environment_name = environment_path[3] if environment_name == "_default" run_list = role["run_list"] diff --git a/lib/chef_zero/endpoints/group_endpoint.rb b/lib/chef_zero/endpoints/group_endpoint.rb index fc21946..7855e98 100644 --- a/lib/chef_zero/endpoints/group_endpoint.rb +++ b/lib/chef_zero/endpoints/group_endpoint.rb @@ -11,7 +11,7 @@ module ChefZero end def populate_defaults(request, response_json) - group = FFI_Yajl::Parser.parse(response_json, :create_additions => false) + group = FFI_Yajl::Parser.parse(response_json) group = ChefData::DataNormalizer.normalize_group(group, request.rest_path[3], request.rest_path[1]) FFI_Yajl::Encoder.encode(group, :pretty => true) end diff --git a/lib/chef_zero/endpoints/node_endpoint.rb b/lib/chef_zero/endpoints/node_endpoint.rb index af0e9e0..98e88a0 100644 --- a/lib/chef_zero/endpoints/node_endpoint.rb +++ b/lib/chef_zero/endpoints/node_endpoint.rb @@ -21,7 +21,7 @@ module ChefZero end def populate_defaults(request, response_json) - node = FFI_Yajl::Parser.parse(response_json, :create_additions => false) + node = FFI_Yajl::Parser.parse(response_json) node = ChefData::DataNormalizer.normalize_node(node, request.rest_path[3]) FFI_Yajl::Encoder.encode(node, :pretty => true) end diff --git a/lib/chef_zero/endpoints/nodes_endpoint.rb b/lib/chef_zero/endpoints/nodes_endpoint.rb index 6011506..42539e1 100644 --- a/lib/chef_zero/endpoints/nodes_endpoint.rb +++ b/lib/chef_zero/endpoints/nodes_endpoint.rb @@ -25,7 +25,7 @@ module ChefZero end def populate_defaults(request, response_json) - node = FFI_Yajl::Parser.parse(response_json, :create_additions => false) + node = FFI_Yajl::Parser.parse(response_json) node = ChefData::DataNormalizer.normalize_node(node, request.rest_path[3]) FFI_Yajl::Encoder.encode(node, :pretty => true) end diff --git a/lib/chef_zero/endpoints/organization_association_request_endpoint.rb b/lib/chef_zero/endpoints/organization_association_request_endpoint.rb index 09be738..0402893 100644 --- a/lib/chef_zero/endpoints/organization_association_request_endpoint.rb +++ b/lib/chef_zero/endpoints/organization_association_request_endpoint.rb @@ -13,7 +13,7 @@ module ChefZero end username = $1 path = request.rest_path[0..-2] + [username] - data = FFI_Yajl::Parser.parse(get_data(request, path), :create_additions => false) + data = FFI_Yajl::Parser.parse(get_data(request, path)) delete_data(request, path) json_response(200, { "id" => id, "username" => username }) end diff --git a/lib/chef_zero/endpoints/organization_association_requests_endpoint.rb b/lib/chef_zero/endpoints/organization_association_requests_endpoint.rb index aeba290..cb4005d 100644 --- a/lib/chef_zero/endpoints/organization_association_requests_endpoint.rb +++ b/lib/chef_zero/endpoints/organization_association_requests_endpoint.rb @@ -6,7 +6,7 @@ module ChefZero # /organizations/ORG/association_requests class OrganizationAssociationRequestsEndpoint < RestBase def post(request) - json = FFI_Yajl::Parser.parse(request.body, :create_additions => false) + json = FFI_Yajl::Parser.parse(request.body) username = json["user"] orgname = request.rest_path[1] id = "#{username}-#{orgname}" diff --git a/lib/chef_zero/endpoints/organization_authenticate_user_endpoint.rb b/lib/chef_zero/endpoints/organization_authenticate_user_endpoint.rb index 174235e..8a7abf7 100644 --- a/lib/chef_zero/endpoints/organization_authenticate_user_endpoint.rb +++ b/lib/chef_zero/endpoints/organization_authenticate_user_endpoint.rb @@ -6,12 +6,12 @@ module ChefZero # /organizations/NAME/authenticate_user class OrganizationAuthenticateUserEndpoint < RestBase def post(request) - request_json = FFI_Yajl::Parser.parse(request.body, :create_additions => false) + request_json = FFI_Yajl::Parser.parse(request.body) name = request_json["name"] password = request_json["password"] begin user = data_store.get(request.rest_path[0..-2] + ["users", name]) - user = FFI_Yajl::Parser.parse(user, :create_additions => false) + user = FFI_Yajl::Parser.parse(user) verified = user["password"] == password rescue DataStore::DataNotFoundError verified = false diff --git a/lib/chef_zero/endpoints/organization_endpoint.rb b/lib/chef_zero/endpoints/organization_endpoint.rb index 108073d..55bd686 100644 --- a/lib/chef_zero/endpoints/organization_endpoint.rb +++ b/lib/chef_zero/endpoints/organization_endpoint.rb @@ -11,8 +11,8 @@ module ChefZero end def put(request) - org = FFI_Yajl::Parser.parse(get_data(request, request.rest_path + [ "org" ]), :create_additions => false) - new_org = FFI_Yajl::Parser.parse(request.body, :create_additions => false) + org = FFI_Yajl::Parser.parse(get_data(request, request.rest_path + [ "org" ])) + new_org = FFI_Yajl::Parser.parse(request.body) new_org.each do |key, value| org[key] = value end @@ -37,7 +37,7 @@ module ChefZero end def populate_defaults(request, response_json) - org = FFI_Yajl::Parser.parse(response_json, :create_additions => false) + org = FFI_Yajl::Parser.parse(response_json) org = ChefData::DataNormalizer.normalize_organization(org, request.rest_path[1]) FFI_Yajl::Encoder.encode(org, :pretty => true) end diff --git a/lib/chef_zero/endpoints/organization_user_endpoint.rb b/lib/chef_zero/endpoints/organization_user_endpoint.rb index 9418e53..7e69439 100644 --- a/lib/chef_zero/endpoints/organization_user_endpoint.rb +++ b/lib/chef_zero/endpoints/organization_user_endpoint.rb @@ -9,14 +9,14 @@ module ChefZero username = request.rest_path[3] get_data(request) # 404 if user is not in org user = get_data(request, [ "users", username ]) - user = FFI_Yajl::Parser.parse(user, :create_additions => false) + user = FFI_Yajl::Parser.parse(user) json_response(200, ChefData::DataNormalizer.normalize_user(user, username, ["username"], server.options[:osc_compat], request.method)) end def delete(request) user = get_data(request) delete_data(request) - user = FFI_Yajl::Parser.parse(user, :create_additions => false) + user = FFI_Yajl::Parser.parse(user) json_response(200, ChefData::DataNormalizer.normalize_user(user, request.rest_path[3], ["username"], server.options[:osc_compat])) end diff --git a/lib/chef_zero/endpoints/organization_users_endpoint.rb b/lib/chef_zero/endpoints/organization_users_endpoint.rb index 7473776..67161b1 100644 --- a/lib/chef_zero/endpoints/organization_users_endpoint.rb +++ b/lib/chef_zero/endpoints/organization_users_endpoint.rb @@ -8,7 +8,7 @@ module ChefZero class OrganizationUsersEndpoint < RestBase def post(request) orgname = request.rest_path[1] - json = FFI_Yajl::Parser.parse(request.body, :create_additions => false) + json = FFI_Yajl::Parser.parse(request.body) username = json["username"] if exists_data?(request, [ "organizations", orgname, "users", username ]) @@ -16,7 +16,7 @@ module ChefZero end users = get_data(request, [ "organizations", orgname, "groups", "users" ]) - users = FFI_Yajl::Parser.parse(users, :create_additions => false) + users = FFI_Yajl::Parser.parse(users) create_data(request, request.rest_path, username, "{}") diff --git a/lib/chef_zero/endpoints/organization_validator_key_endpoint.rb b/lib/chef_zero/endpoints/organization_validator_key_endpoint.rb index d9bac29..ff1ac3b 100644 --- a/lib/chef_zero/endpoints/organization_validator_key_endpoint.rb +++ b/lib/chef_zero/endpoints/organization_validator_key_endpoint.rb @@ -9,7 +9,7 @@ module ChefZero def post(request) org_name = request.rest_path[-2] validator_path = [ "organizations", org_name, "clients", "#{org_name}-validator"] - validator = FFI_Yajl::Parser.parse(get_data(request, validator_path), :create_additions => false) + validator = FFI_Yajl::Parser.parse(get_data(request, validator_path)) private_key, public_key = server.gen_key_pair validator["public_key"] = public_key set_data(request, validator_path, FFI_Yajl::Encoder.encode(validator, :pretty => true)) diff --git a/lib/chef_zero/endpoints/organizations_endpoint.rb b/lib/chef_zero/endpoints/organizations_endpoint.rb index 52fca5f..268b533 100644 --- a/lib/chef_zero/endpoints/organizations_endpoint.rb +++ b/lib/chef_zero/endpoints/organizations_endpoint.rb @@ -15,7 +15,7 @@ module ChefZero end def post(request) - contents = FFI_Yajl::Parser.parse(request.body, :create_additions => false) + contents = FFI_Yajl::Parser.parse(request.body) name = contents["name"] full_name = contents["full_name"] if name.nil? diff --git a/lib/chef_zero/endpoints/rest_list_endpoint.rb b/lib/chef_zero/endpoints/rest_list_endpoint.rb index 0f01a68..b1e3d5c 100644 --- a/lib/chef_zero/endpoints/rest_list_endpoint.rb +++ b/lib/chef_zero/endpoints/rest_list_endpoint.rb @@ -34,7 +34,7 @@ module ChefZero end def get_key(contents) - json = FFI_Yajl::Parser.parse(contents, :create_additions => false) + json = FFI_Yajl::Parser.parse(contents) identity_keys.map { |k| json[k] }.select { |v| v }.first end end diff --git a/lib/chef_zero/endpoints/rest_object_endpoint.rb b/lib/chef_zero/endpoints/rest_object_endpoint.rb index 1f0e9ce..c35133f 100644 --- a/lib/chef_zero/endpoints/rest_object_endpoint.rb +++ b/lib/chef_zero/endpoints/rest_object_endpoint.rb @@ -48,8 +48,8 @@ module ChefZero def patch_request_body(request) existing_value = get_data(request, nil, :nil) if existing_value - request_json = FFI_Yajl::Parser.parse(request.body, :create_additions => false) - existing_json = FFI_Yajl::Parser.parse(existing_value, :create_additions => false) + request_json = FFI_Yajl::Parser.parse(request.body) + existing_json = FFI_Yajl::Parser.parse(existing_value) merged_json = existing_json.merge(request_json) if merged_json.size > request_json.size return FFI_Yajl::Encoder.encode(merged_json, :pretty => true) diff --git a/lib/chef_zero/endpoints/role_endpoint.rb b/lib/chef_zero/endpoints/role_endpoint.rb index 654afca..d4bc4cd 100644 --- a/lib/chef_zero/endpoints/role_endpoint.rb +++ b/lib/chef_zero/endpoints/role_endpoint.rb @@ -7,7 +7,7 @@ module ChefZero # /roles/NAME class RoleEndpoint < RestObjectEndpoint def populate_defaults(request, response_json) - role = FFI_Yajl::Parser.parse(response_json, :create_additions => false) + role = FFI_Yajl::Parser.parse(response_json) role = ChefData::DataNormalizer.normalize_role(role, request.rest_path[3]) FFI_Yajl::Encoder.encode(role, :pretty => true) end diff --git a/lib/chef_zero/endpoints/role_environments_endpoint.rb b/lib/chef_zero/endpoints/role_environments_endpoint.rb index a408138..625e13a 100644 --- a/lib/chef_zero/endpoints/role_environments_endpoint.rb +++ b/lib/chef_zero/endpoints/role_environments_endpoint.rb @@ -6,7 +6,7 @@ module ChefZero # /roles/NAME/environments class RoleEnvironmentsEndpoint < RestBase def get(request) - role = FFI_Yajl::Parser.parse(get_data(request, request.rest_path[0..3]), :create_additions => false) + role = FFI_Yajl::Parser.parse(get_data(request, request.rest_path[0..3])) json_response(200, [ "_default" ] + (role["env_run_lists"].keys || [])) end end diff --git a/lib/chef_zero/endpoints/sandbox_endpoint.rb b/lib/chef_zero/endpoints/sandbox_endpoint.rb index b83a4ca..a35af2c 100644 --- a/lib/chef_zero/endpoints/sandbox_endpoint.rb +++ b/lib/chef_zero/endpoints/sandbox_endpoint.rb @@ -7,7 +7,7 @@ module ChefZero # /sandboxes/ID class SandboxEndpoint < RestBase def put(request) - existing_sandbox = FFI_Yajl::Parser.parse(get_data(request), :create_additions => false) + existing_sandbox = FFI_Yajl::Parser.parse(get_data(request)) existing_sandbox["checksums"].each do |checksum| if !exists_data?(request, request.rest_path[0..1] + ["file_store", "checksums", checksum]) raise RestErrorResponse.new(503, "Checksum not uploaded: #{checksum}") diff --git a/lib/chef_zero/endpoints/sandboxes_endpoint.rb b/lib/chef_zero/endpoints/sandboxes_endpoint.rb index 815ff14..888b72a 100644 --- a/lib/chef_zero/endpoints/sandboxes_endpoint.rb +++ b/lib/chef_zero/endpoints/sandboxes_endpoint.rb @@ -13,7 +13,7 @@ module ChefZero def post(request) sandbox_checksums = [] - needed_checksums = FFI_Yajl::Parser.parse(request.body, :create_additions => false)["checksums"] + needed_checksums = FFI_Yajl::Parser.parse(request.body)["checksums"] result_checksums = {} needed_checksums.keys.each do |needed_checksum| if list_data(request, request.rest_path[0..1] + %w{file_store checksums}).include?(needed_checksum) diff --git a/lib/chef_zero/endpoints/search_endpoint.rb b/lib/chef_zero/endpoints/search_endpoint.rb index 01cfc56..b808ce9 100644 --- a/lib/chef_zero/endpoints/search_endpoint.rb +++ b/lib/chef_zero/endpoints/search_endpoint.rb @@ -12,7 +12,9 @@ module ChefZero def get(request) orgname = request.rest_path[1] results = search(request, orgname) + results["rows"] = results["rows"].map { |name, uri, value, search_value| value } + json_response(200, results) rescue ChefZero::Solr::ParseError bad_search_request(request) @@ -21,7 +23,7 @@ module ChefZero def post(request) orgname = request.rest_path[1] full_results = search(request, orgname) - keys = FFI_Yajl::Parser.parse(request.body, :create_additions => false) + keys = FFI_Yajl::Parser.parse(request.body) partial_results = full_results["rows"].map do |name, uri, doc, search_value| data = {} keys.each_pair do |key, path| @@ -112,10 +114,8 @@ module ChefZero query_string = request.query_params["q"] || "*:*" solr_query = ChefZero::Solr::SolrParser.new(query_string).parse sort_string = request.query_params["sort"] - start = request.query_params["start"] - start = start.to_i if start - rows = request.query_params["rows"] - rows = rows.to_i if rows + start = request.query_params["start"].to_i + rows = request.query_params["rows"].to_i # Get the search container container, expander = search_container(request, index, orgname) @@ -124,7 +124,7 @@ module ChefZero result = [] list_data(request, container).each do |name| value = get_data(request, container + [name]) - expanded = expander.call(FFI_Yajl::Parser.parse(value, :create_additions => false), name) + expanded = expander.call(FFI_Yajl::Parser.parse(value), name) result << [ name, build_uri(request.base_uri, container + [name]), expanded, expand_for_indexing(expanded, index, name) ] end result = result.select do |name, uri, value, search_value| @@ -139,13 +139,18 @@ module ChefZero result = result.reverse if sort_order == "DESC" end - # Paginate - if start - result = result[start..start + (rows || -1)] - end { - "rows" => result, - "start" => start || 0, + # Paginate + # + # Slice the array based on the value of the "rows" query parameter. If + # this is a positive integer, we'll get the number of rows asked for. + # If it's nil, we'll get -1, which gives us all of the elements. + # + # Do the same for "start", which will start at 0 if that value is not + # given. + "rows" => result[start..(rows - 1)], + # Also return start and total in the object + "start" => start, "total" => total, } end @@ -200,7 +205,6 @@ module ChefZero end dest end # deep_merge! - end end end diff --git a/lib/chef_zero/endpoints/system_recovery_endpoint.rb b/lib/chef_zero/endpoints/system_recovery_endpoint.rb index 385101d..0ad2293 100644 --- a/lib/chef_zero/endpoints/system_recovery_endpoint.rb +++ b/lib/chef_zero/endpoints/system_recovery_endpoint.rb @@ -6,7 +6,7 @@ module ChefZero # /system_recovery class SystemRecoveryEndpoint < RestBase def post(request) - request_json = FFI_Yajl::Parser.parse(request.body, :create_additions => false) + request_json = FFI_Yajl::Parser.parse(request.body) name = request_json["username"] password = request_json["password"] user = get_data(request, request.rest_path[0..-2] + ["users", name], :nil) @@ -14,7 +14,7 @@ module ChefZero raise RestErrorResponse.new(403, "Nonexistent user") end - user = FFI_Yajl::Parser.parse(user, :create_additions => false) + user = FFI_Yajl::Parser.parse(user) user = ChefData::DataNormalizer.normalize_user(user, name, [ "username" ], server.options[:osc_compat]) if !user["recovery_authentication_enabled"] raise RestErrorResponse.new(403, "Only users with recovery_authentication_enabled=true may use /system_recovery to log in") diff --git a/lib/chef_zero/endpoints/user_association_request_endpoint.rb b/lib/chef_zero/endpoints/user_association_request_endpoint.rb index 424557e..9433202 100644 --- a/lib/chef_zero/endpoints/user_association_request_endpoint.rb +++ b/lib/chef_zero/endpoints/user_association_request_endpoint.rb @@ -13,11 +13,11 @@ module ChefZero end orgname = $1 - json = FFI_Yajl::Parser.parse(request.body, :create_additions => false) + json = FFI_Yajl::Parser.parse(request.body) association_request_path = [ "organizations", orgname, "association_requests", username ] if json["response"] == "accept" users = get_data(request, [ "organizations", orgname, "groups", "users" ]) - users = FFI_Yajl::Parser.parse(users, :create_additions => false) + users = FFI_Yajl::Parser.parse(users) delete_data(request, association_request_path) create_data(request, [ "organizations", orgname, "users" ], username, "{}") diff --git a/lib/chef_zero/endpoints/user_organizations_endpoint.rb b/lib/chef_zero/endpoints/user_organizations_endpoint.rb index 03eae68..4e40eb0 100644 --- a/lib/chef_zero/endpoints/user_organizations_endpoint.rb +++ b/lib/chef_zero/endpoints/user_organizations_endpoint.rb @@ -12,7 +12,7 @@ module ChefZero end result = result.map do |orgname| org = get_data(request, [ "organizations", orgname, "org" ]) - org = FFI_Yajl::Parser.parse(org, :create_additions => false) + org = FFI_Yajl::Parser.parse(org) { "organization" => ChefData::DataNormalizer.normalize_organization(org, orgname) } end json_response(200, result) diff --git a/lib/chef_zero/rest_base.rb b/lib/chef_zero/rest_base.rb index c2bc5ee..976fade 100644 --- a/lib/chef_zero/rest_base.rb +++ b/lib/chef_zero/rest_base.rb @@ -285,7 +285,7 @@ module ChefZero end def parse_json(json) - FFI_Yajl::Parser.parse(json, create_additions: false) + FFI_Yajl::Parser.parse(json) end def to_json(data) diff --git a/lib/chef_zero/rest_router.rb b/lib/chef_zero/rest_router.rb index 2b5e129..ce08204 100644 --- a/lib/chef_zero/rest_router.rb +++ b/lib/chef_zero/rest_router.rb @@ -60,13 +60,13 @@ module ChefZero end def log_response(response) - ChefZero::Log.debug { + ChefZero::Log.debug do [ "", "--- RESPONSE (#{response[0]}) ---", response[2].chomp, "--- END RESPONSE ---", ].join("\n") - } + end end end end diff --git a/lib/chef_zero/rspec.rb b/lib/chef_zero/rspec.rb index 53f4776..bb3a927 100644 --- a/lib/chef_zero/rspec.rb +++ b/lib/chef_zero/rspec.rb @@ -48,13 +48,13 @@ module ChefZero # Take the passed-in options - define_singleton_method(:chef_server_options) { + define_singleton_method(:chef_server_options) do @chef_server_options ||= begin _chef_server_options = { port: 8900, signals: false, log_requests: true } _chef_server_options = _chef_server_options.merge(tags.last) if tags.last.is_a?(Hash) _chef_server_options = _chef_server_options.freeze end - } + end # Merge in chef_server_options from let(:chef_server_options) def chef_server_options diff --git a/lib/chef_zero/server.rb b/lib/chef_zero/server.rb index dd83fe3..43b42f8 100644 --- a/lib/chef_zero/server.rb +++ b/lib/chef_zero/server.rb @@ -287,9 +287,9 @@ module ChefZero :SSLEnable => options[:ssl], :SSLOptions => ssl_opts, :SSLCertName => [ [ "CN", WEBrick::Utils.getservername ] ], - :StartCallback => proc { + :StartCallback => proc do @running = true - } + end ) ENV["HTTPS"] = "on" if options[:ssl] @server.mount("/", Rack::Handler::WEBrick, app) @@ -320,9 +320,7 @@ module ChefZero end # Do not return until the web server is genuinely started. - while !@running && @thread.alive? - sleep(0.01) - end + sleep(0.01) while !@running && @thread.alive? SocketlessServerMap.instance.register_port(@port, self) diff --git a/lib/chef_zero/version.rb b/lib/chef_zero/version.rb index 77fff14..deaab29 100644 --- a/lib/chef_zero/version.rb +++ b/lib/chef_zero/version.rb @@ -1,3 +1,3 @@ module ChefZero - VERSION = "4.8.0" + VERSION = "5.1.1" end diff --git a/spec/run_oc_pedant.rb b/spec/run_oc_pedant.rb index 0347fbc..e87fc66 100644 --- a/spec/run_oc_pedant.rb +++ b/spec/run_oc_pedant.rb @@ -135,16 +135,17 @@ begin else [] end - # The latest released Chef doesn't do ACLs, Cookbook Artifacts or Policies yet - chef_fs_skips << "--skip-acl" - chef_fs_skips << "--skip-cookbook-artifacts" - chef_fs_skips << "--skip-policies" - # Multi-keys don't work prior to 12.8 unless Gem::Requirement.new(">= 12.8.0").satisfied_by?(Gem::Version.new(Chef::VERSION)) chef_fs_skips << "--skip-keys" end + unless Gem::Requirement.new(">= 12.13.19").satisfied_by?(Gem::Version.new(Chef::VERSION)) + chef_fs_skips << "--skip-acl" + chef_fs_skips << "--skip-cookbook-artifacts" + chef_fs_skips << "--skip-policies" + end + # These things aren't supported by Chef Zero in any mode of operation: default_skips = [ # "the goal is that only authorization, authentication and validation tests |