Module: Chef::Knife::RdsBaseDataBag
- Included in:
- RdsInstanceFromDataBag, RdsInstanceRestoreFromDataBag, RdsPgFromDataBag, RdsSgFromDataBag
- Defined in:
- lib/chef/knife/rds_base_data_bag.rb
Overview
Base module for interfacing with Data Bags
Defined Under Namespace
Modules: ClassMethods
Class Method Summary collapse
Instance Method Summary collapse
-
#assert_data_bag_exists! ⇒ Object
Report error and quit unless data bag exists.
-
#assert_data_bag_item_exists! ⇒ Object
Report error and quit unless data bag item exists.
-
#assert_data_bag_item_valid! ⇒ Object
Data bag assertion.
-
#assert_required_data_bag_options_present! ⇒ Object
Report error and quit unless defined required parameters exits in data bag item.
-
#data_bag_exists? ⇒ Boolean
Check if the configured RDS data bag exists on the Chef Server.
-
#data_bag_item ⇒ Object
The data bag item.
-
#defined_params ⇒ Object
Build a hash containing only the type (integer, string) parameters that exist in the data bag, coerced to their expected type.
-
#required_data_bag_options ⇒ Object
Call the class method for the vale.
Class Method Details
.included(base) ⇒ Object
6 7 8 |
# File 'lib/chef/knife/rds_base_data_bag.rb', line 6 def self.included(base) base.extend(ClassMethods) end |
Instance Method Details
#assert_data_bag_exists! ⇒ Object
Report error and quit unless data bag exists
110 111 112 113 114 115 |
# File 'lib/chef/knife/rds_base_data_bag.rb', line 110 def assert_data_bag_exists! unless data_bag_exists? ui.fatal("Data bag #{config[:data_bag_name]} must exist.") exit 1 end end |
#assert_data_bag_item_exists! ⇒ Object
Report error and quit unless data bag item exists
101 102 103 104 105 106 107 |
# File 'lib/chef/knife/rds_base_data_bag.rb', line 101 def assert_data_bag_item_exists! if data_bag_item.nil? db_item_name = "#{config[:data_bag_name]}/#{data_bag_item_name}" ui.fatal("Cannot load data bag item #{db_item_name}") exit 1 end end |
#assert_data_bag_item_valid! ⇒ Object
Data bag assertion. Calls all boilerplate data bag assertions
84 85 86 87 88 |
# File 'lib/chef/knife/rds_base_data_bag.rb', line 84 def assert_data_bag_item_valid! assert_data_bag_exists! assert_data_bag_item_exists! end |
#assert_required_data_bag_options_present! ⇒ Object
Report error and quit unless defined required parameters exits in data bag item
91 92 93 94 95 96 97 98 |
# File 'lib/chef/knife/rds_base_data_bag.rb', line 91 def .each do |opt| unless data_bag_item[opt] ui.fatal("Missing option #{opt} for #{data_bag_item_name}") exit 1 end end end |
#data_bag_exists? ⇒ Boolean
Check if the configured RDS data bag exists on the Chef Server
Returns boolean
120 121 122 123 124 125 126 127 |
# File 'lib/chef/knife/rds_base_data_bag.rb', line 120 def data_bag_exists? begin Chef::DataBag.load(config[:data_bag_name]) rescue Net::HTTPServerException return false end true end |
#data_bag_item ⇒ Object
The data bag item. Uses the option name data_bag_item, and the parameter group name argument to load the data bag item from the server
Returns Chef::DataBagItem or nil
133 134 135 136 137 138 139 140 141 142 |
# File 'lib/chef/knife/rds_base_data_bag.rb', line 133 def data_bag_item unless @data_bag_item begin @data_bag_item = Chef::DataBagItem.load(config[:data_bag_name], data_bag_item_name) rescue Net::HTTPServerException @data_bag_item = nil end end @data_bag_item end |
#defined_params ⇒ Object
Build a hash containing only the type (integer, string) parameters that exist in the data bag, coerced to their expected type
type - Sym, name of type (:integer, :string)
Returns hash
73 74 75 76 77 78 79 80 81 |
# File 'lib/chef/knife/rds_base_data_bag.rb', line 73 def defined_params values = {} self.class.defined_params.each do |k| v = data_bag_item[k] next if v.nil? values[k.to_sym] = v end values end |
#required_data_bag_options ⇒ Object
Call the class method for the vale
63 64 65 |
# File 'lib/chef/knife/rds_base_data_bag.rb', line 63 def self.class. end |