Module: Bosh::Director::Api::ControllerHelpers

Defined in:
lib/bosh/director/api/controller_helpers.rb

Instance Method Summary collapse

Instance Method Details

#authorized?Boolean

Returns:

  • (Boolean)


22
23
24
25
# File 'lib/bosh/director/api/controller_helpers.rb', line 22

def authorized?
  @auth ||=  Rack::Auth::Basic::Request.new(request.env)
  @auth.provided? && @auth.basic? && @auth.credentials && authenticate(*@auth.credentials)
end

#convert_job_instance_hash(hash) ⇒ Object



27
28
29
30
31
32
# File 'lib/bosh/director/api/controller_helpers.rb', line 27

def convert_job_instance_hash(hash)
  hash.reduce([]) do |jobs, kv|
    job, indicies = kv
    jobs + indicies.map { |index| [job, index] }
  end
end

#protected!Object



15
16
17
18
19
20
# File 'lib/bosh/director/api/controller_helpers.rb', line 15

def protected!
  unless authorized?
    response['WWW-Authenticate'] = 'Basic realm="BOSH Director"'
    throw(:halt, [401, "Not authorized\n"])
  end
end

#task_timeout?(task) ⇒ Boolean

Returns:

  • (Boolean)


3
4
5
6
7
8
9
10
11
12
13
# File 'lib/bosh/director/api/controller_helpers.rb', line 3

def task_timeout?(task)
  # Some of the old task entries might not have the checkpoint_time
  unless task.checkpoint_time
    task.checkpoint_time = Time.now
    task.save
  end

  # If no checkpoint update in 3 cycles --> timeout
  (task.state == 'processing' || task.state == 'cancelling') &&
    (Time.now - task.checkpoint_time > Config.task_checkpoint_interval * 3)
end