antbird 0.2.2 → 0.5.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/build-os.yml +41 -0
- data/.github/workflows/build.yml +23 -20
- data/README.md +3 -3
- data/lib/antbird/client.rb +90 -14
- 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_10.rb +6 -6
- 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_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 +1 -1
- data/lib/antbird/version.rb +1 -1
- metadata +12 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7f6be201e13340d8e4f7cf122049f745af8c9af0d4d6390601a3264bef077992
|
4
|
+
data.tar.gz: 7f1540e56bdc23db02b1300971550bdce93bb0ac426a0010d2fa4a9fc245e8f4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9d135caf322ed4ad9056883283062ffbf5f43073087b29befa60033273f95ac87dae3b0f2b21fac79eb15d1bf21fe23d3cf136acd89e5ac46c4f2add0bee7678
|
7
|
+
data.tar.gz: c8df3422cf55ffad4f18e4016e0ec972570c525f53250a48962d482d9ac7d45585cf0f2ad8357eb74e1b73dbf2309f2949bcc4ec8e3b016e7f71f07588295848
|
@@ -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,33 +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
|
15
23
|
- 7.9.3
|
16
24
|
- 7.8.1
|
17
|
-
-
|
18
|
-
- 7.6.2
|
19
|
-
- 7.5.2
|
20
|
-
- 7.4.2
|
21
|
-
- 7.3.2
|
22
|
-
- 7.2.1
|
23
|
-
- 7.1.1
|
24
|
-
- 6.8.13
|
25
|
-
services:
|
26
|
-
elasticsearch:
|
27
|
-
image: docker.elastic.co/elasticsearch/elasticsearch-oss:${{matrix.elasticsearch}}
|
28
|
-
ports:
|
29
|
-
- 9200:9200
|
30
|
-
- 9300:9300
|
31
|
-
env:
|
32
|
-
discovery.type: single-node
|
25
|
+
- 6.8.18
|
33
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}}
|
34
38
|
- uses: actions/checkout@v2
|
35
39
|
- uses: ruby/setup-ruby@v1
|
36
40
|
with:
|
37
|
-
ruby-version: 2.
|
41
|
+
ruby-version: 2.7
|
38
42
|
bundler-cache: true
|
39
|
-
- run: bundle install --jobs 4 --retry 3
|
40
43
|
- name: Wait for elasticsearch
|
41
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'"
|
42
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
|
[![Build Status](https://github.com/fukayatsu/antbird/workflows/build/badge.svg)](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,27 @@ module Antbird
|
|
19
20
|
@block = block
|
20
21
|
@url = url
|
21
22
|
|
22
|
-
@scope
|
23
|
-
|
23
|
+
@scope = scope.transform_keys(&:to_sym)
|
24
|
+
|
25
|
+
if version
|
26
|
+
@version = version
|
27
|
+
@distribution = distribution
|
28
|
+
else
|
29
|
+
fetch_version_and_distribution
|
30
|
+
end
|
24
31
|
|
25
32
|
@api_specs = {}
|
26
33
|
end
|
27
|
-
attr_reader :scope, :url, :version
|
34
|
+
attr_reader :scope, :url, :version, :distribution
|
28
35
|
attr_reader :read_timeout, :open_timeout, :adapter
|
29
|
-
attr_reader :api_specs
|
36
|
+
attr_reader :api_specs, :last_request
|
30
37
|
|
31
38
|
def scoped(new_scope = {})
|
32
39
|
Client.new(
|
33
40
|
scope: new_scope,
|
34
41
|
url: url,
|
35
42
|
version: version,
|
43
|
+
distribution: distribution,
|
36
44
|
read_timeout: read_timeout,
|
37
45
|
open_timeout: open_timeout
|
38
46
|
)
|
@@ -43,11 +51,13 @@ module Antbird
|
|
43
51
|
|
44
52
|
body = extract_body(params)
|
45
53
|
scopes = extract_scopes(params)
|
54
|
+
forced_method = extract_method(params)
|
46
55
|
|
47
56
|
# Greedy match
|
48
57
|
api_path = nil
|
58
|
+
api_path_template = nil
|
49
59
|
path_methods = nil
|
50
|
-
api_spec['url']['paths'].
|
60
|
+
sort_url_paths(api_spec['url']['paths']).each do |path|
|
51
61
|
if path.is_a?(Hash)
|
52
62
|
path_methods = path['methods']
|
53
63
|
path = path['path']
|
@@ -57,19 +67,40 @@ module Antbird
|
|
57
67
|
scopes[$1.to_sym] || @scope[$1.to_sym] || match
|
58
68
|
end
|
59
69
|
|
60
|
-
|
70
|
+
unless embeded.include?('{')
|
71
|
+
api_path_template = path
|
72
|
+
api_path = embeded
|
73
|
+
break
|
74
|
+
end
|
61
75
|
end
|
62
76
|
|
63
77
|
unless api_path
|
64
78
|
raise "API path not found: paths: #{api_spec['url']['paths']}, scope: #{@scope}"
|
65
79
|
end
|
66
80
|
|
67
|
-
methods = (
|
68
|
-
method =
|
81
|
+
methods = (path_methods || api_spec['methods']).map { |m| m.downcase.to_sym }
|
82
|
+
method =
|
83
|
+
if forced_method
|
84
|
+
forced_method
|
85
|
+
elsif methods.include?(:put)
|
86
|
+
:put
|
87
|
+
elsif methods.include?(:post)
|
88
|
+
:post
|
89
|
+
else
|
90
|
+
methods.first
|
91
|
+
end
|
69
92
|
|
70
93
|
read_timeout = params.delete(:read_timeout)
|
71
94
|
params.reject! { |_, v| v.nil? }
|
72
95
|
|
96
|
+
@last_request = {
|
97
|
+
method: method,
|
98
|
+
forced_method: forced_method,
|
99
|
+
api_path: api_path,
|
100
|
+
api_path_template: api_path_template,
|
101
|
+
params: params
|
102
|
+
}
|
103
|
+
|
73
104
|
response =
|
74
105
|
case method
|
75
106
|
when :head
|
@@ -116,6 +147,10 @@ module Antbird
|
|
116
147
|
response.body
|
117
148
|
end
|
118
149
|
|
150
|
+
def extract_method(params)
|
151
|
+
params.delete(:method)&.to_sym
|
152
|
+
end
|
153
|
+
|
119
154
|
def extract_scopes(params)
|
120
155
|
scopes = {}
|
121
156
|
[:index, :type, :id].each do |s|
|
@@ -163,8 +198,40 @@ module Antbird
|
|
163
198
|
end
|
164
199
|
end
|
165
200
|
|
201
|
+
def elasticsearch?
|
202
|
+
!opensearch?
|
203
|
+
end
|
204
|
+
|
205
|
+
def opensearch?
|
206
|
+
distribution == 'opensearch'
|
207
|
+
end
|
208
|
+
|
209
|
+
def elasticsearch_v7_0_compatible?
|
210
|
+
return true if opensearch?
|
211
|
+
|
212
|
+
elasticsearch? && Gem::Version.new(version) >= Gem::Version.new('7.0.0')
|
213
|
+
end
|
214
|
+
|
215
|
+
def elasticsearch_v7_6_compatible?
|
216
|
+
return true if opensearch?
|
217
|
+
|
218
|
+
elasticsearch? && Gem::Version.new(version) >= Gem::Version.new('7.6.0')
|
219
|
+
end
|
220
|
+
|
166
221
|
private
|
167
222
|
|
223
|
+
# NOTE: stable sort
|
224
|
+
def sort_url_paths(url_paths)
|
225
|
+
i = 0
|
226
|
+
url_paths.sort_by do |path|
|
227
|
+
if path.is_a?(Hash)
|
228
|
+
[-path['path'].count('{'), (path['deprecated'] ? 1 : 0), i += 1]
|
229
|
+
else
|
230
|
+
[-path.count('{'), i += 1]
|
231
|
+
end
|
232
|
+
end
|
233
|
+
end
|
234
|
+
|
168
235
|
def handle_errors!(response)
|
169
236
|
if response.status >= 500
|
170
237
|
raise ServerError, response
|
@@ -182,17 +249,26 @@ module Antbird
|
|
182
249
|
end
|
183
250
|
end
|
184
251
|
|
185
|
-
def
|
186
|
-
connection.get('/').body.dig('version'
|
252
|
+
def fetch_version_and_distribution
|
253
|
+
version_hash = connection.get('/').body.dig('version')
|
254
|
+
@version = version_hash['number']
|
255
|
+
@distribution = version_hash['distribution']
|
256
|
+
end
|
257
|
+
|
258
|
+
def class_version
|
259
|
+
version.split('.')[0, 2].join('_')
|
187
260
|
end
|
188
261
|
|
189
262
|
def ensure_api_spec_loaded
|
190
263
|
return if api_specs_loaded?
|
191
264
|
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
|
265
|
+
if opensearch?
|
266
|
+
require "antbird/rest_api/rest_api_opensearch_v#{class_version}"
|
267
|
+
extend Antbird::RestApi.const_get "RestApiOpensearchV#{class_version}"
|
268
|
+
else
|
269
|
+
require "antbird/rest_api/rest_api_v#{class_version}"
|
270
|
+
extend Antbird::RestApi.const_get "RestApiV#{class_version}"
|
271
|
+
end
|
196
272
|
|
197
273
|
@api_specs_loaded = true
|
198
274
|
end
|