summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLamont Granquist <lamont@scriptkiddie.org>2017-07-17 09:00:14 -0700
committerGitHub <noreply@github.com>2017-07-17 09:00:14 -0700
commit650988adeb80c0eeca8703e5e45390e2acb0073a (patch)
treef082483b9f5db4138e07888e8381a0f55f580eab
parent64f2639f047ae368ff7b3110f1dc9bf477be77f0 (diff)
parent473df0d58dc3c0ef89862aafb111325a9af31389 (diff)
downloadchef-zero-650988adeb80c0eeca8703e5e45390e2acb0073a.tar.gz
Merge pull request #269 from chef/lcg/universe-endpoint
add the universe endpoint
-rw-r--r--lib/chef_zero/endpoints/cookbooks_base.rb16
-rw-r--r--lib/chef_zero/endpoints/universe_endpoint.rb15
-rw-r--r--lib/chef_zero/server.rb4
-rw-r--r--spec/run_oc_pedant.rb3
4 files changed, 34 insertions, 4 deletions
diff --git a/lib/chef_zero/endpoints/cookbooks_base.rb b/lib/chef_zero/endpoints/cookbooks_base.rb
index f97c38c..55b79ca 100644
--- a/lib/chef_zero/endpoints/cookbooks_base.rb
+++ b/lib/chef_zero/endpoints/cookbooks_base.rb
@@ -23,6 +23,22 @@ module ChefZero
results
end
+ def format_universe_list(request, cookbooks_list)
+ results = {}
+ cookbooks_list.each do |name, versions|
+ results[name] ||= {}
+ versions.each do |version|
+ cookbook_data = FFI_Yajl::Parser.parse(get_data(request, request.rest_path[0..1] + [ "cookbooks", name, version ], :nil))
+ results[name][version] ||= {
+ "dependencies" => cookbook_data["metadata"]["dependencies"],
+ "location_path" => build_uri(request.base_uri, request.rest_path[0..1] + ["cookbooks", name, version]),
+ "location_type" => "chef_server",
+ }
+ end
+ end
+ results
+ end
+
def all_cookbooks_list(request)
result = {}
# Race conditions exist here (if someone deletes while listing). I don't care.
diff --git a/lib/chef_zero/endpoints/universe_endpoint.rb b/lib/chef_zero/endpoints/universe_endpoint.rb
new file mode 100644
index 0000000..5ee59b1
--- /dev/null
+++ b/lib/chef_zero/endpoints/universe_endpoint.rb
@@ -0,0 +1,15 @@
+require "ffi_yajl"
+require "chef_zero/endpoints/rest_object_endpoint"
+require "chef_zero/chef_data/data_normalizer"
+
+module ChefZero
+ module Endpoints
+ # /universe
+ class UniverseEndpoint < CookbooksBase
+
+ def get(request)
+ json_response(200, format_universe_list(request, all_cookbooks_list(request)))
+ end
+ end
+ end
+end
diff --git a/lib/chef_zero/server.rb b/lib/chef_zero/server.rb
index 43b42f8..4771412 100644
--- a/lib/chef_zero/server.rb
+++ b/lib/chef_zero/server.rb
@@ -1,6 +1,6 @@
#
# Author:: John Keiser (<jkeiser@opscode.com>)
-# Copyright:: Copyright (c) 2012 Opscode, Inc.
+# Copyright:: Copyright (c) 2012-2017, Chef Software Inc.
# License:: Apache License, Version 2.0
#
# Licensed under the Apache License, Version 2.0 (the "License");
@@ -105,6 +105,7 @@ require "chef_zero/endpoints/file_store_file_endpoint"
require "chef_zero/endpoints/not_found_endpoint"
require "chef_zero/endpoints/version_endpoint"
require "chef_zero/endpoints/server_api_version_endpoint"
+require "chef_zero/endpoints/universe_endpoint"
module ChefZero
@@ -623,6 +624,7 @@ module ChefZero
[ "/organizations/*/sandboxes/*", SandboxEndpoint.new(self) ],
[ "/organizations/*/search", SearchesEndpoint.new(self) ],
[ "/organizations/*/search/*", SearchEndpoint.new(self) ],
+ [ "/organizations/*/universe", UniverseEndpoint.new(self) ],
[ "/version", VersionEndpoint.new(self) ],
[ "/server_api_version", ServerAPIVersionEndpoint.new(self) ],
diff --git a/spec/run_oc_pedant.rb b/spec/run_oc_pedant.rb
index 411b502..0ee94b5 100644
--- a/spec/run_oc_pedant.rb
+++ b/spec/run_oc_pedant.rb
@@ -179,9 +179,6 @@ begin
# Chef 12 features not yet 100% supported by Chef Zero
- # The universe endpoint is unlikely to ever make sense for Chef Zero
- "--skip-universe",
-
# chef-zero has some non-removable quirks, such as the fact that files
# with 255-character names cannot be stored in local mode. This is
# reserved only for quirks that are *irrevocable* and by design; and