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
R
Robert Schilling 已提交
13
      mount ::API::V3::Groups
14
      mount ::API::V3::Issues
R
Robert Schilling 已提交
15
      mount ::API::V3::Labels
16
      mount ::API::V3::Members
R
Robert Schilling 已提交
17
      mount ::API::V3::MergeRequestDiffs
18
      mount ::API::V3::MergeRequests
19
      mount ::API::V3::Notes
R
Robert Schilling 已提交
20
      mount ::API::V3::ProjectHooks
O
Oswaldo Ferreira 已提交
21
      mount ::API::V3::Projects
22
      mount ::API::V3::ProjectSnippets
R
Robert Schilling 已提交
23
      mount ::API::V3::Repositories
24
      mount ::API::V3::Subscriptions
R
Robert Schilling 已提交
25 26
      mount ::API::V3::SystemHooks
      mount ::API::V3::Tags
R
Robert Schilling 已提交
27
      mount ::API::V3::Todos
28
      mount ::API::V3::Templates
R
Robert Schilling 已提交
29
      mount ::API::V3::Users
O
Oswaldo Ferreira 已提交
30
    end
N
Nihad Abbasov 已提交
31

32 33
    before { allow_access_with_scope :api }

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

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

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

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

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

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

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

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