How to enable SSL/TLS in Mongoid 3 client?

爷,独闯天下 提交于 2019-12-10 11:49:41

问题


How do you enable SSL/TLS in the Mongoid 3 client?

I've tried:

options:
  -ssl: true

But I get "undefined method `each_pair' for [{"ssl"=>true}]:Array (NoMethodError)":

/home/user1/.rbenv/versions/2.0.0-p451/lib/ruby/gems/2.0.0/bundler/gems/mongoid-026e32109178/lib/mongoid/config.rb:203:in `options=': undefined method `each_pair' for [{"ssl"=>true}]:Array (NoMethodError)
from /home/jwiley/.rbenv/versions/2.0.0-p451/lib/ruby/gems/2.0.0/bundler/gems/mongoid-026e32109178/lib/mongoid/config.rb:129:in `load_configuration'
from /home/jwiley/.rbenv/versions/2.0.0-p451/lib/ruby/gems/2.0.0/bundler/gems/mongoid-026e32109178/lib/mongoid/config.rb:87:in `load!'
from /home/jwiley/.rbenv/versions/2.0.0-p451/lib/ruby/gems/2.0.0/bundler/gems/mongoid-026e32109178/lib/mongoid.rb:98:in `load!'
from /home/jwiley/.rbenv/versions/2.0.0-p451/lib/ruby/gems/2.0.0/bundler/gems/mongoid-026e32109178/lib/mongoid/railtie.rb:75:in `block in <class:Railtie>'

This post:

https://groups.google.com/forum/#!topic/mongoid/juexwcPWxOk

...Suggests there are options you can feed into Mongoid by it's config file to make it happen. But it's not entirely clear which options are required, and what the allowed values are.


回答1:


The hyphen is not needed in the configuration. To enable SSL, use a configuration like this:

production:
  sessions:
    default:
      options:
        ssl: true

About the available options, the discussion you linked is about an old code. Earlier it was possible to set the SSL certificate in the configuration:

https://github.com/mongoid/moped/blob/dc21475820ff148fb42963752db0bfa6a23f5e1e/lib/moped/sockets/ssl.rb#L95-L125

But that code got removed in this commit:

https://github.com/mongoid/moped/commit/ace43c4d7e4bbe7d32dfcf1f7ac5ee34e47647c9#diff-d808d724705e7cb8b2e11baf137922af

And the Moped version which comes with Mongoid 3 has options only for host and port:

https://github.com/mongoid/moped/blob/1.5.0-stable/lib/moped/sockets/ssl.rb#L12-L29



来源:https://stackoverflow.com/questions/22873735/how-to-enable-ssl-tls-in-mongoid-3-client

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!