Welcome to mirror list, hosted at ThFree Co, Russian Federation.

agent_tokens_finder.rb « clusters « finders « app - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: e241836e1dc2bc3e0e7cd65a64a97ad04aa3f73e (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 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