api.rb 2.6 KB
Newer Older
1
module API
N
Nihad Abbasov 已提交
2
  class API < Grape::API
V
Valery Sizov 已提交
3
    include APIGuard
O
Oswaldo Ferreira 已提交
4 5 6 7

    version %w(v3 v4), using: :path

    version 'v3', using: :path do
8
      mount ::API::V3::DeployKeys
9 10
      mount ::API::V3::Issues
      mount ::API::V3::MergeRequests
O
Oswaldo Ferreira 已提交
11
      mount ::API::V3::Projects
12
      mount ::API::V3::ProjectSnippets
O
Oswaldo Ferreira 已提交
13
    end
N
Nihad Abbasov 已提交
14

15 16
    before { allow_access_with_scope :api }

17 18 19 20
    rescue_from Gitlab::Access::AccessDeniedError do
      rack_response({ 'message' => '403 Forbidden' }.to_json, 403)
    end

N
Nihad Abbasov 已提交
21
    rescue_from ActiveRecord::RecordNotFound do
22
      rack_response({ 'message' => '404 Not found' }.to_json, 404)
N
Nihad Abbasov 已提交
23 24
    end

C
Connor Shea 已提交
25
    # Retain 405 error rather than a 500 error for Grape 0.15.0+.
26 27 28 29 30
    # 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

C
Connor Shea 已提交
31 32
    rescue_from Grape::Exceptions::Base do |e|
      error! e.message, e.status, e.headers
33 34
    end

F
Felix Gilcher 已提交
35
    rescue_from :all do |exception|
S
Stan Hu 已提交
36
      handle_api_exception(exception)
37 38
    end

N
Nihad Abbasov 已提交
39
    format :json
40 41
    content_type :txt, "text/plain"

42
    # Ensure the namespace is right, otherwise we might load Grape::API::Helpers
S
Stan Hu 已提交
43
    helpers ::SentryHelper
44 45
    helpers ::API::Helpers

46
    # Keep in alphabetical order
47
    mount ::API::AccessRequests
48
    mount ::API::AwardEmoji
R
Robert Schilling 已提交
49
    mount ::API::Boards
50
    mount ::API::Branches
51
    mount ::API::BroadcastMessages
52 53
    mount ::API::Builds
    mount ::API::Commits
R
Robert Schilling 已提交
54
    mount ::API::CommitStatuses
55
    mount ::API::DeployKeys
Z
Z.J. van de Weg 已提交
56
    mount ::API::Deployments
57
    mount ::API::Environments
58 59 60
    mount ::API::Files
    mount ::API::Groups
    mount ::API::Internal
61
    mount ::API::Issues
62 63
    mount ::API::Keys
    mount ::API::Labels
64
    mount ::API::Lint
65
    mount ::API::Members
66
    mount ::API::MergeRequestDiffs
R
Robert Schilling 已提交
67
    mount ::API::MergeRequests
68 69
    mount ::API::Milestones
    mount ::API::Namespaces
70
    mount ::API::Notes
71
    mount ::API::NotificationSettings
Z
Z.J. van de Weg 已提交
72
    mount ::API::Pipelines
73
    mount ::API::ProjectHooks
74
    mount ::API::Projects
R
Robert Schilling 已提交
75
    mount ::API::ProjectSnippets
76 77
    mount ::API::Repositories
    mount ::API::Runners
78
    mount ::API::Services
79
    mount ::API::Session
80
    mount ::API::Settings
81
    mount ::API::SidekiqMetrics
82
    mount ::API::Snippets
83 84
    mount ::API::Subscriptions
    mount ::API::SystemHooks
85
    mount ::API::Tags
Z
ZJ van de Weg 已提交
86
    mount ::API::Templates
D
Douglas Barbosa Alexandre 已提交
87
    mount ::API::Todos
88
    mount ::API::Triggers
89
    mount ::API::Users
90
    mount ::API::Variables
R
Robert Schilling 已提交
91
    mount ::API::Version
92 93

    route :any, '*path' do
94
      error!('404 Not Found', 404)
95
    end
N
Nihad Abbasov 已提交
96
  end
97
end