Class: Bosh::Registry::ApiController
- Inherits:
-
Sinatra::Base
- Object
- Sinatra::Base
- Bosh::Registry::ApiController
- Defined in:
- lib/bosh/registry/api_controller.rb
Instance Method Summary collapse
- #authorized? ⇒ Boolean
-
#initialize ⇒ ApiController
constructor
A new instance of ApiController.
- #json(payload) ⇒ Object
- #protected! ⇒ Object
Constructor Details
#initialize ⇒ ApiController
Returns a new instance of ApiController.
38 39 40 41 42 43 44 45 |
# File 'lib/bosh/registry/api_controller.rb', line 38 def initialize super @logger = Bosh::Registry.logger @users = Set.new @users << [Bosh::Registry.http_user, Bosh::Registry.http_password] @instance_manager = Bosh::Registry.instance_manager end |
Instance Method Details
#authorized? ⇒ Boolean
54 55 56 57 58 59 60 |
# File 'lib/bosh/registry/api_controller.rb', line 54 def @auth ||= Rack::Auth::Basic::Request.new(request.env) @auth.provided? && @auth.basic? && @auth.credentials && @users.include?(@auth.credentials) end |
#json(payload) ⇒ Object
62 63 64 |
# File 'lib/bosh/registry/api_controller.rb', line 62 def json(payload) Yajl::Encoder.encode(payload) end |
#protected! ⇒ Object
47 48 49 50 51 52 |
# File 'lib/bosh/registry/api_controller.rb', line 47 def protected! unless headers("WWW-Authenticate" => 'Basic realm="Bosh Registry"') halt(401, json("status" => "access_denied")) end end |