From 27584250fd7b7d0ac76c32fdd93b70fdb3fb2fb9 Mon Sep 17 00:00:00 2001 From: Marc Paradise Date: Wed, 4 Mar 2015 02:43:54 -0500 Subject: [PATCH 01/14] update chef-zero to be fully compatible with CS12 --- lib/chef_zero/chef_data/data_normalizer.rb | 6 ++--- lib/chef_zero/chef_data/default_creator.rb | 2 +- lib/chef_zero/endpoints/actor_endpoint.rb | 12 ++++++++-- .../endpoints/organization_endpoint.rb | 12 +++++++--- .../endpoints/organization_user_endpoint.rb | 24 +------------------ .../endpoints/organizations_endpoint.rb | 7 ++++++ lib/chef_zero/endpoints/search_endpoint.rb | 14 ++++++----- .../endpoints/user_organizations_endpoint.rb | 2 +- 8 files changed, 40 insertions(+), 39 deletions(-) diff --git a/lib/chef_zero/chef_data/data_normalizer.rb b/lib/chef_zero/chef_data/data_normalizer.rb index ab45d762..404db03e 100644 --- a/lib/chef_zero/chef_data/data_normalizer.rb +++ b/lib/chef_zero/chef_data/data_normalizer.rb @@ -14,11 +14,11 @@ def self.normalize_acls(acls) acls end - def self.normalize_client(client, name) + def self.normalize_client(client, name, orgname = nil) client['name'] ||= name - client['admin'] ||= false - client['admin'] = !!client['admin'] + client['clientname'] ||= name client['public_key'] ||= PUBLIC_KEY + client['orgname'] ||= orgname client['validator'] ||= false client['validator'] = !!client['validator'] client['json_class'] ||= "Chef::ApiClient" diff --git a/lib/chef_zero/chef_data/default_creator.rb b/lib/chef_zero/chef_data/default_creator.rb index 60b495af..d1a01187 100644 --- a/lib/chef_zero/chef_data/default_creator.rb +++ b/lib/chef_zero/chef_data/default_creator.rb @@ -160,7 +160,7 @@ def exists?(path) 'users' => {}, 'org' => {}, - 'containers' => %w(clients containers cookbooks data environments groups nodes roles sandboxes), + 'containers' => %w(clients containers cookbooks data environments groups nodes roles sandboxes policies cookbook_artifacts), 'groups' => %w(admins billing-admins clients users), 'association_requests' => {} } diff --git a/lib/chef_zero/endpoints/actor_endpoint.rb b/lib/chef_zero/endpoints/actor_endpoint.rb index 342619cb..a34ad143 100644 --- a/lib/chef_zero/endpoints/actor_endpoint.rb +++ b/lib/chef_zero/endpoints/actor_endpoint.rb @@ -65,7 +65,15 @@ def put(request) else response = FFI_Yajl::Parser.parse(result[2], :create_additions => false) end - response['private_key'] = private_key if private_key + + # TODO some oc_erchef follow-up here. I still don't see that we're returning this + # as a flag in absence of an actual private key. + if request.rest_path[2] == 'clients' + response['private_key'] = private_key ? private_key : false + else + response['private_key'] = private_key if private_key + end + response.delete('public_key') if !updating_public_key && request.rest_path[2] == 'users' response.delete('password') json_response(result[0], response) @@ -77,7 +85,7 @@ def put(request) def populate_defaults(request, response_json) response = FFI_Yajl::Parser.parse(response_json, :create_additions => false) if request.rest_path[2] == 'clients' - response = ChefData::DataNormalizer.normalize_client(response, request.rest_path[3]) + response = ChefData::DataNormalizer.normalize_client(response,request.rest_path[3], request.rest_path[1]) else response = ChefData::DataNormalizer.normalize_user(response, request.rest_path[3], identity_keys, server.options[:osc_compat], request.method) end diff --git a/lib/chef_zero/endpoints/organization_endpoint.rb b/lib/chef_zero/endpoints/organization_endpoint.rb index bc5c3f01..fbc6610f 100644 --- a/lib/chef_zero/endpoints/organization_endpoint.rb +++ b/lib/chef_zero/endpoints/organization_endpoint.rb @@ -16,13 +16,19 @@ def put(request) new_org.each do |key, value| org[key] = value end - org = FFI_Yajl::Encoder.encode(org, :pretty => true) + save_org = FFI_Yajl::Encoder.encode(org, :pretty => true) if new_org['name'] != request.rest_path[-1] # This is a rename return error(400, "Cannot rename org #{request.rest_path[-1]} to #{new_org['name']}: rename not supported for orgs") end - set_data(request, request.rest_path + [ 'org' ], org) - json_response(200, "uri" => "#{build_uri(request.base_uri, request.rest_path)}") + set_data(request, request.rest_path + [ 'org' ], save_org) + pp org + json_response(200, { + "uri" => "#{build_uri(request.base_uri, request.rest_path)}", + "name" => org['name'], + "org_type" => org['org_type'], + "full_name" => org['full_name'] + }) end def delete(request) diff --git a/lib/chef_zero/endpoints/organization_user_endpoint.rb b/lib/chef_zero/endpoints/organization_user_endpoint.rb index ef922d42..8fd97d4d 100644 --- a/lib/chef_zero/endpoints/organization_user_endpoint.rb +++ b/lib/chef_zero/endpoints/organization_user_endpoint.rb @@ -20,29 +20,7 @@ def delete(request) json_response(200, ChefData::DataNormalizer.normalize_user(user, request.rest_path[3], ['username'], server.options[:osc_compat])) end - def post(request) - orgname = request.rest_path[1] - username = request.rest_path[3] - - users = get_data(request, [ 'organizations', orgname, 'groups', 'users' ]) - users = FFI_Yajl::Parser.parse(users, :create_additions => false) - - create_data(request, [ 'organizations', orgname, 'users' ], username, '{}') - - # /organizations/ORG/association_requests/USERNAME-ORG - begin - delete_data(request, [ 'organizations', orgname, 'association_requests', username], :data_store_exceptions) - rescue DataStore::DataNotFoundError - end - - # Add the user to the users group if it isn't already there - if !users['users'] || !users['users'].include?(username) - users['users'] ||= [] - users['users'] |= [ username ] - set_data(request, [ 'organizations', orgname, 'groups', 'users' ], FFI_Yajl::Encoder.encode(users, :pretty => true)) - end - json_response(200, {}) - end + # Note: post to a named org user is not permitted, alllow invalid method handling (405) end end end diff --git a/lib/chef_zero/endpoints/organizations_endpoint.rb b/lib/chef_zero/endpoints/organizations_endpoint.rb index 88816e8a..d7743710 100644 --- a/lib/chef_zero/endpoints/organizations_endpoint.rb +++ b/lib/chef_zero/endpoints/organizations_endpoint.rb @@ -17,8 +17,11 @@ def get(request) def post(request) contents = FFI_Yajl::Parser.parse(request.body, :create_additions => false) name = contents['name'] + full_name = contents['full_name'] if name.nil? error(400, "Must specify 'name' in JSON") + elsif full_name.nil? + error(400, "Must specify 'full_name' in JSON") elsif exists_data_dir?(request, request.rest_path + [ name ]) error(409, "Organization already exists") else @@ -43,8 +46,12 @@ def post(request) set_data(request, validator_path, validator) end + json_response(201, { "uri" => "#{build_uri(request.base_uri, org_path)}", + "name" => name, + "org_type" => "Pleasure", + "full_name" => full_name, "clientname" => validator_name, "private_key" => private_key }) diff --git a/lib/chef_zero/endpoints/search_endpoint.rb b/lib/chef_zero/endpoints/search_endpoint.rb index 3a093be1..a9ad2bfe 100644 --- a/lib/chef_zero/endpoints/search_endpoint.rb +++ b/lib/chef_zero/endpoints/search_endpoint.rb @@ -10,13 +10,15 @@ module Endpoints # /search/INDEX class SearchEndpoint < RestBase def get(request) - results = search(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) end def post(request) - full_results = search(request) + orgname = request.rest_path[1] + full_results = search(request, orgname) keys = FFI_Yajl::Parser.parse(request.body, :create_additions => false) partial_results = full_results['rows'].map do |name, uri, doc, search_value| data = {} @@ -45,10 +47,10 @@ def post(request) private - def search_container(request, index) + def search_container(request, index, orgname) relative_parts, normalize_proc = case index when 'client' - [ ['clients'], Proc.new { |client, name| ChefData::DataNormalizer.normalize_client(client, name) } ] + [ ['clients'], Proc.new { |client, name| ChefData::DataNormalizer.normalize_client(client, name, orgname) } ] when 'node' [ ['nodes'], Proc.new { |node, name| ChefData::DataNormalizer.normalize_node(node, name) } ] when 'environment' @@ -92,7 +94,7 @@ def expand_for_indexing(value, index, id) end end - def search(request) + def search(request, orgname = nil) # Extract parameters index = request.rest_path[3] query_string = request.query_params['q'] || '*:*' @@ -104,7 +106,7 @@ def search(request) rows = rows.to_i if rows # Get the search container - container, expander = search_container(request, index) + container, expander = search_container(request, index, orgname) # Search! result = [] diff --git a/lib/chef_zero/endpoints/user_organizations_endpoint.rb b/lib/chef_zero/endpoints/user_organizations_endpoint.rb index b6decb98..3eb13c4e 100644 --- a/lib/chef_zero/endpoints/user_organizations_endpoint.rb +++ b/lib/chef_zero/endpoints/user_organizations_endpoint.rb @@ -13,7 +13,7 @@ def get(request) result = result.map do |orgname| org = get_data(request, [ 'organizations', orgname, 'org' ]) org = FFI_Yajl::Parser.parse(org, :create_additions => false) - ChefData::DataNormalizer.normalize_organization(org, orgname) + { "organization" => ChefData::DataNormalizer.normalize_organization(org, orgname) } end json_response(200, result) end From fd95d9e31ebb7d042e171fba446de9ed150c1e91 Mon Sep 17 00:00:00 2001 From: Marc Paradise Date: Wed, 4 Mar 2015 02:48:32 -0500 Subject: [PATCH 02/14] integrate oc-chef-pedant 2.0 for cs12, drop chef-pedant support --- CHANGELOG.md | 6 ++ Gemfile | 4 +- Rakefile | 4 +- gemfiles/oc-chef-pedant.gemfile | 1 - spec/run_oc_pedant.rb | 5 +- spec/run_pedant.rb | 103 ------------------------- spec/support/oc_pedant.rb | 1 + spec/support/pedant.rb | 129 -------------------------------- 8 files changed, 14 insertions(+), 239 deletions(-) delete mode 100644 spec/run_pedant.rb delete mode 100644 spec/support/pedant.rb diff --git a/CHANGELOG.md b/CHANGELOG.md index 9cf9890e..743232b7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,12 @@ Chef Zero CHANGELOG =================== +$ 5.0 (pending) + +* updates to be compatible with current Chef Server 12 behaviors +* update oc-chef-pedant to 2.0 +* remove chef-pedant support + # 4.2.3 * [PR#143](https://github.com/chef/chef-zero/pull/143): Fix server_scope: :context diff --git a/Gemfile b/Gemfile index 69dffa06..3db58e36 100644 --- a/Gemfile +++ b/Gemfile @@ -3,7 +3,9 @@ gemspec gem 'rest-client', :github => 'chef/rest-client' -gem 'chef-pedant', :github => 'chef/chef-pedant', :tag => '1.0.46' +#WIP +#gem 'oc-chef-pedant', :github => 'chef/oc-chef-pedant', :tag => '2.0.0' +gem 'oc-chef-pedant', :github => 'chef/oc-chef-pedant', :branch => 'mp/merge-pedants' gem 'chef', :github => 'opscode/chef', :tag => '12.2.1' diff --git a/Rakefile b/Rakefile index 209b5dfd..1ce1b92e 100644 --- a/Rakefile +++ b/Rakefile @@ -10,9 +10,9 @@ task :spec do system('rspec spec/*_spec.rb') end -desc "run pedant" +desc "run oc pedant" task :pedant do - require File.expand_path('spec/run_pedant') + require File.expand_path('spec/run_oc_pedant') end desc "run oc pedant" diff --git a/gemfiles/oc-chef-pedant.gemfile b/gemfiles/oc-chef-pedant.gemfile index 26324c3e..27c87bd2 100644 --- a/gemfiles/oc-chef-pedant.gemfile +++ b/gemfiles/oc-chef-pedant.gemfile @@ -2,6 +2,5 @@ source 'https://rubygems.org' gemspec :path => '../' gem 'rest-client', :github => 'opscode/rest-client', :branch => 'lcg/1.6.7-version-lying' -gem 'chef-pedant', :github => 'opscode/chef-pedant', :ref => '81f3b4ecbc09d04950f2819b38a6a8f906ada2a7' gem 'oc-chef-pedant', :git => 'git@github.com:opscode/oc-chef-pedant', :ref => '3c0eb31f1e49aa947b81ad51387b7a68adbc5f91' gem 'chef', :github => 'opscode/chef' diff --git a/spec/run_oc_pedant.rb b/spec/run_oc_pedant.rb index 79d92e7a..053062af 100644 --- a/spec/run_oc_pedant.rb +++ b/spec/run_oc_pedant.rb @@ -24,8 +24,6 @@ require 'rspec/core' require 'pedant' - require 'pedant/opensource/platform' - require 'pedant/multitenant' require 'pedant/organization' #Pedant::Config.rerun = true @@ -43,7 +41,8 @@ '--skip-omnibus', '--skip-usags', '--skip-internal_orgs', - '--skip-rename_org' + '--skip-rename_org', + '--skip-headers' ]) result = RSpec::Core::Runner.run(Pedant.config.rspec_args) diff --git a/spec/run_pedant.rb b/spec/run_pedant.rb deleted file mode 100644 index 30ffa2dc..00000000 --- a/spec/run_pedant.rb +++ /dev/null @@ -1,103 +0,0 @@ -#!/usr/bin/env ruby -require 'bundler' -require 'bundler/setup' - -require 'chef_zero/server' -require 'rspec/core' - -tmpdir = nil - -def start_local_server(chef_repo_path) - Dir.mkdir(chef_repo_path) if !File.exists?(chef_repo_path) - - # 11.6 and below had a bug where it couldn't create the repo children automatically - if Chef::VERSION.to_f < 11.8 - %w(clients cookbooks data_bags environments nodes roles users).each do |child| - Dir.mkdir("#{chef_repo_path}/#{child}") if !File.exists?("#{chef_repo_path}/#{child}") - end - end - - # Start the new server - Chef::Config.repo_mode = 'everything' - Chef::Config.chef_repo_path = chef_repo_path - Chef::Config.versioned_cookbooks = true - chef_fs = Chef::ChefFS::Config.new.local_fs - data_store = Chef::ChefFS::ChefFSDataStore.new(chef_fs) - server = ChefZero::Server.new(:port => 8889, :data_store => data_store) - ENV['SINGLE_ORG'] = 'true' - server.start_background - server -end - -begin - if ENV['CHEF_FS'] - require 'chef/chef_fs/chef_fs_data_store' - require 'chef/chef_fs/config' - require 'tmpdir' - require 'fileutils' - require 'chef/version' - require 'chef_zero/data_store/v1_to_v2_adapter' - - # Create chef repository - tmpdir = Dir.mktmpdir - chef_repo_path = "#{tmpdir}/repo" - - # Capture setup data into master_chef_repo_path - server = start_local_server(chef_repo_path) - - elsif ENV['SINGLE_ORG'] - server = ChefZero::Server.new(:port => 8889, :single_org => 'chef') - server.start_background - - elsif ENV['FILE_STORE'] - require 'tmpdir' - require 'chef_zero/data_store/raw_file_store' - tmpdir = Dir.mktmpdir - data_store = ChefZero::DataStore::RawFileStore.new(tmpdir, true) - data_store = ChefZero::DataStore::DefaultFacade.new(data_store, true, false) - server = ChefZero::Server.new(:port => 8889, :single_org => 'chef', :data_store => data_store) - server.start_background - - else - server = ChefZero::Server.new(:port => 8889, :single_org => false, :osc_compat => true) - server.data_store.create_dir([ 'organizations' ], 'pedant') - server.start_background - end - - unless ENV['SKIP_PEDANT'] - require 'pedant' - require 'pedant/opensource' - - #Pedant::Config.rerun = true - - Pedant.config.suite = 'api' - Pedant.config[:config_file] = 'spec/support/pedant.rb' - - Pedant.setup([ - '--skip-knife', - '--skip-validation', - '--skip-authentication', - '--skip-authorization', - '--skip-keys', - '--skip-omnibus', - '--skip-cookbook_artifacts' - ]) - - result = RSpec::Core::Runner.run(Pedant.config.rspec_args) - else - require 'net/http' - response = Net::HTTP.new('127.0.0.1', 8889).get("/environments", { 'Accept' => 'application/json'}).body - if response =~ /_default/ - result = 0 - else - puts "GET /environments returned #{response}. Expected _default!" - result = 1 - end - end - - server.stop if server.running? -ensure - FileUtils.remove_entry_secure(tmpdir) if tmpdir -end - -exit(result) diff --git a/spec/support/oc_pedant.rb b/spec/support/oc_pedant.rb index 60e36292..1db663e0 100644 --- a/spec/support/oc_pedant.rb +++ b/spec/support/oc_pedant.rb @@ -132,3 +132,4 @@ ruby_users_endpoint? false ruby_acls_endpoint? false ruby_org_assoc? false +chef_12? true diff --git a/spec/support/pedant.rb b/spec/support/pedant.rb deleted file mode 100644 index 29a0ec13..00000000 --- a/spec/support/pedant.rb +++ /dev/null @@ -1,129 +0,0 @@ -# Copyright: Copyright (c) 2012 Opscode, Inc. -# License: Apache License, Version 2.0 -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -# This annotated Pedant configuration file details the various -# configuration settings available to you. It is separate from the -# actual Pedant::Config class because not all settings have sane -# defaults, and not all settings are appropriate in all settings. - -################################################################################ -# You MUST specify the address of the server the API requests will be -# sent to. Only specify protocol, hostname, and port. -if ENV['SINGLE_ORG'] || ENV['FILE_STORE'] - chef_server 'http://127.0.0.1:8889' -else - chef_server 'http://127.0.0.1:8889/organizations/pedant' -end - -# If you are doing development testing, you can specify the address of -# the Solr server. The presence of this parameter will enable tests -# to force commits to Solr, greatly decreasing the amout of time -# needed for testing the search endpoint. This is only an -# optimization for development! If you are testing a "live" Chef -# Server, or otherwise do not have access to the Solr server from your -# testing location, you should not specify a value for this parameter. -# The tests will still run, albeit slower, as they will now need to -# poll for a period to ensure they are querying committed results. -#search_server "http://localhost:8983" - -# Related to the 'search_server' parameter, this specifies the maximum -# amout of time (in seconds) that search endpoint requests should be -# retried before giving up. If not explicitly set, it will default to -# 65 seconds; only set it if you know that your Solr commit interval -# differs significantly from this. -maximum_search_time 0 - -# OSC sends erchef a host header with a port, so this option needs -# # to be enabled for Pedant tests to work correctly -explicit_port_url true - -# We're starting to break tests up into groups based on different -# criteria. The proper API tests (the results of which are viewable -# to OPC customers) should be the only ones run by Pedant embedded in -# OPC installs. There are other specs that help us keep track of API -# cruft that we want to come back and fix later; these shouldn't be -# viewable to customers, but we should be able to run them in -# development and CI environments. If this parameter is missing or -# explicitly `false` only the customer-friendly tests will be run. -# -# This is mainly here for documentation purposes, since the -# command-line `opscode-pedant` utility ultimately determines this -# value. -include_internal false - -# Test users. The five users specified below are required; their -# names (:user, :non_org_user, etc.) are indicative of their role -# within the tests. All users must have a ':name' key. If they have -# a ':create_me' key, Pedant will create these users for you. If you -# are using pre-existing users, you must supply a ':key_file' key, -# which should be the fully-qualified path /on the machine Pedant is -# running on/ to a private key for that user. -key = 'spec/support/stickywicket.pem' -superuser_name 'admin' -superuser_key key -webui_key key - -# The Policies endpoint is feature-flagged during development. Zero supports -# the policies endpoint, so turn it on: -policies? true - -# Set the platform_class -platform_class Pedant::OpenSourcePlatform - -requestors({ - :clients => { - # The the admin user, for the purposes of getting things rolling - :admin => { - :name => "pedant_admin_client", - :create_me => true, - :create_knife => true, - :admin => true - }, - :non_admin => { - :name => 'pedant_client', - :create_me => true, - :create_knife => true - }, - :bad => { - :name => 'bad_client', - :bogus => true - } - }, - :users => { - :admin => { - :name => "admin", - :key_file => key, - :create_me => false, - :create_knife => false, - :admin => true - }, - :non_admin => { - :name => "pedant_non_admin_user", - :create_me => true, - :create_knife => true, - :admin => false - }, - # A user for Knife tests. A knife.rb and key files will be set up - # for this user - :knife_user => { - :name => "knifey", - :create_me => true, - :create_knife => true - } - } -}) - -self[:tags] = [:validation, :authentication, :authorization] -verify_error_messages false From ad69f428b7ccf0728ecec4f5458f427503b987ce Mon Sep 17 00:00:00 2001 From: Marc Paradise Date: Wed, 4 Mar 2015 02:52:53 -0500 Subject: [PATCH 03/14] cleanup a TODO left behind and clean up some debug code --- lib/chef_zero/endpoints/actor_endpoint.rb | 2 -- lib/chef_zero/endpoints/organization_endpoint.rb | 1 - 2 files changed, 3 deletions(-) diff --git a/lib/chef_zero/endpoints/actor_endpoint.rb b/lib/chef_zero/endpoints/actor_endpoint.rb index a34ad143..1572ac16 100644 --- a/lib/chef_zero/endpoints/actor_endpoint.rb +++ b/lib/chef_zero/endpoints/actor_endpoint.rb @@ -66,8 +66,6 @@ def put(request) response = FFI_Yajl::Parser.parse(result[2], :create_additions => false) end - # TODO some oc_erchef follow-up here. I still don't see that we're returning this - # as a flag in absence of an actual private key. if request.rest_path[2] == 'clients' response['private_key'] = private_key ? private_key : false else diff --git a/lib/chef_zero/endpoints/organization_endpoint.rb b/lib/chef_zero/endpoints/organization_endpoint.rb index fbc6610f..585c46af 100644 --- a/lib/chef_zero/endpoints/organization_endpoint.rb +++ b/lib/chef_zero/endpoints/organization_endpoint.rb @@ -22,7 +22,6 @@ def put(request) return error(400, "Cannot rename org #{request.rest_path[-1]} to #{new_org['name']}: rename not supported for orgs") end set_data(request, request.rest_path + [ 'org' ], save_org) - pp org json_response(200, { "uri" => "#{build_uri(request.base_uri, request.rest_path)}", "name" => org['name'], From eb7ee61cd9ed1ff25ed0d435ac5842f7b524be06 Mon Sep 17 00:00:00 2001 From: Marc Paradise Date: Wed, 4 Mar 2015 02:56:57 -0500 Subject: [PATCH 04/14] use the supplied org_type in org creation --- lib/chef_zero/endpoints/organizations_endpoint.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/chef_zero/endpoints/organizations_endpoint.rb b/lib/chef_zero/endpoints/organizations_endpoint.rb index d7743710..41bf03b2 100644 --- a/lib/chef_zero/endpoints/organizations_endpoint.rb +++ b/lib/chef_zero/endpoints/organizations_endpoint.rb @@ -50,7 +50,7 @@ def post(request) json_response(201, { "uri" => "#{build_uri(request.base_uri, org_path)}", "name" => name, - "org_type" => "Pleasure", + "org_type" => org["org_type"], "full_name" => full_name, "clientname" => validator_name, "private_key" => private_key From d0a148401eee1e995489a58a0c91b10e9010c200 Mon Sep 17 00:00:00 2001 From: Marc Paradise Date: Wed, 4 Mar 2015 03:01:48 -0500 Subject: [PATCH 05/14] update oc-chef-pedant gemfile and remove chef-pedant gemfile --- gemfiles/latest-pedant.gemfile | 7 ------- gemfiles/oc-chef-pedant.gemfile | 2 +- 2 files changed, 1 insertion(+), 8 deletions(-) delete mode 100644 gemfiles/latest-pedant.gemfile diff --git a/gemfiles/latest-pedant.gemfile b/gemfiles/latest-pedant.gemfile deleted file mode 100644 index f5fdb866..00000000 --- a/gemfiles/latest-pedant.gemfile +++ /dev/null @@ -1,7 +0,0 @@ -source 'https://rubygems.org' - -gemspec :path => "../" - -gem 'rest-client', :git => 'git://github.com/opscode/rest-client.git' -gem 'chef-pedant', :github => 'opscode/chef-pedant' -gem 'chef', '>= 11.0' diff --git a/gemfiles/oc-chef-pedant.gemfile b/gemfiles/oc-chef-pedant.gemfile index 27c87bd2..fbd9c07d 100644 --- a/gemfiles/oc-chef-pedant.gemfile +++ b/gemfiles/oc-chef-pedant.gemfile @@ -2,5 +2,5 @@ source 'https://rubygems.org' gemspec :path => '../' gem 'rest-client', :github => 'opscode/rest-client', :branch => 'lcg/1.6.7-version-lying' -gem 'oc-chef-pedant', :git => 'git@github.com:opscode/oc-chef-pedant', :ref => '3c0eb31f1e49aa947b81ad51387b7a68adbc5f91' +gem 'oc-chef-pedant', :git => 'git@github.com:opscode/oc-chef-pedant', :ref => '85b6b7c15a95aba63404cfaf973b6c69a5c9377c' gem 'chef', :github => 'opscode/chef' From aa959000a3ec2582820f4f96e8ec7f97df7ae600 Mon Sep 17 00:00:00 2001 From: Marc Paradise Date: Wed, 4 Mar 2015 10:21:04 -0500 Subject: [PATCH 06/14] remove multitenant from pedant config, no longer valid --- spec/support/oc_pedant.rb | 3 --- 1 file changed, 3 deletions(-) diff --git a/spec/support/oc_pedant.rb b/spec/support/oc_pedant.rb index 1db663e0..e3bcf27d 100644 --- a/spec/support/oc_pedant.rb +++ b/spec/support/oc_pedant.rb @@ -77,9 +77,6 @@ superuser_key key webui_key key -# Set the platform_class -platform_class Pedant::MultiTenantPlatform - requestors({ :clients => { # The the admin user, for the purposes of getting things rolling From a921e1a8b38063269f644cf1904226634539054a Mon Sep 17 00:00:00 2001 From: Marc Paradise Date: Wed, 4 Mar 2015 12:16:33 -0500 Subject: [PATCH 07/14] Force complete deletion of org on DELETE request --- lib/chef_zero/endpoints/organization_endpoint.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/chef_zero/endpoints/organization_endpoint.rb b/lib/chef_zero/endpoints/organization_endpoint.rb index 585c46af..a5512dbf 100644 --- a/lib/chef_zero/endpoints/organization_endpoint.rb +++ b/lib/chef_zero/endpoints/organization_endpoint.rb @@ -32,7 +32,7 @@ def put(request) def delete(request) org = get_data(request, request.rest_path + [ 'org' ]) - delete_data_dir(request, request.rest_path) + delete_data_dir(request, request.rest_path, :recursive) already_json_response(200, populate_defaults(request, org)) end From b2381bf12f75309ba89c4bbae86f00a3f62634d5 Mon Sep 17 00:00:00 2001 From: Marc Paradise Date: Wed, 4 Mar 2015 15:33:28 -0500 Subject: [PATCH 08/14] Set oc-chef-pedant to the 2.0.0 tagged release, remove WIP comment --- Gemfile | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/Gemfile b/Gemfile index 3db58e36..7cae1849 100644 --- a/Gemfile +++ b/Gemfile @@ -3,9 +3,7 @@ gemspec gem 'rest-client', :github => 'chef/rest-client' -#WIP -#gem 'oc-chef-pedant', :github => 'chef/oc-chef-pedant', :tag => '2.0.0' -gem 'oc-chef-pedant', :github => 'chef/oc-chef-pedant', :branch => 'mp/merge-pedants' +gem 'oc-chef-pedant', :github => 'chef/oc-chef-pedant', :tag => '2.0.0' gem 'chef', :github => 'opscode/chef', :tag => '12.2.1' From e38a9bf13d52274011acde16b4cca7184a47d7d5 Mon Sep 17 00:00:00 2001 From: Andrew Brown Date: Fri, 3 Jul 2015 20:55:44 -0400 Subject: [PATCH 09/14] Update gem dependencies This commit simply updates the dependencies for more recent versions. --- Gemfile | 2 +- chef-zero.gemspec | 2 +- gemfiles/latest-chef.gemfile | 2 +- gemfiles/oc-chef-pedant.gemfile | 6 +++--- 4 files changed, 6 insertions(+), 6 deletions(-) diff --git a/Gemfile b/Gemfile index 7cae1849..2320e065 100644 --- a/Gemfile +++ b/Gemfile @@ -5,5 +5,5 @@ gem 'rest-client', :github => 'chef/rest-client' gem 'oc-chef-pedant', :github => 'chef/oc-chef-pedant', :tag => '2.0.0' -gem 'chef', :github => 'opscode/chef', :tag => '12.2.1' +gem 'chef', :github => 'chef/chef', :tag => '12.4.0' diff --git a/chef-zero.gemspec b/chef-zero.gemspec index 85380407..3bb0af67 100644 --- a/chef-zero.gemspec +++ b/chef-zero.gemspec @@ -15,7 +15,7 @@ Gem::Specification.new do |s| s.add_dependency 'mixlib-log', '~> 1.3' s.add_dependency 'hashie', '~> 2.0' s.add_dependency 'uuidtools', '~> 2.1' - s.add_dependency 'ffi-yajl', '>= 1.1', '< 3.0' + s.add_dependency 'ffi-yajl', '~> 2.2' s.add_dependency 'rack' s.add_development_dependency 'rake' diff --git a/gemfiles/latest-chef.gemfile b/gemfiles/latest-chef.gemfile index ba98724a..47420d67 100644 --- a/gemfiles/latest-chef.gemfile +++ b/gemfiles/latest-chef.gemfile @@ -2,4 +2,4 @@ source 'https://rubygems.org' gemspec :path => "../" -gem 'chef', :github => 'opscode/chef' +gem 'chef', :github => 'chef/chef' diff --git a/gemfiles/oc-chef-pedant.gemfile b/gemfiles/oc-chef-pedant.gemfile index fbd9c07d..dcdee27e 100644 --- a/gemfiles/oc-chef-pedant.gemfile +++ b/gemfiles/oc-chef-pedant.gemfile @@ -1,6 +1,6 @@ source 'https://rubygems.org' gemspec :path => '../' -gem 'rest-client', :github => 'opscode/rest-client', :branch => 'lcg/1.6.7-version-lying' -gem 'oc-chef-pedant', :git => 'git@github.com:opscode/oc-chef-pedant', :ref => '85b6b7c15a95aba63404cfaf973b6c69a5c9377c' -gem 'chef', :github => 'opscode/chef' +gem 'rest-client', :github => 'chef/rest-client', :branch => 'lcg/1.6.7-version-lying' +gem 'oc-chef-pedant', :github => 'chef/oc-chef-pedant', :tag => '2.0.0' +gem 'chef', :github => 'chef/chef' From 4366f5e580337876502478500c135b6cfc62d937 Mon Sep 17 00:00:00 2001 From: Andrew Brown Date: Fri, 3 Jul 2015 21:03:04 -0400 Subject: [PATCH 10/14] Support POST /organizations/ORGNAME/users This commit re-adds support for POST /organizations/ORGNAME/users. Since the code is very similar to /organizations/ORG/association_requests, we introduced a helper module to avoid code duplication. --- ...anization_association_requests_endpoint.rb | 17 +++-------- .../endpoints/organization_user_base.rb | 29 +++++++++++++++++++ .../endpoints/organization_users_endpoint.rb | 8 +++-- 3 files changed, 39 insertions(+), 15 deletions(-) create mode 100644 lib/chef_zero/endpoints/organization_user_base.rb diff --git a/lib/chef_zero/endpoints/organization_association_requests_endpoint.rb b/lib/chef_zero/endpoints/organization_association_requests_endpoint.rb index 608d5489..e1b6a7e6 100644 --- a/lib/chef_zero/endpoints/organization_association_requests_endpoint.rb +++ b/lib/chef_zero/endpoints/organization_association_requests_endpoint.rb @@ -6,23 +6,14 @@ module Endpoints # /organizations/ORG/association_requests class OrganizationAssociationRequestsEndpoint < RestBase def post(request) - json = FFI_Yajl::Parser.parse(request.body, :create_additions => false) - username = json['user'] - orgname = request.rest_path[1] - id = "#{username}-#{orgname}" - - if exists_data?(request, [ 'organizations', orgname, 'users', username ]) - raise RestErrorResponse.new(409, "User #{username} is already in organization #{orgname}") - end - - create_data(request, request.rest_path, username, '{}') - json_response(201, { "uri" => build_uri(request.base_uri, request.rest_path + [ id ]) }) + ChefZero::Endpoints::OrganizationUserBase.post(self, request, 'user') end def get(request) orgname = request.rest_path[1] - result = list_data(request).map { |username| { "id" => "#{username}-#{orgname}", 'username' => username } } - json_response(200, result) + ChefZero::Endpoints::OrganizationUserBase.get(self, request) do |username| + { "id" => "#{username}-#{orgname}", 'username' => username } + end end end end diff --git a/lib/chef_zero/endpoints/organization_user_base.rb b/lib/chef_zero/endpoints/organization_user_base.rb new file mode 100644 index 00000000..aaa2e3a6 --- /dev/null +++ b/lib/chef_zero/endpoints/organization_user_base.rb @@ -0,0 +1,29 @@ +require 'ffi_yajl' +require 'chef_zero/rest_base' + +module ChefZero + module Endpoints + module OrganizationUserBase + + def self.get(obj, request, &block) + result = obj.list_data(request).map(&block) + obj.json_response(200, result) + end + + def self.post(obj, request, key) + json = FFI_Yajl::Parser.parse(request.body, :create_additions => false) + username = json[key] + orgname = request.rest_path[1] + id = "#{username}-#{orgname}" + + if obj.exists_data?(request, [ 'organizations', orgname, 'users', username ]) + raise RestErrorResponse.new(409, "User #{username} is already in organization #{orgname}") + end + + obj.create_data(request, request.rest_path, username, '{}') + obj.json_response(201, { "uri" => obj.build_uri(request.base_uri, request.rest_path + [ id ]) }) + end + + end + end +end diff --git a/lib/chef_zero/endpoints/organization_users_endpoint.rb b/lib/chef_zero/endpoints/organization_users_endpoint.rb index ed70cf69..e9148204 100644 --- a/lib/chef_zero/endpoints/organization_users_endpoint.rb +++ b/lib/chef_zero/endpoints/organization_users_endpoint.rb @@ -1,13 +1,17 @@ require 'ffi_yajl' require 'chef_zero/rest_base' +require 'chef_zero/endpoints/organization_user_base' module ChefZero module Endpoints # /organizations/ORG/users class OrganizationUsersEndpoint < RestBase + def post(request) + ChefZero::Endpoints::OrganizationUserBase.post(self, request, 'username') + end + def get(request) - result = list_data(request).map { |username| { "user" => { "username" => username } } } - json_response(200, result) + ChefZero::Endpoints::OrganizationUserBase.get(self, request) { |username| { "user" => { "username" => username } } } end end end From 113e41ee7de1594c68025276de5c91afe719c99a Mon Sep 17 00:00:00 2001 From: Andrew Brown Date: Fri, 10 Jul 2015 13:11:37 -0400 Subject: [PATCH 11/14] Bumping dependency to chef 12.4.1 --- Gemfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Gemfile b/Gemfile index 2320e065..a5413e40 100644 --- a/Gemfile +++ b/Gemfile @@ -5,5 +5,5 @@ gem 'rest-client', :github => 'chef/rest-client' gem 'oc-chef-pedant', :github => 'chef/oc-chef-pedant', :tag => '2.0.0' -gem 'chef', :github => 'chef/chef', :tag => '12.4.0' +gem 'chef', :github => 'chef/chef', :tag => '12.4.1' From aabb201bf324f8c03fd0e55a51b91fa20e2fff55 Mon Sep 17 00:00:00 2001 From: Andrew Brown Date: Wed, 5 Aug 2015 16:00:01 -0400 Subject: [PATCH 12/14] Switch to pedant in chef-server repo Use the embedded pedant in the chef-server repo. This also requires slight changes to the pedant configuration, as the options have changed. --- Gemfile | 2 +- spec/run_oc_pedant.rb | 5 +++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/Gemfile b/Gemfile index a5413e40..6d3fbdf8 100644 --- a/Gemfile +++ b/Gemfile @@ -3,7 +3,7 @@ gemspec gem 'rest-client', :github => 'chef/rest-client' -gem 'oc-chef-pedant', :github => 'chef/oc-chef-pedant', :tag => '2.0.0' +gem 'oc-chef-pedant', :github => 'chef/chef-server' gem 'chef', :github => 'chef/chef', :tag => '12.4.1' diff --git a/spec/run_oc_pedant.rb b/spec/run_oc_pedant.rb index 053062af..efcaf8d4 100644 --- a/spec/run_oc_pedant.rb +++ b/spec/run_oc_pedant.rb @@ -29,7 +29,9 @@ #Pedant::Config.rerun = true Pedant.config.suite = 'api' + Pedant.config.internal_server = 'http://localhost:8889' Pedant.config[:config_file] = 'spec/support/oc_pedant.rb' + Pedant.config[:server_api_version] = 0 Pedant.setup([ '--skip-knife', '--skip-keys', @@ -40,8 +42,7 @@ '--skip-authorization', '--skip-omnibus', '--skip-usags', - '--skip-internal_orgs', - '--skip-rename_org', + '--exclude-internal-orgs', '--skip-headers' ]) From ae7634c600535ba3f64ce8af31afc6fef9dab31c Mon Sep 17 00:00:00 2001 From: Andrew Brown Date: Wed, 12 Aug 2015 08:46:24 -0400 Subject: [PATCH 13/14] Disable CS12 pedant flags Chef Zero does not yet 100% support CS12, hence we need to disable several of the failing tests until the code is written. --- spec/run_oc_pedant.rb | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/spec/run_oc_pedant.rb b/spec/run_oc_pedant.rb index efcaf8d4..c0ba7027 100644 --- a/spec/run_oc_pedant.rb +++ b/spec/run_oc_pedant.rb @@ -43,7 +43,15 @@ '--skip-omnibus', '--skip-usags', '--exclude-internal-orgs', - '--skip-headers' + '--skip-headers', + + # Chef 12 features not yet 100% supported by Chef Zero + '--skip-policies', + '--skip-server-api-version', + '--skip-cookbook-artifacts', + '--skip-containers', + '--skip-api-v1' + ]) result = RSpec::Core::Runner.run(Pedant.config.rspec_args) From 3197fc49cacb71c9c55de40935a5e08303afb7a3 Mon Sep 17 00:00:00 2001 From: Andrew Brown Date: Wed, 12 Aug 2015 08:52:25 -0400 Subject: [PATCH 14/14] Preliminary support for _identifiers API Adding preliminary support for the _identifiers REST endpoint. --- .../endpoints/node_identifiers_endpoint.rb | 22 +++++++++++++++++++ lib/chef_zero/server.rb | 2 ++ 2 files changed, 24 insertions(+) create mode 100644 lib/chef_zero/endpoints/node_identifiers_endpoint.rb diff --git a/lib/chef_zero/endpoints/node_identifiers_endpoint.rb b/lib/chef_zero/endpoints/node_identifiers_endpoint.rb new file mode 100644 index 00000000..9f89a981 --- /dev/null +++ b/lib/chef_zero/endpoints/node_identifiers_endpoint.rb @@ -0,0 +1,22 @@ +require 'ffi_yajl' +require 'chef_zero/rest_base' +require 'uuidtools' + +module ChefZero + module Endpoints + # /organizations/NAME/nodes/NAME/_identifiers + class NodeIdentifiersEndpoint < RestBase + def get(request) + if get_data(request, request.rest_path[0..3]) + result = { + :id => UUIDTools::UUID.parse_raw(request.rest_path[0..4].to_s).to_s.gsub('-',''), + :authz_id => '0'*32, + :org_id => UUIDTools::UUID.parse_raw(request.rest_path[0..1].to_s).to_s.gsub('-','') } + json_response(200, result) + else + raise RestErrorResponse.new(404, "Object not found: #{build_uri(request.base_uri, request.rest_path)}") + end + end + end + end +end diff --git a/lib/chef_zero/server.rb b/lib/chef_zero/server.rb index 9cf7b390..672f7955 100644 --- a/lib/chef_zero/server.rb +++ b/lib/chef_zero/server.rb @@ -61,6 +61,7 @@ require 'chef_zero/endpoints/environment_role_endpoint' require 'chef_zero/endpoints/license_endpoint' require 'chef_zero/endpoints/node_endpoint' +require 'chef_zero/endpoints/node_identifiers_endpoint' require 'chef_zero/endpoints/organizations_endpoint' require 'chef_zero/endpoints/organization_endpoint' require 'chef_zero/endpoints/organization_association_requests_endpoint' @@ -540,6 +541,7 @@ def open_source_endpoints [ "/organizations/*/environments/*/roles/*", EnvironmentRoleEndpoint.new(self) ], [ "/organizations/*/nodes", RestListEndpoint.new(self) ], [ "/organizations/*/nodes/*", NodeEndpoint.new(self) ], + [ "/organizations/*/nodes/*/_identifiers", NodeIdentifiersEndpoint.new(self) ], [ "/organizations/*/policies/*/*", PoliciesEndpoint.new(self) ], [ "/organizations/*/principals/*", PrincipalEndpoint.new(self) ], [ "/organizations/*/roles", RestListEndpoint.new(self) ],