cheffish 4.0.0 → 4.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- 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,17 +1,17 @@
|
|
1
|
-
require
|
2
|
-
require
|
3
|
-
require
|
1
|
+
require "cheffish"
|
2
|
+
require "cheffish/base_resource"
|
3
|
+
require "chef/chef_fs/data_handler/container_data_handler"
|
4
4
|
|
5
5
|
class Chef
|
6
6
|
class Resource
|
7
7
|
class ChefContainer < Cheffish::BaseResource
|
8
8
|
resource_name :chef_container
|
9
9
|
|
10
|
-
property :
|
10
|
+
property :chef_container_name, Cheffish::NAME_REGEX, name_property: true
|
11
11
|
|
12
12
|
action :create do
|
13
13
|
if !@current_exists
|
14
|
-
converge_by "create container #{new_resource.
|
14
|
+
converge_by "create container #{new_resource.chef_container_name} at #{rest.url}" do
|
15
15
|
rest.post("containers", normalize_for_post(new_json))
|
16
16
|
end
|
17
17
|
end
|
@@ -19,8 +19,8 @@ class Chef
|
|
19
19
|
|
20
20
|
action :delete do
|
21
21
|
if @current_exists
|
22
|
-
converge_by "delete container #{new_resource.
|
23
|
-
rest.delete("containers/#{new_resource.
|
22
|
+
converge_by "delete container #{new_resource.chef_container_name} at #{rest.url}" do
|
23
|
+
rest.delete("containers/#{new_resource.chef_container_name}")
|
24
24
|
end
|
25
25
|
end
|
26
26
|
end
|
@@ -28,7 +28,7 @@ class Chef
|
|
28
28
|
action_class.class_eval do
|
29
29
|
def load_current_resource
|
30
30
|
begin
|
31
|
-
@current_exists = rest.get("containers/#{new_resource.
|
31
|
+
@current_exists = rest.get("containers/#{new_resource.chef_container_name}")
|
32
32
|
rescue Net::HTTPServerException => e
|
33
33
|
if e.response.code == "404"
|
34
34
|
@current_exists = false
|
@@ -47,7 +47,7 @@ class Chef
|
|
47
47
|
end
|
48
48
|
|
49
49
|
def keys
|
50
|
-
{
|
50
|
+
{ "containername" => :chef_container_name, "containerpath" => :chef_container_name }
|
51
51
|
end
|
52
52
|
end
|
53
53
|
end
|
@@ -1,25 +1,25 @@
|
|
1
|
-
require
|
2
|
-
require
|
1
|
+
require "cheffish"
|
2
|
+
require "cheffish/base_resource"
|
3
3
|
|
4
4
|
class Chef
|
5
5
|
class Resource
|
6
6
|
class ChefDataBag < Cheffish::BaseResource
|
7
7
|
resource_name :chef_data_bag
|
8
8
|
|
9
|
-
property :
|
9
|
+
property :data_bag_name, Cheffish::NAME_REGEX, name_property: true
|
10
10
|
|
11
11
|
action :create do
|
12
12
|
if !current_resource_exists?
|
13
|
-
converge_by "create data bag #{new_resource.
|
14
|
-
rest.post("data", {
|
13
|
+
converge_by "create data bag #{new_resource.data_bag_name} at #{rest.url}" do
|
14
|
+
rest.post("data", { "name" => new_resource.data_bag_name })
|
15
15
|
end
|
16
16
|
end
|
17
17
|
end
|
18
18
|
|
19
19
|
action :delete do
|
20
20
|
if current_resource_exists?
|
21
|
-
converge_by "delete data bag #{new_resource.
|
22
|
-
rest.delete("data/#{new_resource.
|
21
|
+
converge_by "delete data bag #{new_resource.data_bag_name} at #{rest.url}" do
|
22
|
+
rest.delete("data/#{new_resource.data_bag_name}")
|
23
23
|
end
|
24
24
|
end
|
25
25
|
end
|
@@ -27,7 +27,7 @@ class Chef
|
|
27
27
|
action_class.class_eval do
|
28
28
|
def load_current_resource
|
29
29
|
begin
|
30
|
-
@current_resource = json_to_resource(rest.get("data/#{new_resource.
|
30
|
+
@current_resource = json_to_resource(rest.get("data/#{new_resource.data_bag_name}"))
|
31
31
|
rescue Net::HTTPServerException => e
|
32
32
|
if e.response.code == "404"
|
33
33
|
@current_resource = not_found_resource
|
@@ -47,7 +47,7 @@ class Chef
|
|
47
47
|
end
|
48
48
|
|
49
49
|
def json_to_resource(json)
|
50
|
-
Chef::Resource::ChefDataBag.new(json[
|
50
|
+
Chef::Resource::ChefDataBag.new(json["name"], run_context)
|
51
51
|
end
|
52
52
|
end
|
53
53
|
end
|
@@ -1,8 +1,8 @@
|
|
1
|
-
require
|
2
|
-
require
|
3
|
-
require
|
4
|
-
require
|
5
|
-
require
|
1
|
+
require "cheffish"
|
2
|
+
require "chef/config"
|
3
|
+
require "cheffish/base_resource"
|
4
|
+
require "chef/chef_fs/data_handler/data_bag_item_data_handler"
|
5
|
+
require "chef/encrypted_data_bag_item"
|
6
6
|
|
7
7
|
class Chef
|
8
8
|
class Resource
|
@@ -28,9 +28,9 @@ class Chef
|
|
28
28
|
|
29
29
|
# If data_bag and id are not specified, take them from name.
|
30
30
|
# name can either be id, or data_bag/id
|
31
|
-
property :id, String, default: lazy { name.split(
|
31
|
+
property :id, String, default: lazy { name.split("/", 2)[-1] }
|
32
32
|
property :data_bag, String, default: lazy {
|
33
|
-
split = name.split(
|
33
|
+
split = name.split("/", 2)
|
34
34
|
split.size >= 2 ? split[0] : nil
|
35
35
|
}
|
36
36
|
|
@@ -59,7 +59,7 @@ class Chef
|
|
59
59
|
# end
|
60
60
|
# value 'ip_address', :delete
|
61
61
|
attr_reader :raw_data_modifiers
|
62
|
-
def value(raw_data_path, value=NOT_PASSED, &block)
|
62
|
+
def value(raw_data_path, value = NOT_PASSED, &block)
|
63
63
|
@raw_data_modifiers ||= []
|
64
64
|
if value != NOT_PASSED
|
65
65
|
@raw_data_modifiers << [ raw_data_path, value ]
|
@@ -112,15 +112,15 @@ class Chef
|
|
112
112
|
end
|
113
113
|
|
114
114
|
# Determine if data bag is encrypted and if so, what its version is
|
115
|
-
first_real_key, first_real_value = (current_resource.raw_data || {}).select { |key, value| key !=
|
115
|
+
first_real_key, first_real_value = (current_resource.raw_data || {}).select { |key, value| key != "id" && !value.nil? }.first
|
116
116
|
if first_real_value
|
117
117
|
if first_real_value.is_a?(Hash) &&
|
118
|
-
|
119
|
-
|
120
|
-
|
118
|
+
first_real_value["version"].is_a?(Integer) &&
|
119
|
+
first_real_value["version"] > 0 &&
|
120
|
+
first_real_value.has_key?("encrypted_data")
|
121
121
|
|
122
122
|
current_resource.encrypt true
|
123
|
-
current_resource.encryption_version first_real_value[
|
123
|
+
current_resource.encryption_version first_real_value["version"]
|
124
124
|
|
125
125
|
decrypt_error = nil
|
126
126
|
|
@@ -231,7 +231,7 @@ class Chef
|
|
231
231
|
else
|
232
232
|
result = current_decrypted.merge(new_resource.raw_data || {})
|
233
233
|
end
|
234
|
-
result[
|
234
|
+
result["id"] = new_resource.id
|
235
235
|
result = apply_modifiers(new_resource.raw_data_modifiers, result)
|
236
236
|
end
|
237
237
|
end
|
@@ -240,11 +240,11 @@ class Chef
|
|
240
240
|
def current_decrypted
|
241
241
|
@current_decrypted ||= begin
|
242
242
|
if current_resource.secret
|
243
|
-
decrypt(current_resource.raw_data || {
|
243
|
+
decrypt(current_resource.raw_data || { "id" => new_resource.id }, current_resource.secret)
|
244
244
|
elsif current_resource.encrypt
|
245
245
|
raise "Could not decrypt current data bag item #{current_resource.name}"
|
246
246
|
else
|
247
|
-
current_resource.raw_data || {
|
247
|
+
current_resource.raw_data || { "id" => new_resource.id }
|
248
248
|
end
|
249
249
|
end
|
250
250
|
end
|
@@ -254,15 +254,15 @@ class Chef
|
|
254
254
|
if new_encrypt
|
255
255
|
if current_resource.encrypt
|
256
256
|
# Both are encrypted, check if the encryption type is the same
|
257
|
-
description =
|
257
|
+
description = ""
|
258
258
|
if new_secret != current_resource.secret
|
259
|
-
description <<
|
259
|
+
description << " with new secret"
|
260
260
|
end
|
261
261
|
if new_resource.encryption_version != current_resource.encryption_version
|
262
262
|
description << " from v#{current_resource.encryption_version} to v#{new_resource.encryption_version} encryption"
|
263
263
|
end
|
264
264
|
|
265
|
-
if description !=
|
265
|
+
if description != ""
|
266
266
|
# Encryption is different, we're reencrypting
|
267
267
|
differences = [ "re-encrypt#{description}"]
|
268
268
|
else
|
@@ -276,7 +276,7 @@ class Chef
|
|
276
276
|
|
277
277
|
# Get differences in the actual json
|
278
278
|
if current_resource.secret
|
279
|
-
json_differences(current_decrypted, new_decrypted, false,
|
279
|
+
json_differences(current_decrypted, new_decrypted, false, "", differences)
|
280
280
|
elsif current_resource.encrypt
|
281
281
|
# Encryption is different and we can't read the old values. Only allow the change
|
282
282
|
# if we're overwriting the data bag item
|
@@ -284,11 +284,11 @@ class Chef
|
|
284
284
|
raise "Cannot encrypt #{new_resource.name} due to failure to decrypt existing resource. Set 'complete true' to overwrite or add the old secret as old_secret / old_secret_path."
|
285
285
|
end
|
286
286
|
differences = [ "overwrite data bag item (cannot decrypt old data bag item)"]
|
287
|
-
differences = (new_resource.raw_data.keys & current_resource.raw_data.keys).map { |key| "overwrite #{key}"}
|
288
|
-
differences += (new_resource.raw_data.keys - current_resource.raw_data.keys).map { |key| "add #{key}"}
|
287
|
+
differences = (new_resource.raw_data.keys & current_resource.raw_data.keys).map { |key| "overwrite #{key}" }
|
288
|
+
differences += (new_resource.raw_data.keys - current_resource.raw_data.keys).map { |key| "add #{key}" }
|
289
289
|
differences += (current_resource.raw_data.keys - new_resource.raw_data.keys).map { |key| "remove #{key}" }
|
290
290
|
else
|
291
|
-
json_differences(current_decrypted, new_decrypted, false,
|
291
|
+
json_differences(current_decrypted, new_decrypted, false, "", differences)
|
292
292
|
end
|
293
293
|
else
|
294
294
|
if current_resource.encrypt
|
@@ -297,7 +297,7 @@ class Chef
|
|
297
297
|
else
|
298
298
|
differences = []
|
299
299
|
end
|
300
|
-
json_differences(current_decrypted, new_decrypted, true,
|
300
|
+
json_differences(current_decrypted, new_decrypted, true, "", differences)
|
301
301
|
end
|
302
302
|
differences
|
303
303
|
end
|
@@ -316,9 +316,9 @@ class Chef
|
|
316
316
|
|
317
317
|
def keys
|
318
318
|
{
|
319
|
-
|
320
|
-
|
321
|
-
|
319
|
+
"id" => :id,
|
320
|
+
"data_bag" => :data_bag,
|
321
|
+
"raw_data" => :raw_data,
|
322
322
|
}
|
323
323
|
end
|
324
324
|
|
@@ -1,17 +1,17 @@
|
|
1
|
-
require
|
2
|
-
require
|
3
|
-
require
|
4
|
-
require
|
1
|
+
require "cheffish"
|
2
|
+
require "cheffish/base_resource"
|
3
|
+
require "chef/environment"
|
4
|
+
require "chef/chef_fs/data_handler/environment_data_handler"
|
5
5
|
|
6
6
|
class Chef
|
7
7
|
class Resource
|
8
8
|
class ChefEnvironment < Cheffish::BaseResource
|
9
9
|
resource_name :chef_environment
|
10
10
|
|
11
|
-
property :
|
11
|
+
property :environment_name, Cheffish::NAME_REGEX, name_property: true
|
12
12
|
property :description, String
|
13
13
|
property :cookbook_versions, Hash, callbacks: {
|
14
|
-
"should have valid cookbook versions" => lambda { |value| Chef::Environment.validate_cookbook_versions(value) }
|
14
|
+
"should have valid cookbook versions" => lambda { |value| Chef::Environment.validate_cookbook_versions(value) },
|
15
15
|
}
|
16
16
|
property :default_attributes, Hash
|
17
17
|
property :override_attributes, Hash
|
@@ -23,7 +23,7 @@ class Chef
|
|
23
23
|
# end
|
24
24
|
# default 'ip_address', :delete
|
25
25
|
attr_reader :default_attribute_modifiers
|
26
|
-
def default(attribute_path, value=NOT_PASSED, &block)
|
26
|
+
def default(attribute_path, value = NOT_PASSED, &block)
|
27
27
|
@default_attribute_modifiers ||= []
|
28
28
|
if value != NOT_PASSED
|
29
29
|
@default_attribute_modifiers << [ attribute_path, value ]
|
@@ -41,7 +41,7 @@ class Chef
|
|
41
41
|
# end
|
42
42
|
# override 'ip_address', :delete
|
43
43
|
attr_reader :override_attribute_modifiers
|
44
|
-
def override(attribute_path, value=NOT_PASSED, &block)
|
44
|
+
def override(attribute_path, value = NOT_PASSED, &block)
|
45
45
|
@override_attribute_modifiers ||= []
|
46
46
|
if value != NOT_PASSED
|
47
47
|
@override_attribute_modifiers << [ attribute_path, value ]
|
@@ -55,19 +55,18 @@ class Chef
|
|
55
55
|
alias :attributes :default_attributes
|
56
56
|
alias :attribute :default
|
57
57
|
|
58
|
-
|
59
58
|
action :create do
|
60
59
|
differences = json_differences(current_json, new_json)
|
61
60
|
|
62
61
|
if current_resource_exists?
|
63
62
|
if differences.size > 0
|
64
|
-
description = [ "update environment #{new_resource.
|
63
|
+
description = [ "update environment #{new_resource.environment_name} at #{rest.url}" ] + differences
|
65
64
|
converge_by description do
|
66
|
-
rest.put("environments/#{new_resource.
|
65
|
+
rest.put("environments/#{new_resource.environment_name}", normalize_for_put(new_json))
|
67
66
|
end
|
68
67
|
end
|
69
68
|
else
|
70
|
-
description = [ "create environment #{new_resource.
|
69
|
+
description = [ "create environment #{new_resource.environment_name} at #{rest.url}" ] + differences
|
71
70
|
converge_by description do
|
72
71
|
rest.post("environments", normalize_for_post(new_json))
|
73
72
|
end
|
@@ -76,8 +75,8 @@ class Chef
|
|
76
75
|
|
77
76
|
action :delete do
|
78
77
|
if current_resource_exists?
|
79
|
-
converge_by "delete environment #{new_resource.
|
80
|
-
rest.delete("environments/#{new_resource.
|
78
|
+
converge_by "delete environment #{new_resource.environment_name} at #{rest.url}" do
|
79
|
+
rest.delete("environments/#{new_resource.environment_name}")
|
81
80
|
end
|
82
81
|
end
|
83
82
|
end
|
@@ -85,7 +84,7 @@ class Chef
|
|
85
84
|
action_class.class_eval do
|
86
85
|
def load_current_resource
|
87
86
|
begin
|
88
|
-
@current_resource = json_to_resource(rest.get("environments/#{new_resource.
|
87
|
+
@current_resource = json_to_resource(rest.get("environments/#{new_resource.environment_name}"))
|
89
88
|
rescue Net::HTTPServerException => e
|
90
89
|
if e.response.code == "404"
|
91
90
|
@current_resource = not_found_resource
|
@@ -97,8 +96,8 @@ class Chef
|
|
97
96
|
|
98
97
|
def augment_new_json(json)
|
99
98
|
# Apply modifiers
|
100
|
-
json[
|
101
|
-
json[
|
99
|
+
json["default_attributes"] = apply_modifiers(new_resource.default_attribute_modifiers, json["default_attributes"])
|
100
|
+
json["override_attributes"] = apply_modifiers(new_resource.override_attribute_modifiers, json["override_attributes"])
|
102
101
|
json
|
103
102
|
end
|
104
103
|
|
@@ -116,11 +115,11 @@ class Chef
|
|
116
115
|
|
117
116
|
def keys
|
118
117
|
{
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
118
|
+
"name" => :environment_name,
|
119
|
+
"description" => :description,
|
120
|
+
"cookbook_versions" => :cookbook_versions,
|
121
|
+
"default_attributes" => :default_attributes,
|
122
|
+
"override_attributes" => :override_attributes,
|
124
123
|
}
|
125
124
|
end
|
126
125
|
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/group_data_handler"
|
5
5
|
|
6
6
|
class Chef
|
7
7
|
class Resource
|
8
8
|
class ChefGroup < Cheffish::BaseResource
|
9
9
|
resource_name :chef_group
|
10
10
|
|
11
|
-
property :
|
11
|
+
property :group_name, Cheffish::NAME_REGEX, name_property: true
|
12
12
|
property :users, ArrayType
|
13
13
|
property :clients, ArrayType
|
14
14
|
property :groups, ArrayType
|
@@ -21,13 +21,13 @@ class Chef
|
|
21
21
|
|
22
22
|
if current_resource_exists?
|
23
23
|
if differences.size > 0
|
24
|
-
description = [ "update group #{new_resource.
|
24
|
+
description = [ "update group #{new_resource.group_name} at #{rest.url}" ] + differences
|
25
25
|
converge_by description do
|
26
|
-
rest.put("groups/#{new_resource.
|
26
|
+
rest.put("groups/#{new_resource.group_name}", normalize_for_put(new_json))
|
27
27
|
end
|
28
28
|
end
|
29
29
|
else
|
30
|
-
description = [ "create group #{new_resource.
|
30
|
+
description = [ "create group #{new_resource.group_name} at #{rest.url}" ] + differences
|
31
31
|
converge_by description do
|
32
32
|
rest.post("groups", normalize_for_post(new_json))
|
33
33
|
end
|
@@ -36,8 +36,8 @@ class Chef
|
|
36
36
|
|
37
37
|
action :delete do
|
38
38
|
if current_resource_exists?
|
39
|
-
converge_by "delete group #{new_resource.
|
40
|
-
rest.delete("groups/#{new_resource.
|
39
|
+
converge_by "delete group #{new_resource.group_name} at #{rest.url}" do
|
40
|
+
rest.delete("groups/#{new_resource.group_name}")
|
41
41
|
end
|
42
42
|
end
|
43
43
|
end
|
@@ -45,7 +45,7 @@ class Chef
|
|
45
45
|
action_class.class_eval do
|
46
46
|
def load_current_resource
|
47
47
|
begin
|
48
|
-
@current_resource = json_to_resource(rest.get("groups/#{new_resource.
|
48
|
+
@current_resource = json_to_resource(rest.get("groups/#{new_resource.group_name}"))
|
49
49
|
rescue Net::HTTPServerException => e
|
50
50
|
if e.response.code == "404"
|
51
51
|
@current_resource = not_found_resource
|
@@ -57,12 +57,12 @@ class Chef
|
|
57
57
|
|
58
58
|
def augment_new_json(json)
|
59
59
|
# Apply modifiers
|
60
|
-
json[
|
61
|
-
json[
|
62
|
-
json[
|
63
|
-
json[
|
64
|
-
json[
|
65
|
-
json[
|
60
|
+
json["users"] |= new_resource.users
|
61
|
+
json["clients"] |= new_resource.clients
|
62
|
+
json["groups"] |= new_resource.groups
|
63
|
+
json["users"] -= new_resource.remove_users
|
64
|
+
json["clients"] -= new_resource.remove_clients
|
65
|
+
json["groups"] -= new_resource.remove_groups
|
66
66
|
json
|
67
67
|
end
|
68
68
|
|
@@ -80,8 +80,8 @@ class Chef
|
|
80
80
|
|
81
81
|
def keys
|
82
82
|
{
|
83
|
-
|
84
|
-
|
83
|
+
"name" => :group_name,
|
84
|
+
"groupname" => :group_name,
|
85
85
|
}
|
86
86
|
end
|
87
87
|
end
|
@@ -1,10 +1,10 @@
|
|
1
|
-
require
|
2
|
-
require
|
3
|
-
require
|
4
|
-
require
|
5
|
-
require
|
6
|
-
require
|
7
|
-
require
|
1
|
+
require "cheffish"
|
2
|
+
require "cheffish/base_resource"
|
3
|
+
require "chef/chef_fs/file_pattern"
|
4
|
+
require "chef/chef_fs/file_system"
|
5
|
+
require "chef/chef_fs/parallelizer"
|
6
|
+
require "chef/chef_fs/file_system/chef_server_root_dir"
|
7
|
+
require "chef/chef_fs/file_system/chef_repository_file_system_root_dir"
|
8
8
|
|
9
9
|
class Chef
|
10
10
|
class Resource
|
@@ -33,7 +33,21 @@ class Chef
|
|
33
33
|
property :purge, Boolean
|
34
34
|
|
35
35
|
# Whether to freeze cookbooks on upload
|
36
|
-
property :
|
36
|
+
property :freeze_on_upload, Boolean
|
37
|
+
|
38
|
+
# `freeze` is an already-existing instance method on Object, so we can't use it or we'll throw
|
39
|
+
# a deprecation warning. `freeze` has been renamed to `freeze_on_upload` and this method
|
40
|
+
# is here to log a deprecation warning.
|
41
|
+
def freeze(arg = nil)
|
42
|
+
Chef::Log.warn("Property `freeze` on the `chef_mirror` resource has changed to `freeze_on_upload`." \
|
43
|
+
"Please use `freeze_on_upload` instead. This will raise an exception in a future version of the cheffish gem.")
|
44
|
+
|
45
|
+
set_or_return(
|
46
|
+
:freeze_on_upload,
|
47
|
+
arg,
|
48
|
+
:kind_of => Boolean
|
49
|
+
)
|
50
|
+
end
|
37
51
|
|
38
52
|
# If this is true, only new files will be copied. File contents will not be
|
39
53
|
# diffed, so changed files will never be uploaded.
|
@@ -42,7 +56,6 @@ class Chef
|
|
42
56
|
# Number of parallel threads to list/upload/download with. Defaults to 10.
|
43
57
|
property :concurrency, Integer, default: 10, desired_state: false
|
44
58
|
|
45
|
-
|
46
59
|
action :upload do
|
47
60
|
with_modified_config do
|
48
61
|
copy_to(local_fs, remote_fs)
|
@@ -87,7 +100,7 @@ class Chef
|
|
87
100
|
|
88
101
|
# We don't let the user pass absolute paths; we want to reserve those for
|
89
102
|
# multi-org support (/organizations/foo).
|
90
|
-
if new_resource.path[0] ==
|
103
|
+
if new_resource.path[0] == "/"
|
91
104
|
raise "Absolute paths in chef_mirror not yet supported."
|
92
105
|
end
|
93
106
|
# Copy!
|
@@ -117,10 +130,10 @@ class Chef
|
|
117
130
|
|
118
131
|
# Go through the expected object paths and figure out the local paths for each.
|
119
132
|
case repo_mode
|
120
|
-
when
|
121
|
-
object_names = %w
|
133
|
+
when "hosted_everything"
|
134
|
+
object_names = %w{acls clients cookbooks containers data_bags environments groups nodes roles}
|
122
135
|
else
|
123
|
-
object_names = %w
|
136
|
+
object_names = %w{clients cookbooks data_bags environments nodes roles users}
|
124
137
|
end
|
125
138
|
|
126
139
|
object_paths = {}
|
@@ -144,21 +157,21 @@ class Chef
|
|
144
157
|
:node_name => new_resource.chef_server[:options][:client_name],
|
145
158
|
:client_key => new_resource.chef_server[:options][:signing_key_filename],
|
146
159
|
:repo_mode => repo_mode,
|
147
|
-
:versioned_cookbooks => Chef::Config.versioned_cookbooks
|
160
|
+
:versioned_cookbooks => Chef::Config.versioned_cookbooks,
|
148
161
|
}
|
149
162
|
Chef::ChefFS::FileSystem::ChefServerRootDir.new("remote", config)
|
150
163
|
end
|
151
164
|
|
152
165
|
def repo_mode
|
153
|
-
new_resource.chef_server[:chef_server_url] =~ /\/organizations\// ?
|
166
|
+
new_resource.chef_server[:chef_server_url] =~ /\/organizations\// ? "hosted_everything" : "everything"
|
154
167
|
end
|
155
168
|
|
156
169
|
def options
|
157
170
|
result = {
|
158
171
|
:purge => new_resource.purge,
|
159
|
-
:freeze => new_resource.
|
172
|
+
:freeze => new_resource.freeze_on_upload,
|
160
173
|
:diff => new_resource.no_diff,
|
161
|
-
:dry_run => whyrun_mode
|
174
|
+
:dry_run => whyrun_mode?,
|
162
175
|
}
|
163
176
|
result[:diff] = !result[:diff]
|
164
177
|
result[:repo_mode] = repo_mode
|
@@ -185,10 +198,12 @@ class Chef
|
|
185
198
|
mirror.converge_by str do
|
186
199
|
end
|
187
200
|
end
|
201
|
+
|
188
202
|
def warn(str)
|
189
203
|
mirror.converge_by "WARNING: #{str}" do
|
190
204
|
end
|
191
205
|
end
|
206
|
+
|
192
207
|
def error(str)
|
193
208
|
mirror.converge_by "ERROR: #{str}" do
|
194
209
|
end
|