summaryrefslogtreecommitdiff
path: root/lib/chef_zero
diff options
context:
space:
mode:
authorPhil Dibowitz <phild@fb.com>2015-02-05 11:05:34 -0800
committerPhil Dibowitz <phild@fb.com>2015-03-26 12:35:27 -0700
commit1b2a6e5f107254cce8200a4750035b30265ae0c8 (patch)
tree31329630f047fde21573f3b761c8335a705b8849 /lib/chef_zero
parent986f72c3b9636372873b0ad1031827b454f5e796 (diff)
downloadchef-zero-1b2a6e5f107254cce8200a4750035b30265ae0c8.tar.gz
Support /version; fix some global URIs
Diffstat (limited to 'lib/chef_zero')
-rw-r--r--lib/chef_zero/endpoints/version_endpoint.rb12
-rw-r--r--lib/chef_zero/rest_base.rb4
-rw-r--r--lib/chef_zero/server.rb26
3 files changed, 36 insertions, 6 deletions
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