debian-mirror-gitlab/app/validators/cron_validator.rb

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

17 lines
626 B
Ruby
Raw Normal View History

2018-11-08 19:23:39 +05:30
# frozen_string_literal: true
2017-08-17 22:00:37 +05:30
class CronValidator < ActiveModel::EachValidator
2020-05-24 23:13:21 +05:30
ATTRIBUTE_WHITELIST = %i[cron freeze_start freeze_end].freeze
NonWhitelistedAttributeError = Class.new(StandardError)
2017-08-17 22:00:37 +05:30
def validate_each(record, attribute, value)
2020-05-24 23:13:21 +05:30
if ATTRIBUTE_WHITELIST.include?(attribute)
cron_parser = Gitlab::Ci::CronParser.new(record.public_send(attribute), record.cron_timezone) # rubocop:disable GitlabSecurity/PublicSend
record.errors.add(attribute, " is invalid syntax") unless cron_parser.cron_valid?
else
2021-06-08 01:23:25 +05:30
raise NonWhitelistedAttributeError, "Non-whitelisted attribute"
2020-05-24 23:13:21 +05:30
end
2017-08-17 22:00:37 +05:30
end
end