api.rb 2.4 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 8 9

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

    version 'v3', using: :path do
      mount ::API::V3::Projects
    end
N
Nihad Abbasov 已提交
10

11 12
    before { allow_access_with_scope :api }

13 14 15 16
    rescue_from Gitlab::Access::AccessDeniedError do
      rack_response({ 'message' => '403 Forbidden' }.to_json, 403)
    end

N
Nihad Abbasov 已提交
17
    rescue_from ActiveRecord::RecordNotFound do
18
      rack_response({ 'message' => '404 Not found' }.to_json, 404)
N
Nihad Abbasov 已提交
19 20
    end

C
Connor Shea 已提交
21
    # Retain 405 error rather than a 500 error for Grape 0.15.0+.
22 23 24 25 26
    # 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 已提交
27 28
    rescue_from Grape::Exceptions::Base do |e|
      error! e.message, e.status, e.headers
29 30
    end

F
Felix Gilcher 已提交
31
    rescue_from :all do |exception|
S
Stan Hu 已提交
32
      handle_api_exception(exception)
33 34
    end

N
Nihad Abbasov 已提交
35
    format :json
36 37
    content_type :txt, "text/plain"

38
    # Ensure the namespace is right, otherwise we might load Grape::API::Helpers
S
Stan Hu 已提交
39
    helpers ::SentryHelper
40 41
    helpers ::API::Helpers

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

    route :any, '*path' do
90
      error!('404 Not Found', 404)
91
    end
N
Nihad Abbasov 已提交
92
  end
93
end