diff options
author | Angelo Lakra <alakra@comverge.com> | 2013-09-23 20:58:16 -0600 |
---|---|---|
committer | Angelo Lakra <angelo.lakra@gmail.com> | 2013-10-08 00:43:14 -0600 |
commit | 0984328946aea015402b2254e2d0643def9235ce (patch) | |
tree | 89c3be4648d8c7f2e645d0ba7fcee78837e4f7c1 /lib/api | |
parent | 96fe0415f3968f3766ccd778c17a4cf2abf7782c (diff) | |
download | gitlab-ci-0984328946aea015402b2254e2d0643def9235ce.tar.gz |
Implementing method for authentication via token
Diffstat (limited to 'lib/api')
-rw-r--r-- | lib/api/api.rb | 1 | ||||
-rw-r--r-- | lib/api/entities.rb | 4 | ||||
-rw-r--r-- | lib/api/helpers.rb | 17 | ||||
-rw-r--r-- | lib/api/projects.rb | 19 |
4 files changed, 41 insertions, 0 deletions
diff --git a/lib/api/api.rb b/lib/api/api.rb index 394da09..f41a881 100644 --- a/lib/api/api.rb +++ b/lib/api/api.rb @@ -27,5 +27,6 @@ module API mount Builds mount Runners + mount Projects end end diff --git a/lib/api/entities.rb b/lib/api/entities.rb index bdc9e09..59108da 100644 --- a/lib/api/entities.rb +++ b/lib/api/entities.rb @@ -7,5 +7,9 @@ module API class Runner < Grape::Entity expose :id, :token end + + class Project < Grape::Entity + expose :id, :name, :timeout, :scripts, :token, :default_ref, :gitlab_url, :always_build, :polling_interval, :public, :ssh_url_to_repo, :gitlab_id + end end end diff --git a/lib/api/helpers.rb b/lib/api/helpers.rb index f76b039..13719b4 100644 --- a/lib/api/helpers.rb +++ b/lib/api/helpers.rb @@ -1,5 +1,22 @@ 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 authenticate! + forbidden! unless current_user + end + def authenticate_runners! forbidden! unless params[:token] == GitlabCi::RunnersToken end diff --git a/lib/api/projects.rb b/lib/api/projects.rb new file mode 100644 index 0000000..f9e6e94 --- /dev/null +++ b/lib/api/projects.rb @@ -0,0 +1,19 @@ +module API + # Projects API + class Projects < Grape::API + before { authenticate! } + + resource :projects do + # Retrieve info for a project + # + # Parameters: + # id (required) - The ID of a project + # Example Request: + # GET /projects/:id + get ":id" do + project = Project.where(id: params[:id]) + present project, with: Entities::Project + end + end + end +end |