summaryrefslogtreecommitdiff
path: root/lib/api/helpers.rb
diff options
context:
space:
mode:
Diffstat (limited to 'lib/api/helpers.rb')
-rw-r--r--lib/api/helpers.rb25
1 files changed, 21 insertions, 4 deletions
diff --git a/lib/api/helpers.rb b/lib/api/helpers.rb
index f76b039..4bea5a2 100644
--- a/lib/api/helpers.rb
+++ b/lib/api/helpers.rb
@@ -1,5 +1,26 @@
module API
module Helpers
+ PRIVATE_TOKEN_PARAM = :private_token
+ PRIVATE_TOKEN_HEADER = "HTTP_PRIVATE_TOKEN"
+
+ def current_user
+ @current_user ||= begin
+ options = {
+ :private_token => (params[PRIVATE_TOKEN_PARAM] || env[PRIVATE_TOKEN_HEADER]),
+ :url => params[:url]
+ }
+ UserSession.new.authenticate_by_token(options)
+ end
+ end
+
+ def current_runner
+ @runner ||= Runner.find_by_token(params[:token])
+ end
+
+ def authenticate!
+ forbidden! unless current_user
+ end
+
def authenticate_runners!
forbidden! unless params[:token] == GitlabCi::RunnersToken
end
@@ -8,10 +29,6 @@ module API
forbidden! unless current_runner
end
- def current_runner
- @runner ||= Runner.find_by_token(params[:token])
- end
-
# Checks the occurrences of required attributes, each attribute must be present in the params hash
# or a Bad Request error is invoked.
#