diff options
-rw-r--r-- | CHANGELOG.md | 147 | ||||
-rw-r--r-- | lib/chef_zero/endpoints/version_endpoint.rb | 12 | ||||
-rw-r--r-- | lib/chef_zero/rest_base.rb | 4 | ||||
-rw-r--r-- | lib/chef_zero/server.rb | 26 | ||||
-rw-r--r-- | spec/server_spec.rb | 9 |
5 files changed, 121 insertions, 77 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md index 26dfc27..c2c16c0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,11 @@ Chef Zero CHANGELOG =================== +# unreleased + +* [**Phil Dibowitz**](https://github.com/jaymzh): + Added support for /version + # 4.0 (2/11/2014) - Add policyfile endpoints @@ -8,218 +13,218 @@ Chef Zero CHANGELOG # 3.2 (9/26/2014) -- removed 'json' gem dependency, replaced it with 'ffi-yajl' +* removed 'json' gem dependency, replaced it with 'ffi-yajl' # 3.1.3 (9/3/2014) -- fixes for running Chef local mode in multi-org mode +* fixes for running Chef local mode in multi-org mode # 3.1.2 (8/29/2014) -- add default to rspec for cookbooks -- add /organizations/NAME/organization/_acl as an alias for /organizations/NAME/organizations/_acl +* add default to rspec for cookbooks +* add /organizations/NAME/organization/_acl as an alias for /organizations/NAME/organizations/_acl # 3.1.1 (8/28/2014) -- fix minor bug with unknown container acls +* fix minor bug with unknown container acls # 3.1 (8/28/2014) -- New rspec data directives: organization, acl, group, container -- Fix organizations POST to honor full_name -- Fixes for enterprise rspec data loading -- Fix invites not removing the invite when user is forcibly added to an org +* New rspec data directives: organization, acl, group, container +* Fix organizations POST to honor full_name +* Fixes for enterprise rspec data loading +* Fix invites not removing the invite when user is forcibly added to an org # 3.0 (7/22/2014) -- Enterprise Chef support (organizations, ACLs, groups, much more) -- SSL support (@sawanoboly) +* Enterprise Chef support (organizations, ACLs, groups, much more) +* SSL support (@sawanoboly) # 2.2 (6/18/2014) -- allow port ranges to be passed in as enumerables, which will be tried in sequence until one works: `ChefZero::Server.new(:port => 80.upto(100))` +* allow port ranges to be passed in as enumerables, which will be tried in sequence until one works: `ChefZero::Server.new(:port => 80.upto(100))` # 2.1.5 (6/2/2014) -- fix issue with :single_org => <value> not being honored +* fix issue with :single_org => <value> not being honored # 2.1.4 (5/27/2014) -- fix issue with global Thread.exit_on_exception being set +* fix issue with global Thread.exit_on_exception being set # 2.1.3 (5/27/2014) -- rspec: default port to 8900 to not conflict with normal default port -- rspec: when chef_zero_opts is set, check if current server has those options before continuing +* rspec: default port to 8900 to not conflict with normal default port +* rspec: when chef_zero_opts is set, check if current server has those options before continuing # 2.1.2 (5/27/2014) -- fix build_uri (and thus cookbook downloads) +* fix build_uri (and thus cookbook downloads) # 2.1.1 (5/26/2014) -- flip defaults off in V1ToV2Adapater, allowing most chef tests to pass against 2.1.1 +* flip defaults off in V1ToV2Adapater, allowing most chef tests to pass against 2.1.1 # 2.1 (5/26/2014) -- **Multi-tenancy!** If you set :single_org => nil when starting the server, you will gain /organizations/* at the beginning of all URLs. Internally, all endpoints are rooted at /organizations/ORG anyway, there is just a translation that goes on to add /organizations/single_org to the URL when someone hits chef-zero. -- Fixes to support chef-zero local mode passing pedant +* **Multi-tenancy!** If you set :single_org => nil when starting the server, you will gain /organizations/* at the beginning of all URLs. Internally, all endpoints are rooted at /organizations/ORG anyway, there is just a translation that goes on to add /organizations/single_org to the URL when someone hits chef-zero. +* Fixes to support chef-zero local mode passing pedant # 2.0.2 (1/20/2014) -- Fix a series of typos in the README -- Read JSON, not a file path in `from_json` -- Fix IPV6 support -- Remove moneta as a dependency +* Fix a series of typos in the README +* Read JSON, not a file path in `from_json` +* Fix IPV6 support +* Remove moneta as a dependency # 2.0.1 (1/3/2014) -- Make playground items more semantic -- Fix an issue where an incorrect number of parameters was passed in `environments/NAME/nodes` endpoint -- Fix an issue where the `data_store` was not yet initialized in the server +* Make playground items more semantic +* Fix an issue where an incorrect number of parameters was passed in `environments/NAME/nodes` endpoint +* Fix an issue where the `data_store` was not yet initialized in the server # 2.0.0 (12/17/2013) -- Remove Puma (and `--socket` option) -- Use a cleaner threading approach -- Implement a better `running?` check +* Remove Puma (and `--socket` option) +* Use a cleaner threading approach +* Implement a better `running?` check # 1.7.3 -- (Backport) Read JSON, not a file path in `from_json` +* (Backport) Read JSON, not a file path in `from_json` # 1.6.3 -- (Backport) Read JSON, not a file path in `from_json` +* (Backport) Read JSON, not a file path in `from_json` # 1.5.5 -- Fix issue with - in term (name:a-b) +* Fix issue with - in term (name:a-b) # 1.5.4 -- Fix issue where run_lists in format cookbook::recipe@version do not depsolve +* Fix issue where run_lists in format cookbook::recipe@version do not depsolve # 1.5.3 -- Add Server: chef-zero header to response +* Add Server: chef-zero header to response # 1.5.2 -- Fix a couple of search query issues (make parentheses and NOT term:value work) +* Fix a couple of search query issues (make parentheses and NOT term:value work) # 1.5.1 -- Add Unix domain socket support (e.g. chef-zero --socket /tmp/chef-zero.sock) (stevendanna) +* Add Unix domain socket support (e.g. chef-zero --socket /tmp/chef-zero.sock) (stevendanna) # 1.5 -- Add -d option for daemon mode (sethvargo) -- Fix bug with cookbook metadata.rb files that rely on __FILE__ +* Add -d option for daemon mode (sethvargo) +* Fix bug with cookbook metadata.rb files that rely on __FILE__ # 1.4 -- Run with downgraded Puma 1.6 in order to work on Windows (2.x doesn't yet) +* Run with downgraded Puma 1.6 in order to work on Windows (2.x doesn't yet) # 1.3 -- Fix bug with search when JSON contains the same key in different places +* Fix bug with search when JSON contains the same key in different places # 1.2.1 -- Fix search when JSON contains integers +* Fix search when JSON contains integers # 1.2 -- Allow rspec users to specify cookbook NAME, VERSION, { :frozen => true } -- Documentation fix +* Allow rspec users to specify cookbook NAME, VERSION, { :frozen => true } +* Documentation fix # 1.1.3 -- Return better defaults for cookbooks -- Support /cookbook_versions?cookbook_versions=... query parameter -- Fix server crash when cookbook has multiple identical checksums +* Return better defaults for cookbooks +* Support /cookbook_versions?cookbook_versions=... query parameter +* Fix server crash when cookbook has multiple identical checksums # 1.1.2 -- Allow rspec users to specify the same data twice (overwrites) +* Allow rspec users to specify the same data twice (overwrites) # 1.1.1 -- Fix broken rspec functionality (jkeiser, reset) +* Fix broken rspec functionality (jkeiser, reset) # 1.1 -- Create plugin system to allow other storage besides memory +* Create plugin system to allow other storage besides memory # 1.0.1 -- Fix depsolver crash with frozen version strings (sethvargo) +* Fix depsolver crash with frozen version strings (sethvargo) # 1.0 -- Increased testing of server +* Increased testing of server # 0.9.13 -- Remove extra require of 'thin' so rspec users don't get broke +* Remove extra require of 'thin' so rspec users don't get broke # 0.9.12 -- Switch from thin to puma (sethvargo) +* Switch from thin to puma (sethvargo) # 0.9.11 -- Support full cookbook metadata.rb syntax, including "depends" +* Support full cookbook metadata.rb syntax, including "depends" # 0.9.10 -- Add -d flag to print debug output (sethvargo) +* Add -d flag to print debug output (sethvargo) # 0.9.9 -- Remove chef as a dependency so we can run on jruby (reset) -- Server assumes json is acceptable if Accept header is not sent (stevendanna) +* Remove chef as a dependency so we can run on jruby (reset) +* Server assumes json is acceptable if Accept header is not sent (stevendanna) # 0.9.8 -- Support runlists with a::b in them in depsolver +* Support runlists with a::b in them in depsolver # 0.9.7 -- Return file URLs and other important things in depsolver response +* Return file URLs and other important things in depsolver response # 0.9.6 -- Make 404 a JSON response +* Make 404 a JSON response # 0.9.5 -- Fix crash in 405 error response generator -- Add ability to verify request/response pairs from rspec api +* Fix crash in 405 error response generator +* Add ability to verify request/response pairs from rspec api # 0.9.4 -- Ruby 1.8.7 support +* Ruby 1.8.7 support # 0.9.3 -- rspec fixes: +* rspec fixes: - Faster (0 retries) - Work with more than one test - Allow tags on when_the_chef_server -- make 500 response return actual exception info +* make 500 response return actual exception info # 0.9.2 -- Speed increase for rspec (only start server once) -- Support CTRL+C when running rspec chef-zero tests +* Speed increase for rspec (only start server once) +* Support CTRL+C when running rspec chef-zero tests # 0.9.1 -- Switch from webrick -> thin -- Bugfixes +* Switch from webrick -> thin +* Bugfixes # 0.9 -- Initial code-complete release with working server +* Initial code-complete release with working server diff --git a/lib/chef_zero/endpoints/version_endpoint.rb b/lib/chef_zero/endpoints/version_endpoint.rb new file mode 100644 index 0000000..d38c33e --- /dev/null +++ b/lib/chef_zero/endpoints/version_endpoint.rb @@ -0,0 +1,12 @@ +require 'chef_zero/rest_base' + +module ChefZero + module Endpoints + # /version + class VersionEndpoint < RestBase + def get(request) + text_response(200, "chef-zero #{ChefZero::VERSION}\n") + end + end + end +end diff --git a/lib/chef_zero/rest_base.rb b/lib/chef_zero/rest_base.rb index 3fa017a..8156e7c 100644 --- a/lib/chef_zero/rest_base.rb +++ b/lib/chef_zero/rest_base.rb @@ -181,6 +181,10 @@ module ChefZero already_json_response(response_code, FFI_Yajl::Encoder.encode(json, :pretty => true)) end + def text_response(response_code, text) + [response_code, {"Content-Type" => "text/plain"}, text] + end + def already_json_response(response_code, json_text) [response_code, {"Content-Type" => "application/json"}, json_text] end diff --git a/lib/chef_zero/server.rb b/lib/chef_zero/server.rb index de2a3f5..fd37200 100644 --- a/lib/chef_zero/server.rb +++ b/lib/chef_zero/server.rb @@ -83,6 +83,7 @@ require 'chef_zero/endpoints/user_association_request_endpoint' require 'chef_zero/endpoints/user_organizations_endpoint' require 'chef_zero/endpoints/file_store_file_endpoint' require 'chef_zero/endpoints/not_found_endpoint' +require 'chef_zero/endpoints/version_endpoint' module ChefZero class Server @@ -95,6 +96,12 @@ module ChefZero :ssl => false }.freeze + GLOBAL_ENDPOINTS = [ + '/license', + '/users', + '/version', + ] + def initialize(options = {}) @options = DEFAULT_OPTIONS.merge(options) if @options[:single_org] && !@options.has_key?(:osc_compat) @@ -457,9 +464,9 @@ module ChefZero result = if options[:osc_compat] # OSC-only [ - [ "/organizations/*/users", ActorsEndpoint.new(self) ], - [ "/organizations/*/users/*", ActorEndpoint.new(self) ], - [ "/organizations/*/authenticate_user", OrganizationAuthenticateUserEndpoint.new(self) ], + [ "/users", ActorsEndpoint.new(self) ], + [ "/users/*", ActorEndpoint.new(self) ], + [ "/authenticate_user", OrganizationAuthenticateUserEndpoint.new(self) ], ] else # EC-only @@ -495,8 +502,7 @@ module ChefZero [ "/organizations/*/*/*/_acl/*", AclEndpoint.new(self) ] ] end - result + - [ + result + [ # Both [ "/organizations/*/clients", ActorsEndpoint.new(self) ], [ "/organizations/*/clients/*", ActorEndpoint.new(self) ], @@ -526,12 +532,19 @@ module ChefZero [ "/organizations/*/sandboxes/*", SandboxEndpoint.new(self) ], [ "/organizations/*/search", SearchesEndpoint.new(self) ], [ "/organizations/*/search/*", SearchEndpoint.new(self) ], + [ "/version", VersionEndpoint.new(self) ], # Internal [ "/organizations/*/file_store/**", FileStoreFileEndpoint.new(self) ] ] end + def global_endpoint?(ep) + GLOBAL_ENDPOINTS.any? do |g_ep| + ep.start_with?(g_ep) + end + end + def app router = RestRouter.new(open_source_endpoints) router.not_found = NotFoundEndpoint.new @@ -543,7 +556,8 @@ module ChefZero end return proc do |env| begin - request = RestRequest.new(env, rest_base_prefix) + prefix = global_endpoint?(env['PATH_INFO']) ? [] : rest_base_prefix + request = RestRequest.new(env, prefix) if @on_request_proc @on_request_proc.call(request) end diff --git a/spec/server_spec.rb b/spec/server_spec.rb index d5da281..558ef35 100644 --- a/spec/server_spec.rb +++ b/spec/server_spec.rb @@ -33,6 +33,12 @@ describe ChefZero::Server do httpcall.get('/nodes', 'Accept' => accepts) end + def get_version + uri = URI(@server.url) + httpcall = Net::HTTP.new(uri.host, uri.port) + httpcall.get('/version', 'Accept' => 'text/plain, application/json') + end + it 'accepts requests with no accept header' do request = Net::HTTP::Get.new('/nodes') request.delete('Accept') @@ -77,6 +83,9 @@ describe ChefZero::Server do expect(get_nodes('a/b;a=b;c=d, application/json;a=b, application/xml;a=b').code).to eq '200' end + it 'accepts /version' do + expect(get_version.body.start_with?('chef-zero')).to be true + end end end end |