chef-zero 15.0.17 → 15.0.21
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 +36 -31
- data/LICENSE +201 -201
- data/Rakefile +73 -68
- data/bin/chef-zero +111 -111
- data/chef-zero.gemspec +34 -33
- data/lib/chef_zero/chef_data/acl_path.rb +140 -140
- data/lib/chef_zero/chef_data/cookbook_data.rb +237 -237
- data/lib/chef_zero/chef_data/data_normalizer.rb +276 -276
- data/lib/chef_zero/chef_data/default_creator.rb +476 -476
- data/lib/chef_zero/data_store/data_already_exists_error.rb +29 -29
- data/lib/chef_zero/data_store/data_error.rb +32 -32
- data/lib/chef_zero/data_store/data_not_found_error.rb +29 -29
- data/lib/chef_zero/data_store/default_facade.rb +143 -147
- 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 +159 -159
- data/lib/chef_zero/data_store/raw_file_store.rb +143 -143
- data/lib/chef_zero/data_store/v1_to_v2_adapter.rb +150 -150
- data/lib/chef_zero/data_store/v2_to_v1_adapter.rb +105 -105
- data/lib/chef_zero/dist.rb +9 -9
- data/lib/chef_zero/endpoints/acl_endpoint.rb +39 -39
- data/lib/chef_zero/endpoints/acls_endpoint.rb +41 -41
- data/lib/chef_zero/endpoints/actor_default_key_endpoint.rb +78 -78
- data/lib/chef_zero/endpoints/actor_endpoint.rb +184 -184
- data/lib/chef_zero/endpoints/actor_key_endpoint.rb +62 -62
- data/lib/chef_zero/endpoints/actor_keys_endpoint.rb +129 -129
- data/lib/chef_zero/endpoints/actors_endpoint.rb +104 -104
- data/lib/chef_zero/endpoints/authenticate_user_endpoint.rb +32 -32
- data/lib/chef_zero/endpoints/container_endpoint.rb +22 -22
- data/lib/chef_zero/endpoints/containers_endpoint.rb +25 -25
- data/lib/chef_zero/endpoints/controls_endpoint.rb +16 -16
- data/lib/chef_zero/endpoints/cookbook_artifact_endpoint.rb +24 -24
- data/lib/chef_zero/endpoints/cookbook_artifact_identifier_endpoint.rb +68 -68
- data/lib/chef_zero/endpoints/cookbook_artifacts_endpoint.rb +34 -34
- data/lib/chef_zero/endpoints/cookbook_endpoint.rb +39 -39
- data/lib/chef_zero/endpoints/cookbook_version_endpoint.rb +136 -136
- data/lib/chef_zero/endpoints/cookbooks_base.rb +80 -80
- 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/dummy_endpoint.rb +29 -29
- data/lib/chef_zero/endpoints/environment_cookbook_endpoint.rb +24 -24
- data/lib/chef_zero/endpoints/environment_cookbook_versions_endpoint.rb +126 -126
- 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 +34 -34
- data/lib/chef_zero/endpoints/node_identifiers_endpoint.rb +22 -22
- data/lib/chef_zero/endpoints/nodes_endpoint.rb +34 -34
- 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 +47 -47
- data/lib/chef_zero/endpoints/organization_user_base.rb +15 -15
- data/lib/chef_zero/endpoints/organization_user_default_key_endpoint.rb +16 -16
- data/lib/chef_zero/endpoints/organization_user_endpoint.rb +26 -26
- data/lib/chef_zero/endpoints/organization_user_key_endpoint.rb +17 -17
- data/lib/chef_zero/endpoints/organization_user_keys_endpoint.rb +17 -17
- 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 +61 -61
- data/lib/chef_zero/endpoints/policies_endpoint.rb +26 -26
- data/lib/chef_zero/endpoints/policy_endpoint.rb +24 -24
- data/lib/chef_zero/endpoints/policy_group_endpoint.rb +46 -46
- data/lib/chef_zero/endpoints/policy_group_policy_endpoint.rb +83 -83
- data/lib/chef_zero/endpoints/policy_groups_endpoint.rb +38 -38
- data/lib/chef_zero/endpoints/policy_revision_endpoint.rb +66 -66
- data/lib/chef_zero/endpoints/policy_revisions_endpoint.rb +15 -15
- data/lib/chef_zero/endpoints/principal_endpoint.rb +55 -55
- data/lib/chef_zero/endpoints/rest_list_endpoint.rb +42 -42
- data/lib/chef_zero/endpoints/rest_object_endpoint.rb +78 -78
- 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 +51 -51
- data/lib/chef_zero/endpoints/search_endpoint.rb +208 -208
- 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/universe_endpoint.rb +15 -15
- data/lib/chef_zero/endpoints/user_association_request_endpoint.rb +41 -41
- 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 +13 -13
- data/lib/chef_zero/log.rb +7 -7
- data/lib/chef_zero/rest_base.rb +332 -332
- data/lib/chef_zero/rest_error_response.rb +11 -11
- data/lib/chef_zero/rest_request.rb +84 -88
- data/lib/chef_zero/rest_router.rb +72 -72
- data/lib/chef_zero/rspec.rb +355 -355
- data/lib/chef_zero/server.rb +730 -730
- data/lib/chef_zero/socketless_server_map.rb +92 -93
- 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 +30 -30
- 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 +41 -41
- data/lib/chef_zero/solr/solr_doc.rb +53 -53
- data/lib/chef_zero/solr/solr_parser.rb +208 -208
- data/lib/chef_zero/version.rb +3 -3
- data/lib/chef_zero.rb +10 -10
- data/spec/run_oc_pedant.rb +226 -226
- data/spec/search_spec.rb +36 -36
- data/spec/server_spec.rb +96 -96
- data/spec/socketless_server_map_spec.rb +74 -74
- data/spec/support/oc_pedant.rb +149 -149
- data/spec/support/secrets.json +6 -6
- data/spec/support/stickywicket.pem +27 -27
- metadata +35 -18
@@ -1,93 +1,92 @@
|
|
1
|
-
#
|
2
|
-
# Author:: Daniel DeLeo (<dan@chef.io>)
|
3
|
-
# Copyright:: Copyright (c) 2012 Opscode, 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
|
-
# https://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 "
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
server
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
end
|
1
|
+
#
|
2
|
+
# Author:: Daniel DeLeo (<dan@chef.io>)
|
3
|
+
# Copyright:: Copyright (c) 2012 Opscode, 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
|
+
# https://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 "singleton" unless defined?(Singleton)
|
20
|
+
require_relative "dist"
|
21
|
+
|
22
|
+
module ChefZero
|
23
|
+
|
24
|
+
class ServerNotFound < StandardError
|
25
|
+
end
|
26
|
+
|
27
|
+
class NoSocketlessPortAvailable < StandardError
|
28
|
+
end
|
29
|
+
|
30
|
+
class SocketlessServerMap
|
31
|
+
|
32
|
+
def self.request(port, request_env)
|
33
|
+
instance.request(port, request_env)
|
34
|
+
end
|
35
|
+
|
36
|
+
def self.server_on_port(port)
|
37
|
+
instance.server_on_port(port)
|
38
|
+
end
|
39
|
+
|
40
|
+
MUTEX = Mutex.new
|
41
|
+
|
42
|
+
include Singleton
|
43
|
+
|
44
|
+
def initialize
|
45
|
+
reset!
|
46
|
+
end
|
47
|
+
|
48
|
+
def reset!
|
49
|
+
@servers_by_port = {}
|
50
|
+
end
|
51
|
+
|
52
|
+
def register_port(port, server)
|
53
|
+
MUTEX.synchronize do
|
54
|
+
@servers_by_port[port] = server
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
def register_no_listen_server(server)
|
59
|
+
MUTEX.synchronize do
|
60
|
+
1.upto(1000) do |port|
|
61
|
+
unless @servers_by_port.key?(port)
|
62
|
+
@servers_by_port[port] = server
|
63
|
+
return port
|
64
|
+
end
|
65
|
+
end
|
66
|
+
raise NoSocketlessPortAvailable, "No socketless ports left to register"
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
def has_server_on_port?(port)
|
71
|
+
@servers_by_port.key?(port)
|
72
|
+
end
|
73
|
+
|
74
|
+
def server_on_port(port)
|
75
|
+
@servers_by_port[port]
|
76
|
+
end
|
77
|
+
|
78
|
+
def deregister(port)
|
79
|
+
MUTEX.synchronize do
|
80
|
+
@servers_by_port.delete(port)
|
81
|
+
end
|
82
|
+
end
|
83
|
+
|
84
|
+
def request(port, request_env)
|
85
|
+
server = @servers_by_port[port]
|
86
|
+
raise ServerNotFound, "No socketless #{ChefZero::Dist::PRODUCT} server on given port #{port.inspect}" unless server
|
87
|
+
|
88
|
+
server.handle_socketless_request(request_env)
|
89
|
+
end
|
90
|
+
|
91
|
+
end
|
92
|
+
end
|
@@ -1,52 +1,52 @@
|
|
1
|
-
module ChefZero
|
2
|
-
module Solr
|
3
|
-
module Query
|
4
|
-
class BinaryOperator
|
5
|
-
def initialize(left, operator, right)
|
6
|
-
@left = left
|
7
|
-
@operator = operator
|
8
|
-
@right = right
|
9
|
-
end
|
10
|
-
|
11
|
-
def to_s
|
12
|
-
"(#{left} #{operator} #{right})"
|
13
|
-
end
|
14
|
-
|
15
|
-
attr_reader :left
|
16
|
-
attr_reader :operator
|
17
|
-
attr_reader :right
|
18
|
-
|
19
|
-
def matches_doc?(doc)
|
20
|
-
case @operator
|
21
|
-
when "AND"
|
22
|
-
left.matches_doc?(doc) && right.matches_doc?(doc)
|
23
|
-
when "OR"
|
24
|
-
left.matches_doc?(doc) || right.matches_doc?(doc)
|
25
|
-
when "^"
|
26
|
-
left.matches_doc?(doc)
|
27
|
-
when ":"
|
28
|
-
if left.respond_to?(:literal_string) && left.literal_string
|
29
|
-
values = doc[left.literal_string]
|
30
|
-
else
|
31
|
-
values = doc.matching_values { |key| left.matches_values?([key]) }
|
32
|
-
end
|
33
|
-
right.matches_values?(values)
|
34
|
-
end
|
35
|
-
end
|
36
|
-
|
37
|
-
def matches_values?(values)
|
38
|
-
case @operator
|
39
|
-
when "AND"
|
40
|
-
left.matches_values?(values) && right.matches_values?(values)
|
41
|
-
when "OR"
|
42
|
-
left.matches_values?(values) || right.matches_values?(values)
|
43
|
-
when "^"
|
44
|
-
left.matches_values?(values)
|
45
|
-
when ":"
|
46
|
-
raise ": does not work inside a : or term"
|
47
|
-
end
|
48
|
-
end
|
49
|
-
end
|
50
|
-
end
|
51
|
-
end
|
52
|
-
end
|
1
|
+
module ChefZero
|
2
|
+
module Solr
|
3
|
+
module Query
|
4
|
+
class BinaryOperator
|
5
|
+
def initialize(left, operator, right)
|
6
|
+
@left = left
|
7
|
+
@operator = operator
|
8
|
+
@right = right
|
9
|
+
end
|
10
|
+
|
11
|
+
def to_s
|
12
|
+
"(#{left} #{operator} #{right})"
|
13
|
+
end
|
14
|
+
|
15
|
+
attr_reader :left
|
16
|
+
attr_reader :operator
|
17
|
+
attr_reader :right
|
18
|
+
|
19
|
+
def matches_doc?(doc)
|
20
|
+
case @operator
|
21
|
+
when "AND"
|
22
|
+
left.matches_doc?(doc) && right.matches_doc?(doc)
|
23
|
+
when "OR"
|
24
|
+
left.matches_doc?(doc) || right.matches_doc?(doc)
|
25
|
+
when "^"
|
26
|
+
left.matches_doc?(doc)
|
27
|
+
when ":"
|
28
|
+
if left.respond_to?(:literal_string) && left.literal_string
|
29
|
+
values = doc[left.literal_string]
|
30
|
+
else
|
31
|
+
values = doc.matching_values { |key| left.matches_values?([key]) }
|
32
|
+
end
|
33
|
+
right.matches_values?(values)
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
def matches_values?(values)
|
38
|
+
case @operator
|
39
|
+
when "AND"
|
40
|
+
left.matches_values?(values) && right.matches_values?(values)
|
41
|
+
when "OR"
|
42
|
+
left.matches_values?(values) || right.matches_values?(values)
|
43
|
+
when "^"
|
44
|
+
left.matches_values?(values)
|
45
|
+
when ":"
|
46
|
+
raise ": does not work inside a : or term"
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
52
|
+
end
|
@@ -1,23 +1,23 @@
|
|
1
|
-
require_relative "regexpable_query"
|
2
|
-
|
3
|
-
module ChefZero
|
4
|
-
module Solr
|
5
|
-
module Query
|
6
|
-
class Phrase < RegexpableQuery
|
7
|
-
def initialize(terms)
|
8
|
-
# Phrase is terms separated by whitespace
|
9
|
-
if terms.size == 0 && terms[0].literal_string
|
10
|
-
literal_string = terms[0].literal_string
|
11
|
-
else
|
12
|
-
literal_string = nil
|
13
|
-
end
|
14
|
-
super(terms.map(&:regexp_string).join("#{NON_WORD_CHARACTER}+"), literal_string)
|
15
|
-
end
|
16
|
-
|
17
|
-
def to_s
|
18
|
-
"Phrase(\"#{@regexp_string}\")"
|
19
|
-
end
|
20
|
-
end
|
21
|
-
end
|
22
|
-
end
|
23
|
-
end
|
1
|
+
require_relative "regexpable_query"
|
2
|
+
|
3
|
+
module ChefZero
|
4
|
+
module Solr
|
5
|
+
module Query
|
6
|
+
class Phrase < RegexpableQuery
|
7
|
+
def initialize(terms)
|
8
|
+
# Phrase is terms separated by whitespace
|
9
|
+
if terms.size == 0 && terms[0].literal_string
|
10
|
+
literal_string = terms[0].literal_string
|
11
|
+
else
|
12
|
+
literal_string = nil
|
13
|
+
end
|
14
|
+
super(terms.map(&:regexp_string).join("#{NON_WORD_CHARACTER}+"), literal_string)
|
15
|
+
end
|
16
|
+
|
17
|
+
def to_s
|
18
|
+
"Phrase(\"#{@regexp_string}\")"
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
@@ -1,46 +1,46 @@
|
|
1
|
-
module ChefZero
|
2
|
-
module Solr
|
3
|
-
module Query
|
4
|
-
class RangeQuery
|
5
|
-
def initialize(from, to, from_inclusive, to_inclusive)
|
6
|
-
@from = from
|
7
|
-
@to = to
|
8
|
-
@from_inclusive = from_inclusive
|
9
|
-
@to_inclusive = to_inclusive
|
10
|
-
end
|
11
|
-
|
12
|
-
def to_s
|
13
|
-
"#{@from_inclusive ? "[" : "{"}#{@from} TO #{@to}#{@to_inclusive ? "]" : "}"}"
|
14
|
-
end
|
15
|
-
|
16
|
-
def matches_values?(values)
|
17
|
-
values.any? do |value|
|
18
|
-
unless @from == "*"
|
19
|
-
case @from <=> value
|
20
|
-
when -1
|
21
|
-
return false
|
22
|
-
when 0
|
23
|
-
return false unless @from_inclusive
|
24
|
-
end
|
25
|
-
end
|
26
|
-
unless @to == "*"
|
27
|
-
case value <=> @to
|
28
|
-
when 1
|
29
|
-
return false
|
30
|
-
when 0
|
31
|
-
return false unless @to_inclusive
|
32
|
-
end
|
33
|
-
end
|
34
|
-
return true
|
35
|
-
end
|
36
|
-
end
|
37
|
-
|
38
|
-
def matches_doc?(doc)
|
39
|
-
matches_values?(doc[DEFAULT_FIELD])
|
40
|
-
end
|
41
|
-
|
42
|
-
DEFAULT_FIELD = "text".freeze
|
43
|
-
end
|
44
|
-
end
|
45
|
-
end
|
46
|
-
end
|
1
|
+
module ChefZero
|
2
|
+
module Solr
|
3
|
+
module Query
|
4
|
+
class RangeQuery
|
5
|
+
def initialize(from, to, from_inclusive, to_inclusive)
|
6
|
+
@from = from
|
7
|
+
@to = to
|
8
|
+
@from_inclusive = from_inclusive
|
9
|
+
@to_inclusive = to_inclusive
|
10
|
+
end
|
11
|
+
|
12
|
+
def to_s
|
13
|
+
"#{@from_inclusive ? "[" : "{"}#{@from} TO #{@to}#{@to_inclusive ? "]" : "}"}"
|
14
|
+
end
|
15
|
+
|
16
|
+
def matches_values?(values)
|
17
|
+
values.any? do |value|
|
18
|
+
unless @from == "*"
|
19
|
+
case @from <=> value
|
20
|
+
when -1
|
21
|
+
return false
|
22
|
+
when 0
|
23
|
+
return false unless @from_inclusive
|
24
|
+
end
|
25
|
+
end
|
26
|
+
unless @to == "*"
|
27
|
+
case value <=> @to
|
28
|
+
when 1
|
29
|
+
return false
|
30
|
+
when 0
|
31
|
+
return false unless @to_inclusive
|
32
|
+
end
|
33
|
+
end
|
34
|
+
return true
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
def matches_doc?(doc)
|
39
|
+
matches_values?(doc[DEFAULT_FIELD])
|
40
|
+
end
|
41
|
+
|
42
|
+
DEFAULT_FIELD = "text".freeze
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
@@ -1,30 +1,30 @@
|
|
1
|
-
module ChefZero
|
2
|
-
module Solr
|
3
|
-
module Query
|
4
|
-
class RegexpableQuery
|
5
|
-
def initialize(regexp_string, literal_string)
|
6
|
-
@regexp_string = regexp_string
|
7
|
-
# Surround the regexp with word boundaries
|
8
|
-
@regexp = Regexp.new("(^|#{NON_WORD_CHARACTER})#{regexp_string}($|#{NON_WORD_CHARACTER})", true)
|
9
|
-
@literal_string = literal_string
|
10
|
-
end
|
11
|
-
|
12
|
-
attr_reader :literal_string
|
13
|
-
attr_reader :regexp_string
|
14
|
-
attr_reader :regexp
|
15
|
-
|
16
|
-
def matches_doc?(doc)
|
17
|
-
matches_values?(doc[DEFAULT_FIELD])
|
18
|
-
end
|
19
|
-
|
20
|
-
def matches_values?(values)
|
21
|
-
values.any? { |value| !@regexp.match(value).nil? }
|
22
|
-
end
|
23
|
-
|
24
|
-
DEFAULT_FIELD = "text".freeze
|
25
|
-
WORD_CHARACTER = "[A-Za-z0-9@._'
|
26
|
-
NON_WORD_CHARACTER = "[^A-Za-z0-9@._'
|
27
|
-
end
|
28
|
-
end
|
29
|
-
end
|
30
|
-
end
|
1
|
+
module ChefZero
|
2
|
+
module Solr
|
3
|
+
module Query
|
4
|
+
class RegexpableQuery
|
5
|
+
def initialize(regexp_string, literal_string)
|
6
|
+
@regexp_string = regexp_string
|
7
|
+
# Surround the regexp with word boundaries
|
8
|
+
@regexp = Regexp.new("(^|#{NON_WORD_CHARACTER})#{regexp_string}($|#{NON_WORD_CHARACTER})", true)
|
9
|
+
@literal_string = literal_string
|
10
|
+
end
|
11
|
+
|
12
|
+
attr_reader :literal_string
|
13
|
+
attr_reader :regexp_string
|
14
|
+
attr_reader :regexp
|
15
|
+
|
16
|
+
def matches_doc?(doc)
|
17
|
+
matches_values?(doc[DEFAULT_FIELD])
|
18
|
+
end
|
19
|
+
|
20
|
+
def matches_values?(values)
|
21
|
+
values.any? { |value| !@regexp.match(value).nil? }
|
22
|
+
end
|
23
|
+
|
24
|
+
DEFAULT_FIELD = "text".freeze
|
25
|
+
WORD_CHARACTER = "[A-Za-z0-9@._':-]".freeze
|
26
|
+
NON_WORD_CHARACTER = "[^A-Za-z0-9@._':-]".freeze
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
@@ -1,37 +1,37 @@
|
|
1
|
-
module ChefZero
|
2
|
-
module Solr
|
3
|
-
module Query
|
4
|
-
class Subquery
|
5
|
-
def initialize(subquery)
|
6
|
-
@subquery = subquery
|
7
|
-
end
|
8
|
-
|
9
|
-
attr_reader :subquery
|
10
|
-
|
11
|
-
def to_s
|
12
|
-
"(#{subquery})"
|
13
|
-
end
|
14
|
-
|
15
|
-
def literal_string
|
16
|
-
subquery.literal_string
|
17
|
-
end
|
18
|
-
|
19
|
-
def regexp
|
20
|
-
subquery.regexp
|
21
|
-
end
|
22
|
-
|
23
|
-
def regexp_string
|
24
|
-
subquery.regexp_string
|
25
|
-
end
|
26
|
-
|
27
|
-
def matches_doc?(doc)
|
28
|
-
subquery.matches_doc?(doc)
|
29
|
-
end
|
30
|
-
|
31
|
-
def matches_values?(values)
|
32
|
-
subquery.matches_values?(values)
|
33
|
-
end
|
34
|
-
end
|
35
|
-
end
|
36
|
-
end
|
37
|
-
end
|
1
|
+
module ChefZero
|
2
|
+
module Solr
|
3
|
+
module Query
|
4
|
+
class Subquery
|
5
|
+
def initialize(subquery)
|
6
|
+
@subquery = subquery
|
7
|
+
end
|
8
|
+
|
9
|
+
attr_reader :subquery
|
10
|
+
|
11
|
+
def to_s
|
12
|
+
"(#{subquery})"
|
13
|
+
end
|
14
|
+
|
15
|
+
def literal_string
|
16
|
+
subquery.literal_string
|
17
|
+
end
|
18
|
+
|
19
|
+
def regexp
|
20
|
+
subquery.regexp
|
21
|
+
end
|
22
|
+
|
23
|
+
def regexp_string
|
24
|
+
subquery.regexp_string
|
25
|
+
end
|
26
|
+
|
27
|
+
def matches_doc?(doc)
|
28
|
+
subquery.matches_doc?(doc)
|
29
|
+
end
|
30
|
+
|
31
|
+
def matches_values?(values)
|
32
|
+
subquery.matches_values?(values)
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
@@ -1,45 +1,45 @@
|
|
1
|
-
require_relative "regexpable_query"
|
2
|
-
|
3
|
-
module ChefZero
|
4
|
-
module Solr
|
5
|
-
module Query
|
6
|
-
class Term < RegexpableQuery
|
7
|
-
def initialize(term)
|
8
|
-
# Get rid of escape characters, turn * and ? into .* and . for regex, and
|
9
|
-
# escape everything that needs escaping
|
10
|
-
literal_string = ""
|
11
|
-
regexp_string = ""
|
12
|
-
index = 0
|
13
|
-
while index < term.length
|
14
|
-
if term[index] == "*"
|
15
|
-
regexp_string << "#{WORD_CHARACTER}*"
|
16
|
-
literal_string = nil
|
17
|
-
index += 1
|
18
|
-
elsif term[index] == "?"
|
19
|
-
regexp_string << WORD_CHARACTER
|
20
|
-
literal_string = nil
|
21
|
-
index += 1
|
22
|
-
elsif term[index] == "~"
|
23
|
-
raise "~ unsupported"
|
24
|
-
else
|
25
|
-
if term[index] ==
|
26
|
-
index += 1
|
27
|
-
if index >= term.length
|
28
|
-
raise "Backslash at end of string '#{term}'"
|
29
|
-
end
|
30
|
-
end
|
31
|
-
literal_string << term[index] if literal_string
|
32
|
-
regexp_string << Regexp.escape(term[index])
|
33
|
-
index += 1
|
34
|
-
end
|
35
|
-
end
|
36
|
-
super(regexp_string, literal_string)
|
37
|
-
end
|
38
|
-
|
39
|
-
def to_s
|
40
|
-
"Term(#{regexp_string})"
|
41
|
-
end
|
42
|
-
end
|
43
|
-
end
|
44
|
-
end
|
45
|
-
end
|
1
|
+
require_relative "regexpable_query"
|
2
|
+
|
3
|
+
module ChefZero
|
4
|
+
module Solr
|
5
|
+
module Query
|
6
|
+
class Term < RegexpableQuery
|
7
|
+
def initialize(term)
|
8
|
+
# Get rid of escape characters, turn * and ? into .* and . for regex, and
|
9
|
+
# escape everything that needs escaping
|
10
|
+
literal_string = ""
|
11
|
+
regexp_string = ""
|
12
|
+
index = 0
|
13
|
+
while index < term.length
|
14
|
+
if term[index] == "*"
|
15
|
+
regexp_string << "#{WORD_CHARACTER}*"
|
16
|
+
literal_string = nil
|
17
|
+
index += 1
|
18
|
+
elsif term[index] == "?"
|
19
|
+
regexp_string << WORD_CHARACTER
|
20
|
+
literal_string = nil
|
21
|
+
index += 1
|
22
|
+
elsif term[index] == "~"
|
23
|
+
raise "~ unsupported"
|
24
|
+
else
|
25
|
+
if term[index] == "\\"
|
26
|
+
index += 1
|
27
|
+
if index >= term.length
|
28
|
+
raise "Backslash at end of string '#{term}'"
|
29
|
+
end
|
30
|
+
end
|
31
|
+
literal_string << term[index] if literal_string
|
32
|
+
regexp_string << Regexp.escape(term[index])
|
33
|
+
index += 1
|
34
|
+
end
|
35
|
+
end
|
36
|
+
super(regexp_string, literal_string)
|
37
|
+
end
|
38
|
+
|
39
|
+
def to_s
|
40
|
+
"Term(#{regexp_string})"
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|