summaryrefslogtreecommitdiff
path: root/lib/api/api.rb
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2021-10-20 08:43:02 +0000
committerGitLab Bot <gitlab-bot@gitlab.com>2021-10-20 08:43:02 +0000
commitd9ab72d6080f594d0b3cae15f14b3ef2c6c638cb (patch)
tree2341ef426af70ad1e289c38036737e04b0aa5007 /lib/api/api.rb
parentd6e514dd13db8947884cd58fe2a9c2a063400a9b (diff)
downloadgitlab-ce-3387b3d60d8a8211b84c6f8671fd7c4d050266f0.tar.gz
Add latest changes from gitlab-org/gitlab@14-4-stable-eev14.4.0-rc42
Diffstat (limited to 'lib/api/api.rb')
-rw-r--r--lib/api/api.rb25
1 files changed, 18 insertions, 7 deletions
diff --git a/lib/api/api.rb b/lib/api/api.rb
index d0d96858f61..a4d42c735cb 100644
--- a/lib/api/api.rb
+++ b/lib/api/api.rb
@@ -11,11 +11,12 @@ module API
COMMIT_ENDPOINT_REQUIREMENTS = NAMESPACE_OR_PROJECT_REQUIREMENTS.merge(sha: NO_SLASH_URL_PART_REGEX).freeze
USER_REQUIREMENTS = { user_id: NO_SLASH_URL_PART_REGEX }.freeze
LOG_FILTERS = ::Rails.application.config.filter_parameters + [/^output$/]
+ LOG_FORMATTER = Gitlab::GrapeLogging::Formatters::LogrageWithTimestamp.new
insert_before Grape::Middleware::Error,
GrapeLogging::Middleware::RequestLogger,
logger: Logger.new(LOG_FILENAME),
- formatter: Gitlab::GrapeLogging::Formatters::LogrageWithTimestamp.new,
+ formatter: LOG_FORMATTER,
include: [
GrapeLogging::Loggers::FilterParameters.new(LOG_FILTERS),
Gitlab::GrapeLogging::Loggers::ClientEnvLogger.new,
@@ -49,16 +50,19 @@ module API
before do
coerce_nil_params_to_array!
- api_endpoint = env['api.endpoint']
+ api_endpoint = request.env[Grape::Env::API_ENDPOINT]
feature_category = api_endpoint.options[:for].try(:feature_category_for_app, api_endpoint).to_s
+ # remote_ip is added here and the ContextLogger so that the
+ # client_id field is set correctly, as the user object does not
+ # survive between multiple context pushes.
Gitlab::ApplicationContext.push(
user: -> { @current_user },
project: -> { @project },
namespace: -> { @group },
runner: -> { @current_runner || @runner },
- caller_id: api_endpoint.endpoint_id,
remote_ip: request.ip,
+ caller_id: api_endpoint.endpoint_id,
feature_category: feature_category
)
end
@@ -124,6 +128,11 @@ module API
handle_api_exception(exception)
end
+ rescue_from RateLimitedService::RateLimitedError do |exception|
+ exception.log_request(context.request, context.current_user)
+ rack_response({ 'message' => { 'error' => exception.message } }.to_json, 429, exception.headers)
+ end
+
format :json
formatter :json, Gitlab::Json::GrapeFormatter
content_type :json, 'application/json'
@@ -132,6 +141,7 @@ module API
helpers ::API::Helpers
helpers ::API::Helpers::CommonHelpers
helpers ::API::Helpers::PerformanceBarHelpers
+ helpers ::API::Helpers::RateLimiter
namespace do
after do
@@ -157,6 +167,7 @@ module API
mount ::API::Ci::Jobs
mount ::API::Ci::Pipelines
mount ::API::Ci::PipelineSchedules
+ mount ::API::Ci::ResourceGroups
mount ::API::Ci::Runner
mount ::API::Ci::Runners
mount ::API::Ci::Triggers
@@ -170,9 +181,9 @@ module API
mount ::API::DeployTokens
mount ::API::Deployments
mount ::API::Environments
- mount ::API::ErrorTracking
- mount ::API::ErrorTrackingClientKeys
- mount ::API::ErrorTrackingCollector
+ mount ::API::ErrorTracking::ClientKeys
+ mount ::API::ErrorTracking::Collector
+ mount ::API::ErrorTracking::ProjectSettings
mount ::API::Events
mount ::API::FeatureFlags
mount ::API::FeatureFlagsUserLists
@@ -259,7 +270,7 @@ module API
mount ::API::ResourceAccessTokens
mount ::API::RubygemPackages
mount ::API::Search
- mount ::API::Services
+ mount ::API::Integrations
mount ::API::Settings
mount ::API::SidekiqMetrics
mount ::API::SnippetRepositoryStorageMoves