2016-06-16 23:09:34 +05:30
|
|
|
module Gitlab
|
|
|
|
module Ci
|
|
|
|
class Config
|
2017-08-17 22:00:37 +05:30
|
|
|
module Entry
|
2016-08-24 12:49:21 +05:30
|
|
|
module LegacyValidationHelpers
|
2016-06-16 23:09:34 +05:30
|
|
|
private
|
|
|
|
|
|
|
|
def validate_duration(value)
|
|
|
|
value.is_a?(String) && ChronicDuration.parse(value)
|
|
|
|
rescue ChronicDuration::DurationParseError
|
|
|
|
false
|
|
|
|
end
|
|
|
|
|
|
|
|
def validate_array_of_strings(values)
|
|
|
|
values.is_a?(Array) && values.all? { |value| validate_string(value) }
|
|
|
|
end
|
|
|
|
|
2016-06-22 15:30:34 +05:30
|
|
|
def validate_array_of_strings_or_regexps(values)
|
|
|
|
values.is_a?(Array) && values.all? { |value| validate_string_or_regexp(value) }
|
|
|
|
end
|
|
|
|
|
2016-06-16 23:09:34 +05:30
|
|
|
def validate_variables(variables)
|
|
|
|
variables.is_a?(Hash) &&
|
2017-09-10 17:25:29 +05:30
|
|
|
variables.flatten.all? do |value|
|
|
|
|
validate_string(value) || validate_integer(value)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def validate_integer(value)
|
|
|
|
value.is_a?(Integer)
|
2016-06-16 23:09:34 +05:30
|
|
|
end
|
|
|
|
|
|
|
|
def validate_string(value)
|
|
|
|
value.is_a?(String) || value.is_a?(Symbol)
|
|
|
|
end
|
|
|
|
|
2017-08-17 22:00:37 +05:30
|
|
|
def validate_regexp(value)
|
|
|
|
!value.nil? && Regexp.new(value.to_s) && true
|
|
|
|
rescue RegexpError, TypeError
|
|
|
|
false
|
|
|
|
end
|
|
|
|
|
2016-06-22 15:30:34 +05:30
|
|
|
def validate_string_or_regexp(value)
|
|
|
|
return true if value.is_a?(Symbol)
|
|
|
|
return false unless value.is_a?(String)
|
|
|
|
|
|
|
|
if value.first == '/' && value.last == '/'
|
2017-08-17 22:00:37 +05:30
|
|
|
validate_regexp(value[1...-1])
|
2016-06-22 15:30:34 +05:30
|
|
|
else
|
|
|
|
true
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2016-06-16 23:09:34 +05:30
|
|
|
def validate_boolean(value)
|
|
|
|
value.in?([true, false])
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|