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

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2022-12-06 12:07:14 +0300
committerGitLab Bot <gitlab-bot@gitlab.com>2022-12-06 12:07:14 +0300
commit5bc6fcec0edaa4032afacce1aa5e5289e9ae07ac (patch)
tree85291d07572ef0761dfd214d6d2458dd64150b71 /app/services/clusters/agents
parentf713e4eb11cae4593cfe70554a4a23536ab91357 (diff)
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'app/services/clusters/agents')
-rw-r--r--app/services/clusters/agents/filter_authorizations_service.rb50
1 files changed, 50 insertions, 0 deletions
diff --git a/app/services/clusters/agents/filter_authorizations_service.rb b/app/services/clusters/agents/filter_authorizations_service.rb
new file mode 100644
index 00000000000..68517ceec04
--- /dev/null
+++ b/app/services/clusters/agents/filter_authorizations_service.rb
@@ -0,0 +1,50 @@
+# frozen_string_literal: true
+
+module Clusters
+ module Agents
+ class FilterAuthorizationsService
+ def initialize(authorizations, filter_params)
+ @authorizations = authorizations
+ @filter_params = filter_params
+
+ @environments_matcher = {}
+ end
+
+ def execute
+ filter_by_environment(authorizations)
+ end
+
+ private
+
+ attr_reader :authorizations, :filter_params
+
+ def filter_by_environment(auths)
+ return auths unless filter_by_environment?
+
+ auths.select do |auth|
+ next true if auth.config['environments'].blank?
+
+ auth.config['environments'].any? { |environment_pattern| matches_environment?(environment_pattern) }
+ end
+ end
+
+ def filter_by_environment?
+ filter_params.has_key?(:environment)
+ end
+
+ def environment_filter
+ @environment_filter ||= filter_params[:environment]
+ end
+
+ def matches_environment?(environment_pattern)
+ return false if environment_filter.nil?
+
+ environments_matcher(environment_pattern).match?(environment_filter)
+ end
+
+ def environments_matcher(environment_pattern)
+ @environments_matcher[environment_pattern] ||= ::Gitlab::Ci::EnvironmentMatcher.new(environment_pattern)
+ end
+ end
+ end
+end