Welcome to mirror list, hosted at ThFree Co, Russian Federation.

metadata.rb « api « lib - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 788d9843c6392e1dbb9f7226a8cfb8787aad9b10 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
# frozen_string_literal: true

module API
  class Metadata < ::API::Base
    helpers ::API::Helpers::GraphqlHelpers
    include APIGuard

    allow_access_with_scope :read_user, if: -> (request) { request.get? || request.head? }

    before { authenticate! }

    METADATA_TAGS = %w[metadata].freeze

    feature_category :not_owned # rubocop:todo Gitlab/AvoidFeatureCategoryNotOwned

    METADATA_QUERY = <<~EOF
      {
        metadata {
          version
          revision
          kas {
            enabled
            externalUrl
            version
          }
          enterprise
        }
      }
    EOF

    helpers do
      def run_metadata_query
        run_graphql!(
          query: METADATA_QUERY,
          context: { current_user: current_user },
          transform: ->(result) { result.dig('data', 'metadata') }
        )
      end
    end

    desc 'Retrieve metadata information for this GitLab instance' do
      detail 'This feature was introduced in GitLab 15.2.'
      success Entities::Metadata
      failure [
        { code: 401, message: 'Unauthorized' }
      ]
      tags METADATA_TAGS
    end
    get '/metadata' do
      run_metadata_query
    end

    # Support the deprecated `/version` route.
    # See https://gitlab.com/gitlab-org/gitlab/-/issues/366287
    desc 'Retrieves version information for the GitLab instance' do
      detail 'This feature was introduced in GitLab 8.13 and deprecated in 15.5. ' \
             'We recommend you instead use the Metadata API.'
      success Entities::Metadata
      failure [
        { code: 401, message: 'Unauthorized' }
      ]
      tags METADATA_TAGS
    end

    get '/version' do
      run_metadata_query
    end
  end
end