Adoptable Cookbooks List

Looking for a cookbook to adopt? You can now see a list of cookbooks available for adoption!
List of Adoptable Cookbooks

Supermarket Belongs to the Community

Supermarket belongs to the community. While Chef has the responsibility to keep it running and be stewards of its functionality, what it does and how it works is driven by the community. The chef/supermarket repository will continue to be where development of the Supermarket application takes place. Come be part of shaping the direction of Supermarket by opening issues and pull requests or by joining us on the Chef Mailing List.

Select Badges

Select Supported Platforms

RSS

validation (11) Versions 0.2.2

Perform validation on your node's attributes from a Cookbook's attribute metadata definitions.

Berkshelf/Librarian
Policyfile
Knife
cookbook 'validation', '= 0.2.2'
cookbook 'validation', '= 0.2.2', :supermarket
knife cookbook site install validation
knife cookbook site download validation
README
Dependencies
Changelog
Quality

chef-validation

Perform validation on your node's attributes from a Cookbook's attribute metadata definitions.

Supported Platforms

  • Ubuntu 12.04 / 14.04
  • CentOS

Usage

Add the validation cookbook to your cookbook's metadata and define your attribute rules:

name             "my_app"
maintainer       "Jamie Winsor"
maintainer_email "jamie@vialstudios.com"
license          "MIT"
description      "Installs/Configures my_app"
long_description "Installs/Configures my_app"
version          "0.1.0"

depends "validation"

grouping "my_app",
  title: "My Application"
attribute "my_app/log_level",
  required: "required",
  default: "debug",
  choices: [
    "debug",
    "fatal",
    "warn",
    "info"
  ]
attribute "my_app/cookie",
  required: "required",
  default: "",
  type: "string"

Attribute rules are already part of Chef metadata. However, they are not used at all by the Chef client application itself. You'll need to ensure that you still initialize attributes to their supposedly default value in an attributes file or a recipe.

Since Chef client doesn't do anything with these attribute definitions we need to leverage the validate_attributes definition provided by this cookbook. Place a line like this in one of your cookbook's recipes.

validate_attributes "my_app"

I recommend placing this in the top of your "default" recipe for each cookbook that you maintain.

Compile time validation

By default, attribute validation will occur at convergence time but this can be switched to compile time by setting an attribute on the validate_attributes definition.

validate_attributes "my_app" do
  mode :compile
end

Convergence time validation

You can also explicitly validate at convergence

validate_attributes "my_app" do
  mode :converge
end

However, this is not necessary since :converge is the default mode.

Filtering validation

The name parameter of the validate_attributes definition is also the cookbook parameter. Setting this to the name of a cookbook will cause attribute validations to only be run for the metadata of that cookbook for the resource the definition creates. You can have multiple validate_attributes definitions within your resource chain or you can validate against all of your run context's loaded cookbooks.

validate_attributes "all"

Note: I swear to fucking god - if one of you makes a cookbook called "all" and puts that shit on the community site I will drink myself into the grave faster than I already am.

License and Authors

Author:: Jamie Winsor (jamie@vialstudios.com)

Dependent cookbooks

This cookbook has no specified dependencies.

Contingent cookbooks

elixir Applicable Versions
instrumental Applicable Versions

0.2.2

  • Bug Fixes
    • Allow optional and recommended to be passed in for required attribute rule
    • Display name of cookbook in error when cookbook not in run list

0.2.1

  • Bug Fixes
    • Don't treat 'false' as a missing required attribute

0.2.0

  • Enhancements
    • Validations will not be run for attributes who are dependent upon recipes when those recipes are not in the expanded run list of the node.

0.1.6

  • Bug Fixes
    • Required attribute validations will once again pass if they have values present

0.1.5

  • Bug Fixes
    • Fix issue with running boolean type validations on Ruby 1.9 series

0.1.4

  • Bug Fixes
    • Fix issue with validating non-string required attributes

0.1.3

  • Bug Fixes
    • Fix issue on some versions of Chef where metadata would not be properly loaded at different points of the Chef run
    • Fix crash when a value is nil and checking for it's presence

0.1.2

  • Enhancements
    • Loosen constraint on Chef to allow for any version of Chef from the 11 & 12 series.

0.1.1

  • Bug Fixes
    • 0.1.0 cookbook package was uploaded incorrectly, sigh.

0.1.0

Initial release of validation

Foodcritic Metric
            

0.2.2 failed this metric

FC015: Consider converting definition to a LWRP: /tmp/cook/d83c382746cf9dde05adaace/validation/definitions/validate_attributes.rb:1