blob: ec67d65c526c7e42454c35e3070d507beebcc4d5 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
|
# frozen_string_literal: true
module Gitlab
module Config
module Entry
module LegacyValidationHelpers
private
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, use_complete_matcher: true)
end
rescue ChronicDuration::DurationParseError
false
end
def validate_duration_limit(value, limit, parser = nil)
return false unless value.is_a?(String)
if parser && parser.respond_to?(:validate_duration_limit)
parser.validate_duration_limit(value, limit)
else
ChronicDuration.parse(
value, use_complete_matcher: true
).second.from_now <
ChronicDuration.parse(
limit, use_complete_matcher: true
).second.from_now
end
rescue ChronicDuration::DurationParseError
false
end
def validate_array_of_strings(values)
values.is_a?(Array) && values.all? { |value| validate_string(value) }
end
def validate_array_of_strings_or_regexps(values)
values.is_a?(Array) && values.all? { |value| validate_string_or_regexp(value) }
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.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)
value.is_a?(Integer)
end
def validate_string(value)
value.is_a?(String) || value.is_a?(Symbol)
end
def validate_regexp(value)
Gitlab::UntrustedRegexp::RubySyntax.valid?(value)
end
def validate_string_or_regexp(value)
return true if value.is_a?(Symbol)
return false unless value.is_a?(String)
if Gitlab::UntrustedRegexp::RubySyntax.matches_syntax?(value)
validate_regexp(value)
else
true
end
end
def validate_boolean(value)
value.in?([true, false])
end
end
end
end
end
|