Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2022-07-21 03:08:45 +0300
committerGitLab Bot <gitlab-bot@gitlab.com>2022-07-21 03:08:45 +0300
commitd588fa9e6e2b468b0dca16c746ceae8b6d8f9205 (patch)
treed65f54657a72b247b47714f73db06a97455bfa31 /lib
parentf1f255857dd72d1aa234ea4874eadf6f4f1758ba (diff)
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'lib')
-rw-r--r--lib/api/api.rb1
-rw-r--r--lib/api/api_guard.rb4
-rw-r--r--lib/api/helpers.rb10
-rw-r--r--lib/gitlab/grape_logging/loggers/token_logger.rb17
4 files changed, 31 insertions, 1 deletions
diff --git a/lib/api/api.rb b/lib/api/api.rb
index 8827371546c..89896129760 100644
--- a/lib/api/api.rb
+++ b/lib/api/api.rb
@@ -22,6 +22,7 @@ module API
Gitlab::GrapeLogging::Loggers::ClientEnvLogger.new,
Gitlab::GrapeLogging::Loggers::RouteLogger.new,
Gitlab::GrapeLogging::Loggers::UserLogger.new,
+ Gitlab::GrapeLogging::Loggers::TokenLogger.new,
Gitlab::GrapeLogging::Loggers::ExceptionLogger.new,
Gitlab::GrapeLogging::Loggers::QueueDurationLogger.new,
Gitlab::GrapeLogging::Loggers::PerfLogger.new,
diff --git a/lib/api/api_guard.rb b/lib/api/api_guard.rb
index 8822a30d4a1..df550f12c0d 100644
--- a/lib/api/api_guard.rb
+++ b/lib/api/api_guard.rb
@@ -48,7 +48,9 @@ module API
include Gitlab::Auth::AuthFinders
def access_token
- super || find_personal_access_token_from_http_basic_auth
+ strong_memoize(:api_guard_access_token) do
+ super || find_personal_access_token_from_http_basic_auth
+ end
end
def find_current_user!
diff --git a/lib/api/helpers.rb b/lib/api/helpers.rb
index e462ca19ba6..0bc643b40a3 100644
--- a/lib/api/helpers.rb
+++ b/lib/api/helpers.rb
@@ -11,6 +11,7 @@ module API
GITLAB_SHARED_SECRET_HEADER = "Gitlab-Shared-Secret"
SUDO_PARAM = :sudo
API_USER_ENV = 'gitlab.api.user'
+ API_TOKEN_ENV = 'gitlab.api.token'
API_EXCEPTION_ENV = 'gitlab.api.exception'
API_RESPONSE_STATUS_CODE = 'gitlab.api.response_status_code'
@@ -74,6 +75,8 @@ module API
save_current_user_in_env(@current_user) if @current_user
+ save_current_token_in_env
+
if @current_user
::ApplicationRecord
.sticking
@@ -88,6 +91,13 @@ module API
env[API_USER_ENV] = { user_id: user.id, username: user.username }
end
+ def save_current_token_in_env
+ token = access_token
+ env[API_TOKEN_ENV] = { token_id: token.id, token_type: token.class } if token
+
+ rescue Gitlab::Auth::UnauthorizedError
+ end
+
def sudo?
initial_current_user != current_user
end
diff --git a/lib/gitlab/grape_logging/loggers/token_logger.rb b/lib/gitlab/grape_logging/loggers/token_logger.rb
new file mode 100644
index 00000000000..a7c1b42ec96
--- /dev/null
+++ b/lib/gitlab/grape_logging/loggers/token_logger.rb
@@ -0,0 +1,17 @@
+# frozen_string_literal: true
+
+module Gitlab
+ module GrapeLogging
+ module Loggers
+ class TokenLogger < ::GrapeLogging::Loggers::Base
+ def parameters(request, _)
+ params = request.env[::API::Helpers::API_TOKEN_ENV]
+
+ return {} unless params
+
+ params.slice(:token_type, :token_id)
+ end
+ end
+ end
+ end
+end