summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohn Keiser <jkeiser@opscode.com>2014-04-18 16:29:59 -0700
committerJohn Keiser <jkeiser@opscode.com>2014-04-18 16:29:59 -0700
commitacd80b7e3422d22bc717db40cf26598b7f4e618e (patch)
tree21bc9130c7497cd5d2460eb5bf55d9099ce59325
parente655c7857e9568ece4555e627fc7d3aa372449ae (diff)
downloadchef-zero-acd80b7e3422d22bc717db40cf26598b7f4e618e.tar.gz
Get single_org backcompat mode working
-rw-r--r--lib/chef_zero/data_normalizer.rb4
-rw-r--r--lib/chef_zero/data_store/memory_store.rb2
-rw-r--r--lib/chef_zero/endpoints/cookbook_version_endpoint.rb2
-rw-r--r--lib/chef_zero/endpoints/environment_cookbook_versions_endpoint.rb2
-rw-r--r--lib/chef_zero/rest_base.rb11
-rw-r--r--lib/chef_zero/server.rb21
-rw-r--r--spec/support/pedant.rb2
7 files changed, 29 insertions, 15 deletions
diff --git a/lib/chef_zero/data_normalizer.rb b/lib/chef_zero/data_normalizer.rb
index ffe3c59..8e813fe 100644
--- a/lib/chef_zero/data_normalizer.rb
+++ b/lib/chef_zero/data_normalizer.rb
@@ -61,14 +61,14 @@ module ChefZero
environment
end
- def self.normalize_cookbook(org_prefix, cookbook, name, version, base_uri, method)
+ def self.normalize_cookbook(endpoint, org_prefix, cookbook, name, version, base_uri, method)
# TODO I feel dirty
if method != 'PUT'
cookbook.each_pair do |key, value|
if value.is_a?(Array)
value.each do |file|
if file.is_a?(Hash) && file.has_key?('checksum')
- file['url'] ||= RestBase::build_uri(base_uri, org_prefix + ['file_store', 'checksums', file['checksum']])
+ file['url'] ||= endpoint.build_uri(base_uri, org_prefix + ['file_store', 'checksums', file['checksum']])
end
end
end
diff --git a/lib/chef_zero/data_store/memory_store.rb b/lib/chef_zero/data_store/memory_store.rb
index aa0bb5c..c7e5b7f 100644
--- a/lib/chef_zero/data_store/memory_store.rb
+++ b/lib/chef_zero/data_store/memory_store.rb
@@ -30,8 +30,6 @@ module ChefZero
@data = {}
create_dir([], 'organizations')
- # TODO this should only be automatic when multi_org is false
- create_dir([ 'organizations' ], 'chef')
end
def create_org
diff --git a/lib/chef_zero/endpoints/cookbook_version_endpoint.rb b/lib/chef_zero/endpoints/cookbook_version_endpoint.rb
index 706382a..03eec06 100644
--- a/lib/chef_zero/endpoints/cookbook_version_endpoint.rb
+++ b/lib/chef_zero/endpoints/cookbook_version_endpoint.rb
@@ -105,7 +105,7 @@ module ChefZero
def populate_defaults(request, response_json)
# Inject URIs into each cookbook file
cookbook = JSON.parse(response_json, :create_additions => false)
- cookbook = DataNormalizer.normalize_cookbook(request.rest_path[0..1], cookbook, request.rest_path[3], request.rest_path[4], request.base_uri, request.method)
+ cookbook = DataNormalizer.normalize_cookbook(self, request.rest_path[0..1], cookbook, request.rest_path[3], request.rest_path[4], request.base_uri, request.method)
JSON.pretty_generate(cookbook)
end
diff --git a/lib/chef_zero/endpoints/environment_cookbook_versions_endpoint.rb b/lib/chef_zero/endpoints/environment_cookbook_versions_endpoint.rb
index 3081ba5..d6e1a80 100644
--- a/lib/chef_zero/endpoints/environment_cookbook_versions_endpoint.rb
+++ b/lib/chef_zero/endpoints/environment_cookbook_versions_endpoint.rb
@@ -49,7 +49,7 @@ module ChefZero
result = {}
solved.each_pair do |name, versions|
cookbook = JSON.parse(get_data(request, request.rest_path[0..1] + ['cookbooks', name, versions[0]]), :create_additions => false)
- result[name] = DataNormalizer.normalize_cookbook(request.rest_path[0..1], cookbook, name, versions[0], request.base_uri, 'MIN')
+ result[name] = DataNormalizer.normalize_cookbook(self, request.rest_path[0..1], cookbook, name, versions[0], request.base_uri, 'MIN')
end
json_response(200, result)
end
diff --git a/lib/chef_zero/rest_base.rb b/lib/chef_zero/rest_base.rb
index 72361ab..de81ae6 100644
--- a/lib/chef_zero/rest_base.rb
+++ b/lib/chef_zero/rest_base.rb
@@ -120,11 +120,18 @@ module ChefZero
end
def build_uri(base_uri, rest_path)
- RestBase::build_uri(base_uri, rest_path)
+ if server.options[:single_org]
+ # Strip off /organizations/chef if we are in single org mode
+ if rest_path[0..1] != [ 'organizations', 'chef' ]
+ raise "Unexpected URL #{rest_path[0..1]} passed to build_uri in single org mode"
+ end
+ "#{base_uri}/#{rest_path[2..-1].join('/')}"
+ else
+ "#{base_uri}/#{rest_path.join('/')}"
+ end
end
def self.build_uri(base_uri, rest_path)
- "#{base_uri}/#{rest_path.join('/')}"
end
def populate_defaults(request, response)
diff --git a/lib/chef_zero/server.rb b/lib/chef_zero/server.rb
index 5460d95..a5c0c0d 100644
--- a/lib/chef_zero/server.rb
+++ b/lib/chef_zero/server.rb
@@ -66,7 +66,7 @@ module ChefZero
:port => 8889,
:log_level => :info,
:generate_real_keys => true,
- :multi_org => true
+ :single_org => 'chef'
}.freeze
def initialize(options = {})
@@ -106,7 +106,13 @@ module ChefZero
# @return [~ChefZero::DataStore]
#
def data_store
- @data_store ||= @options[:data_store] || DataStore::MemoryStore.new
+ @data_store ||= begin
+ result = @options[:data_store] || DataStore::MemoryStore.new
+ if options[:single_org]
+ result.create_dir([ 'organizations' ], options[:single_org])
+ end
+ result
+ end
end
#
@@ -267,7 +273,7 @@ module ChefZero
# }
# }
def load_data(contents, org_name = 'chef')
- create_dir('organizations', org_name)
+ data_store.create_dir('organizations', org_name)
%w(clients environments nodes roles users).each do |data_type|
if contents[data_type]
dejsonize_children(contents[data_type]).each_pair do |name, data|
@@ -305,6 +311,9 @@ module ChefZero
def clear_data
data_store.clear
+ if options[:single_org]
+ data_store.create_dir([ 'organizations' ], options[:single_org])
+ end
end
def request_handler(&block)
@@ -362,10 +371,10 @@ module ChefZero
router = RestRouter.new(open_source_endpoints)
router.not_found = NotFoundEndpoint.new
- if options[:multi_org]
- rest_base_prefix = []
- else
+ if options[:single_org]
rest_base_prefix = [ 'organizations', 'chef' ]
+ else
+ rest_base_prefix = []
end
return proc do |env|
request = RestRequest.new(env, rest_base_prefix)
diff --git a/spec/support/pedant.rb b/spec/support/pedant.rb
index 39a234d..d21a2f7 100644
--- a/spec/support/pedant.rb
+++ b/spec/support/pedant.rb
@@ -21,7 +21,7 @@
################################################################################
# You MUST specify the address of the server the API requests will be
# sent to. Only specify protocol, hostname, and port.
-chef_server 'http://127.0.0.1:8889/organizations/chef'
+chef_server 'http://127.0.0.1:8889'
# If you are doing development testing, you can specify the address of
# the Solr server. The presence of this parameter will enable tests