diff options
author | Stan Hu <stanhu@gmail.com> | 2018-01-06 00:41:13 -0800 |
---|---|---|
committer | Stan Hu <stanhu@gmail.com> | 2018-01-08 21:23:24 -0800 |
commit | eaf9088ba8abe8c847a09860b55a86c7ae0d5987 (patch) | |
tree | 6aa8b076c5f598f8c0efa9ea7ef8d4e08870839a /lib/gitlab/grape_logging | |
parent | 7b2f9af4486b26512a2fefb3f385a2b8fa65a068 (diff) | |
download | gitlab-ce-eaf9088ba8abe8c847a09860b55a86c7ae0d5987.tar.gz |
Save user ID and username in Grape API log (api_json.log)sh-store-user-in-api-logs
This will enable admins to identify who actually made the API request.
Relates to #36960
Diffstat (limited to 'lib/gitlab/grape_logging')
-rw-r--r-- | lib/gitlab/grape_logging/loggers/user_logger.rb | 18 |
1 files changed, 18 insertions, 0 deletions
diff --git a/lib/gitlab/grape_logging/loggers/user_logger.rb b/lib/gitlab/grape_logging/loggers/user_logger.rb new file mode 100644 index 00000000000..fa172861967 --- /dev/null +++ b/lib/gitlab/grape_logging/loggers/user_logger.rb @@ -0,0 +1,18 @@ +# This grape_logging module (https://github.com/aserafin/grape_logging) makes it +# possible to log the user who performed the Grape API action by retrieving +# the user context from the request environment. +module Gitlab + module GrapeLogging + module Loggers + class UserLogger < ::GrapeLogging::Loggers::Base + def parameters(request, _) + params = request.env[::API::Helpers::API_USER_ENV] + + return {} unless params + + params.slice(:user_id, :username) + end + end + end + end +end |