Class: Bosh::AwsRegistry::ApiController
- Inherits:
-
Sinatra::Base
- Object
- Sinatra::Base
- Bosh::AwsRegistry::ApiController
- Defined in:
- lib/aws_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.
36 37 38 39 40 41 42 43 |
# File 'lib/aws_registry/api_controller.rb', line 36 def initialize super @logger = Bosh::AwsRegistry.logger @users = Set.new @users << [Bosh::AwsRegistry.http_user, Bosh::AwsRegistry.http_password] @instance_manager = InstanceManager.new end |
Instance Method Details
#authorized? ⇒ Boolean
52 53 54 55 56 57 58 |
# File 'lib/aws_registry/api_controller.rb', line 52 def @auth ||= Rack::Auth::Basic::Request.new(request.env) @auth.provided? && @auth.basic? && @auth.credentials && @users.include?(@auth.credentials) end |
#json(payload) ⇒ Object
60 61 62 |
# File 'lib/aws_registry/api_controller.rb', line 60 def json(payload) Yajl::Encoder.encode(payload) end |
#protected! ⇒ Object
45 46 47 48 49 50 |
# File 'lib/aws_registry/api_controller.rb', line 45 def protected! unless headers("WWW-Authenticate" => 'Basic realm="EC2 Registry"') halt(401, json("status" => "access_denied")) end end |