diff options
author | Dmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com> | 2014-03-20 10:53:03 +0200 |
---|---|---|
committer | Dmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com> | 2014-03-20 10:53:03 +0200 |
commit | 83e83b6617694c03457ca3a36230b54560ce6833 (patch) | |
tree | f99f7ee9f3bbc83767e0d48abb7926b12f0b99c2 /lib | |
parent | 612a909eac58b8ebb6a2d9f68bbe2b8998411b89 (diff) | |
download | gitlab-ce-83e83b6617694c03457ca3a36230b54560ce6833.tar.gz |
Improve grack auth
Signed-off-by: Dmitriy Zaporozhets <dmitriy.zaporozhets@gmail.com>
Diffstat (limited to 'lib')
-rw-r--r-- | lib/gitlab/backend/grack_auth.rb | 21 | ||||
-rw-r--r-- | lib/gitlab/backend/grack_helpers.rb | 28 |
2 files changed, 17 insertions, 32 deletions
diff --git a/lib/gitlab/backend/grack_auth.rb b/lib/gitlab/backend/grack_auth.rb index ee99bd5f7de..b3e111354f5 100644 --- a/lib/gitlab/backend/grack_auth.rb +++ b/lib/gitlab/backend/grack_auth.rb @@ -1,9 +1,7 @@ require_relative 'shell_env' -require_relative 'grack_helpers' module Grack class Auth < Rack::Auth::Basic - include Helpers attr_accessor :user, :project, :env @@ -79,12 +77,14 @@ module Grack def authorize_request(service) case service - when 'git-upload-pack' + when *Gitlab::GitAccess::DOWNLOAD_COMMANDS # Serve only upload request. # Authorization on push will be serverd by update hook in repository Gitlab::GitAccess.new.download_allowed?(user, project) - else + when *Gitlab::GitAccess::PUSH_COMMANDS true + else + false end end @@ -101,5 +101,18 @@ module Grack def project @project ||= project_by_path(@request.path_info) end + + def project_by_path(path) + if m = /^([\w\.\/-]+)\.git/.match(path).to_a + path_with_namespace = m.last + path_with_namespace.gsub!(/\.wiki$/, '') + + Project.find_with_namespace(path_with_namespace) + end + end + + def render_not_found + [404, {"Content-Type" => "text/plain"}, ["Not Found"]] + end end end diff --git a/lib/gitlab/backend/grack_helpers.rb b/lib/gitlab/backend/grack_helpers.rb deleted file mode 100644 index cb747fe0137..00000000000 --- a/lib/gitlab/backend/grack_helpers.rb +++ /dev/null @@ -1,28 +0,0 @@ -module Grack - module Helpers - def project_by_path(path) - if m = /^([\w\.\/-]+)\.git/.match(path).to_a - path_with_namespace = m.last - path_with_namespace.gsub!(/\.wiki$/, '') - - Project.find_with_namespace(path_with_namespace) - end - end - - def render_not_found - [404, {"Content-Type" => "text/plain"}, ["Not Found"]] - end - - def can?(object, action, subject) - abilities.allowed?(object, action, subject) - end - - def abilities - @abilities ||= begin - abilities = Six.new - abilities << Ability - abilities - end - end - end -end |