Module: Chef::Handler::Sns::Config
- Extended by:
- Config
- Includes:
- Mixin::ParamsValidate
- Included in:
- Chef::Handler::Sns, Config
- Defined in:
- lib/chef/handler/sns/config.rb,
lib/chef/handler/sns/config/ohai.rb
Overview
Reads Chef Handler SNS configuration options or calculate them if not set.
Defined Under Namespace
Classes: Ohai
Constant Summary collapse
- REQUIRED =
Required configuration options.
%w(access_key secret_key topic_arn)
Instance Method Summary collapse
-
#access_key(arg = nil) ⇒ String
Gets or sets AWS access key.
-
#body_template(arg = nil) ⇒ String
Gets or sets SNS message body template file path.
-
#config_check(node = nil) ⇒ Object
Checks if any required configuration option is not set.
-
#config_from_ohai(node) ⇒ Object
private
Reads some configuration options from Ohai information.
-
#config_init(config = {}) ⇒ Object
Sets configuration reading it from a Hash.
-
#filter_opsworks_activity(arg = nil) ⇒ Array
Gets or sets [OpsWorks](aws.amazon.com/opsworks/) activities.
-
#region(arg = nil) ⇒ String
Gets or sets AWS region.
-
#secret_key(arg = nil) ⇒ String
Gets or sets AWS secret key.
-
#subject(arg = nil) ⇒ String
Gets or sets SNS message subject.
-
#token(arg = nil) ⇒ String
Gets or sets AWS token.
-
#topic_arn(arg = nil) ⇒ String
Gets or sets AWS Topic ARN.
Instance Method Details
#access_key(arg = nil) ⇒ String
Gets or sets AWS access key.
129 130 131 132 133 134 135 |
# File 'lib/chef/handler/sns/config.rb', line 129 def access_key(arg = nil) set_or_return( :access_key, arg, kind_of: String ) end |
#body_template(arg = nil) ⇒ String
Gets or sets SNS message body template file path.
237 238 239 240 241 242 243 |
# File 'lib/chef/handler/sns/config.rb', line 237 def body_template(arg = nil) set_or_return( :body_template, arg, kind_of: String ) end |
#config_check(node = nil) ⇒ Object
Checks if any required configuration option is not set.
Tries to read some configuration options from Ohai before checking them.
107 108 109 110 111 112 113 114 115 116 117 118 |
# File 'lib/chef/handler/sns/config.rb', line 107 def config_check(node = nil) config_from_ohai(node) if node REQUIRED.each do |key| next unless send(key).nil? fail Exceptions::ValidationFailed, "Required argument #{key} is missing!" end return unless body_template && !::File.exist?(body_template) fail Exceptions::ValidationFailed, "Template file not found: #{body_template}." end |
#config_from_ohai(node) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Reads some configuration options from Ohai information.
Called from #config_check.
58 59 60 61 62 63 64 65 66 67 |
# File 'lib/chef/handler/sns/config.rb', line 58 def config_from_ohai(node) config_ohai = Config::Ohai.new(node) [ :access_key, :secret_key, :token ].each do |attr| send(attr, config_ohai.send(attr)) if send(attr).nil? end end |
#config_init(config = {}) ⇒ Object
Sets configuration reading it from a Hash.
80 81 82 83 84 85 86 87 88 89 90 |
# File 'lib/chef/handler/sns/config.rb', line 80 def config_init(config = {}) config.each do |key, value| if Config.respond_to?(key) && !key.to_s.match(/^config_/) send(key, value) else Chef::Log.warn( "#{self.class}: configuration method not found: #{key}." ) end end end |
#filter_opsworks_activity(arg = nil) ⇒ Array
Gets or sets [OpsWorks](aws.amazon.com/opsworks/) activities.
Notifications will only be triggered for the activities in the array, everything else will be discarded.
257 258 259 260 261 262 263 264 |
# File 'lib/chef/handler/sns/config.rb', line 257 def filter_opsworks_activity(arg = nil) arg = Array(arg) if arg.is_a? String set_or_return( :filter_opsworks_activity, arg, kind_of: Array ) end |
#region(arg = nil) ⇒ String
Gets or sets AWS region.
163 164 165 166 167 168 169 |
# File 'lib/chef/handler/sns/config.rb', line 163 def region(arg = nil) set_or_return( :region, arg, kind_of: String ) end |
#secret_key(arg = nil) ⇒ String
Gets or sets AWS secret key.
146 147 148 149 150 151 152 |
# File 'lib/chef/handler/sns/config.rb', line 146 def secret_key(arg = nil) set_or_return( :secret_key, arg, kind_of: String ) end |
#subject(arg = nil) ⇒ String
Gets or sets SNS message subject.
220 221 222 223 224 225 226 |
# File 'lib/chef/handler/sns/config.rb', line 220 def subject(arg = nil) set_or_return( :subject, arg, kind_of: String ) end |
#token(arg = nil) ⇒ String
Gets or sets AWS token.
180 181 182 183 184 185 186 |
# File 'lib/chef/handler/sns/config.rb', line 180 def token(arg = nil) set_or_return( :token, arg, kind_of: [String, FalseClass] ) end |
#topic_arn(arg = nil) ⇒ String
Gets or sets AWS Topic ARN.
It also tries to set the AWS region reading it from the ARN string.
199 200 201 202 203 204 205 206 207 208 209 |
# File 'lib/chef/handler/sns/config.rb', line 199 def topic_arn(arg = nil) set_or_return( :topic_arn, arg, kind_of: String ).tap do |arn| # Get the region from the ARN: next if arn.nil? || !region.nil? region(arn.split(':', 5)[3]) end end |