2022-01-01 13:38:12 +00:00
|
|
|
# Copyright (C) 2012-2022 Zammad Foundation, https://zammad-foundation.org/
|
2021-06-01 12:20:20 +00:00
|
|
|
|
2021-03-24 16:41:05 +00:00
|
|
|
class GitLab
|
|
|
|
class Credentials
|
|
|
|
|
|
|
|
QUERY = <<-'GRAPHQL'.freeze
|
|
|
|
query {
|
|
|
|
currentUser {
|
|
|
|
username
|
|
|
|
}
|
|
|
|
}
|
|
|
|
GRAPHQL
|
|
|
|
|
|
|
|
attr_reader :client
|
|
|
|
|
|
|
|
def initialize(client)
|
|
|
|
@client = client
|
|
|
|
end
|
|
|
|
|
|
|
|
def verify!
|
|
|
|
response = client.perform(
|
|
|
|
query: GitLab::Credentials::QUERY,
|
|
|
|
)
|
|
|
|
return if response.dig('data', 'currentUser', 'username').present?
|
|
|
|
|
2021-11-15 15:58:19 +00:00
|
|
|
raise __('Invalid GitLab GraphQL API token')
|
2021-03-24 16:41:05 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|