Welcome to mirror list, hosted at ThFree Co, Russian Federation.

cron_validator.rb « validators « app - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 91b9cfcccc494af7c4a0e441d4f0fde63319921a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
# frozen_string_literal: true

class CronValidator < ActiveModel::EachValidator
  ATTRIBUTE_WHITELIST = %i[cron freeze_start freeze_end].freeze

  NonWhitelistedAttributeError = Class.new(StandardError)

  def validate_each(record, attribute, value)
    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
      raise NonWhitelistedAttributeError, "Non-whitelisted attribute"
    end
  end
end