debian-mirror-gitlab/app/graphql/resolvers/clusters/agent_tokens_resolver.rb

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

33 lines
763 B
Ruby
Raw Normal View History

2021-11-18 22:05:49 +05:30
# 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
2022-03-02 08:16:31 +05:30
argument :status, Types::Clusters::AgentTokenStatusEnum,
required: false,
description: 'Status of the token.'
2021-11-18 22:05:49 +05:30
def resolve(**args)
return ::Clusters::AgentToken.none unless can_read_agent_tokens?
2022-03-02 08:16:31 +05:30
tokens = agent.last_used_agent_tokens
tokens = tokens.with_status(args[:status]) if args[:status].present?
tokens
2021-11-18 22:05:49 +05:30
end
private
def can_read_agent_tokens?
2022-04-04 11:22:00 +05:30
current_user.can?(:read_cluster, project)
2021-11-18 22:05:49 +05:30
end
end
end
end