cheffish 4.0.0 → 4.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile +8 -8
- data/Rakefile +24 -12
- data/cheffish.gemspec +15 -15
- data/lib/chef/resource/chef_acl.rb +63 -63
- data/lib/chef/resource/chef_client.rb +9 -9
- data/lib/chef/resource/chef_container.rb +9 -9
- data/lib/chef/resource/chef_data_bag.rb +9 -9
- data/lib/chef/resource/chef_data_bag_item.rb +27 -27
- data/lib/chef/resource/chef_environment.rb +21 -22
- data/lib/chef/resource/chef_group.rb +19 -19
- data/lib/chef/resource/chef_mirror.rb +32 -17
- data/lib/chef/resource/chef_node.rb +14 -14
- data/lib/chef/resource/chef_organization.rb +29 -30
- data/lib/chef/resource/chef_resolved_cookbooks.rb +7 -7
- data/lib/chef/resource/chef_role.rb +25 -22
- data/lib/chef/resource/chef_user.rb +13 -14
- data/lib/chef/resource/private_key.rb +24 -25
- data/lib/chef/resource/public_key.rb +6 -7
- data/lib/cheffish.rb +17 -17
- data/lib/cheffish/array_property.rb +2 -2
- data/lib/cheffish/base_properties.rb +3 -3
- data/lib/cheffish/base_resource.rb +8 -8
- data/lib/cheffish/basic_chef_client.rb +17 -17
- data/lib/cheffish/chef_actor_base.rb +8 -8
- data/lib/cheffish/chef_run.rb +7 -2
- data/lib/cheffish/chef_run_data.rb +2 -2
- data/lib/cheffish/chef_run_listener.rb +1 -1
- data/lib/cheffish/key_formatter.rb +16 -18
- data/lib/cheffish/merged_config.rb +5 -3
- data/lib/cheffish/node_properties.rb +11 -7
- data/lib/cheffish/recipe_dsl.rb +33 -34
- data/lib/cheffish/rspec.rb +3 -3
- data/lib/cheffish/rspec/chef_run_support.rb +13 -13
- data/lib/cheffish/rspec/matchers.rb +4 -4
- data/lib/cheffish/rspec/matchers/be_idempotent.rb +3 -3
- data/lib/cheffish/rspec/matchers/emit_no_warnings_or_errors.rb +3 -3
- data/lib/cheffish/rspec/matchers/have_updated.rb +3 -3
- data/lib/cheffish/rspec/recipe_run_wrapper.rb +8 -7
- data/lib/cheffish/rspec/repository_support.rb +6 -6
- data/lib/cheffish/server_api.rb +11 -11
- data/lib/cheffish/version.rb +1 -1
- data/spec/functional/fingerprint_spec.rb +12 -12
- data/spec/functional/merged_config_spec.rb +46 -6
- data/spec/functional/server_api_spec.rb +3 -3
- data/spec/integration/chef_acl_spec.rb +489 -489
- data/spec/integration/chef_client_spec.rb +39 -39
- data/spec/integration/chef_container_spec.rb +14 -14
- data/spec/integration/chef_data_bag_item_spec.rb +9 -9
- data/spec/integration/chef_group_spec.rb +219 -219
- data/spec/integration/chef_mirror_spec.rb +228 -228
- data/spec/integration/chef_node_spec.rb +511 -511
- data/spec/integration/chef_organization_spec.rb +126 -126
- data/spec/integration/chef_role_spec.rb +33 -33
- data/spec/integration/chef_user_spec.rb +37 -37
- data/spec/integration/private_key_spec.rb +154 -154
- data/spec/integration/recipe_dsl_spec.rb +10 -10
- data/spec/integration/rspec/converge_spec.rb +49 -49
- data/spec/support/key_support.rb +6 -6
- data/spec/support/spec_support.rb +3 -3
- data/spec/unit/get_private_key_spec.rb +19 -19
- data/spec/unit/recipe_run_wrapper_spec.rb +4 -4
- metadata +3 -3
@@ -1,7 +1,7 @@
|
|
1
|
-
require
|
2
|
-
require
|
3
|
-
require
|
4
|
-
require
|
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[
|
54
|
+
json["normal"]["tags"] = current_json["normal"]["tags"] unless json["normal"]["tags"]
|
55
55
|
# Apply modifiers
|
56
|
-
json[
|
57
|
-
json[
|
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[
|
60
|
-
json[
|
61
|
-
json[
|
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
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
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
|
2
|
-
require
|
3
|
-
require
|
4
|
-
require
|
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 :
|
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.
|
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.
|
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.
|
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.
|
51
|
-
rest.delete("#{rest.root_url}/organizations/#{new_resource.
|
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.
|
58
|
-
rest.delete("#{rest.root_url}/organizations/#{new_resource.
|
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.
|
67
|
-
rest.post("#{rest.root_url}/organizations/#{new_resource.
|
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.
|
74
|
-
rest.post("#{rest.root_url}/organizations/#{new_resource.
|
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.
|
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.
|
89
|
-
invites[r[
|
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.
|
126
|
-
rest.delete("#{rest.root_url}/organizations/#{new_resource.
|
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.
|
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
|
-
|
159
|
-
|
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
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
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
|
2
|
-
require
|
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
|
12
|
-
berksfile Berkshelf::Berksfile.new(
|
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 !=
|
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(
|
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] ||
|
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
|
2
|
-
require
|
3
|
-
require
|
4
|
-
require
|
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 :
|
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.
|
98
|
+
description = [ "update role #{new_resource.role_name} at #{rest.url}" ] + differences
|
96
99
|
converge_by description do
|
97
|
-
rest.put("roles/#{new_resource.
|
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.
|
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.
|
111
|
-
rest.delete("roles/#{new_resource.
|
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.
|
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[
|
132
|
-
json[
|
133
|
-
json[
|
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
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
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
|
2
|
-
require
|
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 :
|
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
|
-
|
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
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
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
|
2
|
-
require
|
3
|
-
require
|
4
|
-
require
|
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:
|
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
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
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
|
-
|
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 ?
|
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,
|
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
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
|
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
|