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 ...@@ -18,23 +18,7 @@ module Gitlab
description: 'Specify which paths should be cached across builds.' description: 'Specify which paths should be cached across builds.'
validations do validations do
validate :keys validates :config, allowed_keys: true
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
end end
end end
end end
......
...@@ -51,7 +51,7 @@ module Gitlab ...@@ -51,7 +51,7 @@ module Gitlab
@config @config
else else
defined = @nodes.select { |_key, value| value.defined? } 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
end end
......
...@@ -21,6 +21,11 @@ module Gitlab ...@@ -21,6 +21,11 @@ module Gitlab
'Validator' 'Validator'
end end
def unknown_keys
return [] unless config.is_a?(Hash)
config.keys - @node.class.nodes.keys
end
private private
def location def location
......
...@@ -3,6 +3,16 @@ module Gitlab ...@@ -3,6 +3,16 @@ module Gitlab
class Config class Config
module Node module Node
module Validators 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 class ArrayOfStringsValidator < ActiveModel::EachValidator
include LegacyValidationHelpers 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