chef-handler-users 0.1.0 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -3,7 +3,7 @@ $:.push File.expand_path("../lib", __FILE__)
3
3
 
4
4
  Gem::Specification.new do |gem|
5
5
  gem.name = "chef-handler-users"
6
- gem.version = "0.1.0"
6
+ gem.version = "0.1.1"
7
7
  gem.authors = ["Heavy Water Operations, LLC. (OR)"]
8
8
  gem.email = ["ops@hw-ops.com"]
9
9
  gem.homepage = "http://github.com/heavywater/chef-handler-users"
@@ -20,21 +20,22 @@ require 'rubygems'
20
20
  require 'chef/handler'
21
21
  require 'pony'
22
22
 
23
-
24
-
25
23
  class Chef::Handler::Users < Chef::Handler
26
24
  attr_reader :config
27
25
  class ConfigurationError < StandardError; end
28
26
 
29
27
  def initialize(config={})
30
28
  @config = config
31
- @config
32
29
 
33
- %w[to_address from_address].map(&:to_sym).each do |key|
30
+ %w[to from].each do |key|
34
31
  unless @config.has_key? key
35
32
  raise ConfigurationError.new("Required configuration #{key} not passed to handler")
36
33
  end
37
34
  end
35
+
36
+ if @config[:via] == 'smtp' && !@config[:via_options]
37
+ raise ConfigurationError.new("via_options is required for smtp")
38
+ end
38
39
  end
39
40
 
40
41
  def report
@@ -46,17 +47,19 @@ class Chef::Handler::Users < Chef::Handler
46
47
  Chef::Log.info "Users handler detected no user changes"
47
48
  return
48
49
  else
49
- Chef::Log.info "Users handler detected #{updated_users.length} user changes. Generating summary email for #{@config[:to_address]}"
50
+ Chef::Log.info "Users handler detected #{updated_users.length} user changes. Generating summary email for #{@config[:to]}"
50
51
  end
51
52
 
52
53
  subject = "Chef run on #{node.name} at #{Time.now} resulted in change of #{updated_users.length} users"
53
54
 
54
55
  message = generate_email_body(updated_users)
55
56
 
56
- Pony.mail(:to => @config[:to_address],
57
- :from => @config[:from_address],
58
- :subject => subject,
59
- :body => message)
57
+ Pony.mail(
58
+ ensure_hash(@config).update(
59
+ :subject => subject,
60
+ :body => message
61
+ )
62
+ )
60
63
  end
61
64
 
62
65
  def generate_email_body users
@@ -79,4 +82,11 @@ User #{user.name} updated:
79
82
  EOH
80
83
  end
81
84
 
85
+ def ensure_hash(hash_thing)
86
+ new_h = {}
87
+ hash_thing.each do |k,v|
88
+ new_h[k.to_sym] = v.kind_of?(Hash) || v.kind_of?(Node::Attribute) ? to_hash(v) : v
89
+ end
90
+ new_h
91
+ end
82
92
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: chef-handler-users
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-12-07 00:00:00.000000000 Z
12
+ date: 2013-07-12 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: pony
@@ -77,7 +77,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
77
77
  version: '0'
78
78
  requirements: []
79
79
  rubyforge_project:
80
- rubygems_version: 1.8.24
80
+ rubygems_version: 1.8.23
81
81
  signing_key:
82
82
  specification_version: 3
83
83
  summary: Chef Handler to report changes in users