diff options
author | Grzegorz Bizon <grzesiek.bizon@gmail.com> | 2016-06-29 11:46:30 +0300 |
---|---|---|
committer | Grzegorz Bizon <grzesiek.bizon@gmail.com> | 2016-06-29 12:01:26 +0300 |
commit | c8c930f3ff6e1218e7614e46874bb5279bc30fe9 (patch) | |
tree | 3596970ba647ed1459a21c6b4ebb486343964fdd /lib/gitlab | |
parent | b85d4969a973862414560bd23b5ff4192dfaa372 (diff) |
Add CI config entry validator for allowed keys
Diffstat (limited to 'lib/gitlab')
-rw-r--r-- | lib/gitlab/ci/config/node/cache.rb | 18 | ||||
-rw-r--r-- | lib/gitlab/ci/config/node/entry.rb | 2 | ||||
-rw-r--r-- | lib/gitlab/ci/config/node/validator.rb | 5 | ||||
-rw-r--r-- | lib/gitlab/ci/config/node/validators.rb | 10 |
4 files changed, 17 insertions, 18 deletions
diff --git a/lib/gitlab/ci/config/node/cache.rb b/lib/gitlab/ci/config/node/cache.rb index 01a9ef511ee..d81b2121a99 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 8fece12232b..9e79e170a4f 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 94a8af4d080..1ba2e1dc59d 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 4082c161e81..7b2f57990b5 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 |