elastomer-client 6.2.4 → 6.3.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/.github/workflows/main.yml +4 -1
- data/.gitignore +1 -0
- data/CHANGELOG.md +4 -0
- data/Gemfile +3 -1
- data/elastomer-client.gemspec +2 -2
- data/gemfiles/faraday_1.gemfile +27 -0
- data/gemfiles/faraday_2.gemfile +30 -0
- data/lib/elastomer_client/client.rb +8 -4
- data/lib/elastomer_client/version.rb +1 -1
- data/test/client_test.rb +14 -45
- metadata +15 -7
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 7a044892301bedf212dc00b11279d569786b881c3bb652895ec0847b99ae1c61
|
|
4
|
+
data.tar.gz: 757a5d91447de5110abe9809c7de40557eb9a7334d607b6e8ed3914028db641e
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 284f0dba094d9f3fec31d9b2f6f2cd9ff74d497a60237d5612e012d361fd471dc153bf9ebb3e8fc0c4677290479f06ab1ef8c8820080d008152721628f0184f5
|
|
7
|
+
data.tar.gz: c887fe41f5e8f5ebc5daf6abdc30c89fe2be490999e9115b0cd17f5d9c3fb6d02934ab5273197a2a2b095d7341d54436e3a88e910e184064d915c0932bb2410c
|
data/.github/workflows/main.yml
CHANGED
|
@@ -12,17 +12,20 @@ jobs:
|
|
|
12
12
|
strategy:
|
|
13
13
|
matrix:
|
|
14
14
|
ruby-version: ['3.2']
|
|
15
|
+
gemfile: ['faraday_1', 'faraday_2']
|
|
15
16
|
ES_VERSION: ['8.18.0']
|
|
16
17
|
include:
|
|
17
18
|
- ES_VERSION: '8.18.0'
|
|
18
19
|
ES_DOWNLOAD_URL: >-
|
|
19
20
|
https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-8.18.0-linux-x86_64.tar.gz
|
|
21
|
+
env:
|
|
22
|
+
BUNDLE_GEMFILE: ${{ github.workspace }}/gemfiles/${{ matrix.gemfile }}.gemfile
|
|
20
23
|
steps:
|
|
24
|
+
- uses: actions/checkout@v4
|
|
21
25
|
- uses: ruby/setup-ruby@v1
|
|
22
26
|
with:
|
|
23
27
|
ruby-version: ${{ matrix.ruby-version }}
|
|
24
28
|
bundler-cache: true # runs 'bundle install' and caches installed gems automatically
|
|
25
|
-
- uses: actions/checkout@v4
|
|
26
29
|
- name: Cache Elasticsearch
|
|
27
30
|
id: cache-elasticsearch
|
|
28
31
|
uses: actions/cache@v4
|
data/.gitignore
CHANGED
data/CHANGELOG.md
CHANGED
data/Gemfile
CHANGED
|
@@ -8,6 +8,9 @@ group :development do
|
|
|
8
8
|
gem "activesupport", ">= 7.0"
|
|
9
9
|
gem "bundler", "~> 2.0"
|
|
10
10
|
gem "debug", "~> 1.7"
|
|
11
|
+
# The default bundle resolves Faraday 2.x, where the :retry middleware lives in the
|
|
12
|
+
# faraday-retry gem (it is in core on 1.x). Needed for the retry test; consumers opt in.
|
|
13
|
+
gem "faraday-retry", require: "faraday/retry"
|
|
11
14
|
gem "minitest", "~> 5.17"
|
|
12
15
|
gem "minitest-focus", "~> 1.3"
|
|
13
16
|
gem "rake"
|
|
@@ -17,6 +20,5 @@ group :development do
|
|
|
17
20
|
gem "rubocop-performance", "~> 1.21.0"
|
|
18
21
|
gem "rubocop-rake", "~> 0.6.0"
|
|
19
22
|
gem "simplecov", require: false
|
|
20
|
-
gem "spy", "~> 1.0"
|
|
21
23
|
gem "webmock", "~> 3.5"
|
|
22
24
|
end
|
data/elastomer-client.gemspec
CHANGED
|
@@ -22,8 +22,8 @@ Gem::Specification.new do |spec|
|
|
|
22
22
|
spec.require_paths = ["lib"]
|
|
23
23
|
|
|
24
24
|
spec.add_dependency "addressable", "~> 2.5"
|
|
25
|
-
spec.add_dependency "faraday", ">= 0
|
|
26
|
-
spec.add_dependency "
|
|
25
|
+
spec.add_dependency "faraday", ">= 1.0", "< 3"
|
|
26
|
+
spec.add_dependency "faraday-gzip", ">= 1.0"
|
|
27
27
|
spec.add_dependency "multi_json", "~> 1.12"
|
|
28
28
|
spec.add_dependency "semantic", "~> 1.6"
|
|
29
29
|
end
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
# Tests elastomer-client against Faraday 1.x.
|
|
4
|
+
#
|
|
5
|
+
# faraday-gzip works on both Faraday 1.x and 2.x and provides the :gzip request middleware
|
|
6
|
+
# used for response decompression (replacing the deprecated faraday_middleware).
|
|
7
|
+
source "https://rubygems.org"
|
|
8
|
+
|
|
9
|
+
gem "faraday", "~> 1.10"
|
|
10
|
+
|
|
11
|
+
gemspec path: ".."
|
|
12
|
+
|
|
13
|
+
group :development do
|
|
14
|
+
gem "activesupport", ">= 7.0"
|
|
15
|
+
gem "bundler", "~> 2.0"
|
|
16
|
+
gem "debug", "~> 1.7"
|
|
17
|
+
gem "minitest", "~> 5.17"
|
|
18
|
+
gem "minitest-focus", "~> 1.3"
|
|
19
|
+
gem "rake"
|
|
20
|
+
gem "rubocop", "~> 1.63.0"
|
|
21
|
+
gem "rubocop-github", "~> 0.20.0"
|
|
22
|
+
gem "rubocop-minitest", "~> 0.35.0"
|
|
23
|
+
gem "rubocop-performance", "~> 1.21.0"
|
|
24
|
+
gem "rubocop-rake", "~> 0.6.0"
|
|
25
|
+
gem "simplecov", require: false
|
|
26
|
+
gem "webmock", "~> 3.5"
|
|
27
|
+
end
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
# Tests elastomer-client against Faraday 2.x.
|
|
4
|
+
#
|
|
5
|
+
# This is the configuration the monolith targets after the Faraday 2 upgrade. faraday-gzip
|
|
6
|
+
# provides the :gzip request middleware (response decompression) on Faraday 2.x.
|
|
7
|
+
source "https://rubygems.org"
|
|
8
|
+
|
|
9
|
+
gem "faraday", "~> 2.0"
|
|
10
|
+
|
|
11
|
+
gemspec path: ".."
|
|
12
|
+
|
|
13
|
+
group :development do
|
|
14
|
+
gem "activesupport", ">= 7.0"
|
|
15
|
+
gem "bundler", "~> 2.0"
|
|
16
|
+
gem "debug", "~> 1.7"
|
|
17
|
+
# On Faraday 2.x the :retry middleware lives in the faraday-retry gem (it is in core on
|
|
18
|
+
# 1.x). Consumers opt into retries via a connection block; the suite covers that path.
|
|
19
|
+
gem "faraday-retry", require: "faraday/retry"
|
|
20
|
+
gem "minitest", "~> 5.17"
|
|
21
|
+
gem "minitest-focus", "~> 1.3"
|
|
22
|
+
gem "rake"
|
|
23
|
+
gem "rubocop", "~> 1.63.0"
|
|
24
|
+
gem "rubocop-github", "~> 0.20.0"
|
|
25
|
+
gem "rubocop-minitest", "~> 0.35.0"
|
|
26
|
+
gem "rubocop-performance", "~> 1.21.0"
|
|
27
|
+
gem "rubocop-rake", "~> 0.6.0"
|
|
28
|
+
gem "simplecov", require: false
|
|
29
|
+
gem "webmock", "~> 3.5"
|
|
30
|
+
end
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
require "addressable/template"
|
|
4
4
|
require "faraday"
|
|
5
|
-
require "
|
|
5
|
+
require "faraday/gzip"
|
|
6
6
|
require "multi_json"
|
|
7
7
|
require "semantic"
|
|
8
8
|
require "zlib"
|
|
@@ -132,7 +132,7 @@ module ElastomerClient
|
|
|
132
132
|
@connection ||= Faraday.new(url) do |conn|
|
|
133
133
|
conn.response(:parse_json)
|
|
134
134
|
# Request compressed responses from ES and decompress them
|
|
135
|
-
conn.
|
|
135
|
+
conn.request(:gzip)
|
|
136
136
|
conn.request(:encode_json)
|
|
137
137
|
conn.request(:limit_size, max_request_size:) if max_request_size
|
|
138
138
|
conn.request(:elastomer_compress, compression:) if compress_body
|
|
@@ -140,10 +140,14 @@ module ElastomerClient
|
|
|
140
140
|
conn.options[:timeout] = read_timeout
|
|
141
141
|
conn.options[:open_timeout] = open_timeout
|
|
142
142
|
|
|
143
|
+
# Faraday 2 removed the Connection#token_auth and #basic_auth helpers, and the
|
|
144
|
+
# :authorization middleware emits different header formats across Faraday majors.
|
|
145
|
+
# Set the Authorization header directly so the output is identical on 1.x and 2.x.
|
|
143
146
|
if token_auth?
|
|
144
|
-
conn.
|
|
147
|
+
conn.headers["Authorization"] = %(Token token="#{@token_auth}")
|
|
145
148
|
elsif basic_auth?
|
|
146
|
-
|
|
149
|
+
credentials = ["#{@basic_auth[:username]}:#{@basic_auth[:password]}"].pack("m0")
|
|
150
|
+
conn.headers["Authorization"] = "Basic #{credentials}"
|
|
147
151
|
end
|
|
148
152
|
|
|
149
153
|
@connection_block&.call(conn)
|
data/test/client_test.rb
CHANGED
|
@@ -13,15 +13,15 @@ describe ElastomerClient::Client do
|
|
|
13
13
|
end
|
|
14
14
|
|
|
15
15
|
it "allows configuring the Faraday when a block is given" do
|
|
16
|
-
assert ElastomerClient::Client.new.connection.builder.handlers.none? { |handler| handler.klass ==
|
|
16
|
+
assert ElastomerClient::Client.new.connection.builder.handlers.none? { |handler| handler.klass == ElastomerClient::Middleware::OpaqueId }
|
|
17
17
|
|
|
18
18
|
c = ElastomerClient::Client.new do |connection|
|
|
19
19
|
assert_kind_of(Faraday::Connection, connection)
|
|
20
20
|
|
|
21
|
-
connection.
|
|
21
|
+
connection.request :opaque_id
|
|
22
22
|
end
|
|
23
23
|
|
|
24
|
-
assert c.connection.builder.handlers.any? { |handler| handler.klass ==
|
|
24
|
+
assert c.connection.builder.handlers.any? { |handler| handler.klass == ElastomerClient::Middleware::OpaqueId }
|
|
25
25
|
end
|
|
26
26
|
|
|
27
27
|
it "use Faraday's default adapter if none is specified" do
|
|
@@ -145,14 +145,9 @@ describe ElastomerClient::Client do
|
|
|
145
145
|
})
|
|
146
146
|
client = ElastomerClient::Client.new(**client_params)
|
|
147
147
|
|
|
148
|
-
|
|
149
|
-
basic_auth_spy = Spy.on(connection, :basic_auth).and_return(nil)
|
|
148
|
+
expected = "Basic #{["my_user:my_secret_password"].pack("m0")}"
|
|
150
149
|
|
|
151
|
-
|
|
152
|
-
client.ping
|
|
153
|
-
end
|
|
154
|
-
|
|
155
|
-
assert basic_auth_spy.has_been_called_with?("my_user", "my_secret_password")
|
|
150
|
+
assert_equal expected, client.connection.headers["Authorization"]
|
|
156
151
|
end
|
|
157
152
|
|
|
158
153
|
it "ignores basic authentication if password is missing" do
|
|
@@ -161,14 +156,7 @@ describe ElastomerClient::Client do
|
|
|
161
156
|
})
|
|
162
157
|
client = ElastomerClient::Client.new(**client_params)
|
|
163
158
|
|
|
164
|
-
|
|
165
|
-
basic_auth_spy = Spy.on(connection, :basic_auth).and_return(nil)
|
|
166
|
-
|
|
167
|
-
Faraday.stub(:new, $client_params[:url], connection) do
|
|
168
|
-
client.ping
|
|
169
|
-
end
|
|
170
|
-
|
|
171
|
-
refute_predicate basic_auth_spy, :has_been_called?
|
|
159
|
+
refute client.connection.headers.key?("Authorization")
|
|
172
160
|
end
|
|
173
161
|
|
|
174
162
|
it "ignores basic authentication if username is missing" do
|
|
@@ -177,28 +165,14 @@ describe ElastomerClient::Client do
|
|
|
177
165
|
})
|
|
178
166
|
client = ElastomerClient::Client.new(**client_params)
|
|
179
167
|
|
|
180
|
-
|
|
181
|
-
basic_auth_spy = Spy.on(connection, :basic_auth).and_return(nil)
|
|
182
|
-
|
|
183
|
-
Faraday.stub(:new, $client_params[:url], connection) do
|
|
184
|
-
client.ping
|
|
185
|
-
end
|
|
186
|
-
|
|
187
|
-
refute_predicate basic_auth_spy, :has_been_called?
|
|
168
|
+
refute client.connection.headers.key?("Authorization")
|
|
188
169
|
end
|
|
189
170
|
|
|
190
171
|
it "can use token authentication" do
|
|
191
172
|
client_params = $client_params.merge(token_auth: "my_secret_token")
|
|
192
173
|
client = ElastomerClient::Client.new(**client_params)
|
|
193
174
|
|
|
194
|
-
|
|
195
|
-
token_auth_spy = Spy.on(connection, :token_auth).and_return(nil)
|
|
196
|
-
|
|
197
|
-
Faraday.stub(:new, $client_params[:url], connection) do
|
|
198
|
-
client.ping
|
|
199
|
-
end
|
|
200
|
-
|
|
201
|
-
assert token_auth_spy.has_been_called_with?("my_secret_token")
|
|
175
|
+
assert_equal %(Token token="my_secret_token"), client.connection.headers["Authorization"]
|
|
202
176
|
end
|
|
203
177
|
|
|
204
178
|
it "prefers token authentication over basic" do
|
|
@@ -208,16 +182,7 @@ describe ElastomerClient::Client do
|
|
|
208
182
|
}, token_auth: "my_secret_token")
|
|
209
183
|
client = ElastomerClient::Client.new(**client_params)
|
|
210
184
|
|
|
211
|
-
|
|
212
|
-
basic_auth_spy = Spy.on(connection, :basic_auth).and_return(nil)
|
|
213
|
-
token_auth_spy = Spy.on(connection, :token_auth).and_return(nil)
|
|
214
|
-
|
|
215
|
-
Faraday.stub(:new, $client_params[:url], connection) do
|
|
216
|
-
client.ping
|
|
217
|
-
end
|
|
218
|
-
|
|
219
|
-
refute_predicate basic_auth_spy, :has_been_called?
|
|
220
|
-
assert token_auth_spy.has_been_called_with?("my_secret_token")
|
|
185
|
+
assert_equal %(Token token="my_secret_token"), client.connection.headers["Authorization"]
|
|
221
186
|
end
|
|
222
187
|
end
|
|
223
188
|
|
|
@@ -372,11 +337,15 @@ describe ElastomerClient::Client do
|
|
|
372
337
|
it "adding retry logic retries up to 2 times" do
|
|
373
338
|
retry_count = 0
|
|
374
339
|
|
|
340
|
+
# :retry maps to Faraday::Request::Retry on Faraday 1.x and Faraday::Retry::Middleware
|
|
341
|
+
# on Faraday 2.x (via faraday-retry). Look up whichever the running Faraday registers.
|
|
342
|
+
retry_klass = Faraday::Request.lookup_middleware(:retry)
|
|
343
|
+
|
|
375
344
|
retry_options = {
|
|
376
345
|
max: 2,
|
|
377
346
|
interval: 0.05,
|
|
378
347
|
methods: [:get],
|
|
379
|
-
exceptions:
|
|
348
|
+
exceptions: retry_klass::DEFAULT_EXCEPTIONS + [Faraday::ConnectionFailed],
|
|
380
349
|
retry_block: proc { |env, options, retries, exc| retry_count += 1 }
|
|
381
350
|
}
|
|
382
351
|
retry_client = ElastomerClient::Client.new(port: 9205) do |connection|
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: elastomer-client
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 6.
|
|
4
|
+
version: 6.3.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Tim Pease
|
|
@@ -9,7 +9,7 @@ authors:
|
|
|
9
9
|
autorequire:
|
|
10
10
|
bindir: bin
|
|
11
11
|
cert_chain: []
|
|
12
|
-
date:
|
|
12
|
+
date: 2026-06-25 00:00:00.000000000 Z
|
|
13
13
|
dependencies:
|
|
14
14
|
- !ruby/object:Gem::Dependency
|
|
15
15
|
name: addressable
|
|
@@ -31,28 +31,34 @@ dependencies:
|
|
|
31
31
|
requirements:
|
|
32
32
|
- - ">="
|
|
33
33
|
- !ruby/object:Gem::Version
|
|
34
|
-
version: '0
|
|
34
|
+
version: '1.0'
|
|
35
|
+
- - "<"
|
|
36
|
+
- !ruby/object:Gem::Version
|
|
37
|
+
version: '3'
|
|
35
38
|
type: :runtime
|
|
36
39
|
prerelease: false
|
|
37
40
|
version_requirements: !ruby/object:Gem::Requirement
|
|
38
41
|
requirements:
|
|
39
42
|
- - ">="
|
|
40
43
|
- !ruby/object:Gem::Version
|
|
41
|
-
version: '0
|
|
44
|
+
version: '1.0'
|
|
45
|
+
- - "<"
|
|
46
|
+
- !ruby/object:Gem::Version
|
|
47
|
+
version: '3'
|
|
42
48
|
- !ruby/object:Gem::Dependency
|
|
43
|
-
name:
|
|
49
|
+
name: faraday-gzip
|
|
44
50
|
requirement: !ruby/object:Gem::Requirement
|
|
45
51
|
requirements:
|
|
46
52
|
- - ">="
|
|
47
53
|
- !ruby/object:Gem::Version
|
|
48
|
-
version: '0
|
|
54
|
+
version: '1.0'
|
|
49
55
|
type: :runtime
|
|
50
56
|
prerelease: false
|
|
51
57
|
version_requirements: !ruby/object:Gem::Requirement
|
|
52
58
|
requirements:
|
|
53
59
|
- - ">="
|
|
54
60
|
- !ruby/object:Gem::Version
|
|
55
|
-
version: '0
|
|
61
|
+
version: '1.0'
|
|
56
62
|
- !ruby/object:Gem::Dependency
|
|
57
63
|
name: multi_json
|
|
58
64
|
requirement: !ruby/object:Gem::Requirement
|
|
@@ -120,6 +126,8 @@ files:
|
|
|
120
126
|
- docs/snapshots.md
|
|
121
127
|
- docs/templates.md
|
|
122
128
|
- elastomer-client.gemspec
|
|
129
|
+
- gemfiles/faraday_1.gemfile
|
|
130
|
+
- gemfiles/faraday_2.gemfile
|
|
123
131
|
- lib/elastomer_client/client.rb
|
|
124
132
|
- lib/elastomer_client/client/bulk.rb
|
|
125
133
|
- lib/elastomer_client/client/ccr.rb
|