summaryrefslogtreecommitdiff
path: root/lib/ci/api/helpers.rb
diff options
context:
space:
mode:
authorKamil Trzciński <ayufan@ayufan.eu>2015-09-16 11:57:40 +0000
committerKamil Trzciński <ayufan@ayufan.eu>2015-09-16 11:57:40 +0000
commitcccd269da3f5d82c5d14289980d9b52c9cad08db (patch)
tree2947658dfff44a3873f7d350f0353dbdb7b9b541 /lib/ci/api/helpers.rb
parent7d59ba00b9aa1a8be28f1b7ccaa1c628be90aabb (diff)
parentac8d2eb065e9522679d4eae4649c6815daa5460c (diff)
downloadgitlab-ce-cccd269da3f5d82c5d14289980d9b52c9cad08db.tar.gz
Merge branch 'ci-and-ce-sitting-in-a-tree-k-i-s-s-i-n-g' into 'master'
Merge CI into CE First step of #2164. - [x] Merge latest CE master - [x] Make application start - [x] Re-use gitlab sessions (remove CI oauth part) - [x] Get rid of gitlab_ci.yml config - [x] Make tests start - [x] Make most CI features works - [x] Make tests green - [x] Write migration documentation - [x] Add CI builds to CE backup See merge request !1204
Diffstat (limited to 'lib/ci/api/helpers.rb')
-rw-r--r--lib/ci/api/helpers.rb33
1 files changed, 33 insertions, 0 deletions
diff --git a/lib/ci/api/helpers.rb b/lib/ci/api/helpers.rb
new file mode 100644
index 00000000000..9197f917d73
--- /dev/null
+++ b/lib/ci/api/helpers.rb
@@ -0,0 +1,33 @@
+module Ci
+ module API
+ module Helpers
+ 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
+ if current_runner.contacted_at.nil? || Time.now - current_runner.contacted_at >= UPDATE_RUNNER_EVERY
+ current_runner.update_attributes(contacted_at: Time.now)
+ end
+ end
+
+ def current_runner
+ @runner ||= Runner.find_by_token(params[:token].to_s)
+ end
+
+ 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