summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohn Keiser <jkeiser@opscode.com>2014-06-02 14:56:35 -0700
committerJohn Keiser <jkeiser@opscode.com>2014-06-02 14:56:35 -0700
commita1d5a5d147afad5aa41c99e1b00ce0f543c33dae (patch)
tree0915a339b81e83b9bbf426ec2f8f71caacec021f
parent9a1500be6d98828454a740c77403f1b3e74e28ed (diff)
downloadchef-zero-a1d5a5d147afad5aa41c99e1b00ce0f543c33dae.tar.gz
Honor :single_org => 'orgname' parameter everywhere
-rw-r--r--lib/chef_zero/rest_base.rb2
-rw-r--r--lib/chef_zero/server.rb51
-rw-r--r--spec/run.rb11
-rw-r--r--spec/support/pedant.rb6
4 files changed, 43 insertions, 27 deletions
diff --git a/lib/chef_zero/rest_base.rb b/lib/chef_zero/rest_base.rb
index 1ed7366..f01950f 100644
--- a/lib/chef_zero/rest_base.rb
+++ b/lib/chef_zero/rest_base.rb
@@ -123,7 +123,7 @@ module ChefZero
def 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' ]
+ if rest_path[0..1] != [ 'organizations', server.options[:single_org] ]
raise "Unexpected URL #{rest_path[0..1]} passed to build_uri in single org mode"
end
"#{base_uri}/#{rest_path[2..-1].join('/')}"
diff --git a/lib/chef_zero/server.rb b/lib/chef_zero/server.rb
index e279441..4955282 100644
--- a/lib/chef_zero/server.rb
+++ b/lib/chef_zero/server.rb
@@ -386,35 +386,42 @@ module ChefZero
router.not_found = NotFoundEndpoint.new
if options[:single_org]
- rest_base_prefix = [ 'organizations', 'chef' ]
+ rest_base_prefix = [ 'organizations', options[:single_org] ]
else
rest_base_prefix = []
end
return proc do |env|
- request = RestRequest.new(env, rest_base_prefix)
- if @on_request_proc
- @on_request_proc.call(request)
- end
- response = nil
- if @request_handler
- response = @request_handler.call(request)
- end
- unless response
- response = router.call(request)
- end
- if @on_response_proc
- @on_response_proc.call(request, response)
- end
+ begin
+ request = RestRequest.new(env, rest_base_prefix)
+ if @on_request_proc
+ @on_request_proc.call(request)
+ end
+ response = nil
+ if @request_handler
+ response = @request_handler.call(request)
+ end
+ unless response
+ response = router.call(request)
+ end
+ if @on_response_proc
+ @on_response_proc.call(request, response)
+ end
- # Insert Server header
- response[1]['Server'] = 'chef-zero'
+ # Insert Server header
+ response[1]['Server'] = 'chef-zero'
- # Puma expects the response to be an array (chunked responses). Since
- # we are statically generating data, we won't ever have said chunked
- # response, so fake it.
- response[-1] = Array(response[-1])
+ # Puma expects the response to be an array (chunked responses). Since
+ # we are statically generating data, we won't ever have said chunked
+ # response, so fake it.
+ response[-1] = Array(response[-1])
- response
+ response
+ rescue
+ if options[:log_level] == :debug
+ STDERR.puts "Request Error: #{$!}"
+ STDERR.puts $!.backtrace.join("\n")
+ end
+ end
end
end
diff --git a/spec/run.rb b/spec/run.rb
index aec8176..11084ea 100644
--- a/spec/run.rb
+++ b/spec/run.rb
@@ -7,7 +7,7 @@ require 'rspec/core'
tmpdir = nil
-def start_server(chef_repo_path)
+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
@@ -43,10 +43,15 @@ begin
chef_repo_path = "#{tmpdir}/repo"
# Capture setup data into master_chef_repo_path
- server = start_server(chef_repo_path)
+ server = start_local_server(chef_repo_path)
+
+ elsif ENV['SINGLE_ORG']
+ server = ChefZero::Server.new(:port => 8889, :single_org => 'singleorg')
+ server.start_background
else
- server = ChefZero::Server.new(:port => 8889)
+ server = ChefZero::Server.new(:port => 8889, :single_org => false)
+ server.data_store.create_dir([ 'organizations' ], 'pedant')
server.start_background
end
diff --git a/spec/support/pedant.rb b/spec/support/pedant.rb
index d21a2f7..3ac1922 100644
--- a/spec/support/pedant.rb
+++ b/spec/support/pedant.rb
@@ -21,7 +21,11 @@
################################################################################
# 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'
+if ENV['SINGLE_ORG']
+ 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