diff --git a/lib/gitlab/ci/config/node/cache.rb b/lib/gitlab/ci/config/node/cache.rb index 01a9ef511ee52fb5b59bf9915eb6f3f1bba9d5dc..d81b2121a99ee84820a672306433e06841fe7bed 100644 --- a/lib/gitlab/ci/config/node/cache.rb +++ b/lib/gitlab/ci/config/node/cache.rb @@ -18,23 +18,7 @@ module Gitlab description: 'Specify which paths should be cached across builds.' validations do - validate :keys - - def unknown_keys - return [] unless config.is_a?(Hash) - config.keys - allowed_keys - end - - def keys - if unknown_keys.any? - unknown_list = unknown_keys.join(', ') - errors.add(:config, "contains unknown keys: #{unknown_list}") - end - end - end - - def allowed_keys - self.class.nodes.keys + validates :config, allowed_keys: true end end end diff --git a/lib/gitlab/ci/config/node/entry.rb b/lib/gitlab/ci/config/node/entry.rb index 8fece12232b37d9c81265a60a8fc33b9d2e16548..9e79e170a4fabf8cbc385763e71a0e9fc6133cdf 100644 --- a/lib/gitlab/ci/config/node/entry.rb +++ b/lib/gitlab/ci/config/node/entry.rb @@ -51,7 +51,7 @@ module Gitlab @config else defined = @nodes.select { |_key, value| value.defined? } - Hash[(defined).map { |key, node| [key, node.value] }] + Hash[defined.map { |key, node| [key, node.value] }] end end diff --git a/lib/gitlab/ci/config/node/validator.rb b/lib/gitlab/ci/config/node/validator.rb index 94a8af4d0801b6b2b97f5cb574bccf6b164a1906..1ba2e1dc59de10cd897e8f16ff9d99780ba206b2 100644 --- a/lib/gitlab/ci/config/node/validator.rb +++ b/lib/gitlab/ci/config/node/validator.rb @@ -21,6 +21,11 @@ module Gitlab 'Validator' end + def unknown_keys + return [] unless config.is_a?(Hash) + config.keys - @node.class.nodes.keys + end + private def location diff --git a/lib/gitlab/ci/config/node/validators.rb b/lib/gitlab/ci/config/node/validators.rb index 4082c161e818c223802bbee297c84227ab0159b4..7b2f57990b5c468fb99b0051b4888853a79666f8 100644 --- a/lib/gitlab/ci/config/node/validators.rb +++ b/lib/gitlab/ci/config/node/validators.rb @@ -3,6 +3,16 @@ module Gitlab class Config module Node module Validators + class AllowedKeysValidator < ActiveModel::EachValidator + def validate_each(record, attribute, value) + if record.unknown_keys.any? + unknown_list = record.unknown_keys.join(', ') + record.errors.add(:config, + "contains unknown keys: #{unknown_list}") + end + end + end + class ArrayOfStringsValidator < ActiveModel::EachValidator include LegacyValidationHelpers