credentials.rb 554 B

1234567891011121314151617181920212223242526272829
  1. # Copyright (C) 2012-2024 Zammad Foundation, https://zammad-foundation.org/
  2. class GitLab
  3. class Credentials
  4. QUERY = <<-GRAPHQL.freeze
  5. query {
  6. currentUser {
  7. username
  8. }
  9. }
  10. GRAPHQL
  11. attr_reader :client
  12. def initialize(client)
  13. @client = client
  14. end
  15. def verify!
  16. response = client.perform(
  17. query: GitLab::Credentials::QUERY,
  18. )
  19. return if response.dig('data', 'currentUser', 'username').present?
  20. raise __('Invalid GitLab GraphQL API token')
  21. end
  22. end
  23. end