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

101 lines
2.5 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! }
feature_category :not_owned # rubocop:todo Gitlab/AvoidFeatureCategoryNotOwned
METADATA_QUERY = <<~EOF
{
metadata {
version
revision
kas {
enabled
externalUrl
version
}
}
}
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
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.'
2022-11-25 23:54:43 +05:30
success [
{
code: 200,
model: Entities::Metadata,
message: 'successful operation',
examples: {
successful_response: {
'value' => {
version: "15.0-pre",
revision: "c401a659d0c",
kas: {
enabled: true,
externalUrl: "grpc://gitlab.example.com:8150",
version: "15.0.0"
}
}
}
}
}
]
failure [{ code: 401, message: 'unauthorized operation' }]
tags %w[metadata]
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
desc 'Get the version information of 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 [
{
code: 200,
model: Entities::Metadata,
message: 'successful operation',
examples: {
'Example' => {
'value' => {
version: "15.0-pre",
revision: "c401a659d0c",
kas: {
enabled: true,
externalUrl: "grpc://gitlab.example.com:8150",
version: "15.0.0"
}
}
}
}
}
]
failure [{ code: 401, message: 'unauthorized operation' }]
tags %w[metadata]
end
get '/version' do
run_metadata_query
2022-08-13 15:12:31 +05:30
end
end
end