cheffish 4.0.0 → 4.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (63) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile +8 -8
  3. data/Rakefile +24 -12
  4. data/cheffish.gemspec +15 -15
  5. data/lib/chef/resource/chef_acl.rb +63 -63
  6. data/lib/chef/resource/chef_client.rb +9 -9
  7. data/lib/chef/resource/chef_container.rb +9 -9
  8. data/lib/chef/resource/chef_data_bag.rb +9 -9
  9. data/lib/chef/resource/chef_data_bag_item.rb +27 -27
  10. data/lib/chef/resource/chef_environment.rb +21 -22
  11. data/lib/chef/resource/chef_group.rb +19 -19
  12. data/lib/chef/resource/chef_mirror.rb +32 -17
  13. data/lib/chef/resource/chef_node.rb +14 -14
  14. data/lib/chef/resource/chef_organization.rb +29 -30
  15. data/lib/chef/resource/chef_resolved_cookbooks.rb +7 -7
  16. data/lib/chef/resource/chef_role.rb +25 -22
  17. data/lib/chef/resource/chef_user.rb +13 -14
  18. data/lib/chef/resource/private_key.rb +24 -25
  19. data/lib/chef/resource/public_key.rb +6 -7
  20. data/lib/cheffish.rb +17 -17
  21. data/lib/cheffish/array_property.rb +2 -2
  22. data/lib/cheffish/base_properties.rb +3 -3
  23. data/lib/cheffish/base_resource.rb +8 -8
  24. data/lib/cheffish/basic_chef_client.rb +17 -17
  25. data/lib/cheffish/chef_actor_base.rb +8 -8
  26. data/lib/cheffish/chef_run.rb +7 -2
  27. data/lib/cheffish/chef_run_data.rb +2 -2
  28. data/lib/cheffish/chef_run_listener.rb +1 -1
  29. data/lib/cheffish/key_formatter.rb +16 -18
  30. data/lib/cheffish/merged_config.rb +5 -3
  31. data/lib/cheffish/node_properties.rb +11 -7
  32. data/lib/cheffish/recipe_dsl.rb +33 -34
  33. data/lib/cheffish/rspec.rb +3 -3
  34. data/lib/cheffish/rspec/chef_run_support.rb +13 -13
  35. data/lib/cheffish/rspec/matchers.rb +4 -4
  36. data/lib/cheffish/rspec/matchers/be_idempotent.rb +3 -3
  37. data/lib/cheffish/rspec/matchers/emit_no_warnings_or_errors.rb +3 -3
  38. data/lib/cheffish/rspec/matchers/have_updated.rb +3 -3
  39. data/lib/cheffish/rspec/recipe_run_wrapper.rb +8 -7
  40. data/lib/cheffish/rspec/repository_support.rb +6 -6
  41. data/lib/cheffish/server_api.rb +11 -11
  42. data/lib/cheffish/version.rb +1 -1
  43. data/spec/functional/fingerprint_spec.rb +12 -12
  44. data/spec/functional/merged_config_spec.rb +46 -6
  45. data/spec/functional/server_api_spec.rb +3 -3
  46. data/spec/integration/chef_acl_spec.rb +489 -489
  47. data/spec/integration/chef_client_spec.rb +39 -39
  48. data/spec/integration/chef_container_spec.rb +14 -14
  49. data/spec/integration/chef_data_bag_item_spec.rb +9 -9
  50. data/spec/integration/chef_group_spec.rb +219 -219
  51. data/spec/integration/chef_mirror_spec.rb +228 -228
  52. data/spec/integration/chef_node_spec.rb +511 -511
  53. data/spec/integration/chef_organization_spec.rb +126 -126
  54. data/spec/integration/chef_role_spec.rb +33 -33
  55. data/spec/integration/chef_user_spec.rb +37 -37
  56. data/spec/integration/private_key_spec.rb +154 -154
  57. data/spec/integration/recipe_dsl_spec.rb +10 -10
  58. data/spec/integration/rspec/converge_spec.rb +49 -49
  59. data/spec/support/key_support.rb +6 -6
  60. data/spec/support/spec_support.rb +3 -3
  61. data/spec/unit/get_private_key_spec.rb +19 -19
  62. data/spec/unit/recipe_run_wrapper_spec.rb +4 -4
  63. metadata +3 -3
@@ -1,7 +1,7 @@
1
- require 'cheffish'
2
- require 'cheffish/base_resource'
3
- require 'chef/chef_fs/data_handler/node_data_handler'
4
- require 'cheffish/node_properties'
1
+ require "cheffish"
2
+ require "cheffish/base_resource"
3
+ require "chef/chef_fs/data_handler/node_data_handler"
4
+ require "cheffish/node_properties"
5
5
 
6
6
  class Chef
7
7
  class Resource
@@ -51,14 +51,14 @@ class Chef
51
51
 
52
52
  def augment_new_json(json)
53
53
  # Preserve tags even if "attributes" was overwritten directly
54
- json['normal']['tags'] = current_json['normal']['tags'] unless json['normal']['tags']
54
+ json["normal"]["tags"] = current_json["normal"]["tags"] unless json["normal"]["tags"]
55
55
  # Apply modifiers
56
- json['run_list'] = apply_run_list_modifiers(new_resource.run_list_modifiers, new_resource.run_list_removers, json['run_list'])
57
- json['normal'] = apply_modifiers(new_resource.attribute_modifiers, json['normal'])
56
+ json["run_list"] = apply_run_list_modifiers(new_resource.run_list_modifiers, new_resource.run_list_removers, json["run_list"])
57
+ json["normal"] = apply_modifiers(new_resource.attribute_modifiers, json["normal"])
58
58
  # Preserve default/override/automatic even when "complete true"
59
- json['default'] = current_json['default']
60
- json['override'] = current_json['override']
61
- json['automatic'] = current_json['automatic']
59
+ json["default"] = current_json["default"]
60
+ json["override"] = current_json["override"]
61
+ json["automatic"] = current_json["automatic"]
62
62
  json
63
63
  end
64
64
 
@@ -76,10 +76,10 @@ class Chef
76
76
 
77
77
  def keys
78
78
  {
79
- 'name' => :name,
80
- 'chef_environment' => :chef_environment,
81
- 'run_list' => :run_list,
82
- 'normal' => :attributes
79
+ "name" => :name,
80
+ "chef_environment" => :chef_environment,
81
+ "run_list" => :run_list,
82
+ "normal" => :attributes,
83
83
  }
84
84
  end
85
85
  end
@@ -1,14 +1,14 @@
1
- require 'cheffish'
2
- require 'cheffish/base_resource'
3
- require 'chef/run_list/run_list_item'
4
- require 'chef/chef_fs/data_handler/data_handler_base'
1
+ require "cheffish"
2
+ require "cheffish/base_resource"
3
+ require "chef/run_list/run_list_item"
4
+ require "chef/chef_fs/data_handler/data_handler_base"
5
5
 
6
6
  class Chef
7
7
  class Resource
8
8
  class ChefOrganization < Cheffish::BaseResource
9
9
  resource_name :chef_organization
10
10
 
11
- property :name, Cheffish::NAME_REGEX, name_property: true
11
+ property :organization_name, Cheffish::NAME_REGEX, name_property: true
12
12
  property :full_name, String
13
13
 
14
14
  # A list of users who must at least be invited to the org (but may already be
@@ -26,19 +26,18 @@ class Chef
26
26
  # from the org and invites will be revoked (if any).
27
27
  property :remove_members, ArrayType
28
28
 
29
-
30
29
  action :create do
31
30
  differences = json_differences(current_json, new_json)
32
31
 
33
32
  if current_resource_exists?
34
33
  if differences.size > 0
35
- description = [ "update organization #{new_resource.name} at #{rest.url}" ] + differences
34
+ description = [ "update organization #{new_resource.organization_name} at #{rest.url}" ] + differences
36
35
  converge_by description do
37
- rest.put("#{rest.root_url}/organizations/#{new_resource.name}", normalize_for_put(new_json))
36
+ rest.put("#{rest.root_url}/organizations/#{new_resource.organization_name}", normalize_for_put(new_json))
38
37
  end
39
38
  end
40
39
  else
41
- description = [ "create organization #{new_resource.name} at #{rest.url}" ] + differences
40
+ description = [ "create organization #{new_resource.organization_name} at #{rest.url}" ] + differences
42
41
  converge_by description do
43
42
  rest.post("#{rest.root_url}/organizations", normalize_for_post(new_json))
44
43
  end
@@ -47,15 +46,15 @@ class Chef
47
46
  # Revoke invites and memberships when asked
48
47
  invites_to_remove.each do |user|
49
48
  if outstanding_invites.has_key?(user)
50
- converge_by "revoke #{user}'s invitation to organization #{new_resource.name}" do
51
- rest.delete("#{rest.root_url}/organizations/#{new_resource.name}/association_requests/#{outstanding_invites[user]}")
49
+ converge_by "revoke #{user}'s invitation to organization #{new_resource.organization_name}" do
50
+ rest.delete("#{rest.root_url}/organizations/#{new_resource.organization_name}/association_requests/#{outstanding_invites[user]}")
52
51
  end
53
52
  end
54
53
  end
55
54
  members_to_remove.each do |user|
56
55
  if existing_members.include?(user)
57
- converge_by "remove #{user} from organization #{new_resource.name}" do
58
- rest.delete("#{rest.root_url}/organizations/#{new_resource.name}/users/#{user}")
56
+ converge_by "remove #{user} from organization #{new_resource.organization_name}" do
57
+ rest.delete("#{rest.root_url}/organizations/#{new_resource.organization_name}/users/#{user}")
59
58
  end
60
59
  end
61
60
  end
@@ -63,15 +62,15 @@ class Chef
63
62
  # Invite and add members when asked
64
63
  new_resource.invites.each do |user|
65
64
  if !existing_members.include?(user) && !outstanding_invites.has_key?(user)
66
- converge_by "invite #{user} to organization #{new_resource.name}" do
67
- rest.post("#{rest.root_url}/organizations/#{new_resource.name}/association_requests", { 'user' => user })
65
+ converge_by "invite #{user} to organization #{new_resource.organization_name}" do
66
+ rest.post("#{rest.root_url}/organizations/#{new_resource.organization_name}/association_requests", { "user" => user })
68
67
  end
69
68
  end
70
69
  end
71
70
  new_resource.members.each do |user|
72
71
  if !existing_members.include?(user)
73
- converge_by "Add #{user} to organization #{new_resource.name}" do
74
- rest.post("#{rest.root_url}/organizations/#{new_resource.name}/users/", { 'username' => user })
72
+ converge_by "Add #{user} to organization #{new_resource.organization_name}" do
73
+ rest.post("#{rest.root_url}/organizations/#{new_resource.organization_name}/users/", { "username" => user })
75
74
  end
76
75
  end
77
76
  end
@@ -79,14 +78,14 @@ class Chef
79
78
 
80
79
  action_class.class_eval do
81
80
  def existing_members
82
- @existing_members ||= rest.get("#{rest.root_url}/organizations/#{new_resource.name}/users").map { |u| u['user']['username'] }
81
+ @existing_members ||= rest.get("#{rest.root_url}/organizations/#{new_resource.organization_name}/users").map { |u| u["user"]["username"] }
83
82
  end
84
83
 
85
84
  def outstanding_invites
86
85
  @outstanding_invites ||= begin
87
86
  invites = {}
88
- rest.get("#{rest.root_url}/organizations/#{new_resource.name}/association_requests").each do |r|
89
- invites[r['username']] = r['id']
87
+ rest.get("#{rest.root_url}/organizations/#{new_resource.organization_name}/association_requests").each do |r|
88
+ invites[r["username"]] = r["id"]
90
89
  end
91
90
  invites
92
91
  end
@@ -122,8 +121,8 @@ class Chef
122
121
 
123
122
  action :delete do
124
123
  if current_resource_exists?
125
- converge_by "delete organization #{new_resource.name} at #{rest.url}" do
126
- rest.delete("#{rest.root_url}/organizations/#{new_resource.name}")
124
+ converge_by "delete organization #{new_resource.organization_name} at #{rest.url}" do
125
+ rest.delete("#{rest.root_url}/organizations/#{new_resource.organization_name}")
127
126
  end
128
127
  end
129
128
  end
@@ -131,7 +130,7 @@ class Chef
131
130
  action_class.class_eval do
132
131
  def load_current_resource
133
132
  begin
134
- @current_resource = json_to_resource(rest.get("#{rest.root_url}/organizations/#{new_resource.name}"))
133
+ @current_resource = json_to_resource(rest.get("#{rest.root_url}/organizations/#{new_resource.organization_name}"))
135
134
  rescue Net::HTTPServerException => e
136
135
  if e.response.code == "404"
137
136
  @current_resource = not_found_resource
@@ -155,8 +154,8 @@ class Chef
155
154
 
156
155
  def keys
157
156
  {
158
- 'name' => :name,
159
- 'full_name' => :full_name
157
+ "name" => :organization_name,
158
+ "full_name" => :full_name,
160
159
  }
161
160
  end
162
161
 
@@ -164,11 +163,11 @@ class Chef
164
163
  def normalize(organization, entry)
165
164
  # Normalize the order of the keys for easier reading
166
165
  normalize_hash(organization, {
167
- 'name' => remove_dot_json(entry.name),
168
- 'full_name' => remove_dot_json(entry.name),
169
- 'org_type' => 'Business',
170
- 'clientname' => "#{remove_dot_json(entry.name)}-validator",
171
- 'billing_plan' => 'platform-free'
166
+ "name" => remove_dot_json(entry.name),
167
+ "full_name" => remove_dot_json(entry.name),
168
+ "org_type" => "Business",
169
+ "clientname" => "#{remove_dot_json(entry.name)}-validator",
170
+ "billing_plan" => "platform-free",
172
171
  })
173
172
  end
174
173
  end
@@ -1,5 +1,5 @@
1
- require 'cheffish/base_resource'
2
- require 'chef_zero'
1
+ require "cheffish/base_resource"
2
+ require "chef_zero"
3
3
 
4
4
  class Chef
5
5
  class Resource
@@ -8,8 +8,8 @@ class Chef
8
8
 
9
9
  def initialize(*args)
10
10
  super
11
- require 'berkshelf'
12
- berksfile Berkshelf::Berksfile.new('/tmp/Berksfile')
11
+ require "berkshelf"
12
+ berksfile Berkshelf::Berksfile.new("/tmp/Berksfile")
13
13
  @cookbooks_from = []
14
14
  end
15
15
 
@@ -30,7 +30,7 @@ class Chef
30
30
  action :resolve do
31
31
  new_resource.cookbooks_from.each do |path|
32
32
  ::Dir.entries(path).each do |name|
33
- if ::File.directory?(::File.join(path, name)) && name != '.' && name != '..'
33
+ if ::File.directory?(::File.join(path, name)) && name != "." && name != ".."
34
34
  new_resource.berksfile.cookbook name, :path => ::File.join(path, name)
35
35
  end
36
36
  end
@@ -45,14 +45,14 @@ class Chef
45
45
  :client_name => new_resource.chef_server[:options][:client_name],
46
46
  :client_key => new_resource.chef_server[:options][:signing_key_filename])
47
47
  else
48
- file = Tempfile.new('privatekey')
48
+ file = Tempfile.new("privatekey")
49
49
  begin
50
50
  file.write(ChefZero::PRIVATE_KEY)
51
51
  file.close
52
52
 
53
53
  new_resource.berksfile.upload(
54
54
  :server_url => new_resource.chef_server[:chef_server_url],
55
- :client_name => new_resource.chef_server[:options][:client_name] || 'me',
55
+ :client_name => new_resource.chef_server[:options][:client_name] || "me",
56
56
  :client_key => file.path)
57
57
 
58
58
  ensure
@@ -1,14 +1,14 @@
1
- require 'cheffish'
2
- require 'cheffish/base_resource'
3
- require 'chef/run_list/run_list_item'
4
- require 'chef/chef_fs/data_handler/role_data_handler'
1
+ require "cheffish"
2
+ require "cheffish/base_resource"
3
+ require "chef/run_list/run_list_item"
4
+ require "chef/chef_fs/data_handler/role_data_handler"
5
5
 
6
6
  class Chef
7
7
  class Resource
8
8
  class ChefRole < Cheffish::BaseResource
9
9
  resource_name :chef_role
10
10
 
11
- property :name, Cheffish::NAME_REGEX, name_property: true
11
+ property :role_name, Cheffish::NAME_REGEX, name_property: true
12
12
  property :description, String
13
13
  property :run_list, Array # We should let them specify it as a series of parameters too
14
14
  property :env_run_lists, Hash
@@ -22,7 +22,7 @@ class Chef
22
22
  # end
23
23
  # default_attribute 'ip_address', :delete
24
24
  attr_reader :default_attribute_modifiers
25
- def default_attribute(attribute_path, value=NOT_PASSED, &block)
25
+ def default_attribute(attribute_path, value = NOT_PASSED, &block)
26
26
  @default_attribute_modifiers ||= []
27
27
  if value != NOT_PASSED
28
28
  @default_attribute_modifiers << [ attribute_path, value ]
@@ -40,7 +40,7 @@ class Chef
40
40
  # end
41
41
  # override_attribute 'ip_address', :delete
42
42
  attr_reader :override_attribute_modifiers
43
- def override_attribute(attribute_path, value=NOT_PASSED, &block)
43
+ def override_attribute(attribute_path, value = NOT_PASSED, &block)
44
44
  @override_attribute_modifiers ||= []
45
45
  if value != NOT_PASSED
46
46
  @override_attribute_modifiers << [ attribute_path, value ]
@@ -65,6 +65,7 @@ class Chef
65
65
  @run_list_modifiers ||= []
66
66
  @run_list_modifiers += recipes.map { |recipe| Chef::RunList::RunListItem.new("recipe[#{recipe}]") }
67
67
  end
68
+
68
69
  def role(*roles)
69
70
  if roles.size == 0
70
71
  raise ArgumentError, "At least one role must be specified"
@@ -72,6 +73,7 @@ class Chef
72
73
  @run_list_modifiers ||= []
73
74
  @run_list_modifiers += roles.map { |role| Chef::RunList::RunListItem.new("role[#{role}]") }
74
75
  end
76
+
75
77
  def remove_recipe(*recipes)
76
78
  if recipes.size == 0
77
79
  raise ArgumentError, "At least one recipe must be specified"
@@ -79,6 +81,7 @@ class Chef
79
81
  @run_list_removers ||= []
80
82
  @run_list_removers += recipes.map { |recipe| Chef::RunList::RunListItem.new("recipe[#{recipe}]") }
81
83
  end
84
+
82
85
  def remove_role(*roles)
83
86
  if roles.size == 0
84
87
  raise ArgumentError, "At least one role must be specified"
@@ -92,13 +95,13 @@ class Chef
92
95
 
93
96
  if current_resource_exists?
94
97
  if differences.size > 0
95
- description = [ "update role #{new_resource.name} at #{rest.url}" ] + differences
98
+ description = [ "update role #{new_resource.role_name} at #{rest.url}" ] + differences
96
99
  converge_by description do
97
- rest.put("roles/#{new_resource.name}", normalize_for_put(new_json))
100
+ rest.put("roles/#{new_resource.role_name}", normalize_for_put(new_json))
98
101
  end
99
102
  end
100
103
  else
101
- description = [ "create role #{new_resource.name} at #{rest.url}" ] + differences
104
+ description = [ "create role #{new_resource.role_name} at #{rest.url}" ] + differences
102
105
  converge_by description do
103
106
  rest.post("roles", normalize_for_post(new_json))
104
107
  end
@@ -107,8 +110,8 @@ class Chef
107
110
 
108
111
  action :delete do
109
112
  if current_resource_exists?
110
- converge_by "delete role #{new_resource.name} at #{rest.url}" do
111
- rest.delete("roles/#{new_resource.name}")
113
+ converge_by "delete role #{new_resource.role_name} at #{rest.url}" do
114
+ rest.delete("roles/#{new_resource.role_name}")
112
115
  end
113
116
  end
114
117
  end
@@ -116,7 +119,7 @@ class Chef
116
119
  action_class.class_eval do
117
120
  def load_current_resource
118
121
  begin
119
- @current_resource = json_to_resource(rest.get("roles/#{new_resource.name}"))
122
+ @current_resource = json_to_resource(rest.get("roles/#{new_resource.role_name}"))
120
123
  rescue Net::HTTPServerException => e
121
124
  if e.response.code == "404"
122
125
  @current_resource = not_found_resource
@@ -128,9 +131,9 @@ class Chef
128
131
 
129
132
  def augment_new_json(json)
130
133
  # Apply modifiers
131
- json['run_list'] = apply_run_list_modifiers(new_resource.run_list_modifiers, new_resource.run_list_removers, json['run_list'])
132
- json['default_attributes'] = apply_modifiers(new_resource.default_attribute_modifiers, json['default_attributes'])
133
- json['override_attributes'] = apply_modifiers(new_resource.override_attribute_modifiers, json['override_attributes'])
134
+ json["run_list"] = apply_run_list_modifiers(new_resource.run_list_modifiers, new_resource.run_list_removers, json["run_list"])
135
+ json["default_attributes"] = apply_modifiers(new_resource.default_attribute_modifiers, json["default_attributes"])
136
+ json["override_attributes"] = apply_modifiers(new_resource.override_attribute_modifiers, json["override_attributes"])
134
137
  json
135
138
  end
136
139
 
@@ -148,12 +151,12 @@ class Chef
148
151
 
149
152
  def keys
150
153
  {
151
- 'name' => :name,
152
- 'description' => :description,
153
- 'run_list' => :run_list,
154
- 'env_run_lists' => :env_run_lists,
155
- 'default_attributes' => :default_attributes,
156
- 'override_attributes' => :override_attributes
154
+ "name" => :role_name,
155
+ "description" => :description,
156
+ "run_list" => :run_list,
157
+ "env_run_lists" => :env_run_lists,
158
+ "default_attributes" => :default_attributes,
159
+ "override_attributes" => :override_attributes,
157
160
  }
158
161
  end
159
162
  end
@@ -1,5 +1,5 @@
1
- require 'cheffish'
2
- require 'cheffish/chef_actor_base'
1
+ require "cheffish"
2
+ require "cheffish/chef_actor_base"
3
3
 
4
4
  class Chef
5
5
  class Resource
@@ -7,7 +7,7 @@ class Chef
7
7
  resource_name :chef_user
8
8
 
9
9
  # Client attributes
10
- property :name, Cheffish::NAME_REGEX, name_property: true
10
+ property :user_name, Cheffish::NAME_REGEX, name_property: true
11
11
  property :display_name, String
12
12
  property :admin, Boolean
13
13
  property :email, String
@@ -37,7 +37,6 @@ class Chef
37
37
  block ? @after = block : @after
38
38
  end
39
39
 
40
-
41
40
  action :create do
42
41
  create_actor
43
42
  end
@@ -53,7 +52,7 @@ class Chef
53
52
  # Gives us new_json, current_json, not_found_json, etc.
54
53
 
55
54
  def actor_type
56
- 'user'
55
+ "user"
57
56
  end
58
57
 
59
58
  def actor_path
@@ -70,15 +69,15 @@ class Chef
70
69
 
71
70
  def keys
72
71
  {
73
- 'name' => :name,
74
- 'username' => :name,
75
- 'display_name' => :display_name,
76
- 'admin' => :admin,
77
- 'email' => :email,
78
- 'password' => :password,
79
- 'external_authentication_uid' => :external_authentication_uid,
80
- 'recovery_authentication_enabled' => :recovery_authentication_enabled,
81
- 'public_key' => :source_key
72
+ "name" => :user_name,
73
+ "username" => :user_name,
74
+ "display_name" => :display_name,
75
+ "admin" => :admin,
76
+ "email" => :email,
77
+ "password" => :password,
78
+ "external_authentication_uid" => :external_authentication_uid,
79
+ "recovery_authentication_enabled" => :recovery_authentication_enabled,
80
+ "public_key" => :source_key,
82
81
  }
83
82
  end
84
83
  end
@@ -1,7 +1,7 @@
1
- require 'openssl/cipher'
2
- require 'cheffish/base_resource'
3
- require 'openssl'
4
- require 'cheffish/key_formatter'
1
+ require "openssl/cipher"
2
+ require "cheffish/base_resource"
3
+ require "openssl"
4
+ require "cheffish/key_formatter"
5
5
 
6
6
  class Chef
7
7
  class Resource
@@ -31,7 +31,7 @@ class Chef
31
31
 
32
32
  # PEM-only
33
33
  property :pass_phrase, String
34
- property :cipher, OpenSSL::Cipher.ciphers, default: 'DES-EDE3-CBC'
34
+ property :cipher, OpenSSL::Cipher.ciphers, default: "DES-EDE3-CBC"
35
35
 
36
36
  # Set this to regenerate the key if it does not have the desired characteristics (like size, type, etc.)
37
37
  property :regenerate_if_different, Boolean
@@ -46,7 +46,6 @@ class Chef
46
46
  Chef::Log.debug("Overloading #{resource_name}.load_prior_resource with NOOP")
47
47
  end
48
48
 
49
-
50
49
  action :create do
51
50
  create_key(false, :create)
52
51
  end
@@ -90,12 +89,12 @@ class Chef
90
89
  # Generate a new key
91
90
  #
92
91
  if current_resource.action == [ :delete ] || regenerate ||
93
- (new_resource.regenerate_if_different &&
94
- (!current_private_key ||
95
- current_resource.size != new_resource.size ||
96
- current_resource.type != new_resource.type))
92
+ (new_resource.regenerate_if_different &&
93
+ (!current_private_key ||
94
+ current_resource.size != new_resource.size ||
95
+ current_resource.type != new_resource.type))
97
96
 
98
- case new_resource.type
97
+ case new_resource.type
99
98
  when :rsa
100
99
  if new_resource.exponent
101
100
  final_private_key = OpenSSL::PKey::RSA.generate(new_resource.size, new_resource.exponent)
@@ -118,7 +117,7 @@ class Chef
118
117
  generated_description = " (#{new_resource.size} bits#{new_resource.pass_phrase ? ", #{new_resource.cipher} password" : ""})"
119
118
 
120
119
  if new_path != :none
121
- action = current_resource.path == :none ? 'create' : 'overwrite'
120
+ action = current_resource.path == :none ? "create" : "overwrite"
122
121
  converge_by "#{action} #{new_resource.type} private key #{new_path}#{generated_description}" do
123
122
  write_private_key(final_private_key)
124
123
  end
@@ -172,7 +171,7 @@ class Chef
172
171
  end
173
172
 
174
173
  def write_private_key(key)
175
- ::File.open(new_path, 'w') do |file|
174
+ ::File.open(new_path, "w") do |file|
176
175
  file.chmod(0600)
177
176
  file.write(encode_private_key(key))
178
177
  end
@@ -180,18 +179,18 @@ class Chef
180
179
 
181
180
  def new_source_key
182
181
  @new_source_key ||= begin
183
- if new_resource.source_key.is_a?(String)
184
- source_key, source_key_format = Cheffish::KeyFormatter.decode(new_resource.source_key, new_resource.source_key_pass_phrase)
185
- source_key
186
- elsif new_resource.source_key
187
- new_resource.source_key
188
- elsif new_resource.source_key_path
189
- source_key, source_key_format = Cheffish::KeyFormatter.decode(IO.read(new_resource.source_key_path), new_resource.source_key_pass_phrase, new_resource.source_key_path)
190
- source_key
191
- else
192
- nil
193
- end
194
- end
182
+ if new_resource.source_key.is_a?(String)
183
+ source_key, source_key_format = Cheffish::KeyFormatter.decode(new_resource.source_key, new_resource.source_key_pass_phrase)
184
+ source_key
185
+ elsif new_resource.source_key
186
+ new_resource.source_key
187
+ elsif new_resource.source_key_path
188
+ source_key, source_key_format = Cheffish::KeyFormatter.decode(IO.read(new_resource.source_key_path), new_resource.source_key_pass_phrase, new_resource.source_key_path)
189
+ source_key
190
+ else
191
+ nil
192
+ end
193
+ end
195
194
  end
196
195
 
197
196
  attr_reader :current_private_key