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: 72692777bc6f1fb7f5dcbfcda44f58327cf9d130 (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
26
27
28
29
30
31
# frozen_string_literal: true

module Clusters
  class AgentTokensFinder
    include FinderMethods

    def initialize(agent, current_user, params = {})
      @agent = agent
      @current_user = current_user
      @params = params
    end

    def execute
      return ::Clusters::AgentToken.none unless can_read_cluster_agents?

      agent.agent_tokens.then { |agent_tokens| by_status(agent_tokens) }
    end

    private

    attr_reader :agent, :current_user, :params

    def by_status(agent_tokens)
      params[:status].present? ? agent_tokens.with_status(params[:status]) : agent_tokens
    end

    def can_read_cluster_agents?
      current_user&.can?(:read_cluster, agent&.project)
    end
  end
end