summaryrefslogtreecommitdiff
path: root/app/graphql/resolvers/clusters/agent_tokens_resolver.rb
blob: 5ae19700fd5503f0ac75c670605a1a956f8902f8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# frozen_string_literal: true

module Resolvers
  module Clusters
    class AgentTokensResolver < BaseResolver
      type Types::Clusters::AgentTokenType, null: true

      alias_method :agent, :object

      delegate :project, to: :agent

      def resolve(**args)
        return ::Clusters::AgentToken.none unless can_read_agent_tokens?

        agent.last_used_agent_tokens
      end

      private

      def can_read_agent_tokens?
        current_user.can?(:admin_cluster, project)
      end
    end
  end
end