2013-05-14 08:33:31 -04:00
|
|
|
module API
|
2012-06-27 07:32:56 -04:00
|
|
|
class API < Grape::API
|
2014-12-19 09:15:29 -05:00
|
|
|
include APIGuard
|
2017-01-30 12:41:56 -05:00
|
|
|
|
2017-06-20 03:40:24 -04:00
|
|
|
allow_access_with_scope :api
|
|
|
|
|
2017-01-30 12:41:56 -05:00
|
|
|
version %w(v3 v4), using: :path
|
|
|
|
|
|
|
|
version 'v3', using: :path do
|
2017-02-25 03:44:09 -05:00
|
|
|
helpers ::API::V3::Helpers
|
2017-05-04 08:11:15 -04:00
|
|
|
helpers ::API::Helpers::CommonHelpers
|
2017-02-25 03:44:09 -05:00
|
|
|
|
2017-02-20 14:32:44 -05:00
|
|
|
mount ::API::V3::AwardEmoji
|
2017-02-06 13:38:17 -05:00
|
|
|
mount ::API::V3::Boards
|
|
|
|
mount ::API::V3::Branches
|
2017-02-20 14:32:44 -05:00
|
|
|
mount ::API::V3::BroadcastMessages
|
2017-02-22 05:13:59 -05:00
|
|
|
mount ::API::V3::Builds
|
2017-02-02 09:24:30 -05:00
|
|
|
mount ::API::V3::Commits
|
2017-02-06 08:39:22 -05:00
|
|
|
mount ::API::V3::DeployKeys
|
2017-02-20 14:32:44 -05:00
|
|
|
mount ::API::V3::Environments
|
2017-02-02 09:24:30 -05:00
|
|
|
mount ::API::V3::Files
|
2017-02-24 03:29:53 -05:00
|
|
|
mount ::API::V3::Groups
|
2017-01-25 16:35:27 -05:00
|
|
|
mount ::API::V3::Issues
|
2017-02-06 13:38:17 -05:00
|
|
|
mount ::API::V3::Labels
|
2017-02-09 07:39:39 -05:00
|
|
|
mount ::API::V3::Members
|
2017-02-06 13:38:17 -05:00
|
|
|
mount ::API::V3::MergeRequestDiffs
|
2017-01-25 16:35:27 -05:00
|
|
|
mount ::API::V3::MergeRequests
|
2017-02-20 09:35:05 -05:00
|
|
|
mount ::API::V3::Notes
|
2017-01-30 06:11:58 -05:00
|
|
|
mount ::API::V3::Pipelines
|
2017-02-06 13:38:17 -05:00
|
|
|
mount ::API::V3::ProjectHooks
|
2017-02-09 09:28:19 -05:00
|
|
|
mount ::API::V3::Milestones
|
2017-01-30 12:41:56 -05:00
|
|
|
mount ::API::V3::Projects
|
2017-02-06 08:25:49 -05:00
|
|
|
mount ::API::V3::ProjectSnippets
|
2017-02-06 13:38:17 -05:00
|
|
|
mount ::API::V3::Repositories
|
2017-02-20 14:32:44 -05:00
|
|
|
mount ::API::V3::Runners
|
|
|
|
mount ::API::V3::Services
|
2017-02-17 08:50:02 -05:00
|
|
|
mount ::API::V3::Settings
|
2017-02-16 10:42:17 -05:00
|
|
|
mount ::API::V3::Snippets
|
2017-02-17 04:45:05 -05:00
|
|
|
mount ::API::V3::Subscriptions
|
2017-02-06 13:38:17 -05:00
|
|
|
mount ::API::V3::SystemHooks
|
|
|
|
mount ::API::V3::Tags
|
2017-01-27 13:53:27 -05:00
|
|
|
mount ::API::V3::Templates
|
2017-02-20 14:32:44 -05:00
|
|
|
mount ::API::V3::Todos
|
|
|
|
mount ::API::V3::Triggers
|
2017-02-06 13:38:17 -05:00
|
|
|
mount ::API::V3::Users
|
2017-02-20 14:32:44 -05:00
|
|
|
mount ::API::V3::Variables
|
2017-01-30 12:41:56 -05:00
|
|
|
end
|
2012-07-04 03:48:00 -04:00
|
|
|
|
2017-06-08 12:54:24 -04:00
|
|
|
before { header['X-Frame-Options'] = 'SAMEORIGIN' }
|
2017-05-25 11:22:45 -04:00
|
|
|
before { Gitlab::I18n.locale = current_user&.preferred_language }
|
2017-05-03 22:05:38 -04:00
|
|
|
|
2017-05-25 11:22:45 -04:00
|
|
|
after { Gitlab::I18n.use_default_locale }
|
2016-11-22 04:04:23 -05:00
|
|
|
|
2016-06-23 11:14:31 -04:00
|
|
|
rescue_from Gitlab::Access::AccessDeniedError do
|
|
|
|
rack_response({ 'message' => '403 Forbidden' }.to_json, 403)
|
|
|
|
end
|
|
|
|
|
2012-07-05 11:12:09 -04:00
|
|
|
rescue_from ActiveRecord::RecordNotFound do
|
2015-02-02 23:36:54 -05:00
|
|
|
rack_response({ 'message' => '404 Not found' }.to_json, 404)
|
2012-07-05 11:12:09 -04:00
|
|
|
end
|
|
|
|
|
2016-08-02 17:56:27 -04:00
|
|
|
# Retain 405 error rather than a 500 error for Grape 0.15.0+.
|
2017-01-04 12:24:39 -05:00
|
|
|
# https://github.com/ruby-grape/grape/blob/a3a28f5b5dfbb2797442e006dbffd750b27f2a76/UPGRADING.md#changes-to-method-not-allowed-routes
|
|
|
|
rescue_from Grape::Exceptions::MethodNotAllowed do |e|
|
|
|
|
error! e.message, e.status, e.headers
|
|
|
|
end
|
|
|
|
|
2016-08-02 17:56:27 -04:00
|
|
|
rescue_from Grape::Exceptions::Base do |e|
|
|
|
|
error! e.message, e.status, e.headers
|
2016-07-29 06:14:36 -04:00
|
|
|
end
|
|
|
|
|
2017-02-17 06:52:27 -05:00
|
|
|
rescue_from Gitlab::Auth::TooManyIps do |e|
|
2017-02-17 08:44:57 -05:00
|
|
|
rack_response({ 'message' => '403 Forbidden' }.to_json, 403)
|
2017-02-17 06:52:27 -05:00
|
|
|
end
|
|
|
|
|
2013-02-01 04:42:02 -05:00
|
|
|
rescue_from :all do |exception|
|
2016-08-18 20:06:33 -04:00
|
|
|
handle_api_exception(exception)
|
2013-01-29 12:20:59 -05:00
|
|
|
end
|
|
|
|
|
2012-06-27 07:32:56 -04:00
|
|
|
format :json
|
2014-02-18 04:40:45 -05:00
|
|
|
content_type :txt, "text/plain"
|
|
|
|
|
2016-04-15 11:35:40 -04:00
|
|
|
# Ensure the namespace is right, otherwise we might load Grape::API::Helpers
|
2016-08-18 20:06:33 -04:00
|
|
|
helpers ::SentryHelper
|
2016-04-15 11:35:40 -04:00
|
|
|
helpers ::API::Helpers
|
2017-05-04 08:11:15 -04:00
|
|
|
helpers ::API::Helpers::CommonHelpers
|
2016-04-15 11:35:40 -04:00
|
|
|
|
2016-09-25 04:28:23 -04:00
|
|
|
# Keep in alphabetical order
|
2016-06-23 11:14:31 -04:00
|
|
|
mount ::API::AccessRequests
|
2016-06-10 02:57:56 -04:00
|
|
|
mount ::API::AwardEmoji
|
2016-10-13 06:52:51 -04:00
|
|
|
mount ::API::Boards
|
2016-06-10 02:57:56 -04:00
|
|
|
mount ::API::Branches
|
2016-08-25 19:34:01 -04:00
|
|
|
mount ::API::BroadcastMessages
|
2016-06-10 02:57:56 -04:00
|
|
|
mount ::API::Commits
|
2016-10-13 06:52:51 -04:00
|
|
|
mount ::API::CommitStatuses
|
2016-06-10 02:57:56 -04:00
|
|
|
mount ::API::DeployKeys
|
2016-08-16 02:45:23 -04:00
|
|
|
mount ::API::Deployments
|
2016-07-26 03:37:02 -04:00
|
|
|
mount ::API::Environments
|
2017-05-29 01:49:17 -04:00
|
|
|
mount ::API::Events
|
2017-05-31 17:06:01 -04:00
|
|
|
mount ::API::Features
|
2016-06-10 02:57:56 -04:00
|
|
|
mount ::API::Files
|
|
|
|
mount ::API::Groups
|
|
|
|
mount ::API::Internal
|
2016-04-15 11:35:40 -04:00
|
|
|
mount ::API::Issues
|
2017-02-22 05:13:59 -05:00
|
|
|
mount ::API::Jobs
|
2016-06-10 02:57:56 -04:00
|
|
|
mount ::API::Keys
|
|
|
|
mount ::API::Labels
|
2016-08-24 05:42:48 -04:00
|
|
|
mount ::API::Lint
|
2016-06-23 11:14:31 -04:00
|
|
|
mount ::API::Members
|
2016-09-25 04:28:23 -04:00
|
|
|
mount ::API::MergeRequestDiffs
|
2016-10-13 06:52:51 -04:00
|
|
|
mount ::API::MergeRequests
|
2016-06-10 02:57:56 -04:00
|
|
|
mount ::API::Milestones
|
|
|
|
mount ::API::Namespaces
|
2016-04-15 11:35:40 -04:00
|
|
|
mount ::API::Notes
|
2016-08-02 16:52:55 -04:00
|
|
|
mount ::API::NotificationSettings
|
2016-08-17 04:09:42 -04:00
|
|
|
mount ::API::Pipelines
|
2017-05-11 15:12:04 -04:00
|
|
|
mount ::API::PipelineSchedules
|
2016-04-15 11:35:40 -04:00
|
|
|
mount ::API::ProjectHooks
|
2016-06-10 02:57:56 -04:00
|
|
|
mount ::API::Projects
|
2016-10-13 06:52:51 -04:00
|
|
|
mount ::API::ProjectSnippets
|
2016-06-10 02:57:56 -04:00
|
|
|
mount ::API::Repositories
|
2017-02-15 19:30:46 -05:00
|
|
|
mount ::API::Runner
|
2016-06-10 02:57:56 -04:00
|
|
|
mount ::API::Runners
|
2016-04-15 11:35:40 -04:00
|
|
|
mount ::API::Services
|
2016-06-10 02:57:56 -04:00
|
|
|
mount ::API::Session
|
2016-04-15 11:35:40 -04:00
|
|
|
mount ::API::Settings
|
2016-06-10 02:57:56 -04:00
|
|
|
mount ::API::SidekiqMetrics
|
2016-11-26 10:37:26 -05:00
|
|
|
mount ::API::Snippets
|
2016-06-10 02:57:56 -04:00
|
|
|
mount ::API::Subscriptions
|
|
|
|
mount ::API::SystemHooks
|
2016-04-15 11:35:40 -04:00
|
|
|
mount ::API::Tags
|
2016-05-27 05:00:56 -04:00
|
|
|
mount ::API::Templates
|
2016-03-11 14:04:42 -05:00
|
|
|
mount ::API::Todos
|
2016-04-15 11:35:40 -04:00
|
|
|
mount ::API::Triggers
|
2016-06-10 02:57:56 -04:00
|
|
|
mount ::API::Users
|
2016-04-15 11:35:40 -04:00
|
|
|
mount ::API::Variables
|
2016-10-12 07:32:48 -04:00
|
|
|
mount ::API::Version
|
2016-10-07 09:39:57 -04:00
|
|
|
|
|
|
|
route :any, '*path' do
|
2016-10-07 13:18:02 -04:00
|
|
|
error!('404 Not Found', 404)
|
2016-10-07 09:39:57 -04:00
|
|
|
end
|
2012-06-27 07:32:56 -04:00
|
|
|
end
|
2012-06-27 05:26:16 -04:00
|
|
|
end
|