elastomer-client 3.1.5 → 3.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: 3a92c72bbd6205383dc51f6f1886c59b6dcd80c6
4
- data.tar.gz: 5461381ed8be4b188ab38517365abcc35f2b6c8a
2
+ SHA256:
3
+ metadata.gz: a3abce6a0da503d9a912b1f444cfb1911aa230db717c703d3eba42d31122295f
4
+ data.tar.gz: 5ad2807d576cf3a48665217ad8601a531d308de10a1264ee63b131779014bdda
5
5
  SHA512:
6
- metadata.gz: 62e6218d00e3a0957af8be8f1e5cc2bcb13bfdc275bd6ab75dc88cdb79564f416abf5e606561dcb3d9226032a4fc03d56b585cb0c8ae6c0c07e74d2e2b7040cc
7
- data.tar.gz: 1612c188db262177c9a2d11cc4982165ab42057538d62a073f5a80e9a257b3d415be108fb5de52b3a19ceec1864d2193db289371d5740433e86f8e70d38fc513
6
+ metadata.gz: 8c390f6c7fb21ae298beacd9eac8d471a897b7e6f53a642c4db2024b011f1f8b07118edcb0e3df6ce217509a86a05735c51424c46eb7bda537c8d4e213512c71
7
+ data.tar.gz: b4ff217cd41090457e10cbb70b0beabfc5f672745d626afe4552f618ddb69367ff070691cc0743f00325ef06e8808e03a5c1509ff7da3e0e9fb9bcf1b983d8d8
@@ -1,17 +1,21 @@
1
1
  language: ruby
2
2
  rvm:
3
- - 2.3.3
3
+ - 2.3.8
4
4
  env:
5
5
  # NOTE: Ancient versions of Elasticsearch have different download URLs
6
6
  - ES_VERSION=2.3.5 ES_DOWNLOAD_URL=https://download.elastic.co/elasticsearch/release/org/elasticsearch/distribution/tar/elasticsearch/${ES_VERSION}/elasticsearch-${ES_VERSION}.tar.gz
7
- - ES_VERSION=5.6.4 ES_DOWNLOAD_URL=https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-${ES_VERSION}.tar.gz
7
+ - ES_VERSION=2.4.6 ES_DOWNLOAD_URL=https://download.elastic.co/elasticsearch/release/org/elasticsearch/distribution/tar/elasticsearch/${ES_VERSION}/elasticsearch-${ES_VERSION}.tar.gz
8
+ - ES_VERSION=5.6.15 ES_DOWNLOAD_URL=https://artifacts.elastic.co/downloads/elasticsearch/elasticsearch-${ES_VERSION}.tar.gz
8
9
 
9
10
  # Configure a specific version of Elasticsearch
10
11
  # See: https://docs.travis-ci.com/user/database-setup/#Installing-ElasticSearch-on-trusty-container-based-infrastructure
11
12
  install:
13
+ # - sudo apt install openjdk-8-jdk
14
+ # - sudo update-java-alternatives -l
12
15
  - wget ${ES_DOWNLOAD_URL}
13
16
  - tar -xzf elasticsearch-${ES_VERSION}.tar.gz
14
17
  - ./elasticsearch-${ES_VERSION}/bin/elasticsearch &
18
+ - gem install bundler
15
19
  - bundle install
16
20
  - wget --quiet --waitretry=1 --retry-connrefused --timeout=10 --output-document=- http://127.0.0.1:9200
17
21
 
@@ -21,3 +25,10 @@ notifications:
21
25
  email: false
22
26
 
23
27
  sudo: false
28
+ dist: trusty
29
+ jdk:
30
+ - oraclejdk8
31
+ addons:
32
+ apt:
33
+ packages:
34
+ - oracle-java8-installer
@@ -1,3 +1,8 @@
1
+ ## 3.2.0 (2019-08-22)
2
+ - Add config based basic and token auth to `Elastomer::Client#connection`
3
+ - Filter `Elastomer::Client#inspect` output to hide basic and token auth info,
4
+ and reduce noisiness when debugging
5
+
1
6
  ## 3.1.5 (2019-06-26)
2
7
  - Add new more granular exception type
3
8
 
data/README.md CHANGED
@@ -10,7 +10,7 @@ Get started by cloning and running a few scripts:
10
10
  $ git clone https://github.com/github/elastomer-client.git
11
11
  $ cd elastomer-client
12
12
  $ script/bootstrap
13
- $ rake test
13
+ $ bundle exec rake test
14
14
  ```
15
15
 
16
16
  ## Client
@@ -105,3 +105,17 @@ thusly:
105
105
  ```ruby
106
106
  Elastomer::Client.new(url: YOUR_ES_URL, adapter: :excon)
107
107
  ```
108
+
109
+ ## Releasing
110
+
111
+ 1. Create a new branch from `master`
112
+ 2. Bump the version number in `lib/elastomer/version.rb`
113
+ 3. Update `CHANGELOG.md` with info about the new version
114
+ 4. Execute `bin/rake build`. This will place a new gem file in the `pkg/` folder.
115
+ 5. Run `gem install pkg/elastomer-client-{VERSION}.gem` to install the new gem locally
116
+ 6. Start an `irb` session, `require "elastomer/client"` and make sure things work as you expect
117
+ 7. Once everything is working as you expect, commit the version bump and open a PR
118
+ 8. Once you get approval and merge it to master, pull down a fresh copy of master and then...
119
+ 9. Run `rake release`
120
+ 10. If necessary, manually push the new version to rubygems.org
121
+ 11. 🕺 💃 🎉
@@ -25,7 +25,7 @@ Gem::Specification.new do |spec|
25
25
  spec.add_dependency "multi_json", "~> 1.12"
26
26
  spec.add_dependency "semantic", "~> 1.6"
27
27
 
28
- spec.add_development_dependency "bundler", "~> 1.14"
28
+ spec.add_development_dependency "bundler", "~> 2.0"
29
29
  spec.add_development_dependency "activesupport", ">= 3.0"
30
30
  spec.add_development_dependency "minitest", "~> 5.10"
31
31
  spec.add_development_dependency "minitest-fail-fast", "~> 0.1.0"
@@ -33,5 +33,6 @@ Gem::Specification.new do |spec|
33
33
  spec.add_development_dependency "webmock", "~> 2.3"
34
34
  spec.add_development_dependency "awesome_print", "~> 1.8"
35
35
  spec.add_development_dependency "pry-byebug", "~> 3.4"
36
+ spec.add_development_dependency "spy", "~> 1.0"
36
37
  spec.add_development_dependency "rake"
37
38
  end
@@ -3,6 +3,7 @@ require "faraday"
3
3
  require "faraday_middleware"
4
4
  require "multi_json"
5
5
  require "semantic"
6
+ require "zlib"
6
7
 
7
8
  require "elastomer/version"
8
9
  require "elastomer/version_support"
@@ -10,6 +11,9 @@ require "elastomer/version_support"
10
11
  module Elastomer
11
12
 
12
13
  class Client
14
+ IVAR_BLACK_LIST = [:@basic_auth, :@token_auth]
15
+ IVAR_NOISY_LIST = [:@api_spec, :@cluster]
16
+
13
17
  MAX_REQUEST_SIZE = 250 * 2**20 # 250 MB
14
18
 
15
19
  RETRYABLE_METHODS = %i[get head].freeze
@@ -36,11 +40,14 @@ module Elastomer
36
40
  # :es_version - set to the Elasticsearch version (example: "5.6.6") to avoid an HTTP request to get the version.
37
41
  # :compress_body - set to true to enable request body compression (default: false)
38
42
  # :compression - The compression level (0-9) when request body compression is enabled (default: Zlib::DEFAULT_COMPRESSION)
43
+ # :basic_auth - a Hash containing basic authentication :username and :password values to use on connections
44
+ # :token_auth - an authentication token as a String to use on connections (overrides :basic_auth)
39
45
  #
40
46
  def initialize(host: "localhost", port: 9200, url: nil,
41
47
  read_timeout: 5, open_timeout: 2, max_retries: 0, retry_delay: 0.075,
42
48
  opaque_id: false, adapter: Faraday.default_adapter, max_request_size: MAX_REQUEST_SIZE,
43
- strict_params: false, es_version: nil, compress_body: false, compression: Zlib::DEFAULT_COMPRESSION)
49
+ strict_params: false, es_version: nil, compress_body: false, compression: Zlib::DEFAULT_COMPRESSION,
50
+ basic_auth: nil, token_auth: nil)
44
51
 
45
52
  @url = url || "http://#{host}:#{port}"
46
53
 
@@ -59,6 +66,8 @@ module Elastomer
59
66
  @es_version = es_version
60
67
  @compress_body = compress_body
61
68
  @compression = compression
69
+ @basic_auth = basic_auth
70
+ @token_auth = token_auth
62
71
  end
63
72
 
64
73
  attr_reader :host, :port, :url
@@ -79,7 +88,9 @@ module Elastomer
79
88
  open_timeout: open_timeout,
80
89
  adapter: @adapter,
81
90
  opaque_id: @opaque_id,
82
- max_request_size: max_request_size
91
+ max_request_size: max_request_size,
92
+ basic_auth: @basic_auth,
93
+ token_auth: @token_auth
83
94
  end
84
95
 
85
96
  # Returns true if the server is available; returns false otherwise.
@@ -133,14 +144,20 @@ module Elastomer
133
144
  conn.request(:limit_size, max_request_size: max_request_size) if max_request_size
134
145
  conn.request(:elastomer_compress, compression: compression) if compress_body
135
146
 
147
+ conn.options[:timeout] = read_timeout
148
+ conn.options[:open_timeout] = open_timeout
149
+
150
+ if @token_auth.present?
151
+ conn.token_auth(@token_auth)
152
+ elsif @basic_auth.present?
153
+ conn.basic_auth(@basic_auth.fetch(:username), @basic_auth.fetch(:password))
154
+ end
155
+
136
156
  if @adapter.is_a?(Array)
137
157
  conn.adapter(*@adapter)
138
158
  else
139
159
  conn.adapter(@adapter)
140
160
  end
141
-
142
- conn.options[:timeout] = read_timeout
143
- conn.options[:open_timeout] = open_timeout
144
161
  end
145
162
  end
146
163
 
@@ -458,6 +475,14 @@ module Elastomer
458
475
  @version_support ||= VersionSupport.new(version)
459
476
  end
460
477
 
478
+ def inspect
479
+ public_vars = self.instance_variables.reject do |var|
480
+ IVAR_NOISY_LIST.include?(var)
481
+ end.map do |var|
482
+ "#{var}=#{IVAR_BLACK_LIST.include?(var) ? "[FILTERED]" : instance_variable_get(var).inspect}"
483
+ end.join(", ")
484
+ "<##{self.class}:#{self.object_id.to_s(16)} #{public_vars}>"
485
+ end
461
486
  end # Client
462
487
  end # Elastomer
463
488
 
@@ -1,5 +1,5 @@
1
1
  module Elastomer
2
- VERSION = "3.1.5"
2
+ VERSION = "3.2.0"
3
3
 
4
4
  def self.version
5
5
  VERSION
@@ -1,7 +1,7 @@
1
1
  #!/bin/sh
2
2
  set -e
3
3
 
4
- cd "$(dirname "$0")/.."
4
+ cd "$(dirname "$0:a")/.."
5
5
  if bundle check 1>/dev/null 2>&1; then
6
6
  echo "Gem environment up-to-date"
7
7
  else
@@ -1 +1 @@
1
- cibuild-elastomer-client-es24
1
+ script/cibuild-elastomer-client-es24
@@ -88,6 +88,71 @@ describe Elastomer::Client do
88
88
  }
89
89
  end
90
90
 
91
+ it "hides basic_auth and token_auth params from inspection" do
92
+ client_params = $client_params.merge(basic_auth: {
93
+ username: "my_user",
94
+ password: "my_secret_password"
95
+ }, token_auth: "my_secret_token")
96
+ client = Elastomer::Client.new client_params
97
+ refute_match(/my_user/, client.inspect)
98
+ refute_match(/my_secret_password/, client.inspect)
99
+ refute_match(/my_secret_token/, client.inspect)
100
+ assert_match(/@basic_auth=\[FILTERED\]/, client.inspect)
101
+ assert_match(/@token_auth=\[FILTERED\]/, client.inspect)
102
+ end
103
+
104
+ describe "authorization" do
105
+ it "can use basic authentication" do
106
+ client_params = $client_params.merge(basic_auth: {
107
+ username: "my_user",
108
+ password: "my_secret_password"
109
+ })
110
+ client = Elastomer::Client.new client_params
111
+
112
+ connection = Faraday::Connection.new
113
+ basic_auth_spy = Spy.on(connection, :basic_auth).and_return(nil)
114
+
115
+ Faraday.stub(:new, $client_params[:url], connection) do
116
+ client.ping
117
+ end
118
+
119
+ assert basic_auth_spy.has_been_called_with?("my_user", "my_secret_password")
120
+ end
121
+
122
+ it "can use token authentication" do
123
+ client_params = $client_params.merge(token_auth: "my_secret_token")
124
+ client = Elastomer::Client.new client_params
125
+
126
+ connection = Faraday::Connection.new
127
+ token_auth_spy = Spy.on(connection, :token_auth).and_return(nil)
128
+
129
+ Faraday.stub(:new, $client_params[:url], connection) do
130
+ client.ping
131
+ end
132
+
133
+ assert token_auth_spy.has_been_called_with?("my_secret_token")
134
+ end
135
+
136
+ it "prefers token authentication over basic" do
137
+ client_params = $client_params.merge(basic_auth: {
138
+ username: "my_user",
139
+ password: "my_secret_password"
140
+ }, token_auth: "my_secret_token")
141
+ client = Elastomer::Client.new client_params
142
+
143
+ connection = Faraday::Connection.new
144
+ basic_auth_spy = Spy.on(connection, :basic_auth).and_return(nil)
145
+ token_auth_spy = Spy.on(connection, :token_auth).and_return(nil)
146
+
147
+ Faraday.stub(:new, $client_params[:url], connection) do
148
+ client.ping
149
+ end
150
+
151
+ refute basic_auth_spy.has_been_called?
152
+ assert token_auth_spy.has_been_called_with?("my_secret_token")
153
+ end
154
+ end
155
+
91
156
  describe "when extracting and converting :body params" do
92
157
  it "deletes the :body from the params (or it gets the hose)" do
93
158
  params = { :body => nil, :q => "what what?" }
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: 3.1.5
4
+ version: 3.2.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: 2019-06-26 00:00:00.000000000 Z
12
+ date: 2019-08-22 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: addressable
@@ -87,14 +87,14 @@ dependencies:
87
87
  requirements:
88
88
  - - "~>"
89
89
  - !ruby/object:Gem::Version
90
- version: '1.14'
90
+ version: '2.0'
91
91
  type: :development
92
92
  prerelease: false
93
93
  version_requirements: !ruby/object:Gem::Requirement
94
94
  requirements:
95
95
  - - "~>"
96
96
  - !ruby/object:Gem::Version
97
- version: '1.14'
97
+ version: '2.0'
98
98
  - !ruby/object:Gem::Dependency
99
99
  name: activesupport
100
100
  requirement: !ruby/object:Gem::Requirement
@@ -199,6 +199,20 @@ dependencies:
199
199
  - - "~>"
200
200
  - !ruby/object:Gem::Version
201
201
  version: '3.4'
202
+ - !ruby/object:Gem::Dependency
203
+ name: spy
204
+ requirement: !ruby/object:Gem::Requirement
205
+ requirements:
206
+ - - "~>"
207
+ - !ruby/object:Gem::Version
208
+ version: '1.0'
209
+ type: :development
210
+ prerelease: false
211
+ version_requirements: !ruby/object:Gem::Requirement
212
+ requirements:
213
+ - - "~>"
214
+ - !ruby/object:Gem::Version
215
+ version: '1.0'
202
216
  - !ruby/object:Gem::Dependency
203
217
  name: rake
204
218
  requirement: !ruby/object:Gem::Requirement
@@ -340,8 +354,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
340
354
  - !ruby/object:Gem::Version
341
355
  version: '0'
342
356
  requirements: []
343
- rubyforge_project:
344
- rubygems_version: 2.5.2
357
+ rubygems_version: 3.0.3
345
358
  signing_key:
346
359
  specification_version: 4
347
360
  summary: A library for interacting with Elasticsearch