summaryrefslogtreecommitdiff
path: root/app/finders/terraform
diff options
context:
space:
mode:
Diffstat (limited to 'app/finders/terraform')
-rw-r--r--app/finders/terraform/states_finder.rb28
1 files changed, 28 insertions, 0 deletions
diff --git a/app/finders/terraform/states_finder.rb b/app/finders/terraform/states_finder.rb
new file mode 100644
index 00000000000..bbe90fead2b
--- /dev/null
+++ b/app/finders/terraform/states_finder.rb
@@ -0,0 +1,28 @@
+# frozen_string_literal: true
+
+module Terraform
+ class StatesFinder
+ def initialize(project, current_user, params: {})
+ @project = project
+ @current_user = current_user
+ @params = params
+ end
+
+ def execute
+ return ::Terraform::State.none unless can_read_terraform_states?
+
+ states = project.terraform_states
+ states = states.with_name(params[:name]) if params[:name].present?
+
+ states.ordered_by_name
+ end
+
+ private
+
+ attr_reader :project, :current_user, :params
+
+ def can_read_terraform_states?
+ current_user.can?(:read_terraform_state, project)
+ end
+ end
+end