gitlab-org--gitlab-foss/lib/ci/api/helpers.rb

38 lines
1.1 KiB
Ruby
Raw Normal View History

2015-08-26 01:42:46 +00:00
module Ci
module API
module Helpers
2015-09-16 14:46:26 +00:00
UPDATE_RUNNER_EVERY = 60
2015-08-26 01:42:46 +00:00
def authenticate_runners!
forbidden! unless params[:token] == GitlabCi::REGISTRATION_TOKEN
end
def authenticate_runner!
forbidden! unless current_runner
end
def authenticate_project_token!(project)
forbidden! unless project.valid_token?(params[:project_token])
end
def update_runner_last_contact
2015-11-02 15:02:47 +00:00
# Use a random threshold to prevent beating DB updates
contacted_at_max_age = UPDATE_RUNNER_EVERY + Random.rand(UPDATE_RUNNER_EVERY)
if current_runner.contacted_at.nil? || Time.now - current_runner.contacted_at >= contacted_at_max_age
2015-08-26 01:42:46 +00:00
current_runner.update_attributes(contacted_at: Time.now)
end
end
2015-09-14 15:14:17 +00:00
def current_runner
@runner ||= Runner.find_by_token(params[:token].to_s)
end
2015-08-26 01:42:46 +00:00
def update_runner_info
return unless params["info"].present?
info = attributes_for_keys(["name", "version", "revision", "platform", "architecture"], params["info"])
current_runner.update(info)
end
end
end
end