Module: Chef::Validation

Defined in:
lib/chef/validation.rb,
lib/chef/validation/version.rb,
lib/chef/validation/ext/hash.rb,
lib/chef/validation/formatter.rb,
lib/chef/validation/validator.rb,
lib/chef/validation/ext/context.rb

Defined Under Namespace

Modules: ContextExt, Formatter, HashExt, Validator

Constant Summary collapse

VERSION =
"0.2.3"

Class Method Summary collapse

Class Method Details

.validate(node, cookbook = nil) ⇒ Hash

Validates the given node object against all attribute rules defined in all the metadata of all loaded cookbooks for the node’s current run context.

If an optional cookbook name is provided then the validations will only be run for the metadata of that particular cookbook.

An errors hash is returned where keys are populated with the names of cookbooks that are failing validation and the values are an error hash returned from ‘Chef::Validation::Validator.run/2`. That error hash is made up of keys representing the name of an attribute which did not pass all rules and the values are error message strings.

{
  "elixir" => {
    "elixir/version" => [
      "'elixir/version' is a required attribute but was nil."
    ]
  }
}

Parameters:

  • node (Chef::Node)
  • cookbook (String, nil) (defaults to: nil)

Returns:



36
37
38
# File 'lib/chef/validation.rb', line 36

def validate(node, cookbook = nil)
  cookbook.nil? ? validate_all(node) : validate_one(node, cookbook)
end