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>2020-08-20 21:42:06 +0300
committerGitLab Bot <gitlab-bot@gitlab.com>2020-08-20 21:42:06 +0300
commit6e4e1050d9dba2b7b2523fdd1768823ab85feef4 (patch)
tree78be5963ec075d80116a932011d695dd33910b4e /lib/gitlab/config
parent1ce776de4ae122aba3f349c02c17cebeaa8ecf07 (diff)
Add latest changes from gitlab-org/gitlab@13-3-stable-ee
Diffstat (limited to 'lib/gitlab/config')
-rw-r--r--lib/gitlab/config/entry/legacy_validation_helpers.rb34
-rw-r--r--lib/gitlab/config/entry/validators.rb18
2 files changed, 42 insertions, 10 deletions
diff --git a/lib/gitlab/config/entry/legacy_validation_helpers.rb b/lib/gitlab/config/entry/legacy_validation_helpers.rb
index 0a629075302..415f6f77214 100644
--- a/lib/gitlab/config/entry/legacy_validation_helpers.rb
+++ b/lib/gitlab/config/entry/legacy_validation_helpers.rb
@@ -6,17 +6,27 @@ module Gitlab
module LegacyValidationHelpers
private
- def validate_duration(value)
- value.is_a?(String) && ChronicDuration.parse(value)
+ def validate_duration(value, parser = nil)
+ return false unless value.is_a?(String)
+
+ if parser && parser.respond_to?(:validate_duration)
+ parser.validate_duration(value)
+ else
+ ChronicDuration.parse(value)
+ end
rescue ChronicDuration::DurationParseError
false
end
- def validate_duration_limit(value, limit)
+ def validate_duration_limit(value, limit, parser = nil)
return false unless value.is_a?(String)
- ChronicDuration.parse(value).second.from_now <
- ChronicDuration.parse(limit).second.from_now
+ if parser && parser.respond_to?(:validate_duration_limit)
+ parser.validate_duration_limit(value, limit)
+ else
+ ChronicDuration.parse(value).second.from_now <
+ ChronicDuration.parse(limit).second.from_now
+ end
rescue ChronicDuration::DurationParseError
false
end
@@ -30,10 +40,18 @@ module Gitlab
end
def validate_variables(variables)
+ variables.is_a?(Hash) && variables.flatten.all?(&method(:validate_alphanumeric))
+ end
+
+ def validate_array_value_variables(variables)
variables.is_a?(Hash) &&
- variables.flatten.all? do |value|
- validate_string(value) || validate_integer(value)
- end
+ variables.keys.all?(&method(:validate_alphanumeric)) &&
+ variables.values.all?(&:present?) &&
+ variables.values.flatten(1).all?(&method(:validate_alphanumeric))
+ end
+
+ def validate_alphanumeric(value)
+ validate_string(value) || validate_integer(value)
end
def validate_integer(value)
diff --git a/lib/gitlab/config/entry/validators.rb b/lib/gitlab/config/entry/validators.rb
index d1c23c41d35..a7ec98ace6e 100644
--- a/lib/gitlab/config/entry/validators.rb
+++ b/lib/gitlab/config/entry/validators.rb
@@ -106,12 +106,12 @@ module Gitlab
include LegacyValidationHelpers
def validate_each(record, attribute, value)
- unless validate_duration(value)
+ unless validate_duration(value, options[:parser])
record.errors.add(attribute, 'should be a duration')
end
if options[:limit]
- unless validate_duration_limit(value, options[:limit])
+ unless validate_duration_limit(value, options[:limit], options[:parser])
record.errors.add(attribute, 'should not exceed the limit')
end
end
@@ -272,10 +272,24 @@ module Gitlab
include LegacyValidationHelpers
def validate_each(record, attribute, value)
+ if options[:array_values]
+ validate_key_array_values(record, attribute, value)
+ else
+ validate_key_values(record, attribute, value)
+ end
+ end
+
+ def validate_key_values(record, attribute, value)
unless validate_variables(value)
record.errors.add(attribute, 'should be a hash of key value pairs')
end
end
+
+ def validate_key_array_values(record, attribute, value)
+ unless validate_array_value_variables(value)
+ record.errors.add(attribute, 'should be a hash of key value pairs, value can be an array')
+ end
+ end
end
class ExpressionValidator < ActiveModel::EachValidator