opensearch-ruby 1.0.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.

Potentially problematic release.


This version of opensearch-ruby might be problematic. Click here for more details.

@@ -0,0 +1,81 @@
1
+ # SPDX-License-Identifier: Apache-2.0
2
+ #
3
+ # The OpenSearch Contributors require contributions made to
4
+ # this file be licensed under the Apache-2.0 license or a
5
+ # compatible open source license.
6
+ #
7
+ # Modifications Copyright OpenSearch Contributors. See
8
+ # GitHub history for details.
9
+ #
10
+ # Licensed to Elasticsearch B.V. under one or more contributor
11
+ # license agreements. See the NOTICE file distributed with
12
+ # this work for additional information regarding copyright
13
+ # ownership. Elasticsearch B.V. licenses this file to you under
14
+ # the Apache License, Version 2.0 (the "License"); you may
15
+ # not use this file except in compliance with the License.
16
+ # You may obtain a copy of the License at
17
+ #
18
+ # http://www.apache.org/licenses/LICENSE-2.0
19
+ #
20
+ # Unless required by applicable law or agreed to in writing,
21
+ # software distributed under the License is distributed on an
22
+ # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
23
+ # KIND, either express or implied. See the License for the
24
+ # specific language governing permissions and limitations
25
+ # under the License.
26
+
27
+ lib = File.expand_path('../lib', __FILE__)
28
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
29
+ require 'opensearch/version'
30
+
31
+ signing_key_path = File.expand_path("../gem-private_key.pem")
32
+
33
+ Gem::Specification.new do |s|
34
+ s.name = 'opensearch-ruby'
35
+ s.version = OpenSearch::VERSION
36
+ s.authors = ['Jayesh Hathila', 'Vamshi Vijay Nakkirtha', 'Vijayan Balasubramanian' , 'Yuvraj Jaiswal']
37
+ s.email = ['jayehh@amazon.com', 'vamshin@amazon.com', 'balasvij@amazon.com', 'jaiyuvra@amazon.com']
38
+ s.summary = 'Ruby integrations for OpenSearch'
39
+ s.homepage = 'https://opensearch.org/docs/latest'
40
+ s.license = 'Apache-2.0'
41
+ s.metadata = {
42
+ 'homepage_uri' => 'https://opensearch.org/docs/latest/',
43
+ 'source_code_uri' => 'https://github.com/opensearch-project/opensearch-ruby/tree/main',
44
+ 'bug_tracker_uri' => 'https://github.com/opensearch-project/opensearch-ruby/issues'
45
+ }
46
+ s.files = `git ls-files`.split($/)
47
+ s.executables = s.files.grep(%r{^bin/}) { |f| File.basename(f) }
48
+ s.executables << 'opensearch_ruby_console'
49
+ s.test_files = s.files.grep(%r{^(test|spec|features)/})
50
+
51
+ if $PROGRAM_NAME.end_with?("gem") && ARGV == ["build", __FILE__] && File.exist?(signing_key_path)
52
+ s.signing_key = signing_key_path
53
+ s.cert_chain = ['../certs/opensearch-rubygems.pem']
54
+ end
55
+
56
+ s.require_paths = ['lib']
57
+ s.bindir = 'bin'
58
+
59
+ s.extra_rdoc_files = [ 'README.md', 'LICENSE' ]
60
+ s.rdoc_options = [ '--charset=UTF-8' ]
61
+
62
+ s.required_ruby_version = '>= 2.4'
63
+
64
+ s.add_dependency 'opensearch-transport', '1.0.0'
65
+ s.add_dependency 'opensearch-api', '1.0.0'
66
+
67
+ s.add_development_dependency 'bundler'
68
+ s.add_development_dependency 'byebug' unless defined?(JRUBY_VERSION) || defined?(Rubinius)
69
+ s.add_development_dependency 'pry'
70
+ s.add_development_dependency 'rake', '~> 13'
71
+ s.add_development_dependency 'require-prof' unless defined?(JRUBY_VERSION) || defined?(Rubinius)
72
+ s.add_development_dependency 'rspec'
73
+ s.add_development_dependency 'ruby-prof' unless defined?(JRUBY_VERSION) || defined?(Rubinius)
74
+ s.add_development_dependency 'simplecov'
75
+ s.add_development_dependency 'webmock'
76
+ s.add_development_dependency 'yard'
77
+
78
+ s.description = <<-DESC.gsub(/^ /, '')
79
+ Ruby integrations for OpenSearch (client, API, etc.)
80
+ DESC
81
+ end
@@ -0,0 +1,59 @@
1
+ # SPDX-License-Identifier: Apache-2.0
2
+ #
3
+ # The OpenSearch Contributors require contributions made to
4
+ # this file be licensed under the Apache-2.0 license or a
5
+ # compatible open source license.
6
+ #
7
+ # Modifications Copyright OpenSearch Contributors. See
8
+ # GitHub history for details.
9
+ #
10
+ # Licensed to Elasticsearch B.V. under one or more contributor
11
+ # license agreements. See the NOTICE file distributed with
12
+ # this work for additional information regarding copyright
13
+ # ownership. Elasticsearch B.V. licenses this file to you under
14
+ # the Apache License, Version 2.0 (the "License"); you may
15
+ # not use this file except in compliance with the License.
16
+ # You may obtain a copy of the License at
17
+ #
18
+ # http://www.apache.org/licenses/LICENSE-2.0
19
+ #
20
+ # Unless required by applicable law or agreed to in writing,
21
+ # software distributed under the License is distributed on an
22
+ # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
23
+ # KIND, either express or implied. See the License for the
24
+ # specific language governing permissions and limitations
25
+ # under the License.
26
+ require 'spec_helper'
27
+ require 'logger'
28
+
29
+ context 'OpenSearch client' do
30
+ let(:logger) { Logger.new($stderr) }
31
+
32
+ let(:client) do
33
+ OpenSearch::Client.new(
34
+ host: OPENSEARCH_URL,
35
+ logger: logger
36
+ )
37
+ end
38
+
39
+ context 'Integrates with opensearch API' do
40
+ it 'should perform the API methods' do
41
+ expect do
42
+ # Index a document
43
+ client.index(index: 'test-index', id: '1', body: { title: 'Test' })
44
+
45
+ # Refresh the index
46
+ client.indices.refresh(index: 'test-index')
47
+
48
+ # Search
49
+ response = client.search(index: 'test-index', body: { query: { match: { title: 'test' } } })
50
+
51
+ expect(response['hits']['total']['value']).to eq 1
52
+ expect(response['hits']['hits'][0]['_source']['title']).to eq 'Test'
53
+
54
+ # Delete the index
55
+ client.indices.delete(index: 'test-index')
56
+ end.not_to raise_error
57
+ end
58
+ end
59
+ end
@@ -0,0 +1,39 @@
1
+ # SPDX-License-Identifier: Apache-2.0
2
+ #
3
+ # The OpenSearch Contributors require contributions made to
4
+ # this file be licensed under the Apache-2.0 license or a
5
+ # compatible open source license.
6
+ #
7
+ # Modifications Copyright OpenSearch Contributors. See
8
+ # GitHub history for details.
9
+ #
10
+ # Licensed to Elasticsearch B.V. under one or more contributor
11
+ # license agreements. See the NOTICE file distributed with
12
+ # this work for additional information regarding copyright
13
+ # ownership. Elasticsearch B.V. licenses this file to you under
14
+ # the Apache License, Version 2.0 (the "License"); you may
15
+ # not use this file except in compliance with the License.
16
+ # You may obtain a copy of the License at
17
+ #
18
+ # http://www.apache.org/licenses/LICENSE-2.0
19
+ #
20
+ # Unless required by applicable law or agreed to in writing,
21
+ # software distributed under the License is distributed on an
22
+ # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
23
+ # KIND, either express or implied. See the License for the
24
+ # specific language governing permissions and limitations
25
+ # under the License.
26
+ require 'spec_helper'
27
+ require 'logger'
28
+
29
+ describe 'OpenSearch validation integration' do
30
+ it 'Validates for OpenSearch 1.0.0-SNAPSHOT' do
31
+ client = OpenSearch::Client.new(
32
+ host: OPENSEARCH_URL,
33
+ logger: Logger.new($stderr)
34
+ )
35
+ expect(client.instance_variable_get('@verified')).to be false
36
+ client.count
37
+ expect(client.instance_variable_get('@verified')).to be true
38
+ end
39
+ end
@@ -0,0 +1,35 @@
1
+ # SPDX-License-Identifier: Apache-2.0
2
+ #
3
+ # The OpenSearch Contributors require contributions made to
4
+ # this file be licensed under the Apache-2.0 license or a
5
+ # compatible open source license.
6
+ #
7
+ # Modifications Copyright OpenSearch Contributors. See
8
+ # GitHub history for details.
9
+ #
10
+ # Licensed to Elasticsearch B.V. under one or more contributor
11
+ # license agreements. See the NOTICE file distributed with
12
+ # this work for additional information regarding copyright
13
+ # ownership. Elasticsearch B.V. licenses this file to you under
14
+ # the Apache License, Version 2.0 (the "License"); you may
15
+ # not use this file except in compliance with the License.
16
+ # You may obtain a copy of the License at
17
+ #
18
+ # http://www.apache.org/licenses/LICENSE-2.0
19
+ #
20
+ # Unless required by applicable law or agreed to in writing,
21
+ # software distributed under the License is distributed on an
22
+ # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
23
+ # KIND, either express or implied. See the License for the
24
+ # specific language governing permissions and limitations
25
+ # under the License.
26
+
27
+ require 'opensearch'
28
+ require 'rspec'
29
+
30
+ OPENSEARCH_URL = ENV['TEST_OPENSEARCH_SERVER'] || "http://localhost:#{(ENV['PORT'] || 9200)}"
31
+ raise URI::InvalidURIError unless OPENSEARCH_URL =~ /\A#{URI::DEFAULT_PARSER.make_regexp}\z/
32
+
33
+ RSpec.configure do |config|
34
+ config.formatter = :documentation
35
+ end
@@ -0,0 +1,198 @@
1
+ # SPDX-License-Identifier: Apache-2.0
2
+ #
3
+ # The OpenSearch Contributors require contributions made to
4
+ # this file be licensed under the Apache-2.0 license or a
5
+ # compatible open source license.
6
+ #
7
+ # Modifications Copyright OpenSearch Contributors. See
8
+ # GitHub history for details.
9
+ #
10
+ # Licensed to Elasticsearch B.V. under one or more contributor
11
+ # license agreements. See the NOTICE file distributed with
12
+ # this work for additional information regarding copyright
13
+ # ownership. Elasticsearch B.V. licenses this file to you under
14
+ # the Apache License, Version 2.0 (the "License"); you may
15
+ # not use this file except in compliance with the License.
16
+ # You may obtain a copy of the License at
17
+ #
18
+ # http://www.apache.org/licenses/LICENSE-2.0
19
+ #
20
+ # Unless required by applicable law or agreed to in writing,
21
+ # software distributed under the License is distributed on an
22
+ # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
23
+ # KIND, either express or implied. See the License for the
24
+ # specific language governing permissions and limitations
25
+ # under the License.
26
+
27
+ require 'spec_helper'
28
+ require 'webmock/rspec'
29
+
30
+ describe 'OpenSearch: Validation' do
31
+ let(:host) { 'http://localhost:9200' }
32
+ let(:verify_request_stub) do
33
+ stub_request(:get, host)
34
+ .to_return(status: status, body: body, headers: headers)
35
+ end
36
+ let(:count_request_stub) do
37
+ stub_request(:post, "#{host}/_count")
38
+ .to_return(status: 200, body: nil, headers: {})
39
+ end
40
+ let(:status) { 200 }
41
+ let(:body) { {}.to_json }
42
+ let(:client) { OpenSearch::Client.new }
43
+ let(:headers) do
44
+ { 'content-type' => 'json' }
45
+ end
46
+
47
+ def error_requests_and_expectations(message = OpenSearch::NOT_SUPPORTED_WARNING)
48
+ expect { client.count }.to raise_error OpenSearch::UnsupportedProductError, message
49
+ assert_requested :get, host
50
+ assert_not_requested :post, "#{host}/_count"
51
+ expect { client.cluster.health }.to raise_error OpenSearch::UnsupportedProductError, message
52
+ expect(client.instance_variable_get('@verified')).to be false
53
+ expect { client.cluster.health }.to raise_error OpenSearch::UnsupportedProductError, message
54
+ end
55
+
56
+ def valid_requests_and_expectations
57
+ expect(client.instance_variable_get('@verified')).to be false
58
+ assert_not_requested :get, host
59
+
60
+ client.count
61
+ expect(client.instance_variable_get('@verified'))
62
+ assert_requested :get, host
63
+ assert_requested :post, "#{host}/_count"
64
+ end
65
+
66
+ context 'When OpenSearch replies with status 401' do
67
+ let(:status) { 401 }
68
+ let(:body) { {}.to_json }
69
+
70
+ it 'Verifies the request but shows a warning' do
71
+ stderr = $stderr
72
+ fake_stderr = StringIO.new
73
+ $stderr = fake_stderr
74
+
75
+ verify_request_stub
76
+ count_request_stub
77
+
78
+ valid_requests_and_expectations
79
+
80
+ fake_stderr.rewind
81
+ expect(fake_stderr.string).to eq("#{OpenSearch::SECURITY_PRIVILEGES_VALIDATION_WARNING}\n")
82
+ ensure
83
+ $stderr = stderr
84
+ end
85
+ end
86
+
87
+ context 'When Elasticsearch replies with status 403' do
88
+ let(:status) { 403 }
89
+ let(:body) { {}.to_json }
90
+
91
+ it 'Verifies the request but shows a warning' do
92
+ stderr = $stderr
93
+ fake_stderr = StringIO.new
94
+ $stderr = fake_stderr
95
+
96
+ verify_request_stub
97
+ count_request_stub
98
+
99
+ valid_requests_and_expectations
100
+
101
+ fake_stderr.rewind
102
+ expect(fake_stderr.string).to eq("#{OpenSearch::SECURITY_PRIVILEGES_VALIDATION_WARNING}\n")
103
+ ensure
104
+ $stderr = stderr
105
+ end
106
+ end
107
+
108
+ context 'When the OpenSearch version is 1.0.0-SNAPSHOT' do
109
+ context 'With a valid OpenSearch response' do
110
+ let(:body) { { 'version' => { 'number' => '1.0.0-SNAPSHOT', 'distribution' => 'opensearch' } }.to_json }
111
+ let(:headers) do
112
+ {
113
+ 'content-type' => 'json'
114
+ }
115
+ end
116
+
117
+ it 'Makes requests and passes validation' do
118
+ verify_request_stub
119
+ count_request_stub
120
+
121
+ valid_requests_and_expectations
122
+ end
123
+ end
124
+
125
+ context 'When the distribution is not present' do
126
+ let(:body) { { 'version' => { 'number' => '1.0.0-SNAPSHOT' } }.to_json }
127
+ it 'Fails validation' do
128
+ verify_request_stub
129
+
130
+ expect(client.instance_variable_get('@verified')).to be false
131
+ assert_not_requested :get, host
132
+
133
+ error_requests_and_expectations
134
+ end
135
+ end
136
+ end
137
+
138
+
139
+ context 'When the Elasticsearch version is >= 6.0' do
140
+ context 'With a valid Elasticsearch response' do
141
+ let(:body) { { 'version' => { 'number' => '6.0.0' } }.to_json }
142
+ let(:headers) do
143
+ {
144
+ 'content-type' => 'json'
145
+ }
146
+ end
147
+
148
+ it 'Makes requests and passes validation' do
149
+ verify_request_stub
150
+ count_request_stub
151
+
152
+ valid_requests_and_expectations
153
+ end
154
+ end
155
+
156
+ end
157
+
158
+ context 'When the Elasticsearch version is >= 8.0.0' do
159
+ context 'With a valid Elasticsearch response' do
160
+ let(:body) { { 'version' => { 'number' => '8.0.0' } }.to_json }
161
+ let(:headers) do
162
+ {
163
+ 'content-type' => 'json'
164
+ }
165
+ end
166
+
167
+ it 'Fails validation' do
168
+ verify_request_stub
169
+ count_request_stub
170
+
171
+ error_requests_and_expectations
172
+ end
173
+ end
174
+ end
175
+
176
+ context 'When there is no version data' do
177
+ let(:body) { {}.to_json }
178
+ it 'Raises an exception and client doesnae work' do
179
+ verify_request_stub
180
+ error_requests_and_expectations
181
+ end
182
+ end
183
+
184
+ context 'When doing a yaml content-type request' do
185
+ let(:client) do
186
+ OpenSearch::Client.new(transport_options: {headers: { accept: 'application/yaml', content_type: 'application/yaml' }})
187
+ end
188
+
189
+ let(:headers) { { 'content-type' => 'application/yaml'} }
190
+ let(:body) { "---\nversion:\n number: \"1.0.0-SNAPSHOT\"\n distribution: \"opensearch\"\n" }
191
+
192
+ it 'validates' do
193
+ verify_request_stub
194
+ count_request_stub
195
+ valid_requests_and_expectations
196
+ end
197
+ end
198
+ end
@@ -0,0 +1,48 @@
1
+ # SPDX-License-Identifier: Apache-2.0
2
+ #
3
+ # The OpenSearch Contributors require contributions made to
4
+ # this file be licensed under the Apache-2.0 license or a
5
+ # compatible open source license.
6
+ #
7
+ # Modifications Copyright OpenSearch Contributors. See
8
+ # GitHub history for details.
9
+ #
10
+ # Licensed to Elasticsearch B.V. under one or more contributor
11
+ # license agreements. See the NOTICE file distributed with
12
+ # this work for additional information regarding copyright
13
+ # ownership. Elasticsearch B.V. licenses this file to you under
14
+ # the Apache License, Version 2.0 (the "License"); you may
15
+ # not use this file except in compliance with the License.
16
+ # You may obtain a copy of the License at
17
+ #
18
+ # http://www.apache.org/licenses/LICENSE-2.0
19
+ #
20
+ # Unless required by applicable law or agreed to in writing,
21
+ # software distributed under the License is distributed on an
22
+ # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
23
+ # KIND, either express or implied. See the License for the
24
+ # specific language governing permissions and limitations
25
+ # under the License.
26
+ require 'opensearch'
27
+ require 'webmock/rspec'
28
+
29
+ describe 'OpenSearch: wrapper gem' do
30
+ it 'requires all neccessary subgems' do
31
+ expect(defined?(OpenSearch::Client))
32
+ expect(defined?(OpenSearch::API))
33
+ end
34
+
35
+ it 'mixes the API into the client' do
36
+ client = OpenSearch::Client.new
37
+
38
+ expect(client).to respond_to(:search)
39
+ expect(client).to respond_to(:cluster)
40
+ expect(client).to respond_to(:indices)
41
+ end
42
+
43
+ it 'can access the client transport' do
44
+ client = OpenSearch::Client.new
45
+ expect(client.transport).to be_a(OpenSearch::Transport::Client)
46
+ expect(client.transport.transport).to be_a(OpenSearch::Transport::Transport::HTTP::Faraday)
47
+ end
48
+ end
data.tar.gz.sig ADDED
Binary file