chef 12.0.0.alpha.1-x86-mingw32 → 12.0.0.alpha.2-x86-mingw32
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/lib/chef/application.rb +8 -1
- data/lib/chef/application/apply.rb +4 -0
- data/lib/chef/application/client.rb +7 -7
- data/lib/chef/application/solo.rb +21 -13
- data/lib/chef/chef_fs/chef_fs_data_store.rb +60 -6
- data/lib/chef/chef_fs/config.rb +78 -4
- data/lib/chef/chef_fs/data_handler/acl_data_handler.rb +2 -2
- data/lib/chef/chef_fs/data_handler/client_data_handler.rb +1 -1
- data/lib/chef/chef_fs/data_handler/container_data_handler.rb +1 -1
- data/lib/chef/chef_fs/data_handler/cookbook_data_handler.rb +1 -1
- data/lib/chef/chef_fs/data_handler/data_bag_item_data_handler.rb +1 -1
- data/lib/chef/chef_fs/data_handler/data_handler_base.rb +76 -2
- data/lib/chef/chef_fs/data_handler/environment_data_handler.rb +1 -1
- data/lib/chef/chef_fs/data_handler/group_data_handler.rb +1 -1
- data/lib/chef/chef_fs/data_handler/node_data_handler.rb +1 -1
- data/lib/chef/chef_fs/data_handler/organization_data_handler.rb +30 -0
- data/lib/chef/chef_fs/data_handler/organization_invites_data_handler.rb +17 -0
- data/lib/chef/chef_fs/data_handler/organization_members_data_handler.rb +17 -0
- data/lib/chef/chef_fs/data_handler/role_data_handler.rb +1 -1
- data/lib/chef/chef_fs/data_handler/user_data_handler.rb +2 -1
- data/lib/chef/chef_fs/file_system.rb +0 -1
- data/lib/chef/chef_fs/file_system/acl_entry.rb +1 -1
- data/lib/chef/chef_fs/file_system/chef_repository_file_system_cookbook_dir.rb +1 -1
- data/lib/chef/chef_fs/file_system/chef_repository_file_system_entry.rb +5 -1
- data/lib/chef/chef_fs/file_system/chef_repository_file_system_root_dir.rb +73 -13
- data/lib/chef/chef_fs/file_system/chef_server_root_dir.rb +44 -5
- data/lib/chef/chef_fs/file_system/cookbook_dir.rb +1 -1
- data/lib/chef/chef_fs/file_system/cookbooks_dir.rb +3 -3
- data/lib/chef/chef_fs/file_system/org_entry.rb +34 -0
- data/lib/chef/chef_fs/file_system/organization_invites_entry.rb +58 -0
- data/lib/chef/chef_fs/file_system/organization_members_entry.rb +57 -0
- data/lib/chef/chef_fs/file_system/rest_list_entry.rb +13 -4
- data/lib/chef/chef_fs/knife.rb +1 -1
- data/lib/chef/client.rb +8 -2
- data/lib/chef/config.rb +75 -57
- data/lib/chef/config_fetcher.rb +6 -21
- data/lib/chef/dsl/data_query.rb +48 -3
- data/lib/chef/dsl/platform_introspection.rb +42 -0
- data/lib/chef/dsl/reboot_pending.rb +6 -3
- data/lib/chef/encrypted_data_bag_item.rb +1 -1
- data/lib/chef/encrypted_data_bag_item/encryptor.rb +12 -0
- data/lib/chef/exceptions.rb +2 -0
- data/lib/chef/http/basic_client.rb +14 -0
- data/lib/chef/http/json_output.rb +7 -2
- data/lib/chef/knife.rb +36 -121
- data/lib/chef/knife/bootstrap.rb +68 -54
- data/lib/chef/knife/bootstrap/archlinux-gems.erb +6 -1
- data/lib/chef/knife/bootstrap/chef-aix.erb +5 -0
- data/lib/chef/knife/bootstrap/chef-full.erb +5 -1
- data/lib/chef/knife/core/bootstrap_context.rb +70 -29
- data/lib/chef/knife/search.rb +56 -12
- data/lib/chef/knife/serve.rb +1 -1
- data/lib/chef/local_mode.rb +10 -4
- data/lib/chef/mixin/deep_merge.rb +6 -3
- data/lib/chef/mixin/shell_out.rb +33 -17
- data/lib/chef/null_logger.rb +72 -0
- data/lib/chef/platform.rb +2 -1
- data/lib/chef/platform/provider_mapping.rb +1 -1
- data/lib/chef/platform/rebooter.rb +54 -0
- data/lib/chef/provider/ifconfig.rb +15 -16
- data/lib/chef/provider/link.rb +1 -1
- data/lib/chef/provider/mount/mount.rb +1 -1
- data/lib/chef/provider/mount/solaris.rb +102 -64
- data/lib/chef/provider/package/aix.rb +4 -12
- data/lib/chef/provider/package/ips.rb +8 -12
- data/lib/chef/provider/package/macports.rb +4 -12
- data/lib/chef/provider/package/pacman.rb +2 -6
- data/lib/chef/provider/package/portage.rb +2 -6
- data/lib/chef/provider/package/rpm.rb +4 -12
- data/lib/chef/provider/package/solaris.rb +4 -12
- data/lib/chef/provider/reboot.rb +69 -0
- data/lib/chef/provider/service/debian.rb +10 -10
- data/lib/chef/provider/service/freebsd.rb +89 -73
- data/lib/chef/provider/service/gentoo.rb +2 -2
- data/lib/chef/provider/service/init.rb +6 -4
- data/lib/chef/provider/service/insserv.rb +3 -3
- data/lib/chef/provider/service/macosx.rb +2 -2
- data/lib/chef/provider/service/simple.rb +6 -4
- data/lib/chef/provider/service/solaris.rb +1 -1
- data/lib/chef/provider/service/systemd.rb +9 -9
- data/lib/chef/provider/service/upstart.rb +6 -6
- data/lib/chef/provider/subversion.rb +6 -6
- data/lib/chef/provider/user/dscl.rb +32 -28
- data/lib/chef/provider/user/windows.rb +6 -6
- data/lib/chef/provider/whyrun_safe_ruby_block.rb +1 -1
- data/lib/chef/providers.rb +1 -0
- data/lib/chef/recipe.rb +0 -1
- data/lib/chef/resource.rb +3 -5
- data/lib/chef/resource/mount.rb +9 -0
- data/lib/chef/resource/reboot.rb +48 -0
- data/lib/chef/resources.rb +1 -0
- data/lib/chef/run_context.rb +25 -0
- data/lib/chef/search/query.rb +122 -14
- data/lib/chef/util/path_helper.rb +54 -6
- data/lib/chef/util/windows/net_user.rb +4 -1
- data/lib/chef/version.rb +1 -1
- data/lib/chef/win32/api/file.rb +1 -5
- data/lib/chef/win32/api/net.rb +1 -0
- data/lib/chef/workstation_config_loader.rb +177 -0
- data/spec/functional/http/simple_spec.rb +57 -1
- data/spec/functional/mixin/shell_out_spec.rb +2 -2
- data/spec/functional/provider/whyrun_safe_ruby_block_spec.rb +51 -0
- data/spec/functional/rebooter_spec.rb +105 -0
- data/spec/functional/resource/deploy_revision_spec.rb +0 -4
- data/spec/functional/resource/file_spec.rb +26 -3
- data/spec/functional/resource/group_spec.rb +5 -3
- data/spec/functional/resource/link_spec.rb +16 -16
- data/spec/functional/resource/reboot_spec.rb +103 -0
- data/spec/integration/client/client_spec.rb +4 -8
- data/spec/integration/client/ipv6_spec.rb +1 -1
- data/spec/integration/knife/cookbook_api_ipv6_spec.rb +3 -2
- data/spec/integration/knife/delete_spec.rb +39 -0
- data/spec/integration/knife/deps_spec.rb +30 -20
- data/spec/integration/knife/download_spec.rb +77 -1
- data/spec/integration/knife/list_spec.rb +221 -0
- data/spec/integration/knife/raw_spec.rb +1 -1
- data/spec/integration/knife/show_spec.rb +2 -2
- data/spec/integration/knife/upload_spec.rb +154 -1
- data/spec/support/pedant/run_pedant.rb +0 -1
- data/spec/support/shared/functional/http.rb +8 -1
- data/spec/support/shared/integration/integration_helper.rb +11 -19
- data/spec/support/shared/unit/platform_introspector.rb +22 -0
- data/spec/unit/application/apply.rb +11 -1
- data/spec/unit/application/solo_spec.rb +19 -3
- data/spec/unit/chef_fs/config_spec.rb +58 -0
- data/spec/unit/config_fetcher_spec.rb +1 -3
- data/spec/unit/config_spec.rb +247 -220
- data/spec/unit/dsl/data_query_spec.rb +165 -23
- data/spec/unit/dsl/reboot_pending_spec.rb +1 -7
- data/spec/unit/encrypted_data_bag_item_spec.rb +1 -1
- data/spec/unit/knife/bootstrap_spec.rb +354 -182
- data/spec/unit/knife/core/bootstrap_context_spec.rb +67 -30
- data/spec/unit/knife_spec.rb +3 -30
- data/spec/unit/mixin/deep_merge_spec.rb +14 -0
- data/spec/unit/mixin/shell_out_spec.rb +134 -64
- data/spec/unit/provider/ifconfig/debian_spec.rb +19 -9
- data/spec/unit/provider/ifconfig/redhat_spec.rb +16 -14
- data/spec/unit/provider/ifconfig_spec.rb +3 -3
- data/spec/unit/provider/link_spec.rb +5 -5
- data/spec/unit/provider/mount/mount_spec.rb +10 -1
- data/spec/unit/provider/mount/solaris_spec.rb +185 -11
- data/spec/unit/provider/package/aix_spec.rb +5 -17
- data/spec/unit/provider/package/ips_spec.rb +8 -21
- data/spec/unit/provider/package/macports_spec.rb +12 -12
- data/spec/unit/provider/package/pacman_spec.rb +4 -12
- data/spec/unit/provider/package/portage_spec.rb +5 -15
- data/spec/unit/provider/package/rpm_spec.rb +7 -22
- data/spec/unit/provider/package/solaris_spec.rb +5 -16
- data/spec/unit/provider/service/arch_service_spec.rb +8 -14
- data/spec/unit/provider/service/debian_service_spec.rb +1 -1
- data/spec/unit/provider/service/freebsd_service_spec.rb +457 -225
- data/spec/unit/provider/service/gentoo_service_spec.rb +2 -2
- data/spec/unit/provider/service/init_service_spec.rb +10 -10
- data/spec/unit/provider/service/insserv_service_spec.rb +3 -4
- data/spec/unit/provider/service/invokercd_service_spec.rb +8 -9
- data/spec/unit/provider/service/macosx_spec.rb +5 -5
- data/spec/unit/provider/service/simple_service_spec.rb +4 -6
- data/spec/unit/provider/service/solaris_smf_service_spec.rb +1 -3
- data/spec/unit/provider/service/systemd_service_spec.rb +20 -20
- data/spec/unit/provider/service/upstart_service_spec.rb +15 -17
- data/spec/unit/provider/subversion_spec.rb +5 -6
- data/spec/unit/provider/user/dscl_spec.rb +2 -1
- data/spec/unit/provider/user/windows_spec.rb +7 -0
- data/spec/unit/provider/whyrun_safe_ruby_block_spec.rb +2 -2
- data/spec/unit/resource/mount_spec.rb +9 -0
- data/spec/unit/resource_spec.rb +0 -4
- data/spec/unit/rest_spec.rb +1 -1
- data/spec/unit/run_context_spec.rb +15 -0
- data/spec/unit/search/query_spec.rb +196 -40
- data/spec/unit/util/path_helper_spec.rb +111 -28
- data/spec/unit/workstation_config_loader_spec.rb +283 -0
- metadata +36 -20
- data/lib/chef/knife/bootstrap/centos5-gems.erb +0 -62
- data/lib/chef/knife/bootstrap/fedora13-gems.erb +0 -44
- data/lib/chef/knife/bootstrap/ubuntu10.04-apt.erb +0 -53
- data/lib/chef/knife/bootstrap/ubuntu10.04-gems.erb +0 -48
- data/lib/chef/knife/bootstrap/ubuntu12.04-gems.erb +0 -46
- data/spec/support/shared/integration/chef_zero_support.rb +0 -130
- data/spec/unit/knife/config_file_selection_spec.rb +0 -135
@@ -19,7 +19,7 @@
|
|
19
19
|
class Chef
|
20
20
|
class Provider
|
21
21
|
class WhyrunSafeRubyBlock < Chef::Provider::RubyBlock
|
22
|
-
def
|
22
|
+
def action_run
|
23
23
|
@new_resource.block.call
|
24
24
|
@new_resource.updated_by_last_action(true)
|
25
25
|
@run_context.events.resource_update_applied(@new_resource, :create, "execute the whyrun_safe_ruby_block #{@new_resource.name}")
|
data/lib/chef/providers.rb
CHANGED
@@ -39,6 +39,7 @@ require 'chef/provider/mdadm'
|
|
39
39
|
require 'chef/provider/mount'
|
40
40
|
require 'chef/provider/package'
|
41
41
|
require 'chef/provider/powershell_script'
|
42
|
+
require 'chef/provider/reboot'
|
42
43
|
require 'chef/provider/remote_directory'
|
43
44
|
require 'chef/provider/remote_file'
|
44
45
|
require 'chef/provider/route'
|
data/lib/chef/recipe.rb
CHANGED
data/lib/chef/resource.rb
CHANGED
@@ -23,7 +23,7 @@ require 'chef/dsl/data_query'
|
|
23
23
|
require 'chef/dsl/registry_helper'
|
24
24
|
require 'chef/dsl/reboot_pending'
|
25
25
|
require 'chef/mixin/convert_to_class_name'
|
26
|
-
require 'chef
|
26
|
+
require 'chef/guard_interpreter/resource_guard_interpreter'
|
27
27
|
require 'chef/resource/conditional'
|
28
28
|
require 'chef/resource/conditional_action_not_nothing'
|
29
29
|
require 'chef/resource_collection'
|
@@ -121,8 +121,8 @@ F
|
|
121
121
|
|
122
122
|
end
|
123
123
|
|
124
|
-
FORBIDDEN_IVARS = [:@run_context, :@
|
125
|
-
HIDDEN_IVARS = [:@allowed_actions, :@resource_name, :@source_line, :@run_context, :@name, :@
|
124
|
+
FORBIDDEN_IVARS = [:@run_context, :@not_if, :@only_if, :@enclosing_provider]
|
125
|
+
HIDDEN_IVARS = [:@allowed_actions, :@resource_name, :@source_line, :@run_context, :@name, :@not_if, :@only_if, :@elapsed_time, :@enclosing_provider]
|
126
126
|
|
127
127
|
include Chef::DSL::DataQuery
|
128
128
|
include Chef::Mixin::ParamsValidate
|
@@ -253,8 +253,6 @@ F
|
|
253
253
|
@guard_interpreter = :default
|
254
254
|
@elapsed_time = 0
|
255
255
|
@sensitive = false
|
256
|
-
|
257
|
-
@node = run_context ? deprecated_ivar(run_context.node, :node, :warn) : nil
|
258
256
|
end
|
259
257
|
|
260
258
|
# Returns a Hash of attribute => value for the state attributes declared in
|
data/lib/chef/resource/mount.rb
CHANGED
@@ -33,6 +33,7 @@ class Chef
|
|
33
33
|
@mount_point = name
|
34
34
|
@device = nil
|
35
35
|
@device_type = :device
|
36
|
+
@fsck_device = '-'
|
36
37
|
@fstype = "auto"
|
37
38
|
@options = ["defaults"]
|
38
39
|
@dump = 0
|
@@ -77,6 +78,14 @@ class Chef
|
|
77
78
|
)
|
78
79
|
end
|
79
80
|
|
81
|
+
def fsck_device(arg=nil)
|
82
|
+
set_or_return(
|
83
|
+
:fsck_device,
|
84
|
+
arg,
|
85
|
+
:kind_of => [ String ]
|
86
|
+
)
|
87
|
+
end
|
88
|
+
|
80
89
|
def fstype(arg=nil)
|
81
90
|
set_or_return(
|
82
91
|
:fstype,
|
@@ -0,0 +1,48 @@
|
|
1
|
+
#
|
2
|
+
# Author:: Chris Doherty <cdoherty@getchef.com>)
|
3
|
+
# Copyright:: Copyright (c) 2014 Chef, Inc.
|
4
|
+
# License:: Apache License, Version 2.0
|
5
|
+
#
|
6
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
7
|
+
# you may not use this file except in compliance with the License.
|
8
|
+
# You may obtain a copy of the License at
|
9
|
+
#
|
10
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
11
|
+
#
|
12
|
+
# Unless required by applicable law or agreed to in writing, software
|
13
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
14
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
15
|
+
# See the License for the specific language governing permissions and
|
16
|
+
# limitations under the License.
|
17
|
+
#
|
18
|
+
|
19
|
+
require 'chef/resource'
|
20
|
+
|
21
|
+
# In using this resource via notifications, it's important to *only* use
|
22
|
+
# immediate notifications. Delayed notifications produce unintuitive and
|
23
|
+
# probably undesired results.
|
24
|
+
class Chef
|
25
|
+
class Resource
|
26
|
+
class Reboot < Chef::Resource
|
27
|
+
def initialize(name, run_context=nil)
|
28
|
+
super
|
29
|
+
@resource_name = :reboot
|
30
|
+
@provider = Chef::Provider::Reboot
|
31
|
+
@allowed_actions = [:request_reboot, :reboot_now, :cancel]
|
32
|
+
|
33
|
+
@reason = "Reboot by Chef"
|
34
|
+
@delay_mins = 0
|
35
|
+
|
36
|
+
# no default action.
|
37
|
+
end
|
38
|
+
|
39
|
+
def reason(arg=nil)
|
40
|
+
set_or_return(:reason, arg, :kind_of => String)
|
41
|
+
end
|
42
|
+
|
43
|
+
def delay_mins(arg=nil)
|
44
|
+
set_or_return(:delay_mins, arg, :kind_of => Fixnum)
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
data/lib/chef/resources.rb
CHANGED
@@ -53,6 +53,7 @@ require 'chef/resource/perl'
|
|
53
53
|
require 'chef/resource/portage_package'
|
54
54
|
require 'chef/resource/powershell_script'
|
55
55
|
require 'chef/resource/python'
|
56
|
+
require 'chef/resource/reboot'
|
56
57
|
require 'chef/resource/registry_key'
|
57
58
|
require 'chef/resource/remote_directory'
|
58
59
|
require 'chef/resource/remote_file'
|
data/lib/chef/run_context.rb
CHANGED
@@ -61,6 +61,9 @@ class Chef
|
|
61
61
|
# Event dispatcher for this run.
|
62
62
|
attr_reader :events
|
63
63
|
|
64
|
+
# Hash of factoids for a reboot request.
|
65
|
+
attr_reader :reboot_info
|
66
|
+
|
64
67
|
# Creates a new Chef::RunContext object and populates its fields. This object gets
|
65
68
|
# used by the Chef Server to generate a fully compiled recipe list for a node.
|
66
69
|
#
|
@@ -76,6 +79,7 @@ class Chef
|
|
76
79
|
@loaded_recipes = {}
|
77
80
|
@loaded_attributes = {}
|
78
81
|
@events = events
|
82
|
+
@reboot_info = {}
|
79
83
|
|
80
84
|
@node.run_context = self
|
81
85
|
|
@@ -271,6 +275,27 @@ ERROR_MESSAGE
|
|
271
275
|
end
|
272
276
|
end
|
273
277
|
|
278
|
+
# there are options for how to handle multiple calls to these functions:
|
279
|
+
# 1. first call always wins (never change @reboot_info once set).
|
280
|
+
# 2. last call always wins (happily change @reboot_info whenever).
|
281
|
+
# 3. raise an exception on the first conflict.
|
282
|
+
# 4. disable reboot after this run if anyone ever calls :cancel.
|
283
|
+
# 5. raise an exception on any second call.
|
284
|
+
# 6. ?
|
285
|
+
def request_reboot(reboot_info)
|
286
|
+
Chef::Log::info "Changing reboot status from #{@reboot_info.inspect} to #{reboot_info.inspect}"
|
287
|
+
@reboot_info = reboot_info
|
288
|
+
end
|
289
|
+
|
290
|
+
def cancel_reboot
|
291
|
+
Chef::Log::info "Changing reboot status from #{@reboot_info.inspect} to {}"
|
292
|
+
@reboot_info = {}
|
293
|
+
end
|
294
|
+
|
295
|
+
def reboot_requested?
|
296
|
+
@reboot_info.size > 0
|
297
|
+
end
|
298
|
+
|
274
299
|
private
|
275
300
|
|
276
301
|
def loaded_recipe(cookbook, recipe)
|
data/lib/chef/search/query.rb
CHANGED
@@ -23,6 +23,7 @@ require 'chef/node'
|
|
23
23
|
require 'chef/role'
|
24
24
|
require 'chef/data_bag'
|
25
25
|
require 'chef/data_bag_item'
|
26
|
+
require 'chef/exceptions'
|
26
27
|
|
27
28
|
class Chef
|
28
29
|
class Search
|
@@ -34,17 +35,112 @@ class Chef
|
|
34
35
|
@rest = Chef::REST.new(url ||Chef::Config[:chef_server_url])
|
35
36
|
end
|
36
37
|
|
37
|
-
# Search Solr for objects of a given type, for a given query. If you give
|
38
|
-
# it a block, it will handle the paging for you dynamically.
|
39
|
-
def search(type, query="*:*", sort='X_CHEF_id_CHEF_X asc', start=0, rows=1000, &block)
|
40
|
-
raise ArgumentError, "Type must be a string or a symbol!" unless (type.kind_of?(String) || type.kind_of?(Symbol))
|
41
38
|
|
42
|
-
|
43
|
-
|
44
|
-
|
39
|
+
# This search is only kept for backwards compatibility, since the results of the
|
40
|
+
# new filtered search method will be in a slightly different format
|
41
|
+
def partial_search(type, query='*:*', *args, &block)
|
42
|
+
Chef::Log.warn("DEPRECATED: The 'partial_search' api is deprecated, please use the search api with 'filter_result'")
|
43
|
+
# accept both types of args
|
44
|
+
if args.length == 1 && args[0].is_a?(Hash)
|
45
|
+
args_hash = args[0].dup
|
46
|
+
# partial_search implemented in the partial search cookbook uses the
|
47
|
+
# arg hash :keys instead of :filter_result to filter returned data
|
48
|
+
args_hash[:filter_result] = args_hash[:keys]
|
49
|
+
else
|
50
|
+
args_hash = {}
|
51
|
+
args_hash[:sort] = args[0] if args.length >= 1
|
52
|
+
args_hash[:start] = args[1] if args.length >= 2
|
53
|
+
args_hash[:rows] = args[2] if args.length >= 3
|
54
|
+
end
|
55
|
+
|
56
|
+
unless block.nil?
|
57
|
+
raw_results = search(type,query,args_hash)
|
58
|
+
else
|
59
|
+
raw_results = search(type,query,args_hash,&block)
|
60
|
+
end
|
61
|
+
results = Array.new
|
62
|
+
raw_results[0].each do |r|
|
63
|
+
results << r["data"]
|
64
|
+
end
|
65
|
+
return results
|
66
|
+
end
|
67
|
+
|
68
|
+
#
|
69
|
+
# New search input, designed to be backwards compatible with the old method signature
|
70
|
+
# 'type' and 'query' are the same as before, args now will accept either a Hash of
|
71
|
+
# search arguments with symbols as the keys (ie :sort, :start, :rows) and a :filter_result
|
72
|
+
# option.
|
73
|
+
#
|
74
|
+
# :filter_result should be in the format of another Hash with the structure of:
|
75
|
+
# {
|
76
|
+
# :returned_name1 => ["path", "to", "variable"],
|
77
|
+
# :returned_name2 => ["shorter", "path"]
|
78
|
+
# }
|
79
|
+
# a real world example might be something like:
|
80
|
+
# {
|
81
|
+
# :ip_address => ["ipaddress"],
|
82
|
+
# :ruby_version => ["languages", "ruby", "version"]
|
83
|
+
# }
|
84
|
+
# this will bring back 2 variables 'ip_address' and 'ruby_version' with whatever value was found
|
85
|
+
# an example of the returned json may be:
|
86
|
+
# {"ip_address":"127.0.0.1", "ruby_version": "1.9.3"}
|
87
|
+
#
|
88
|
+
def search(type, query='*:*', *args, &block)
|
89
|
+
validate_type(type)
|
90
|
+
validate_args(args)
|
91
|
+
|
92
|
+
scrubbed_args = Hash.new
|
93
|
+
|
94
|
+
# argify everything
|
95
|
+
if args[0].kind_of?(Hash)
|
96
|
+
scrubbed_args = args[0]
|
97
|
+
else
|
98
|
+
# This api will be deprecated in a future release
|
99
|
+
scrubbed_args = { :sort => args[0], :start => args[1], :rows => args[2] }
|
100
|
+
end
|
101
|
+
|
102
|
+
# set defaults, if they haven't been set yet.
|
103
|
+
scrubbed_args[:sort] ||= 'X_CHEF_id_CHEF_X asc'
|
104
|
+
scrubbed_args[:start] ||= 0
|
105
|
+
scrubbed_args[:rows] ||= 1000
|
106
|
+
|
107
|
+
do_search(type, query, scrubbed_args, &block)
|
108
|
+
end
|
109
|
+
|
110
|
+
def list_indexes
|
111
|
+
@rest.get_rest("search")
|
112
|
+
end
|
113
|
+
|
114
|
+
private
|
115
|
+
def validate_type(t)
|
116
|
+
unless t.kind_of?(String) || t.kind_of?(Symbol)
|
117
|
+
msg = "Invalid search object type #{t.inspect} (#{t.class}), must be a String or Symbol." +
|
118
|
+
"Useage: search(:node, QUERY, [OPTIONAL_ARGS])" +
|
119
|
+
" `knife search environment QUERY (options)`"
|
120
|
+
raise Chef::Exceptions::InvalidSearchQuery, msg
|
121
|
+
end
|
122
|
+
end
|
123
|
+
|
124
|
+
def validate_args(a)
|
125
|
+
max_args = 3
|
126
|
+
raise Chef::Exceptions::InvalidSearchQuery, "Too many arguments! (#{a.size} for <= #{max_args})" if a.size > max_args
|
127
|
+
end
|
128
|
+
|
129
|
+
def escape(s)
|
130
|
+
s && URI.escape(s.to_s)
|
131
|
+
end
|
132
|
+
|
133
|
+
# new search api that allows for a cleaner implementation of things like return filters
|
134
|
+
# (formerly known as 'partial search').
|
135
|
+
# Also args should never be nil, but that is required for Ruby 1.8 compatibility
|
136
|
+
def do_search(type, query="*:*", args=nil, &block)
|
137
|
+
query_string = create_query_string(type, query, args)
|
138
|
+
response = call_rest_service(query_string, args)
|
139
|
+
unless block.nil?
|
140
|
+
response["rows"].each { |rowset| block.call(rowset) unless rowset.nil?}
|
45
141
|
unless (response["start"] + response["rows"].length) >= response["total"]
|
46
|
-
|
47
|
-
|
142
|
+
args[:start] = response["start"] + args[:rows]
|
143
|
+
do_search(type, query, args, &block)
|
48
144
|
end
|
49
145
|
true
|
50
146
|
else
|
@@ -52,14 +148,26 @@ class Chef
|
|
52
148
|
end
|
53
149
|
end
|
54
150
|
|
55
|
-
|
56
|
-
|
151
|
+
# create the full rest url string
|
152
|
+
def create_query_string(type, query, args)
|
153
|
+
# create some default variables just so we don't break backwards compatibility
|
154
|
+
sort = args[:sort]
|
155
|
+
start = args[:start]
|
156
|
+
rows = args[:rows]
|
157
|
+
|
158
|
+
return "search/#{type}?q=#{escape(query)}&sort=#{escape(sort)}&start=#{escape(start)}&rows=#{escape(rows)}"
|
57
159
|
end
|
58
160
|
|
59
|
-
|
60
|
-
|
61
|
-
|
161
|
+
def call_rest_service(query_string, args)
|
162
|
+
if args.key?(:filter_result)
|
163
|
+
response = @rest.post_rest(query_string, args[:filter_result])
|
164
|
+
response_rows = response['rows'].map { |row| row['data'] }
|
165
|
+
else
|
166
|
+
response = @rest.get_rest(query_string)
|
167
|
+
response_rows = response['rows']
|
62
168
|
end
|
169
|
+
return response
|
170
|
+
end
|
63
171
|
end
|
64
172
|
end
|
65
173
|
end
|
@@ -16,15 +16,50 @@
|
|
16
16
|
# limitations under the License.
|
17
17
|
#
|
18
18
|
|
19
|
-
require 'chef/platform'
|
20
|
-
require 'chef/exceptions'
|
21
|
-
|
22
19
|
class Chef
|
23
20
|
class Util
|
24
21
|
class PathHelper
|
25
22
|
# Maximum characters in a standard Windows path (260 including drive letter and NUL)
|
26
23
|
WIN_MAX_PATH = 259
|
27
24
|
|
25
|
+
def self.dirname(path)
|
26
|
+
if Chef::Platform.windows?
|
27
|
+
# Find the first slash, not counting trailing slashes
|
28
|
+
end_slash = path.size
|
29
|
+
while true
|
30
|
+
slash = path.rindex(/[#{Regexp.escape(File::SEPARATOR)}#{Regexp.escape(path_separator)}]/, end_slash - 1)
|
31
|
+
if !slash
|
32
|
+
return end_slash == path.size ? '.' : path_separator
|
33
|
+
elsif slash == end_slash - 1
|
34
|
+
end_slash = slash
|
35
|
+
else
|
36
|
+
return path[0..slash-1]
|
37
|
+
end
|
38
|
+
end
|
39
|
+
else
|
40
|
+
::File.dirname(path)
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
BACKSLASH = '\\'.freeze
|
45
|
+
|
46
|
+
def self.path_separator
|
47
|
+
if Chef::Platform.windows?
|
48
|
+
File::ALT_SEPARATOR || BACKSLASH
|
49
|
+
else
|
50
|
+
File::SEPARATOR
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
54
|
+
def self.join(*args)
|
55
|
+
args.flatten.inject do |joined_path, component|
|
56
|
+
# Joined path ends with /
|
57
|
+
joined_path = joined_path.sub(/[#{Regexp.escape(File::SEPARATOR)}#{Regexp.escape(path_separator)}]+$/, '')
|
58
|
+
component = component.sub(/^[#{Regexp.escape(File::SEPARATOR)}#{Regexp.escape(path_separator)}]+/, '')
|
59
|
+
joined_path += "#{path_separator}#{component}"
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
28
63
|
def self.validate_path(path)
|
29
64
|
if Chef::Platform.windows?
|
30
65
|
unless printable?(path)
|
@@ -32,7 +67,7 @@ class Chef
|
|
32
67
|
Chef::Log.error(msg)
|
33
68
|
raise Chef::Exceptions::ValidationFailed, msg
|
34
69
|
end
|
35
|
-
|
70
|
+
|
36
71
|
if windows_max_length_exceeded?(path)
|
37
72
|
Chef::Log.debug("Path '#{path}' is longer than #{WIN_MAX_PATH}, prefixing with'\\\\?\\'")
|
38
73
|
path.insert(0, "\\\\?\\")
|
@@ -50,7 +85,7 @@ class Chef
|
|
50
85
|
return true
|
51
86
|
end
|
52
87
|
end
|
53
|
-
|
88
|
+
|
54
89
|
false
|
55
90
|
end
|
56
91
|
|
@@ -75,7 +110,7 @@ class Chef
|
|
75
110
|
if Chef::Platform.windows?
|
76
111
|
# Add the \\?\ API prefix on Windows unless add_prefix is false
|
77
112
|
# Downcase on Windows where paths are still case-insensitive
|
78
|
-
abs_path.gsub!(::File::SEPARATOR,
|
113
|
+
abs_path.gsub!(::File::SEPARATOR, path_separator)
|
79
114
|
if add_prefix && abs_path !~ /^\\\\?\\/
|
80
115
|
abs_path.insert(0, "\\\\?\\")
|
81
116
|
end
|
@@ -86,9 +121,22 @@ class Chef
|
|
86
121
|
abs_path
|
87
122
|
end
|
88
123
|
|
124
|
+
def self.cleanpath(path)
|
125
|
+
path = Pathname.new(path).cleanpath.to_s
|
126
|
+
# ensure all forward slashes are backslashes
|
127
|
+
if Chef::Platform.windows?
|
128
|
+
path = path.gsub(File::SEPARATOR, path_separator)
|
129
|
+
end
|
130
|
+
path
|
131
|
+
end
|
132
|
+
|
89
133
|
def self.paths_eql?(path1, path2)
|
90
134
|
canonical_path(path1) == canonical_path(path2)
|
91
135
|
end
|
92
136
|
end
|
93
137
|
end
|
94
138
|
end
|
139
|
+
|
140
|
+
# Break a require loop when require chef/util/path_helper
|
141
|
+
require 'chef/platform'
|
142
|
+
require 'chef/exceptions'
|