diff options
Diffstat (limited to 'app/finders/clusters/agent_tokens_finder.rb')
-rw-r--r-- | app/finders/clusters/agent_tokens_finder.rb | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/app/finders/clusters/agent_tokens_finder.rb b/app/finders/clusters/agent_tokens_finder.rb new file mode 100644 index 00000000000..e241836e1dc --- /dev/null +++ b/app/finders/clusters/agent_tokens_finder.rb @@ -0,0 +1,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 |