diff options
author | Shinya Maeda <shinya@gitlab.com> | 2018-10-04 12:59:34 +0300 |
---|---|---|
committer | Shinya Maeda <shinya@gitlab.com> | 2018-10-04 12:59:34 +0300 |
commit | e84230ebb6db5ff9e5990e945aa1e1aebf4e9fa9 (patch) | |
tree | 6fcbcf0d02a0b34177ee9af4b29972526a3308a8 /lib/gitlab/ci | |
parent | 28f895e495a7868e44602781c99bcd51fac08ccc (diff) |
Add limitation for start_in keyword
Diffstat (limited to 'lib/gitlab/ci')
-rw-r--r-- | lib/gitlab/ci/config/entry/job.rb | 2 | ||||
-rw-r--r-- | lib/gitlab/ci/config/entry/legacy_validation_helpers.rb | 9 | ||||
-rw-r--r-- | lib/gitlab/ci/config/entry/validators.rb | 6 |
3 files changed, 16 insertions, 1 deletions
diff --git a/lib/gitlab/ci/config/entry/job.rb b/lib/gitlab/ci/config/entry/job.rb index 03971254310..f290ff3a565 100644 --- a/lib/gitlab/ci/config/entry/job.rb +++ b/lib/gitlab/ci/config/entry/job.rb @@ -36,7 +36,7 @@ module Gitlab validates :extends, type: String end - validates :start_in, duration: true, if: :delayed? + validates :start_in, duration: { limit: '1 day' }, if: :delayed? validates :start_in, absence: true, unless: :delayed? end diff --git a/lib/gitlab/ci/config/entry/legacy_validation_helpers.rb b/lib/gitlab/ci/config/entry/legacy_validation_helpers.rb index a78a85397bd..a3d4432be82 100644 --- a/lib/gitlab/ci/config/entry/legacy_validation_helpers.rb +++ b/lib/gitlab/ci/config/entry/legacy_validation_helpers.rb @@ -11,6 +11,15 @@ module Gitlab false end + def validate_duration_limit(value, limit) + return false unless value.is_a?(String) + + ChronicDuration.parse(value).second.from_now < + ChronicDuration.parse(limit).second.from_now + rescue ChronicDuration::DurationParseError + false + end + def validate_array_of_strings(values) values.is_a?(Array) && values.all? { |value| validate_string(value) } end diff --git a/lib/gitlab/ci/config/entry/validators.rb b/lib/gitlab/ci/config/entry/validators.rb index b3c889ee92f..f6b4ba7843e 100644 --- a/lib/gitlab/ci/config/entry/validators.rb +++ b/lib/gitlab/ci/config/entry/validators.rb @@ -49,6 +49,12 @@ module Gitlab unless validate_duration(value) record.errors.add(attribute, 'should be a duration') end + + if options[:limit] + unless validate_duration_limit(value, options[:limit]) + record.errors.add(attribute, 'should not exceed the limit') + end + end end end |