mongodb_meilisearch 2.0.0 → 2.1.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: f94879936fd02812f5a9e9887ce71774edf2049f5b03610196e8a25af558e32c
4
+ data.tar.gz: 1078bb0b874e10957d95a5583423a22304fba95b6016f4115407dee6c4c9bee2
5
5
  SHA512:
6
- metadata.gz: db89325982a30521bec7fcaee27f0da61a177b7738591dbf0b95c36666f3a02e94a85e3403a7c2b81a92d0396839b1344dc7c63a4a4ae937793c743bcbb26e4f
7
- data.tar.gz: 05415b71991b53ff28ab4c10e5c3b9ea27ef7399f1c91d1e0444974469b9649d24191ec0438a91045438c95207fa4dcf6f4c4ea545008e5d30b52574daf5752b
6
+ metadata.gz: f41b528068bf5bd587e399ab71f502dcbf9ccdb4f8b4c1c282448335f0f4bc98a69372345f205c536c27e88585bfaa080d1f8c76b42ceac396aa5c8f9ae478f0
7
+ data.tar.gz: f594659bcdd20c7e0a2cdebfc30731d17f3e82abf681a2bc343f92b98f2f204b42e3193653b2af11ff1fa517d54f02fc51a26a10073ee07616e0437b8b1d82e4
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- mongodb_meilisearch (2.0.0)
4
+ mongodb_meilisearch (2.1.0)
5
5
  meilisearch
6
6
  mongoid (~> 7.0)
7
7
  rails
@@ -111,6 +111,7 @@ GEM
111
111
  httparty (>= 0.17.1, < 0.22.0)
112
112
  method_source (1.0.0)
113
113
  mini_mime (1.1.2)
114
+ mini_portile2 (2.8.7)
114
115
  minitest (5.18.1)
115
116
  mongo (2.19.0)
116
117
  bson (>= 4.14.1, < 5.0.0)
@@ -129,9 +130,8 @@ GEM
129
130
  net-smtp (0.3.3)
130
131
  net-protocol
131
132
  nio4r (2.5.9)
132
- nokogiri (1.15.3-arm64-darwin)
133
- racc (~> 1.4)
134
- nokogiri (1.15.3-x86_64-linux)
133
+ nokogiri (1.15.3)
134
+ mini_portile2 (~> 2.8.2)
135
135
  racc (~> 1.4)
136
136
  parallel (1.23.0)
137
137
  parser (3.2.2.3)
@@ -222,6 +222,7 @@ GEM
222
222
 
223
223
  PLATFORMS
224
224
  arm64-darwin-22
225
+ arm64-darwin-23
225
226
  x86_64-linux
226
227
 
227
228
  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.1.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,14 +1,14 @@
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.1.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-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -188,7 +188,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
188
188
  - !ruby/object:Gem::Version
189
189
  version: '0'
190
190
  requirements: []
191
- rubygems_version: 3.4.20
191
+ rubygems_version: 3.5.11
192
192
  signing_key:
193
193
  specification_version: 4
194
194
  summary: MeiliSearch integration for MongoDB