如何在Mongoid 3客户端启用SSL / TLS?

时间:2014-04-04 21:57:35

标签: mongodb mongoid

如何在Mongoid 3客户端中启用SSL / TLS?

我试过了:

options:
  -ssl: true

但是我得到了未定义的方法`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>'

这篇文章:

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

...建议您可以通过它的配置文件为Mongoid提供选项以实现它。但是,并不完全清楚需要哪些选项,以及允许的值是什么。

1 个答案:

答案 0 :(得分:2)

配置中不需要连字符。要启用SSL,请使用以下配置:

production:
  sessions:
    default:
      options:
        ssl: true

关于可用选项,您链接的讨论是关于旧代码的。之前可以在配置中设置SSL证书:

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

但是在此提交中删除了该代码:

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

Mongoid 3附带的Moped版本只有主机和端口选项:

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