diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2022-07-21 03:08:45 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2022-07-21 03:08:45 +0300 |
commit | d588fa9e6e2b468b0dca16c746ceae8b6d8f9205 (patch) | |
tree | d65f54657a72b247b47714f73db06a97455bfa31 /lib/api/helpers.rb | |
parent | f1f255857dd72d1aa234ea4874eadf6f4f1758ba (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'lib/api/helpers.rb')
-rw-r--r-- | lib/api/helpers.rb | 10 |
1 files changed, 10 insertions, 0 deletions
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 |