api.rb 3.1 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
R
Robert Schilling 已提交
8 9
      mount ::API::V3::Boards
      mount ::API::V3::Branches
10
      mount ::API::V3::Commits
11
      mount ::API::V3::DeployKeys
12
      mount ::API::V3::Files
13
      mount ::API::V3::Issues
R
Robert Schilling 已提交
14
      mount ::API::V3::Labels
15
      mount ::API::V3::Members
R
Robert Schilling 已提交
16
      mount ::API::V3::MergeRequestDiffs
17
      mount ::API::V3::MergeRequests
18
      mount ::API::V3::Notes
R
Robert Schilling 已提交
19
      mount ::API::V3::ProjectHooks
O
Oswaldo Ferreira 已提交
20
      mount ::API::V3::Projects
21
      mount ::API::V3::ProjectSnippets
R
Robert Schilling 已提交
22
      mount ::API::V3::Repositories
23
      mount ::API::V3::Subscriptions
R
Robert Schilling 已提交
24 25
      mount ::API::V3::SystemHooks
      mount ::API::V3::Tags
R
Robert Schilling 已提交
26
      mount ::API::V3::Todos
27
      mount ::API::V3::Templates
R
Robert Schilling 已提交
28
      mount ::API::V3::Users
O
Oswaldo Ferreira 已提交
29
    end
N
Nihad Abbasov 已提交
30

31 32
    before { allow_access_with_scope :api }

33 34 35 36
    rescue_from Gitlab::Access::AccessDeniedError do
      rack_response({ 'message' => '403 Forbidden' }.to_json, 403)
    end

N
Nihad Abbasov 已提交
37
    rescue_from ActiveRecord::RecordNotFound do
38
      rack_response({ 'message' => '404 Not found' }.to_json, 404)
N
Nihad Abbasov 已提交
39 40
    end

C
Connor Shea 已提交
41
    # Retain 405 error rather than a 500 error for Grape 0.15.0+.
42 43 44 45 46
    # 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 已提交
47 48
    rescue_from Grape::Exceptions::Base do |e|
      error! e.message, e.status, e.headers
49 50
    end

F
Felix Gilcher 已提交
51
    rescue_from :all do |exception|
S
Stan Hu 已提交
52
      handle_api_exception(exception)
53 54
    end

N
Nihad Abbasov 已提交
55
    format :json
56 57
    content_type :txt, "text/plain"

58
    # Ensure the namespace is right, otherwise we might load Grape::API::Helpers
S
Stan Hu 已提交
59
    helpers ::SentryHelper
60 61
    helpers ::API::Helpers

62
    # Keep in alphabetical order
63
    mount ::API::AccessRequests
64
    mount ::API::AwardEmoji
R
Robert Schilling 已提交
65
    mount ::API::Boards
66
    mount ::API::Branches
67
    mount ::API::BroadcastMessages
68 69
    mount ::API::Builds
    mount ::API::Commits
R
Robert Schilling 已提交
70
    mount ::API::CommitStatuses
71
    mount ::API::DeployKeys
Z
Z.J. van de Weg 已提交
72
    mount ::API::Deployments
73
    mount ::API::Environments
74 75 76
    mount ::API::Files
    mount ::API::Groups
    mount ::API::Internal
77
    mount ::API::Issues
78 79
    mount ::API::Keys
    mount ::API::Labels
80
    mount ::API::Lint
81
    mount ::API::Members
82
    mount ::API::MergeRequestDiffs
R
Robert Schilling 已提交
83
    mount ::API::MergeRequests
84 85
    mount ::API::Milestones
    mount ::API::Namespaces
86
    mount ::API::Notes
87
    mount ::API::NotificationSettings
Z
Z.J. van de Weg 已提交
88
    mount ::API::Pipelines
89
    mount ::API::ProjectHooks
90
    mount ::API::Projects
R
Robert Schilling 已提交
91
    mount ::API::ProjectSnippets
92 93
    mount ::API::Repositories
    mount ::API::Runners
94
    mount ::API::Services
95
    mount ::API::Session
96
    mount ::API::Settings
97
    mount ::API::SidekiqMetrics
98
    mount ::API::Snippets
99 100
    mount ::API::Subscriptions
    mount ::API::SystemHooks
101
    mount ::API::Tags
Z
ZJ van de Weg 已提交
102
    mount ::API::Templates
D
Douglas Barbosa Alexandre 已提交
103
    mount ::API::Todos
104
    mount ::API::Triggers
105
    mount ::API::Users
106
    mount ::API::Variables
R
Robert Schilling 已提交
107
    mount ::API::Version
108 109

    route :any, '*path' do
110
      error!('404 Not Found', 404)
111
    end
N
Nihad Abbasov 已提交
112
  end
113
end