meilisearch 0.18.1 → 0.18.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +1 -1
- data/lib/meilisearch/client.rb +2 -2
- data/lib/meilisearch/error.rb +6 -0
- data/lib/meilisearch/tenant_token.rb +70 -0
- data/lib/meilisearch/version.rb +1 -1
- data/lib/meilisearch.rb +2 -0
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9b69f3c0d8bf43393b59abe4e44aabf40ff673dd08bde8f6e60d1c996be8b7bf
|
4
|
+
data.tar.gz: d2ff90fe7e1cf738dc4e3297cf7e7215e80c7a63317d06144681fab39206d1b2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 59dfc2b7ced1fec8a75c32b4b02b49d42a8a63af862bcb86931692be8e9c92b89657b93958c150937ddbe295d645eff5192a181ef439885462c2f6174c1519c3
|
7
|
+
data.tar.gz: 71b81d762f8c609a7e2d50ac0052e6c8e0b904c28b2cb7b98f0c55934122c97c1160a4c0b4a2659adcf474a59be85ea609a75183e69550ca4971d177afb8e2b0
|
data/README.md
CHANGED
@@ -198,7 +198,7 @@ JSON output:
|
|
198
198
|
|
199
199
|
## 🤖 Compatibility with Meilisearch
|
200
200
|
|
201
|
-
This package only guarantees the compatibility with the [version v0.
|
201
|
+
This package only guarantees the compatibility with the [version v0.26.0 of Meilisearch](https://github.com/meilisearch/meilisearch/releases/tag/v0.26.0).
|
202
202
|
|
203
203
|
## 💡 Learn More
|
204
204
|
|
data/lib/meilisearch/client.rb
CHANGED
data/lib/meilisearch/error.rb
CHANGED
@@ -0,0 +1,70 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module MeiliSearch
|
4
|
+
module TenantToken
|
5
|
+
HEADER = {
|
6
|
+
typ: 'JWT',
|
7
|
+
alg: 'HS256'
|
8
|
+
}.freeze
|
9
|
+
|
10
|
+
def generate_tenant_token(search_rules, api_key: nil, expires_at: nil)
|
11
|
+
signature = retrieve_valid_key!(api_key, @api_key)
|
12
|
+
expiration = validate_expires_at!(expires_at)
|
13
|
+
rules = validate_search_rules!(search_rules)
|
14
|
+
unsigned_data = build_payload(expiration, rules, signature)
|
15
|
+
|
16
|
+
combine(unsigned_data, to_base64(sign_data(signature, unsigned_data)))
|
17
|
+
end
|
18
|
+
|
19
|
+
private
|
20
|
+
|
21
|
+
def build_payload(expiration, rules, signature)
|
22
|
+
payload = {
|
23
|
+
searchRules: rules,
|
24
|
+
apiKeyPrefix: signature[0..7],
|
25
|
+
exp: expiration
|
26
|
+
}
|
27
|
+
|
28
|
+
combine(encode(HEADER), encode(payload))
|
29
|
+
end
|
30
|
+
|
31
|
+
def validate_expires_at!(expires_at)
|
32
|
+
return unless expires_at
|
33
|
+
return expires_at.to_i if expires_at.utc? && expires_at > Time.now.utc
|
34
|
+
|
35
|
+
raise
|
36
|
+
rescue StandardError
|
37
|
+
raise ExpireOrInvalidSignature
|
38
|
+
end
|
39
|
+
|
40
|
+
def validate_search_rules!(data)
|
41
|
+
return data if data
|
42
|
+
|
43
|
+
raise InvalidSearchRules
|
44
|
+
end
|
45
|
+
|
46
|
+
def retrieve_valid_key!(*keys)
|
47
|
+
key = keys.compact.find { |k| !k.empty? }
|
48
|
+
|
49
|
+
raise InvalidApiKey if key.nil?
|
50
|
+
|
51
|
+
key
|
52
|
+
end
|
53
|
+
|
54
|
+
def sign_data(key, msg)
|
55
|
+
OpenSSL::HMAC.digest('SHA256', key, msg)
|
56
|
+
end
|
57
|
+
|
58
|
+
def to_base64(data)
|
59
|
+
Base64.urlsafe_encode64(data, padding: false)
|
60
|
+
end
|
61
|
+
|
62
|
+
def encode(data)
|
63
|
+
to_base64(JSON.generate(data))
|
64
|
+
end
|
65
|
+
|
66
|
+
def combine(*parts)
|
67
|
+
parts.join('.')
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
data/lib/meilisearch/version.rb
CHANGED
data/lib/meilisearch.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: meilisearch
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.18.
|
4
|
+
version: 0.18.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Meili
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2022-
|
11
|
+
date: 2022-03-14 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: httparty
|
@@ -44,6 +44,7 @@ files:
|
|
44
44
|
- lib/meilisearch/http_request.rb
|
45
45
|
- lib/meilisearch/index.rb
|
46
46
|
- lib/meilisearch/task.rb
|
47
|
+
- lib/meilisearch/tenant_token.rb
|
47
48
|
- lib/meilisearch/utils.rb
|
48
49
|
- lib/meilisearch/version.rb
|
49
50
|
homepage: https://github.com/meilisearch/meilisearch-ruby
|