-
Type: Improvement
-
Resolution: Fixed
-
Priority: Unknown
-
Affects Version/s: None
-
Component/s: fle-sample-app
-
None
Instead of having the user supply the filename+extension in the config just detect the environment and apply it for them. Falls back to the linux configuration if the environement can't be detected from RUBY_PLATFORM.
Unable to find source-code formatter for language: diff. Available languages are: actionscript, ada, applescript, bash, c, c#, c++, cpp, css, erlang, go, groovy, haskell, html, java, javascript, js, json, lua, none, nyan, objc, perl, php, python, r, rainbow, ruby, scala, sh, sql, swift, visualbasic, xml, yaml
Author: Alex Bevilacqua <alex@alexbevi.com> Date: Fri Aug 18 10:22:57 2023 -0400 Add a mongocrypt_path_helper for use in the mongoid.yml diff --git a/config/initializers/mongoid.rb b/config/initializers/mongoid.rb index 7ceeac9..e249045 100644 --- a/config/initializers/mongoid.rb +++ b/config/initializers/mongoid.rb @@ -9,17 +9,35 @@ Mongoid.configure do # It is recommended to use config/mongoid.yml for most Mongoid-related # configuration, whenever possible, but if you prefer, you can set # configuration values here, instead: - # + # # config.log_level = :debug # # Note that the settings in config/mongoid.yml always take precedence, # whatever else is set here. end - + # Enable Mongo driver query cache for Rack # Rails.application.config.middleware.use(Mongo::QueryCache::Middleware) - + # Enable Mongo driver query cache for ActiveJob # ActiveSupport.on_load(:active_job) do # include Mongo::QueryCache::Middleware::ActiveJob # end + +# Identify the current environment based on the RUBY_PLATFORMS environment +# variable, and use this to autopopulate the path to the crypt_shared +# library at ./vendor/crypt_shared/mongo_crypt_v1.[dll|dynlib|so] +# +# If detection fails the default file extension will be Linux's .so +def mongocrypt_path_helper + platform = RUBY_PLATFORM.downcase + ext = if RUBY_PLATFORM =~ /mswin32/ + "dll" + elsif RUBY_PLATFORM =~ /darwin/ + "dylib" + else + "so" # default to Linux + end + + File.join(Rails.root, 'vendor', 'crypt_shared', "mongo_crypt_v1.#{ext}") +end \ No newline at end of file diff --git a/config/mongoid.yml b/config/mongoid.yml index 33b5f9b..a496f0f 100644 --- a/config/mongoid.yml +++ b/config/mongoid.yml @@ -26,9 +26,13 @@ development: # This app assumes that crypt shared library is located in the vendor/crypt_shared directory. # You can download the library from here: # https://www.mongodb.com/try/download/enterprise - # Please adjust the file path accordingly to your operating system - # (.so for Linux, .dylib for macOS, .dll for Windows) - crypt_shared_lib_path: <%= File.join(Rails.root, 'vendor', 'crypt_shared', 'mongo_crypt_v1.so') %> + # + # The mongocrypt_path_helper method will attempt to fill in the + # path to the mongo_crypt_v1.[dll|so|dynlib] based on the detected + # environment, however this can manually be set via: + # + # <%= File.join(Rails.root, 'vendor', 'crypt_shared', "mongo_crypt_v1.<ext>") %> + crypt_shared_lib_path: <%= mongocrypt_path_helper %> options: # This is recommended for auto encryption to work properly in development.