chef-zero 4.3.0 → 4.3.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/LICENSE +201 -201
- data/README.md +155 -155
- data/Rakefile +31 -31
- data/bin/chef-zero +100 -100
- data/lib/chef_zero.rb +10 -10
- data/lib/chef_zero/chef_data/acl_path.rb +139 -139
- data/lib/chef_zero/chef_data/cookbook_data.rb +240 -240
- data/lib/chef_zero/chef_data/data_normalizer.rb +208 -207
- data/lib/chef_zero/chef_data/default_creator.rb +446 -446
- data/lib/chef_zero/data_store/data_already_exists_error.rb +29 -29
- data/lib/chef_zero/data_store/data_error.rb +31 -31
- data/lib/chef_zero/data_store/data_not_found_error.rb +28 -28
- data/lib/chef_zero/data_store/default_facade.rb +149 -149
- data/lib/chef_zero/data_store/interface_v1.rb +67 -67
- data/lib/chef_zero/data_store/interface_v2.rb +18 -18
- data/lib/chef_zero/data_store/memory_store.rb +33 -33
- data/lib/chef_zero/data_store/memory_store_v2.rb +155 -155
- data/lib/chef_zero/data_store/raw_file_store.rb +147 -147
- data/lib/chef_zero/data_store/v1_to_v2_adapter.rb +142 -142
- data/lib/chef_zero/data_store/v2_to_v1_adapter.rb +107 -107
- data/lib/chef_zero/endpoints/acl_endpoint.rb +38 -38
- data/lib/chef_zero/endpoints/acls_endpoint.rb +29 -29
- data/lib/chef_zero/endpoints/actor_endpoint.rb +94 -94
- data/lib/chef_zero/endpoints/actors_endpoint.rb +64 -64
- data/lib/chef_zero/endpoints/authenticate_user_endpoint.rb +31 -31
- data/lib/chef_zero/endpoints/container_endpoint.rb +22 -22
- data/lib/chef_zero/endpoints/containers_endpoint.rb +13 -13
- data/lib/chef_zero/endpoints/cookbook_endpoint.rb +39 -39
- data/lib/chef_zero/endpoints/cookbook_version_endpoint.rb +119 -119
- data/lib/chef_zero/endpoints/cookbooks_base.rb +65 -65
- data/lib/chef_zero/endpoints/cookbooks_endpoint.rb +19 -19
- data/lib/chef_zero/endpoints/data_bag_endpoint.rb +45 -45
- data/lib/chef_zero/endpoints/data_bag_item_endpoint.rb +25 -25
- data/lib/chef_zero/endpoints/data_bags_endpoint.rb +23 -23
- data/lib/chef_zero/endpoints/environment_cookbook_endpoint.rb +24 -24
- data/lib/chef_zero/endpoints/environment_cookbook_versions_endpoint.rb +123 -123
- data/lib/chef_zero/endpoints/environment_cookbooks_endpoint.rb +22 -22
- data/lib/chef_zero/endpoints/environment_endpoint.rb +33 -33
- data/lib/chef_zero/endpoints/environment_nodes_endpoint.rb +23 -23
- data/lib/chef_zero/endpoints/environment_recipes_endpoint.rb +22 -22
- data/lib/chef_zero/endpoints/environment_role_endpoint.rb +36 -36
- data/lib/chef_zero/endpoints/file_store_file_endpoint.rb +22 -22
- data/lib/chef_zero/endpoints/group_endpoint.rb +20 -20
- data/lib/chef_zero/endpoints/groups_endpoint.rb +13 -13
- data/lib/chef_zero/endpoints/license_endpoint.rb +25 -25
- data/lib/chef_zero/endpoints/node_endpoint.rb +17 -17
- data/lib/chef_zero/endpoints/node_identifiers_endpoint.rb +22 -22
- data/lib/chef_zero/endpoints/not_found_endpoint.rb +11 -11
- data/lib/chef_zero/endpoints/organization_association_request_endpoint.rb +22 -22
- data/lib/chef_zero/endpoints/organization_association_requests_endpoint.rb +30 -30
- data/lib/chef_zero/endpoints/organization_authenticate_user_endpoint.rb +26 -26
- data/lib/chef_zero/endpoints/organization_endpoint.rb +46 -46
- data/lib/chef_zero/endpoints/organization_user_base.rb +15 -15
- data/lib/chef_zero/endpoints/organization_user_endpoint.rb +26 -26
- data/lib/chef_zero/endpoints/organization_users_endpoint.rb +43 -43
- data/lib/chef_zero/endpoints/organization_validator_key_endpoint.rb +20 -20
- data/lib/chef_zero/endpoints/organizations_endpoint.rb +62 -62
- data/lib/chef_zero/endpoints/policies_endpoint.rb +151 -151
- data/lib/chef_zero/endpoints/principal_endpoint.rb +42 -42
- data/lib/chef_zero/endpoints/rest_list_endpoint.rb +42 -42
- data/lib/chef_zero/endpoints/rest_object_endpoint.rb +63 -63
- data/lib/chef_zero/endpoints/role_endpoint.rb +16 -16
- data/lib/chef_zero/endpoints/role_environments_endpoint.rb +14 -14
- data/lib/chef_zero/endpoints/sandbox_endpoint.rb +27 -27
- data/lib/chef_zero/endpoints/sandboxes_endpoint.rb +50 -50
- data/lib/chef_zero/endpoints/search_endpoint.rb +194 -194
- data/lib/chef_zero/endpoints/searches_endpoint.rb +18 -18
- data/lib/chef_zero/endpoints/server_api_version_endpoint.rb +14 -14
- data/lib/chef_zero/endpoints/system_recovery_endpoint.rb +30 -30
- data/lib/chef_zero/endpoints/user_association_request_endpoint.rb +40 -40
- data/lib/chef_zero/endpoints/user_association_requests_count_endpoint.rb +19 -19
- data/lib/chef_zero/endpoints/user_association_requests_endpoint.rb +19 -19
- data/lib/chef_zero/endpoints/user_organizations_endpoint.rb +22 -22
- data/lib/chef_zero/endpoints/version_endpoint.rb +12 -12
- data/lib/chef_zero/log.rb +7 -7
- data/lib/chef_zero/rest_base.rb +242 -242
- data/lib/chef_zero/rest_error_response.rb +11 -11
- data/lib/chef_zero/rest_request.rb +69 -69
- data/lib/chef_zero/rest_router.rb +45 -45
- data/lib/chef_zero/rspec.rb +308 -308
- data/lib/chef_zero/server.rb +642 -642
- data/lib/chef_zero/socketless_server_map.rb +92 -92
- data/lib/chef_zero/solr/query/binary_operator.rb +52 -52
- data/lib/chef_zero/solr/query/phrase.rb +23 -23
- data/lib/chef_zero/solr/query/range_query.rb +46 -46
- data/lib/chef_zero/solr/query/regexpable_query.rb +29 -29
- data/lib/chef_zero/solr/query/subquery.rb +37 -37
- data/lib/chef_zero/solr/query/term.rb +45 -45
- data/lib/chef_zero/solr/query/unary_operator.rb +43 -43
- data/lib/chef_zero/solr/solr_doc.rb +53 -53
- data/lib/chef_zero/solr/solr_parser.rb +203 -203
- data/lib/chef_zero/version.rb +3 -3
- data/spec/run_oc_pedant.rb +63 -63
- data/spec/search_spec.rb +32 -32
- data/spec/server_spec.rb +92 -92
- data/spec/socketless_server_map_spec.rb +76 -76
- data/spec/support/oc_pedant.rb +132 -132
- data/spec/support/stickywicket.pem +27 -27
- metadata +3 -3
@@ -1,194 +1,194 @@
|
|
1
|
-
require 'ffi_yajl'
|
2
|
-
require 'chef_zero/endpoints/rest_object_endpoint'
|
3
|
-
require 'chef_zero/chef_data/data_normalizer'
|
4
|
-
require 'chef_zero/rest_error_response'
|
5
|
-
require 'chef_zero/solr/solr_parser'
|
6
|
-
require 'chef_zero/solr/solr_doc'
|
7
|
-
|
8
|
-
module ChefZero
|
9
|
-
module Endpoints
|
10
|
-
# /search/INDEX
|
11
|
-
class SearchEndpoint < RestBase
|
12
|
-
def get(request)
|
13
|
-
orgname = request.rest_path[1]
|
14
|
-
results = search(request, orgname)
|
15
|
-
results['rows'] = results['rows'].map { |name,uri,value,search_value| value }
|
16
|
-
json_response(200, results)
|
17
|
-
end
|
18
|
-
|
19
|
-
def post(request)
|
20
|
-
orgname = request.rest_path[1]
|
21
|
-
full_results = search(request, orgname)
|
22
|
-
keys = FFI_Yajl::Parser.parse(request.body, :create_additions => false)
|
23
|
-
partial_results = full_results['rows'].map do |name, uri, doc, search_value|
|
24
|
-
data = {}
|
25
|
-
keys.each_pair do |key, path|
|
26
|
-
if path.size > 0
|
27
|
-
value = search_value
|
28
|
-
path.each do |path_part|
|
29
|
-
value = value[path_part] if !value.nil?
|
30
|
-
end
|
31
|
-
data[key] = value
|
32
|
-
else
|
33
|
-
data[key] = nil
|
34
|
-
end
|
35
|
-
end
|
36
|
-
{
|
37
|
-
'url' => uri,
|
38
|
-
'data' => data
|
39
|
-
}
|
40
|
-
end
|
41
|
-
json_response(200, {
|
42
|
-
'rows' => partial_results,
|
43
|
-
'start' => full_results['start'],
|
44
|
-
'total' => full_results['total']
|
45
|
-
})
|
46
|
-
end
|
47
|
-
|
48
|
-
private
|
49
|
-
|
50
|
-
def search_container(request, index, orgname)
|
51
|
-
relative_parts, normalize_proc = case index
|
52
|
-
when 'client'
|
53
|
-
[ ['clients'], Proc.new { |client, name| ChefData::DataNormalizer.normalize_client(client, name, orgname) } ]
|
54
|
-
when 'node'
|
55
|
-
[ ['nodes'], Proc.new { |node, name| ChefData::DataNormalizer.normalize_node(node, name) } ]
|
56
|
-
when 'environment'
|
57
|
-
[ ['environments'], Proc.new { |environment, name| ChefData::DataNormalizer.normalize_environment(environment, name) } ]
|
58
|
-
when 'role'
|
59
|
-
[ ['roles'], Proc.new { |role, name| ChefData::DataNormalizer.normalize_role(role, name) } ]
|
60
|
-
else
|
61
|
-
[ ['data', index], Proc.new { |data_bag_item, id| ChefData::DataNormalizer.normalize_data_bag_item(data_bag_item, index, id, 'DELETE') } ]
|
62
|
-
end
|
63
|
-
[
|
64
|
-
request.rest_path[0..1] + relative_parts,
|
65
|
-
normalize_proc
|
66
|
-
]
|
67
|
-
end
|
68
|
-
|
69
|
-
def expand_for_indexing(value, index, id)
|
70
|
-
if index == 'node'
|
71
|
-
result = {}
|
72
|
-
deep_merge!(value['default'] || {}, result)
|
73
|
-
deep_merge!(value['normal'] || {}, result)
|
74
|
-
deep_merge!(value['override'] || {}, result)
|
75
|
-
deep_merge!(value['automatic'] || {}, result)
|
76
|
-
result['recipe'] = []
|
77
|
-
result['role'] = []
|
78
|
-
if value['run_list']
|
79
|
-
value['run_list'].each do |run_list_entry|
|
80
|
-
if run_list_entry =~ /^(recipe|role)\[(.*)\]/
|
81
|
-
result[$1] << $2
|
82
|
-
end
|
83
|
-
end
|
84
|
-
end
|
85
|
-
value.each_pair do |key, value|
|
86
|
-
result[key] = value unless %w(default normal override automatic).include?(key)
|
87
|
-
end
|
88
|
-
result
|
89
|
-
|
90
|
-
elsif !%w(client environment role).include?(index)
|
91
|
-
ChefData::DataNormalizer.normalize_data_bag_item(value, index, id, 'GET')
|
92
|
-
else
|
93
|
-
value
|
94
|
-
end
|
95
|
-
end
|
96
|
-
|
97
|
-
def search(request, orgname = nil)
|
98
|
-
# Extract parameters
|
99
|
-
index = request.rest_path[3]
|
100
|
-
query_string = request.query_params['q'] || '*:*'
|
101
|
-
solr_query = ChefZero::Solr::SolrParser.new(query_string).parse
|
102
|
-
sort_string = request.query_params['sort']
|
103
|
-
start = request.query_params['start']
|
104
|
-
start = start.to_i if start
|
105
|
-
rows = request.query_params['rows']
|
106
|
-
rows = rows.to_i if rows
|
107
|
-
|
108
|
-
# Get the search container
|
109
|
-
container, expander = search_container(request, index, orgname)
|
110
|
-
|
111
|
-
# Search!
|
112
|
-
result = []
|
113
|
-
list_data(request, container).each do |name|
|
114
|
-
value = get_data(request, container + [name])
|
115
|
-
expanded = expander.call(FFI_Yajl::Parser.parse(value, :create_additions => false), name)
|
116
|
-
result << [ name, build_uri(request.base_uri, container + [name]), expanded, expand_for_indexing(expanded, index, name) ]
|
117
|
-
end
|
118
|
-
result = result.select do |name, uri, value, search_value|
|
119
|
-
solr_query.matches_doc?(ChefZero::Solr::SolrDoc.new(search_value, name))
|
120
|
-
end
|
121
|
-
total = result.size
|
122
|
-
|
123
|
-
# Sort
|
124
|
-
if sort_string
|
125
|
-
sort_key, sort_order = sort_string.split(/\s+/, 2)
|
126
|
-
result = result.sort_by { |name,uri,value,search_value| ChefZero::Solr::SolrDoc.new(search_value, name)[sort_key] }
|
127
|
-
result = result.reverse if sort_order == "DESC"
|
128
|
-
end
|
129
|
-
|
130
|
-
# Paginate
|
131
|
-
if start
|
132
|
-
result = result[start..start+(rows||-1)]
|
133
|
-
end
|
134
|
-
{
|
135
|
-
'rows' => result,
|
136
|
-
'start' => start || 0,
|
137
|
-
'total' => total
|
138
|
-
}
|
139
|
-
end
|
140
|
-
|
141
|
-
private
|
142
|
-
|
143
|
-
# Deep Merge core documentation.
|
144
|
-
# deep_merge! method permits merging of arbitrary child elements. The two top level
|
145
|
-
# elements must be hashes. These hashes can contain unlimited (to stack limit) levels
|
146
|
-
# of child elements. These child elements to not have to be of the same types.
|
147
|
-
# Where child elements are of the same type, deep_merge will attempt to merge them together.
|
148
|
-
# Where child elements are not of the same type, deep_merge will skip or optionally overwrite
|
149
|
-
# the destination element with the contents of the source element at that level.
|
150
|
-
# So if you have two hashes like this:
|
151
|
-
# source = {:x => [1,2,3], :y => 2}
|
152
|
-
# dest = {:x => [4,5,'6'], :y => [7,8,9]}
|
153
|
-
# dest.deep_merge!(source)
|
154
|
-
# Results: {:x => [1,2,3,4,5,'6'], :y => 2}
|
155
|
-
# By default, "deep_merge!" will overwrite any unmergeables and merge everything else.
|
156
|
-
# To avoid this, use "deep_merge" (no bang/exclamation mark)
|
157
|
-
def deep_merge!(source, dest)
|
158
|
-
# if dest doesn't exist, then simply copy source to it
|
159
|
-
if dest.nil?
|
160
|
-
dest = source; return dest
|
161
|
-
end
|
162
|
-
|
163
|
-
case source
|
164
|
-
when nil
|
165
|
-
dest
|
166
|
-
when Hash
|
167
|
-
source.each do |src_key, src_value|
|
168
|
-
if dest.kind_of?(Hash)
|
169
|
-
if dest[src_key]
|
170
|
-
dest[src_key] = deep_merge!(src_value, dest[src_key])
|
171
|
-
else # dest[src_key] doesn't exist so we take whatever source has
|
172
|
-
dest[src_key] = src_value
|
173
|
-
end
|
174
|
-
else # dest isn't a hash, so we overwrite it completely
|
175
|
-
dest = source
|
176
|
-
end
|
177
|
-
end
|
178
|
-
when Array
|
179
|
-
if dest.kind_of?(Array)
|
180
|
-
dest = dest | source
|
181
|
-
else
|
182
|
-
dest = source
|
183
|
-
end
|
184
|
-
when String
|
185
|
-
dest = source
|
186
|
-
else # src_hash is not an array or hash, so we'll have to overwrite dest
|
187
|
-
dest = source
|
188
|
-
end
|
189
|
-
dest
|
190
|
-
end # deep_merge!
|
191
|
-
|
192
|
-
end
|
193
|
-
end
|
194
|
-
end
|
1
|
+
require 'ffi_yajl'
|
2
|
+
require 'chef_zero/endpoints/rest_object_endpoint'
|
3
|
+
require 'chef_zero/chef_data/data_normalizer'
|
4
|
+
require 'chef_zero/rest_error_response'
|
5
|
+
require 'chef_zero/solr/solr_parser'
|
6
|
+
require 'chef_zero/solr/solr_doc'
|
7
|
+
|
8
|
+
module ChefZero
|
9
|
+
module Endpoints
|
10
|
+
# /search/INDEX
|
11
|
+
class SearchEndpoint < RestBase
|
12
|
+
def get(request)
|
13
|
+
orgname = request.rest_path[1]
|
14
|
+
results = search(request, orgname)
|
15
|
+
results['rows'] = results['rows'].map { |name,uri,value,search_value| value }
|
16
|
+
json_response(200, results)
|
17
|
+
end
|
18
|
+
|
19
|
+
def post(request)
|
20
|
+
orgname = request.rest_path[1]
|
21
|
+
full_results = search(request, orgname)
|
22
|
+
keys = FFI_Yajl::Parser.parse(request.body, :create_additions => false)
|
23
|
+
partial_results = full_results['rows'].map do |name, uri, doc, search_value|
|
24
|
+
data = {}
|
25
|
+
keys.each_pair do |key, path|
|
26
|
+
if path.size > 0
|
27
|
+
value = search_value
|
28
|
+
path.each do |path_part|
|
29
|
+
value = value[path_part] if !value.nil?
|
30
|
+
end
|
31
|
+
data[key] = value
|
32
|
+
else
|
33
|
+
data[key] = nil
|
34
|
+
end
|
35
|
+
end
|
36
|
+
{
|
37
|
+
'url' => uri,
|
38
|
+
'data' => data
|
39
|
+
}
|
40
|
+
end
|
41
|
+
json_response(200, {
|
42
|
+
'rows' => partial_results,
|
43
|
+
'start' => full_results['start'],
|
44
|
+
'total' => full_results['total']
|
45
|
+
})
|
46
|
+
end
|
47
|
+
|
48
|
+
private
|
49
|
+
|
50
|
+
def search_container(request, index, orgname)
|
51
|
+
relative_parts, normalize_proc = case index
|
52
|
+
when 'client'
|
53
|
+
[ ['clients'], Proc.new { |client, name| ChefData::DataNormalizer.normalize_client(client, name, orgname) } ]
|
54
|
+
when 'node'
|
55
|
+
[ ['nodes'], Proc.new { |node, name| ChefData::DataNormalizer.normalize_node(node, name) } ]
|
56
|
+
when 'environment'
|
57
|
+
[ ['environments'], Proc.new { |environment, name| ChefData::DataNormalizer.normalize_environment(environment, name) } ]
|
58
|
+
when 'role'
|
59
|
+
[ ['roles'], Proc.new { |role, name| ChefData::DataNormalizer.normalize_role(role, name) } ]
|
60
|
+
else
|
61
|
+
[ ['data', index], Proc.new { |data_bag_item, id| ChefData::DataNormalizer.normalize_data_bag_item(data_bag_item, index, id, 'DELETE') } ]
|
62
|
+
end
|
63
|
+
[
|
64
|
+
request.rest_path[0..1] + relative_parts,
|
65
|
+
normalize_proc
|
66
|
+
]
|
67
|
+
end
|
68
|
+
|
69
|
+
def expand_for_indexing(value, index, id)
|
70
|
+
if index == 'node'
|
71
|
+
result = {}
|
72
|
+
deep_merge!(value['default'] || {}, result)
|
73
|
+
deep_merge!(value['normal'] || {}, result)
|
74
|
+
deep_merge!(value['override'] || {}, result)
|
75
|
+
deep_merge!(value['automatic'] || {}, result)
|
76
|
+
result['recipe'] = []
|
77
|
+
result['role'] = []
|
78
|
+
if value['run_list']
|
79
|
+
value['run_list'].each do |run_list_entry|
|
80
|
+
if run_list_entry =~ /^(recipe|role)\[(.*)\]/
|
81
|
+
result[$1] << $2
|
82
|
+
end
|
83
|
+
end
|
84
|
+
end
|
85
|
+
value.each_pair do |key, value|
|
86
|
+
result[key] = value unless %w(default normal override automatic).include?(key)
|
87
|
+
end
|
88
|
+
result
|
89
|
+
|
90
|
+
elsif !%w(client environment role).include?(index)
|
91
|
+
ChefData::DataNormalizer.normalize_data_bag_item(value, index, id, 'GET')
|
92
|
+
else
|
93
|
+
value
|
94
|
+
end
|
95
|
+
end
|
96
|
+
|
97
|
+
def search(request, orgname = nil)
|
98
|
+
# Extract parameters
|
99
|
+
index = request.rest_path[3]
|
100
|
+
query_string = request.query_params['q'] || '*:*'
|
101
|
+
solr_query = ChefZero::Solr::SolrParser.new(query_string).parse
|
102
|
+
sort_string = request.query_params['sort']
|
103
|
+
start = request.query_params['start']
|
104
|
+
start = start.to_i if start
|
105
|
+
rows = request.query_params['rows']
|
106
|
+
rows = rows.to_i if rows
|
107
|
+
|
108
|
+
# Get the search container
|
109
|
+
container, expander = search_container(request, index, orgname)
|
110
|
+
|
111
|
+
# Search!
|
112
|
+
result = []
|
113
|
+
list_data(request, container).each do |name|
|
114
|
+
value = get_data(request, container + [name])
|
115
|
+
expanded = expander.call(FFI_Yajl::Parser.parse(value, :create_additions => false), name)
|
116
|
+
result << [ name, build_uri(request.base_uri, container + [name]), expanded, expand_for_indexing(expanded, index, name) ]
|
117
|
+
end
|
118
|
+
result = result.select do |name, uri, value, search_value|
|
119
|
+
solr_query.matches_doc?(ChefZero::Solr::SolrDoc.new(search_value, name))
|
120
|
+
end
|
121
|
+
total = result.size
|
122
|
+
|
123
|
+
# Sort
|
124
|
+
if sort_string
|
125
|
+
sort_key, sort_order = sort_string.split(/\s+/, 2)
|
126
|
+
result = result.sort_by { |name,uri,value,search_value| ChefZero::Solr::SolrDoc.new(search_value, name)[sort_key] }
|
127
|
+
result = result.reverse if sort_order == "DESC"
|
128
|
+
end
|
129
|
+
|
130
|
+
# Paginate
|
131
|
+
if start
|
132
|
+
result = result[start..start+(rows||-1)]
|
133
|
+
end
|
134
|
+
{
|
135
|
+
'rows' => result,
|
136
|
+
'start' => start || 0,
|
137
|
+
'total' => total
|
138
|
+
}
|
139
|
+
end
|
140
|
+
|
141
|
+
private
|
142
|
+
|
143
|
+
# Deep Merge core documentation.
|
144
|
+
# deep_merge! method permits merging of arbitrary child elements. The two top level
|
145
|
+
# elements must be hashes. These hashes can contain unlimited (to stack limit) levels
|
146
|
+
# of child elements. These child elements to not have to be of the same types.
|
147
|
+
# Where child elements are of the same type, deep_merge will attempt to merge them together.
|
148
|
+
# Where child elements are not of the same type, deep_merge will skip or optionally overwrite
|
149
|
+
# the destination element with the contents of the source element at that level.
|
150
|
+
# So if you have two hashes like this:
|
151
|
+
# source = {:x => [1,2,3], :y => 2}
|
152
|
+
# dest = {:x => [4,5,'6'], :y => [7,8,9]}
|
153
|
+
# dest.deep_merge!(source)
|
154
|
+
# Results: {:x => [1,2,3,4,5,'6'], :y => 2}
|
155
|
+
# By default, "deep_merge!" will overwrite any unmergeables and merge everything else.
|
156
|
+
# To avoid this, use "deep_merge" (no bang/exclamation mark)
|
157
|
+
def deep_merge!(source, dest)
|
158
|
+
# if dest doesn't exist, then simply copy source to it
|
159
|
+
if dest.nil?
|
160
|
+
dest = source; return dest
|
161
|
+
end
|
162
|
+
|
163
|
+
case source
|
164
|
+
when nil
|
165
|
+
dest
|
166
|
+
when Hash
|
167
|
+
source.each do |src_key, src_value|
|
168
|
+
if dest.kind_of?(Hash)
|
169
|
+
if dest[src_key]
|
170
|
+
dest[src_key] = deep_merge!(src_value, dest[src_key])
|
171
|
+
else # dest[src_key] doesn't exist so we take whatever source has
|
172
|
+
dest[src_key] = src_value
|
173
|
+
end
|
174
|
+
else # dest isn't a hash, so we overwrite it completely
|
175
|
+
dest = source
|
176
|
+
end
|
177
|
+
end
|
178
|
+
when Array
|
179
|
+
if dest.kind_of?(Array)
|
180
|
+
dest = dest | source
|
181
|
+
else
|
182
|
+
dest = source
|
183
|
+
end
|
184
|
+
when String
|
185
|
+
dest = source
|
186
|
+
else # src_hash is not an array or hash, so we'll have to overwrite dest
|
187
|
+
dest = source
|
188
|
+
end
|
189
|
+
dest
|
190
|
+
end # deep_merge!
|
191
|
+
|
192
|
+
end
|
193
|
+
end
|
194
|
+
end
|
@@ -1,18 +1,18 @@
|
|
1
|
-
require 'chef_zero/rest_base'
|
2
|
-
|
3
|
-
module ChefZero
|
4
|
-
module Endpoints
|
5
|
-
# /search
|
6
|
-
class SearchesEndpoint < RestBase
|
7
|
-
def get(request)
|
8
|
-
# Get the result
|
9
|
-
result_hash = {}
|
10
|
-
indices = (%w(client environment node role) + data_store.list(request.rest_path[0..1] + ['data'])).sort
|
11
|
-
indices.each do |index|
|
12
|
-
result_hash[index] = build_uri(request.base_uri, request.rest_path + [index])
|
13
|
-
end
|
14
|
-
json_response(200, result_hash)
|
15
|
-
end
|
16
|
-
end
|
17
|
-
end
|
18
|
-
end
|
1
|
+
require 'chef_zero/rest_base'
|
2
|
+
|
3
|
+
module ChefZero
|
4
|
+
module Endpoints
|
5
|
+
# /search
|
6
|
+
class SearchesEndpoint < RestBase
|
7
|
+
def get(request)
|
8
|
+
# Get the result
|
9
|
+
result_hash = {}
|
10
|
+
indices = (%w(client environment node role) + data_store.list(request.rest_path[0..1] + ['data'])).sort
|
11
|
+
indices.each do |index|
|
12
|
+
result_hash[index] = build_uri(request.base_uri, request.rest_path + [index])
|
13
|
+
end
|
14
|
+
json_response(200, result_hash)
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
@@ -1,14 +1,14 @@
|
|
1
|
-
require 'chef_zero/rest_base'
|
2
|
-
|
3
|
-
module ChefZero
|
4
|
-
module Endpoints
|
5
|
-
# /server_api_version
|
6
|
-
class ServerAPIVersionEndpoint < RestBase
|
7
|
-
API_VERSION = 1
|
8
|
-
def get(request)
|
9
|
-
json_response(200, {"min_api_version"=>MIN_API_VERSION, "max_api_version"=>MAX_API_VERSION},
|
10
|
-
request.api_version, API_VERSION)
|
11
|
-
end
|
12
|
-
end
|
13
|
-
end
|
14
|
-
end
|
1
|
+
require 'chef_zero/rest_base'
|
2
|
+
|
3
|
+
module ChefZero
|
4
|
+
module Endpoints
|
5
|
+
# /server_api_version
|
6
|
+
class ServerAPIVersionEndpoint < RestBase
|
7
|
+
API_VERSION = 1
|
8
|
+
def get(request)
|
9
|
+
json_response(200, {"min_api_version"=>MIN_API_VERSION, "max_api_version"=>MAX_API_VERSION},
|
10
|
+
request.api_version, API_VERSION)
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|