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

Defined Under Namespace

Classes: Ohai

Constant Summary collapse

REQUIRED =
[ 'access_key', 'secret_key', 'topic_arn' ]

Instance Method Summary collapse

Instance Method Details

#access_key(arg = nil) ⇒ Object



69
70
71
72
73
74
75
# File 'lib/chef/handler/sns/config.rb', line 69

def access_key(arg=nil)
  set_or_return(
    :access_key,
    arg,
    :kind_of => String
  )
end

#body_template(arg = nil) ⇒ Object



117
118
119
120
121
122
123
# File 'lib/chef/handler/sns/config.rb', line 117

def body_template(arg=nil)
  set_or_return(
    :body_template,
    arg,
    :kind_of => String
  )
end

#config_check(node = nil) ⇒ Object



54
55
56
57
58
59
60
61
62
63
64
65
66
67
# File 'lib/chef/handler/sns/config.rb', line 54

def config_check(node=nil)
  config_from_ohai(node) if node
  REQUIRED.each do |key|
    if self.send(key).nil?
      raise Exceptions::ValidationFailed,
        "Required argument #{key.to_s} is missing!"
    end
  end

  if body_template and not ::File.exists?(body_template)
    raise Exceptions::ValidationFailed,
      "Template file not found: #{body_template}."
  end
end

#config_from_ohai(node) ⇒ Object



32
33
34
35
36
37
38
39
40
41
42
# File 'lib/chef/handler/sns/config.rb', line 32

def config_from_ohai(node)
  config_ohai = Config::Ohai.new(node)
  [
    :region,
    :access_key,
    :secret_key,
    :token,
  ].each do |attr|
    self.send(attr, config_ohai.send(attr)) if self.send(attr).nil?
  end
end

#config_init(config = {}) ⇒ Object



44
45
46
47
48
49
50
51
52
# File 'lib/chef/handler/sns/config.rb', line 44

def config_init(config={})
  config.each do |key, value|
    if Config.respond_to?(key) and not /^config_/ =~ key.to_s
      self.send(key, value)
    else
      Chef::Log.warn("#{self.class.to_s}: configuration method not found: #{key}.")
    end
  end
end

#filter_opsworks_activity(arg = nil) ⇒ Object



125
126
127
128
129
130
131
132
# File 'lib/chef/handler/sns/config.rb', line 125

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) ⇒ Object



85
86
87
88
89
90
91
# File 'lib/chef/handler/sns/config.rb', line 85

def region(arg=nil)
  set_or_return(
    :region,
    arg,
    :kind_of => String
  )
end

#secret_key(arg = nil) ⇒ Object



77
78
79
80
81
82
83
# File 'lib/chef/handler/sns/config.rb', line 77

def secret_key(arg=nil)
  set_or_return(
    :secret_key,
    arg,
    :kind_of => String
  )
end

#subject(arg = nil) ⇒ Object



109
110
111
112
113
114
115
# File 'lib/chef/handler/sns/config.rb', line 109

def subject(arg=nil)
  set_or_return(
    :subject,
    arg,
    :kind_of => String
  )
end

#token(arg = nil) ⇒ Object



93
94
95
96
97
98
99
# File 'lib/chef/handler/sns/config.rb', line 93

def token(arg=nil)
  set_or_return(
    :token,
    arg,
    :kind_of => String
  )
end

#topic_arn(arg = nil) ⇒ Object



101
102
103
104
105
106
107
# File 'lib/chef/handler/sns/config.rb', line 101

def topic_arn(arg=nil)
  set_or_return(
    :topic_arn,
    arg,
    :kind_of => String
  )
end