Commit c8c930f3 authored by Grzegorz Bizon's avatar Grzegorz Bizon

Add CI config entry validator for allowed keys

parent b85d4969
......@@ -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
......
......@@ -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
......
......@@ -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
......
......@@ -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
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment