debian-mirror-gitlab/app/finders/clusters/agent_tokens_finder.rb
2023-01-12 18:35:48 +00:00

25 lines
566 B
Ruby

# frozen_string_literal: true
module Clusters
class AgentTokensFinder
def initialize(object, current_user, agent_id)
@object = object
@current_user = current_user
@agent_id = agent_id
end
def execute
raise_not_found_unless_can_read_cluster
object.cluster_agents.find(agent_id).agent_tokens
end
private
attr_reader :object, :current_user, :agent_id
def raise_not_found_unless_can_read_cluster
raise ActiveRecord::RecordNotFound unless current_user&.can?(:read_cluster, object)
end
end
end