diff options
author | Thong Kuah <tkuah@gitlab.com> | 2019-09-12 01:35:10 +0300 |
---|---|---|
committer | Thong Kuah <tkuah@gitlab.com> | 2019-09-12 01:35:10 +0300 |
commit | eef1a7fe2c0964e0b507e3d7e557fc437570454c (patch) | |
tree | 6a1e5fdfb8014e68d75d6fca2a612d0824deff96 /lib | |
parent | 6c89bc7eae70ad9a63c4014d6457a80c18412fe5 (diff) | |
parent | 3c2b4a1cede956d5160ccf08d0a561bf31248161 (diff) |
Merge branch 'static-objects-external-storage' into 'master'
Enable serving static objects from an external storage
See merge request gitlab-org/gitlab-ce!31025
Diffstat (limited to 'lib')
-rw-r--r-- | lib/gitlab/auth/request_authenticator.rb | 4 | ||||
-rw-r--r-- | lib/gitlab/auth/user_auth_finders.rb | 22 |
2 files changed, 25 insertions, 1 deletions
diff --git a/lib/gitlab/auth/request_authenticator.rb b/lib/gitlab/auth/request_authenticator.rb index 176766d1a8b..aca8804b04c 100644 --- a/lib/gitlab/auth/request_authenticator.rb +++ b/lib/gitlab/auth/request_authenticator.rb @@ -24,7 +24,9 @@ module Gitlab end def find_sessionless_user(request_format) - find_user_from_web_access_token(request_format) || find_user_from_feed_token(request_format) + find_user_from_web_access_token(request_format) || + find_user_from_feed_token(request_format) || + find_user_from_static_object_token(request_format) rescue Gitlab::Auth::AuthenticationError nil end diff --git a/lib/gitlab/auth/user_auth_finders.rb b/lib/gitlab/auth/user_auth_finders.rb index 97755117edc..76d41eede23 100644 --- a/lib/gitlab/auth/user_auth_finders.rb +++ b/lib/gitlab/auth/user_auth_finders.rb @@ -28,6 +28,15 @@ module Gitlab current_request.env['warden']&.authenticate if verified_request? end + def find_user_from_static_object_token(request_format) + return unless valid_static_objects_format?(request_format) + + token = current_request.params[:token].presence || current_request.headers['X-Gitlab-Static-Object-Token'].presence + return unless token + + User.find_by_static_object_token(token) || raise(UnauthorizedError) + end + def find_user_from_feed_token(request_format) return unless valid_rss_format?(request_format) @@ -154,6 +163,15 @@ module Gitlab end end + def valid_static_objects_format?(request_format) + case request_format + when :archive + archive_request? + else + false + end + end + def rss_request? current_request.path.ends_with?('.atom') || current_request.format.atom? end @@ -165,6 +183,10 @@ module Gitlab def api_request? current_request.path.starts_with?("/api/") end + + def archive_request? + current_request.path.include?('/-/archive/') + end end end end |