debian-mirror-gitlab/lib/api/metadata.rb

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

70 lines
1.7 KiB
Ruby
Raw Normal View History

2022-08-13 15:12:31 +05:30
# 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! }
2023-01-13 00:05:48 +05:30
METADATA_TAGS = %w[metadata].freeze
2022-08-13 15:12:31 +05:30
feature_category :not_owned # rubocop:todo Gitlab/AvoidFeatureCategoryNotOwned
METADATA_QUERY = <<~EOF
{
metadata {
version
revision
kas {
enabled
externalUrl
version
}
2023-01-13 00:05:48 +05:30
enterprise
2022-08-13 15:12:31 +05:30
}
}
EOF
2022-11-25 23:54:43 +05:30
helpers do
def run_metadata_query
run_graphql!(
query: METADATA_QUERY,
context: { current_user: current_user },
transform: ->(result) { result.dig('data', 'metadata') }
)
end
end
2023-01-13 00:05:48 +05:30
desc 'Retrieve metadata information for this GitLab instance' do
2022-08-13 15:12:31 +05:30
detail 'This feature was introduced in GitLab 15.2.'
2023-01-13 00:05:48 +05:30
success Entities::Metadata
failure [
{ code: 401, message: 'Unauthorized' }
2022-11-25 23:54:43 +05:30
]
2023-01-13 00:05:48 +05:30
tags METADATA_TAGS
2022-08-13 15:12:31 +05:30
end
get '/metadata' do
2022-11-25 23:54:43 +05:30
run_metadata_query
end
# Support the deprecated `/version` route.
# See https://gitlab.com/gitlab-org/gitlab/-/issues/366287
2023-01-13 00:05:48 +05:30
desc 'Retrieves version information for the GitLab instance' do
2022-11-25 23:54:43 +05:30
detail 'This feature was introduced in GitLab 8.13 and deprecated in 15.5. ' \
'We recommend you instead use the Metadata API.'
2023-01-13 00:05:48 +05:30
success Entities::Metadata
failure [
{ code: 401, message: 'Unauthorized' }
2022-11-25 23:54:43 +05:30
]
2023-01-13 00:05:48 +05:30
tags METADATA_TAGS
2022-11-25 23:54:43 +05:30
end
get '/version' do
run_metadata_query
2022-08-13 15:12:31 +05:30
end
end
end