2022-06-20 20:08:43 -04:00
|
|
|
# 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-10-03 05:09:43 -04:00
|
|
|
helpers do
|
|
|
|
def run_metadata_query
|
|
|
|
run_graphql!(
|
|
|
|
query: METADATA_QUERY,
|
|
|
|
context: { current_user: current_user },
|
|
|
|
transform: ->(result) { result.dig('data', 'metadata') }
|
|
|
|
)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2022-10-14 05:09:13 -04:00
|
|
|
desc 'Retrieve metadata information for this GitLab instance.' do
|
2022-06-28 08:09:11 -04:00
|
|
|
detail 'This feature was introduced in GitLab 15.2.'
|
2022-10-14 05:09:13 -04:00
|
|
|
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-06-20 20:08:43 -04:00
|
|
|
end
|
|
|
|
get '/metadata' do
|
2022-10-03 05:09:43 -04:00
|
|
|
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.'
|
2022-10-14 05:09:13 -04:00
|
|
|
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]
|
2022-10-03 05:09:43 -04:00
|
|
|
end
|
2022-10-14 05:09:13 -04:00
|
|
|
|
2022-10-03 05:09:43 -04:00
|
|
|
get '/version' do
|
|
|
|
run_metadata_query
|
2022-06-20 20:08:43 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|