module Chef::Handler::Sns::Config

Reads Chef Handler SNS configuration options or calculate them if not set.

Constants

REQUIRED

Required configuration options.

Public Instance Methods

access_key(arg = nil) click to toggle source

Gets or sets AWS access key.

@param arg [String] Access key.

@return [String] Access Key.

@api public

# 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) click to toggle source

Gets or sets SNS message body template file path.

@param arg [String] SNS body template.

@return [String] SNS body template.

@api public

# 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) click to toggle source

Checks if any required configuration option is not set.

Tries to read some configuration options from Ohai before checking them.

@param node [Chef::Node] Node to read Ohai information from.

@return void

@raise [Exceptions::ValidationFailed] When any required configuration

option is not set.

@api public

# 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) click to toggle source

Reads some configuration options from Ohai information.

Called from {.config_check}.

@param node [Chef::Node] No objects to read the information from.

@return void

@api private

# 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 = {}) click to toggle source

Sets configuration reading it from a Hash.

@param config [Hash] Configuration options to set.

@return void

@see Sns.initialize

@api public

# 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) click to toggle source

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.

@param arg [Array] Activities list.

@return [Array] Activities list.

@api public

# 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) click to toggle source

Gets or sets MessageStructure SNS request parameter.

@param arg [String] MessageStructure.

@return [String] MessageStructure.

@api public

# File lib/chef/handler/sns/config.rb, line 200
def message_structure(arg = nil)
  set_or_return(:message_structure, arg, kind_of: String)
end
region(arg = nil) click to toggle source

Gets or sets AWS region.

@param arg [String] Region.

@return [String] Region.

@api public

# 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) click to toggle source

Gets or sets AWS secret key.

@param arg [String] Secret key.

@return [String] Secret Key.

@api public

# 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) click to toggle source

Gets or sets SNS message subject.

@param arg [String] SNS subject.

@return [String] SNS subject.

@api public

# 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) click to toggle source

Gets or sets AWS token.

@param arg [String] Token.

@return [String] Token.

@api public

# 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) click to toggle source

Gets or sets AWS Topic ARN.

It also tries to set the AWS region reading it from the ARN string.

@param arg [String] Topic ARN.

@return [String] Topic ARN.

@api public

# 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