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).freeze
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.
-
#message_structure(arg = nil) ⇒ String
Gets or sets MessageStructure SNS request parameter.
-
#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.
127 128 129 |
# File 'lib/chef/handler/sns/config.rb', line 127 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.
226 227 228 |
# File 'lib/chef/handler/sns/config.rb', line 226 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.
105 106 107 108 109 110 111 112 113 114 115 116 |
# File 'lib/chef/handler/sns/config.rb', line 105 def config_check(node = nil) config_from_ohai(node) if node REQUIRED.each do |key| next unless send(key).nil? raise Exceptions::ValidationFailed, "Required argument #{key} is missing!" end return unless body_template && !::File.exist?(body_template) raise 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 |
# 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.
78 79 80 81 82 83 84 85 86 87 88 |
# File 'lib/chef/handler/sns/config.rb', line 78 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.
242 243 244 245 |
# File 'lib/chef/handler/sns/config.rb', line 242 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 |
#message_structure(arg = nil) ⇒ String
Gets or sets MessageStructure SNS request parameter.
200 201 202 |
# File 'lib/chef/handler/sns/config.rb', line 200 def (arg = nil) set_or_return(:message_structure, arg, kind_of: String) end |
#region(arg = nil) ⇒ String
Gets or sets AWS region.
153 154 155 |
# File 'lib/chef/handler/sns/config.rb', line 153 def region(arg = nil) set_or_return(:region, arg, kind_of: String) end |
#secret_key(arg = nil) ⇒ String
Gets or sets AWS secret key.
140 141 142 |
# File 'lib/chef/handler/sns/config.rb', line 140 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.
213 214 215 |
# File 'lib/chef/handler/sns/config.rb', line 213 def subject(arg = nil) set_or_return(:subject, arg, kind_of: String) end |
#token(arg = nil) ⇒ String
Gets or sets AWS token.
166 167 168 |
# File 'lib/chef/handler/sns/config.rb', line 166 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.
181 182 183 184 185 186 187 188 189 |
# File 'lib/chef/handler/sns/config.rb', line 181 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 |