cookbook 'app_config', '~> 1.0.0'
app_config (1) Versions 1.0.0 Follow3
Library for managing application configuration
cookbook 'app_config', '~> 1.0.0', :supermarket
knife supermarket install app_config
knife supermarket download app_config
AppConfig Cookbook
This cookbook provides some tools that make managing application configuration
more convenient.
How's That?
When using Chef to configure an application, what's the best mechanism to use to
store that configuration data? Node attributes? Sure, those are good for some
things. What about secrets? chef-vault or encrypted data bag items might be
good, but not for everything. How about data bags? OK, sure. Maybe you just have
a few things in a Hash that you want to add too.
The AppConfig object lets you take data from different sources like this, deep merge
it all together, and output it in ways amenable to using in configuration files.
Usage
Add this cookbook to your dependencies in metadata.rb:
depends "app_config"
In a recipe:
app_config = AppConfig.new( chef_vault_item("secrets", "my_app_secrets"), data_bag_item("my_app"), node['my_app'], { :other_data_for => "my_app" } )
Any list of Hash-like objects will do as arguments.
The AppConfig object inherits from Chef's
Mash, and inherits all of those
methods.
Output Formats
It's best to use a file
resource along with AppConfig objects:
file "my_config.yml" do content app_config.to_yaml end
to_yaml
Outputs YAML, but doesn't use any of the object indicators (!ruby/hash:Mash
,
etc.), which can cause problems with some applications that read YAML as
configuration data.
to_environment_variables
Programs like direnv and
dotenv, make it easy to load environment
variables from files into your app. With #to_environment_variables
, you can
write those files. A data structure that looks like:
{ :github_key => "abcde", :api_username => "testuser", :feature_flag_x => true }
Will output a string that looks like:
export GITHUB_KEY="abcde"
export API_USERNAME="testuser"
export FEATURE_FLAG_X="true"
This works if you use a flat structure. Strings, numbers, and booleans will all
output as strings. Collection objects like arrays and hashes will be ignored.
Keys will be uppercased, as is conventional with environment variables.
Sharing Data Across Recipes
If you need to share the config data object between separate recipes, create the
AppConfig object in the first recipe you load and use the node.run_state
:
# recipe A node.run_state[:app_config] ||= AppConfig.new(...) # recipe B include_recipe "my_cookbook:recipe_a" app_config = node.run_state[:app_config]
Contributing
Running the Specs
If you're using ChefDK, run
chef exec rspec
to run the RSpec tests.
License
Copyright (c) 2015 Nathan L Smith
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
Dependent cookbooks
This cookbook has no specified dependencies.
Contingent cookbooks
There are no cookbooks that are contingent upon this one.
Collaborator Number Metric
1.0.0 failed this metric
Failure: Cookbook has 0 collaborators. A cookbook must have at least 2 collaborators to pass this metric.
Contributing File Metric
1.0.0 failed this metric
Failure: To pass this metric, your cookbook metadata must include a source url, the source url must be in the form of https://github.com/user/repo, and your repo must contain a CONTRIBUTING.md file
Foodcritic Metric
1.0.0 failed this metric
FC064: Ensure issues_url is set in metadata: app_config/metadata.rb:1
FC065: Ensure source_url is set in metadata: app_config/metadata.rb:1
FC066: Ensure chef_version is set in metadata: app_config/metadata.rb:1
FC067: Ensure at least one platform supported in metadata: app_config/metadata.rb:1
FC069: Ensure standardized license defined in metadata: app_config/metadata.rb:1
Run with Foodcritic Version 16.3.0 with tags metadata,correctness ~FC031 ~FC045 and failure tags any
No Binaries Metric
1.0.0 passed this metric
Testing File Metric
1.0.0 failed this metric
Failure: To pass this metric, your cookbook metadata must include a source url, the source url must be in the form of https://github.com/user/repo, and your repo must contain a TESTING.md file
Version Tag Metric
1.0.0 failed this metric
Failure: To pass this metric, your cookbook metadata must include a source url, the source url must be in the form of https://github.com/user/repo, and your repo must include a tag that matches this cookbook version number
1.0.0 failed this metric
1.0.0 failed this metric
Failure: To pass this metric, your cookbook metadata must include a source url, the source url must be in the form of https://github.com/user/repo, and your repo must contain a CONTRIBUTING.md file
Foodcritic Metric
1.0.0 failed this metric
FC064: Ensure issues_url is set in metadata: app_config/metadata.rb:1
FC065: Ensure source_url is set in metadata: app_config/metadata.rb:1
FC066: Ensure chef_version is set in metadata: app_config/metadata.rb:1
FC067: Ensure at least one platform supported in metadata: app_config/metadata.rb:1
FC069: Ensure standardized license defined in metadata: app_config/metadata.rb:1
Run with Foodcritic Version 16.3.0 with tags metadata,correctness ~FC031 ~FC045 and failure tags any
No Binaries Metric
1.0.0 passed this metric
Testing File Metric
1.0.0 failed this metric
Failure: To pass this metric, your cookbook metadata must include a source url, the source url must be in the form of https://github.com/user/repo, and your repo must contain a TESTING.md file
Version Tag Metric
1.0.0 failed this metric
Failure: To pass this metric, your cookbook metadata must include a source url, the source url must be in the form of https://github.com/user/repo, and your repo must include a tag that matches this cookbook version number
1.0.0 failed this metric
FC065: Ensure source_url is set in metadata: app_config/metadata.rb:1
FC066: Ensure chef_version is set in metadata: app_config/metadata.rb:1
FC067: Ensure at least one platform supported in metadata: app_config/metadata.rb:1
FC069: Ensure standardized license defined in metadata: app_config/metadata.rb:1
Run with Foodcritic Version 16.3.0 with tags metadata,correctness ~FC031 ~FC045 and failure tags any
1.0.0 passed this metric
Testing File Metric
1.0.0 failed this metric
Failure: To pass this metric, your cookbook metadata must include a source url, the source url must be in the form of https://github.com/user/repo, and your repo must contain a TESTING.md file
Version Tag Metric
1.0.0 failed this metric
Failure: To pass this metric, your cookbook metadata must include a source url, the source url must be in the form of https://github.com/user/repo, and your repo must include a tag that matches this cookbook version number
1.0.0 failed this metric
1.0.0 failed this metric
Failure: To pass this metric, your cookbook metadata must include a source url, the source url must be in the form of https://github.com/user/repo, and your repo must include a tag that matches this cookbook version number