antbird 0.2.1 → 0.5.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/build-os.yml +41 -0
- data/.github/workflows/build.yml +24 -20
- data/README.md +3 -3
- data/lib/antbird/client.rb +84 -12
- data/lib/antbird/rest_api/rest_api_opensearch_v1_0.rb +1222 -0
- data/lib/antbird/rest_api/rest_api_opensearch_v1_1.rb +1222 -0
- data/lib/antbird/rest_api/rest_api_opensearch_v1_2.rb +1222 -0
- data/lib/antbird/rest_api/rest_api_v6_8.rb +2 -2
- data/lib/antbird/rest_api/rest_api_v7_1.rb +1 -1
- data/lib/antbird/rest_api/rest_api_v7_10.rb +1190 -0
- data/lib/antbird/rest_api/rest_api_v7_11.rb +1190 -0
- data/lib/antbird/rest_api/rest_api_v7_12.rb +1198 -0
- data/lib/antbird/rest_api/rest_api_v7_13.rb +3046 -0
- data/lib/antbird/rest_api/rest_api_v7_14.rb +3142 -0
- data/lib/antbird/rest_api/rest_api_v7_15.rb +3190 -0
- data/lib/antbird/rest_api/rest_api_v7_2.rb +1 -1
- data/lib/antbird/rest_api/rest_api_v7_3.rb +1 -1
- data/lib/antbird/rest_api/rest_api_v7_4.rb +1 -1
- data/lib/antbird/rest_api/rest_api_v7_5.rb +1 -1
- data/lib/antbird/rest_api/rest_api_v7_6.rb +1 -1
- data/lib/antbird/rest_api/rest_api_v7_7.rb +1 -1
- data/lib/antbird/rest_api/rest_api_v7_8.rb +1 -1
- data/lib/antbird/rest_api/rest_api_v7_9.rb +2 -2
- data/lib/antbird/version.rb +1 -1
- metadata +16 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3c8c8fecccb123dbea652666e8c3afe9c0bb82b05addd4c16184285fc8d883fa
|
4
|
+
data.tar.gz: 300f03046a12082dc0f7ee92dc0283f1228cdc6dc1975cfa965e56d7baf065db
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e5e54fed3437d547f92bfead50aeab29612694a955d6ed3f762962eaa29a7bec0743027557c8f0d15c82f032f5f5f188e138eb1a58a53afdb893b4e9abfa09b6
|
7
|
+
data.tar.gz: 37595c88f4e1df53b79d3f859c9a551d9ebfd49fd005f6e75136c91b677c84def615f3022bbac99149da8f00ff1991884c9a18a9d43f50e476fbfe2875adec6a
|
@@ -0,0 +1,41 @@
|
|
1
|
+
name: build-os
|
2
|
+
|
3
|
+
on: [push]
|
4
|
+
env:
|
5
|
+
ENGINE_NAME: opensearch
|
6
|
+
REST_API_SPEC_REPO: opensearch-project/OpenSearch
|
7
|
+
|
8
|
+
jobs:
|
9
|
+
build:
|
10
|
+
runs-on: ubuntu-latest
|
11
|
+
strategy:
|
12
|
+
fail-fast: false
|
13
|
+
matrix:
|
14
|
+
# https://github.com/opensearch-project/OpenSearch/releases
|
15
|
+
search_versions:
|
16
|
+
- 1.2.0
|
17
|
+
- 1.1.0
|
18
|
+
- 1.0.0
|
19
|
+
services:
|
20
|
+
opensearch:
|
21
|
+
image: opensearchproject/opensearch:${{matrix.search_versions}}
|
22
|
+
ports:
|
23
|
+
- 9200:9200
|
24
|
+
env:
|
25
|
+
discovery.type: single-node
|
26
|
+
plugins.security.disabled: true
|
27
|
+
steps:
|
28
|
+
- name: Configure sysctl limits
|
29
|
+
run: |
|
30
|
+
sudo swapoff -a
|
31
|
+
sudo sysctl -w vm.swappiness=1
|
32
|
+
sudo sysctl -w fs.file-max=262144
|
33
|
+
sudo sysctl -w vm.max_map_count=262144
|
34
|
+
- uses: actions/checkout@v2
|
35
|
+
- uses: ruby/setup-ruby@v1
|
36
|
+
with:
|
37
|
+
ruby-version: 2.7
|
38
|
+
bundler-cache: true
|
39
|
+
- name: Wait for OpenSearch
|
40
|
+
run: timeout 60 bash -c "until curl --silent --output /dev/null localhost:9200/_cat/health?h=st; do printf '.'; sleep 5; done; printf '\n'"
|
41
|
+
- run: bundle exec rspec
|
data/.github/workflows/build.yml
CHANGED
@@ -1,6 +1,9 @@
|
|
1
1
|
name: build
|
2
2
|
|
3
3
|
on: [push]
|
4
|
+
env:
|
5
|
+
ENGINE_NAME: elasticsearch
|
6
|
+
REST_API_SPEC_REPO: elastic/elasticsearch
|
4
7
|
|
5
8
|
jobs:
|
6
9
|
build:
|
@@ -10,32 +13,33 @@ jobs:
|
|
10
13
|
matrix:
|
11
14
|
# 1. Run script/list_versions
|
12
15
|
# 2. Check https://www.elastic.co/jp/support/eol
|
13
|
-
|
14
|
-
- 7.
|
16
|
+
search_versions:
|
17
|
+
- 7.15.2
|
18
|
+
- 7.14.2
|
19
|
+
- 7.13.4
|
20
|
+
- 7.12.1
|
21
|
+
- 7.11.2
|
22
|
+
- 7.10.2
|
23
|
+
- 7.9.3
|
15
24
|
- 7.8.1
|
16
|
-
-
|
17
|
-
- 7.6.2
|
18
|
-
- 7.5.2
|
19
|
-
- 7.4.2
|
20
|
-
- 7.3.2
|
21
|
-
- 7.2.1
|
22
|
-
- 7.1.1
|
23
|
-
- 6.8.12
|
24
|
-
services:
|
25
|
-
elasticsearch:
|
26
|
-
image: docker.elastic.co/elasticsearch/elasticsearch-oss:${{matrix.elasticsearch}}
|
27
|
-
ports:
|
28
|
-
- 9200:9200
|
29
|
-
- 9300:9300
|
30
|
-
env:
|
31
|
-
discovery.type: single-node
|
25
|
+
- 6.8.18
|
32
26
|
steps:
|
27
|
+
# @see https://github.com/elastic/elastic-github-actions/tree/master/elasticsearch
|
28
|
+
- name: Configure sysctl limits for Elasticsearch
|
29
|
+
run: |
|
30
|
+
sudo swapoff -a
|
31
|
+
sudo sysctl -w vm.swappiness=1
|
32
|
+
sudo sysctl -w fs.file-max=262144
|
33
|
+
sudo sysctl -w vm.max_map_count=262144
|
34
|
+
- name: Runs Elasticsearch
|
35
|
+
uses: elastic/elastic-github-actions/elasticsearch@master
|
36
|
+
with:
|
37
|
+
stack-version: ${{matrix.search_versions}}
|
33
38
|
- uses: actions/checkout@v2
|
34
39
|
- uses: ruby/setup-ruby@v1
|
35
40
|
with:
|
36
|
-
ruby-version: 2.
|
41
|
+
ruby-version: 2.7
|
37
42
|
bundler-cache: true
|
38
|
-
- run: bundle install --jobs 4 --retry 3
|
39
43
|
- name: Wait for elasticsearch
|
40
44
|
run: timeout 60 bash -c "until curl --silent --output /dev/null localhost:9200/_cat/health?h=st; do printf '.'; sleep 5; done; printf '\n'"
|
41
45
|
- run: bundle exec rspec
|
data/README.md
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
# Antbird
|
2
2
|
|
3
|
-
Nearly auto-generated Elasticsearch client
|
3
|
+
Nearly auto-generated Elasticsearch/OpenSearch client
|
4
4
|
|
5
5
|
[](https://github.com/fukayatsu/antbird/actions)
|
6
6
|
|
@@ -113,9 +113,9 @@ To install this gem onto your local machine, run `bundle exec rake install`. To
|
|
113
113
|
|
114
114
|
Bug reports and pull requests are welcome on GitHub at https://github.com/fukayatsu/antbird. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
|
115
115
|
|
116
|
-
### How to support newer version of Elasticsearch
|
116
|
+
### How to support newer version of Elasticsearch/OpenSearch
|
117
117
|
|
118
|
-
1. Add Elasticsearch version to `jobs.build.strategy.matrix.
|
118
|
+
1. Add Elasticsearch version to `jobs.build.strategy.matrix.search_versions` on `.github/workflows/build.yml` / `.github/workflows/build-os.yml`
|
119
119
|
- Only one line for `x.y.*` version
|
120
120
|
1. `script/generate_api_methods`
|
121
121
|
- Set `GITHUB_TOKEN=***` env for GitHub API Limit
|
data/lib/antbird/client.rb
CHANGED
@@ -8,6 +8,7 @@ module Antbird
|
|
8
8
|
scope: {},
|
9
9
|
url: "http://localhost:9200",
|
10
10
|
version: nil,
|
11
|
+
distribution: nil,
|
11
12
|
read_timeout: 5,
|
12
13
|
open_timeout: 2,
|
13
14
|
adapter: ::Faraday.default_adapter,
|
@@ -19,20 +20,22 @@ module Antbird
|
|
19
20
|
@block = block
|
20
21
|
@url = url
|
21
22
|
|
22
|
-
@scope
|
23
|
-
@version
|
23
|
+
@scope = scope.transform_keys(&:to_sym)
|
24
|
+
@version = version
|
25
|
+
@distribution = distribution
|
24
26
|
|
25
27
|
@api_specs = {}
|
26
28
|
end
|
27
|
-
attr_reader :scope, :url, :version
|
29
|
+
attr_reader :scope, :url, :version, :distribution
|
28
30
|
attr_reader :read_timeout, :open_timeout, :adapter
|
29
|
-
attr_reader :api_specs
|
31
|
+
attr_reader :api_specs, :last_request
|
30
32
|
|
31
33
|
def scoped(new_scope = {})
|
32
34
|
Client.new(
|
33
35
|
scope: new_scope,
|
34
36
|
url: url,
|
35
37
|
version: version,
|
38
|
+
distribution: distribution,
|
36
39
|
read_timeout: read_timeout,
|
37
40
|
open_timeout: open_timeout
|
38
41
|
)
|
@@ -43,11 +46,13 @@ module Antbird
|
|
43
46
|
|
44
47
|
body = extract_body(params)
|
45
48
|
scopes = extract_scopes(params)
|
49
|
+
forced_method = extract_method(params)
|
46
50
|
|
47
51
|
# Greedy match
|
48
52
|
api_path = nil
|
53
|
+
api_path_template = nil
|
49
54
|
path_methods = nil
|
50
|
-
api_spec['url']['paths'].
|
55
|
+
sort_url_paths(api_spec['url']['paths']).each do |path|
|
51
56
|
if path.is_a?(Hash)
|
52
57
|
path_methods = path['methods']
|
53
58
|
path = path['path']
|
@@ -57,19 +62,40 @@ module Antbird
|
|
57
62
|
scopes[$1.to_sym] || @scope[$1.to_sym] || match
|
58
63
|
end
|
59
64
|
|
60
|
-
|
65
|
+
unless embeded.include?('{')
|
66
|
+
api_path_template = path
|
67
|
+
api_path = embeded
|
68
|
+
break
|
69
|
+
end
|
61
70
|
end
|
62
71
|
|
63
72
|
unless api_path
|
64
73
|
raise "API path not found: paths: #{api_spec['url']['paths']}, scope: #{@scope}"
|
65
74
|
end
|
66
75
|
|
67
|
-
methods = (
|
68
|
-
method =
|
76
|
+
methods = (path_methods || api_spec['methods']).map { |m| m.downcase.to_sym }
|
77
|
+
method =
|
78
|
+
if forced_method
|
79
|
+
forced_method
|
80
|
+
elsif methods.include?(:put)
|
81
|
+
:put
|
82
|
+
elsif methods.include?(:post)
|
83
|
+
:post
|
84
|
+
else
|
85
|
+
methods.first
|
86
|
+
end
|
69
87
|
|
70
88
|
read_timeout = params.delete(:read_timeout)
|
71
89
|
params.reject! { |_, v| v.nil? }
|
72
90
|
|
91
|
+
@last_request = {
|
92
|
+
method: method,
|
93
|
+
forced_method: forced_method,
|
94
|
+
api_path: api_path,
|
95
|
+
api_path_template: api_path_template,
|
96
|
+
params: params
|
97
|
+
}
|
98
|
+
|
73
99
|
response =
|
74
100
|
case method
|
75
101
|
when :head
|
@@ -116,6 +142,10 @@ module Antbird
|
|
116
142
|
response.body
|
117
143
|
end
|
118
144
|
|
145
|
+
def extract_method(params)
|
146
|
+
params.delete(:method)&.to_sym
|
147
|
+
end
|
148
|
+
|
119
149
|
def extract_scopes(params)
|
120
150
|
scopes = {}
|
121
151
|
[:index, :type, :id].each do |s|
|
@@ -163,8 +193,41 @@ module Antbird
|
|
163
193
|
end
|
164
194
|
end
|
165
195
|
|
196
|
+
def elasticsearch?
|
197
|
+
!opensearch?
|
198
|
+
end
|
199
|
+
|
200
|
+
def opensearch?
|
201
|
+
fetch_version
|
202
|
+
distribution == 'opensearch'
|
203
|
+
end
|
204
|
+
|
205
|
+
def elasticsearch_v7_0_compatible?
|
206
|
+
return true if opensearch?
|
207
|
+
|
208
|
+
elasticsearch? && Gem::Version.new(version) >= Gem::Version.new('7.0.0')
|
209
|
+
end
|
210
|
+
|
211
|
+
def elasticsearch_v7_6_compatible?
|
212
|
+
return true if opensearch?
|
213
|
+
|
214
|
+
elasticsearch? && Gem::Version.new(version) >= Gem::Version.new('7.6.0')
|
215
|
+
end
|
216
|
+
|
166
217
|
private
|
167
218
|
|
219
|
+
# NOTE: stable sort
|
220
|
+
def sort_url_paths(url_paths)
|
221
|
+
i = 0
|
222
|
+
url_paths.sort_by do |path|
|
223
|
+
if path.is_a?(Hash)
|
224
|
+
[-path['path'].count('{'), (path['deprecated'] ? 1 : 0), i += 1]
|
225
|
+
else
|
226
|
+
[-path.count('{'), i += 1]
|
227
|
+
end
|
228
|
+
end
|
229
|
+
end
|
230
|
+
|
168
231
|
def handle_errors!(response)
|
169
232
|
if response.status >= 500
|
170
233
|
raise ServerError, response
|
@@ -183,16 +246,25 @@ module Antbird
|
|
183
246
|
end
|
184
247
|
|
185
248
|
def fetch_version
|
186
|
-
|
249
|
+
return if @version
|
250
|
+
|
251
|
+
version_hash = connection.get('/').body.dig('version')
|
252
|
+
@version ||= version_hash['number']
|
253
|
+
@distribution ||= version_hash['distribution']
|
187
254
|
end
|
188
255
|
|
189
256
|
def ensure_api_spec_loaded
|
190
257
|
return if api_specs_loaded?
|
191
258
|
|
192
|
-
|
259
|
+
fetch_version
|
193
260
|
class_version = @version.split('.')[0, 2].join('_')
|
194
|
-
|
195
|
-
|
261
|
+
if opensearch?
|
262
|
+
require "antbird/rest_api/rest_api_opensearch_v#{class_version}"
|
263
|
+
extend Antbird::RestApi.const_get "RestApiOpensearchV#{class_version}"
|
264
|
+
else
|
265
|
+
require "antbird/rest_api/rest_api_v#{class_version}"
|
266
|
+
extend Antbird::RestApi.const_get "RestApiV#{class_version}"
|
267
|
+
end
|
196
268
|
|
197
269
|
@api_specs_loaded = true
|
198
270
|
end
|