summaryrefslogtreecommitdiff
path: root/lib/gitlab/ci/config
diff options
context:
space:
mode:
Diffstat (limited to 'lib/gitlab/ci/config')
-rw-r--r--lib/gitlab/ci/config/external/mapper.rb3
-rw-r--r--lib/gitlab/ci/config/external/rules.rb16
2 files changed, 16 insertions, 3 deletions
diff --git a/lib/gitlab/ci/config/external/mapper.rb b/lib/gitlab/ci/config/external/mapper.rb
index 97e4922b2a1..95f1a842c50 100644
--- a/lib/gitlab/ci/config/external/mapper.rb
+++ b/lib/gitlab/ci/config/external/mapper.rb
@@ -58,9 +58,6 @@ module Gitlab
end
def verify_rules(location)
- # Behaves like there is no `rules`
- return location unless ::Feature.enabled?(:ci_include_rules, context.project, default_enabled: :yaml)
-
return unless Rules.new(location[:rules]).evaluate(context).pass?
location
diff --git a/lib/gitlab/ci/config/external/rules.rb b/lib/gitlab/ci/config/external/rules.rb
index 5a788427172..95470537de3 100644
--- a/lib/gitlab/ci/config/external/rules.rb
+++ b/lib/gitlab/ci/config/external/rules.rb
@@ -5,7 +5,13 @@ module Gitlab
class Config
module External
class Rules
+ ALLOWED_KEYS = Entry::Include::Rules::Rule::ALLOWED_KEYS
+
+ InvalidIncludeRulesError = Class.new(Mapper::Error)
+
def initialize(rule_hashes)
+ validate(rule_hashes)
+
@rule_list = Build::Rules::Rule.fabricate_list(rule_hashes)
end
@@ -19,6 +25,16 @@ module Gitlab
@rule_list.find { |rule| rule.matches?(nil, context) }
end
+ def validate(rule_hashes)
+ return unless rule_hashes.is_a?(Array)
+
+ rule_hashes.each do |rule_hash|
+ next if (rule_hash.keys - ALLOWED_KEYS).empty?
+
+ raise InvalidIncludeRulesError, "invalid include rule: #{rule_hash}"
+ end
+ end
+
Result = Struct.new(:result) do
def pass?
!!result