summaryrefslogtreecommitdiff
path: root/lib/gitlab/config/entry/validators.rb
diff options
context:
space:
mode:
Diffstat (limited to 'lib/gitlab/config/entry/validators.rb')
-rw-r--r--lib/gitlab/config/entry/validators.rb40
1 files changed, 12 insertions, 28 deletions
diff --git a/lib/gitlab/config/entry/validators.rb b/lib/gitlab/config/entry/validators.rb
index b2bc56f46ee..cc24ae837f3 100644
--- a/lib/gitlab/config/entry/validators.rb
+++ b/lib/gitlab/config/entry/validators.rb
@@ -39,6 +39,17 @@ module Gitlab
end
end
+ class MutuallyExclusiveKeysValidator < ActiveModel::EachValidator
+ def validate_each(record, attribute, value)
+ mutually_exclusive_keys = value.try(:keys).to_a & options[:in]
+
+ if mutually_exclusive_keys.length > 1
+ record.errors.add(attribute, "please use only one the following keys: " +
+ mutually_exclusive_keys.join(', '))
+ end
+ end
+ end
+
class AllowedValuesValidator < ActiveModel::EachValidator
def validate_each(record, attribute, value)
unless options[:in].include?(value.to_s)
@@ -217,12 +228,6 @@ module Gitlab
end
end
- protected
-
- def fallback
- false
- end
-
private
def matches_syntax?(value)
@@ -231,7 +236,7 @@ module Gitlab
def validate_regexp(value)
matches_syntax?(value) &&
- Gitlab::UntrustedRegexp::RubySyntax.valid?(value, fallback: fallback)
+ Gitlab::UntrustedRegexp::RubySyntax.valid?(value)
end
end
@@ -260,27 +265,6 @@ module Gitlab
end
end
- class ArrayOfStringsOrRegexpsWithFallbackValidator < ArrayOfStringsOrRegexpsValidator
- protected
-
- # TODO
- #
- # Remove ArrayOfStringsOrRegexpsWithFallbackValidator class too when
- # you are removing the `:allow_unsafe_ruby_regexp` feature flag.
- #
- def validation_message
- if ::Feature.enabled?(:allow_unsafe_ruby_regexp, default_enabled: :yaml)
- 'should be an array of strings or regular expressions'
- else
- super
- end
- end
-
- def fallback
- true
- end
- end
-
class ArrayOfStringsOrStringValidator < RegexpValidator
def validate_each(record, attribute, value)
unless validate_array_of_strings_or_string(value)