mongodb_meilisearch 2.0.0 → 2.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
2
  SHA256:
3
- metadata.gz: 0c07c25d10efdfee292401ba54dacb34aee8abd153226a3618a2c88de96661dc
4
- data.tar.gz: 40ec770c86ab522f3cf49ff950230a8f82f6527d4a3b33842f8d56c12f47067a
3
+ metadata.gz: bd055e2a0c8c754e3fe7d6b770217b65eb6552b5ff9099b5b9c05d052b5de32d
4
+ data.tar.gz: a79a6b7980a4b809c6e868344fc41ecc512e75a3a30c5a129e5d6f1099a9b667
5
5
  SHA512:
6
- metadata.gz: db89325982a30521bec7fcaee27f0da61a177b7738591dbf0b95c36666f3a02e94a85e3403a7c2b81a92d0396839b1344dc7c63a4a4ae937793c743bcbb26e4f
7
- data.tar.gz: 05415b71991b53ff28ab4c10e5c3b9ea27ef7399f1c91d1e0444974469b9649d24191ec0438a91045438c95207fa4dcf6f4c4ea545008e5d30b52574daf5752b
6
+ metadata.gz: bf63ed5f1e2efc95b194efe8bbcb0c53d615f8f65d4c9774a4e3aa559408d515e2152940f6a49b43ae0a9840a27615f045577ca30341c5bc6249a92adac8d258
7
+ data.tar.gz: 13a2adbc8f06838f184d431ac0c523f7bc24987abb32485109ce994fa2780ba2491e676f5d49afec035209b1560d7419644838e3879fee21aeca2e403e9012c2
data/Gemfile.lock CHANGED
@@ -1,74 +1,15 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- mongodb_meilisearch (2.0.0)
4
+ mongodb_meilisearch (2.2.0)
5
5
  meilisearch
6
- mongoid (~> 7.0)
7
- rails
6
+ mongoid (>= 7.0)
8
7
 
9
8
  GEM
10
9
  remote: https://rubygems.org/
11
10
  specs:
12
- actioncable (7.0.6)
13
- actionpack (= 7.0.6)
14
- activesupport (= 7.0.6)
15
- nio4r (~> 2.0)
16
- websocket-driver (>= 0.6.1)
17
- actionmailbox (7.0.6)
18
- actionpack (= 7.0.6)
19
- activejob (= 7.0.6)
20
- activerecord (= 7.0.6)
21
- activestorage (= 7.0.6)
22
- activesupport (= 7.0.6)
23
- mail (>= 2.7.1)
24
- net-imap
25
- net-pop
26
- net-smtp
27
- actionmailer (7.0.6)
28
- actionpack (= 7.0.6)
29
- actionview (= 7.0.6)
30
- activejob (= 7.0.6)
31
- activesupport (= 7.0.6)
32
- mail (~> 2.5, >= 2.5.4)
33
- net-imap
34
- net-pop
35
- net-smtp
36
- rails-dom-testing (~> 2.0)
37
- actionpack (7.0.6)
38
- actionview (= 7.0.6)
39
- activesupport (= 7.0.6)
40
- rack (~> 2.0, >= 2.2.4)
41
- rack-test (>= 0.6.3)
42
- rails-dom-testing (~> 2.0)
43
- rails-html-sanitizer (~> 1.0, >= 1.2.0)
44
- actiontext (7.0.6)
45
- actionpack (= 7.0.6)
46
- activerecord (= 7.0.6)
47
- activestorage (= 7.0.6)
48
- activesupport (= 7.0.6)
49
- globalid (>= 0.6.0)
50
- nokogiri (>= 1.8.5)
51
- actionview (7.0.6)
52
- activesupport (= 7.0.6)
53
- builder (~> 3.1)
54
- erubi (~> 1.4)
55
- rails-dom-testing (~> 2.0)
56
- rails-html-sanitizer (~> 1.1, >= 1.2.0)
57
- activejob (7.0.6)
58
- activesupport (= 7.0.6)
59
- globalid (>= 0.3.6)
60
11
  activemodel (7.0.6)
61
12
  activesupport (= 7.0.6)
62
- activerecord (7.0.6)
63
- activemodel (= 7.0.6)
64
- activesupport (= 7.0.6)
65
- activestorage (7.0.6)
66
- actionpack (= 7.0.6)
67
- activejob (= 7.0.6)
68
- activerecord (= 7.0.6)
69
- activesupport (= 7.0.6)
70
- marcel (~> 1.0)
71
- mini_mime (>= 1.1.0)
72
13
  activesupport (7.0.6)
73
14
  concurrent-ruby (~> 1.0, >= 1.0.2)
74
15
  i18n (>= 1.6, < 2)
@@ -76,18 +17,12 @@ GEM
76
17
  tzinfo (~> 2.0)
77
18
  ast (2.4.2)
78
19
  bson (4.15.0)
79
- builder (3.2.4)
80
20
  concurrent-ruby (1.2.2)
81
- crass (1.0.6)
82
- date (3.3.3)
83
21
  debug (1.8.0)
84
22
  irb (>= 1.5.0)
85
23
  reline (>= 0.3.1)
86
24
  diff-lcs (1.5.0)
87
25
  dotenv (2.8.1)
88
- erubi (1.12.0)
89
- globalid (1.1.0)
90
- activesupport (>= 5.0)
91
26
  httparty (0.21.0)
92
27
  mini_mime (>= 1.0.0)
93
28
  multi_xml (>= 0.5.2)
@@ -98,18 +33,8 @@ GEM
98
33
  reline (>= 0.3.6)
99
34
  json (2.6.3)
100
35
  lefthook (1.4.5)
101
- loofah (2.21.3)
102
- crass (~> 1.0.2)
103
- nokogiri (>= 1.12.0)
104
- mail (2.8.1)
105
- mini_mime (>= 0.1.1)
106
- net-imap
107
- net-pop
108
- net-smtp
109
- marcel (1.0.2)
110
36
  meilisearch (0.24.0)
111
37
  httparty (>= 0.17.1, < 0.22.0)
112
- method_source (1.0.0)
113
38
  mini_mime (1.1.2)
114
39
  minitest (5.18.1)
115
40
  mongo (2.19.0)
@@ -119,58 +44,12 @@ GEM
119
44
  mongo (>= 2.10.5, < 3.0.0)
120
45
  ruby2_keywords (~> 0.0.5)
121
46
  multi_xml (0.6.0)
122
- net-imap (0.3.6)
123
- date
124
- net-protocol
125
- net-pop (0.1.2)
126
- net-protocol
127
- net-protocol (0.2.1)
128
- timeout
129
- net-smtp (0.3.3)
130
- net-protocol
131
- nio4r (2.5.9)
132
- nokogiri (1.15.3-arm64-darwin)
133
- racc (~> 1.4)
134
- nokogiri (1.15.3-x86_64-linux)
135
- racc (~> 1.4)
136
47
  parallel (1.23.0)
137
48
  parser (3.2.2.3)
138
49
  ast (~> 2.4.1)
139
50
  racc
140
51
  racc (1.7.1)
141
- rack (2.2.7)
142
- rack-test (2.1.0)
143
- rack (>= 1.3)
144
- rails (7.0.6)
145
- actioncable (= 7.0.6)
146
- actionmailbox (= 7.0.6)
147
- actionmailer (= 7.0.6)
148
- actionpack (= 7.0.6)
149
- actiontext (= 7.0.6)
150
- actionview (= 7.0.6)
151
- activejob (= 7.0.6)
152
- activemodel (= 7.0.6)
153
- activerecord (= 7.0.6)
154
- activestorage (= 7.0.6)
155
- activesupport (= 7.0.6)
156
- bundler (>= 1.15.0)
157
- railties (= 7.0.6)
158
- rails-dom-testing (2.1.1)
159
- activesupport (>= 5.0.0)
160
- minitest
161
- nokogiri (>= 1.6)
162
- rails-html-sanitizer (1.6.0)
163
- loofah (~> 2.21)
164
- nokogiri (~> 1.14)
165
- railties (7.0.6)
166
- actionpack (= 7.0.6)
167
- activesupport (= 7.0.6)
168
- method_source
169
- rake (>= 12.2)
170
- thor (~> 1.0)
171
- zeitwerk (~> 2.5)
172
52
  rainbow (3.1.1)
173
- rake (13.0.6)
174
53
  regexp_parser (2.8.1)
175
54
  reline (0.3.6)
176
55
  io-console (~> 0.5)
@@ -210,18 +89,13 @@ GEM
210
89
  rubocop-factory_bot (~> 2.22)
211
90
  ruby-progressbar (1.13.0)
212
91
  ruby2_keywords (0.0.5)
213
- thor (1.2.2)
214
- timeout (0.4.0)
215
92
  tzinfo (2.0.6)
216
93
  concurrent-ruby (~> 1.0)
217
94
  unicode-display_width (2.4.2)
218
- websocket-driver (0.7.5)
219
- websocket-extensions (>= 0.1.0)
220
- websocket-extensions (0.1.5)
221
- zeitwerk (2.6.8)
222
95
 
223
96
  PLATFORMS
224
97
  arm64-darwin-22
98
+ arm64-darwin-23
225
99
  x86_64-linux
226
100
 
227
101
  DEPENDENCIES
data/README.org CHANGED
@@ -97,6 +97,33 @@ This will return a hash with the keys you'll need.
97
97
 
98
98
  Use those keys in your environment. The next time the =Search::Client= is initialized it'll use them.
99
99
 
100
+ ***** Validating Search & Admin keys
101
+ When switching between Meilisearch instances the same master key doesn't result in the same default admin and search keys. Being able to easily validate this is useful in situations like testing code against Meilisearch instances that are inside a Docker container /and/ in the Host OS.
102
+
103
+ Practically speaking you may want to simply /not/ provide these keys during development, and only use the =MEILI_MASTER_KEY=. Just be sure to include them when talking to a production instance.
104
+
105
+ #+begin_src ruby
106
+ Search::Client.instance.validate_default_keys(ENV['MEILI_MASTER_KEY'])
107
+ #+end_src
108
+
109
+ This returns a hash like the following.
110
+
111
+ - =status= is always either ="provided"= or ="missing"= and indicates if the =MEILISEARCH_SEARCH_KEY= or =MEILISEARCH_ADMIN_KEY= were found in the environment.
112
+ - =matches= is always either =true= or =false=, and indicates if the provided Search & Admin keys (if any) match the defaults the current instance is returning.
113
+
114
+ #+begin_src ruby
115
+ {
116
+ :search_key=>{
117
+ :status=>"provided",
118
+ :matches=>true
119
+ },
120
+ :admin_key=>{
121
+ :status=>"provided",
122
+ :matches=>true
123
+ }
124
+ }
125
+ #+end_src
126
+
100
127
  ** Model Integration
101
128
  Add the following near the top of your model. Only the =extend= and
102
129
  =include= lines are required. This assumes your model also includes
@@ -611,9 +638,9 @@ but not share all your source.
611
638
 
612
639
  ** Code of Conduct
613
640
  Everyone interacting in this project's codebases, issue trackers, chat
614
- rooms and mailing lists is expected to follow the
615
- [[https://github.com/masukomi/mongodb_meilisearch/blob/main/CODE_OF_CONDUCT.md][code
616
- of conduct]].
641
+ rooms and mailing lists is expected to follow the [[https://github.com/masukomi/mongodb_meilisearch/blob/main/CODE_OF_CONDUCT.md][code of conduct]].
642
+
643
+ It is furthermore /fully/ acknowledged that "master" is a problematic term that shouldn't be used. However, we're stuck with it until Meilisearch changes the name of that key.
617
644
 
618
645
  * Footnotes
619
646
  [fn:macos] MacOS users I have not found a way to successfully automatically Meilisearch with launchctl (brew services uses this) that allows it to see the ~MEILI_MASTER_KEY~ environment variable. As such, I can /not/ recommend using launchctl for running Meilisearch. Running it without a master key only works in development mode, and introduces complications.
@@ -5,5 +5,5 @@ module MongodbMeilisearch
5
5
  # @note This library will adhere to strict semantic versioning.
6
6
  # See https://semver.org/
7
7
  #
8
- VERSION = "2.0.0"
8
+ VERSION = "2.2.0"
9
9
  end
data/lib/search/client.rb CHANGED
@@ -6,10 +6,17 @@ module Search
6
6
  include Singleton
7
7
  attr_reader :admin_client, :search_client
8
8
  attr_accessor :logger
9
+ MASTER_KEY = "MEILI_MASTER_KEY".freeze
10
+ SEARCH_KEY = "MEILISEARCH_SEARCH_KEY".freeze
11
+ ADMIN_KEY = "MEILISEARCH_ADMIN_KEY".freeze
12
+ URL_KEY = "MEILISEARCH_URL".freeze
13
+ TIMEOUT_KEY = "MEILISEARCH_TIMEOUT".freeze
14
+ MAX_RETRIES_KEY = "MEILISEARCH_MAX_RETRIES".freeze
15
+ SEARCH_ENABLED_KEY = "SEARCH_ENABLED".freeze
9
16
 
10
17
  def initialize
11
18
  @logger = default_logger
12
- if ENV.fetch("SEARCH_ENABLED", "true") == "true"
19
+ if ENV.fetch(SEARCH_ENABLED_KEY, "true") == "true"
13
20
  initialize_clients
14
21
  # WARNING: ⚠ clients MAY be nil depending on what api keys were provided
15
22
  # In this case rails logger warnings and/or errors will have already
@@ -20,7 +27,7 @@ module Search
20
27
  )
21
28
  end
22
29
  else
23
- @logger.info("SEARCH_ENABLED is not \"true\" - mongodb_meilisearch NOT initialized")
30
+ @logger.info("#{SEARCH_ENABLED_KEY} is not \"true\" - mongodb_meilisearch NOT initialized")
24
31
  end
25
32
  end
26
33
 
@@ -45,8 +52,8 @@ module Search
45
52
 
46
53
  def initialize_clients
47
54
  # see what env vars they've configured
48
- search_api_key = ENV.fetch("MEILISEARCH_SEARCH_KEY", nil)
49
- admin_api_key = ENV.fetch("MEILISEARCH_ADMIN_KEY", nil)
55
+ search_api_key = ENV.fetch(SEARCH_KEY, nil)
56
+ admin_api_key = ENV.fetch(ADMIN_KEY, nil)
50
57
  search_api_key = nil if search_api_key == ""
51
58
  admin_api_key = nil if admin_api_key == ""
52
59
 
@@ -98,12 +105,12 @@ module Search
98
105
 
99
106
  def master_client(master_api_key = nil)
100
107
  master_api_key = nil if master_api_key == ""
101
- master_api_key ||= ENV.fetch("MEILI_MASTER_KEY", nil)
108
+ master_api_key ||= ENV.fetch(MASTER_KEY, nil)
102
109
  if !url || !master_api_key
103
110
 
104
111
  unless master_api_key
105
112
  @logger.error(
106
- "MEILI_MASTER_KEY is not set. Cannot create master client."
113
+ "#{MASTER_KEY} is not set. Cannot create master client."
107
114
  )
108
115
  end
109
116
 
@@ -112,28 +119,28 @@ module Search
112
119
 
113
120
  initialize_new_client(
114
121
  url: url,
115
- api_key: ENV.fetch("MEILI_MASTER_KEY"),
122
+ api_key: ENV.fetch(MASTER_KEY),
116
123
  timeout: timeout,
117
124
  max_retries: max_retries
118
125
  )
119
126
  end
120
127
 
121
128
  def url
122
- maybe_url = ENV.fetch("MEILISEARCH_URL", nil)
129
+ maybe_url = ENV.fetch(URL_KEY, nil)
123
130
  unless maybe_url
124
131
  @logger.error(
125
- "MEILI_MASTER_KEY is not set. Cannot create master client."
132
+ "#{MASTER_KEY} is not set. Cannot create master client."
126
133
  )
127
134
  end
128
135
  maybe_url
129
136
  end
130
137
 
131
138
  def timeout
132
- ENV.fetch("MEILISEARCH_TIMEOUT", 10).to_i
139
+ ENV.fetch(TIMEOUT_KEY, 10).to_i
133
140
  end
134
141
 
135
142
  def max_retries
136
- ENV.fetch("MEILISEARCH_MAX_RETRIES", 2).to_i
143
+ ENV.fetch(MAX_RETRIES_KEY, 2).to_i
137
144
  end
138
145
 
139
146
  def get_default_keys(m_c)
@@ -162,6 +169,28 @@ module Search
162
169
  response
163
170
  end
164
171
 
172
+ # Validates that the keys keys provided for search & admin
173
+ # correspond to the default keys Meilisearch returns
174
+ # @param [String] m_c - the Meilisearch Master Key to use.
175
+ # This is most likely found in ENV['MEILI_MASTER_KEY']
176
+ # @return [Hash[Hash]]
177
+ def validate_default_keys(m_c)
178
+ default_keys = get_default_keys(m_c)
179
+ search_key = ENV.fetch(SEARCH_KEY, nil)
180
+ admin_key = ENV.fetch(ADMIN_KEY, nil)
181
+
182
+ {
183
+ search_key: {
184
+ status: search_key.nil? ? "missing" : "provided",
185
+ matches: default_keys[:search] == search_key
186
+ },
187
+ admin_key: {
188
+ status: admin_key.nil? ? "missing" : "provided",
189
+ matches: default_keys[:admin] == admin_key
190
+ }
191
+ }
192
+ end
193
+
165
194
  def default_logger
166
195
  in_rails = Module.constants.include?(:Rails)
167
196
  in_rails ? Rails.logger : Logger.new($stdout)
metadata CHANGED
@@ -1,29 +1,15 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mongodb_meilisearch
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.0
4
+ version: 2.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - masukomi
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2024-07-16 00:00:00.000000000 Z
11
+ date: 2024-08-09 00:00:00.000000000 Z
12
12
  dependencies:
13
- - !ruby/object:Gem::Dependency
14
- name: rails
15
- requirement: !ruby/object:Gem::Requirement
16
- requirements:
17
- - - ">="
18
- - !ruby/object:Gem::Version
19
- version: '0'
20
- type: :runtime
21
- prerelease: false
22
- version_requirements: !ruby/object:Gem::Requirement
23
- requirements:
24
- - - ">="
25
- - !ruby/object:Gem::Version
26
- version: '0'
27
13
  - !ruby/object:Gem::Dependency
28
14
  name: meilisearch
29
15
  requirement: !ruby/object:Gem::Requirement
@@ -42,14 +28,14 @@ dependencies:
42
28
  name: mongoid
43
29
  requirement: !ruby/object:Gem::Requirement
44
30
  requirements:
45
- - - "~>"
31
+ - - ">="
46
32
  - !ruby/object:Gem::Version
47
33
  version: '7.0'
48
34
  type: :runtime
49
35
  prerelease: false
50
36
  version_requirements: !ruby/object:Gem::Requirement
51
37
  requirements:
52
- - - "~>"
38
+ - - ">="
53
39
  - !ruby/object:Gem::Version
54
40
  version: '7.0'
55
41
  - !ruby/object:Gem::Dependency
@@ -188,7 +174,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
188
174
  - !ruby/object:Gem::Version
189
175
  version: '0'
190
176
  requirements: []
191
- rubygems_version: 3.4.20
177
+ rubygems_version: 3.5.11
192
178
  signing_key:
193
179
  specification_version: 4
194
180
  summary: MeiliSearch integration for MongoDB