Forum: JRuby Obtaining the Trinidad config for SSL

3b8ad006781b1a3ab36dc76e2a05ce9c?d=identicon&s=25 Cris Shupp (cshupp)
on 2014-02-26 21:57
I am trying out the SSL features of Trinidad, and so far so good, but
how do I obtain the Trinidad config to integrate with my code?

For example, in trinidad.yml, suppose I have:

 ssl: # SSL configuration
    port: 3443

I want to obtain this information to integrate it with the rails APIs.
This is what I have so far...

In an initializer:
require "trinidad"

$trinidad_config = Trinidad.configuration

This will allow me hash like access to the yaml file, next I add to a
module TrinidadHelper
  def trinidad_ssl_enforcer(action_array)
    if (!$trinidad_config[:ssl].nil? &&
      force_ssl only: action_array, port: $trinidad_config[:ssl][:port]
      #take the default of 443
      force_ssl only: action_array unless $trinidad_config[:ssl].nil?

In my controller I then do:
class AdminUserEditController < ApplicationController
  extend TrinidadHelper

  trinidad_ssl_enforcer [:list, :update]

This certainly seems to work, but I am not in love with my code that
seems to have married Trinidad...


Caa2df9372ffa0a9e95b2bab1e8fea34?d=identicon&s=25 Karol Bucek (Guest)
on 2014-02-27 08:02
(Received via mailing list)
it's probably best to simply provide something external such as an ENV
variable to setup SSL ... which than can be detected in both runtimes
Trinidad's as well as the actual app :

e.g. using config/trinidad.rb (you can use the .yml as well it's ERB
thus <&= ssl_port = ENV['SSL_PORT'] &> would work ) :

Trinidad.configure do |config|
  config[:threadsafe] = true
  if ssl_port = ENV['SSL_PORT']
    config.ssl = { :port => ssl_port.to_i }
    config.port = 3003 # only start HTTP

3b8ad006781b1a3ab36dc76e2a05ce9c?d=identicon&s=25 Cris Shupp (cshupp)
on 2014-03-03 20:03

Thanks.  That worked like a charm.  I will put my code out here in the
hopes it might help anyone else with this issue!

In trinidad.yml I added:

<% unless ENV['SSL_PORT'].nil? %>
  ssl: # SSL configuration
    port: <%= "#{ENV['SSL_PORT']}"%>
    #keystore: c:\temp$trin/etc/trinidad/default.keystore
    #keystorePass: somepassword
<% end %>

In a controller code like this worked well:

force_ssl only: [:new, :create], port: ENV['SSL_PORT'].to_i unless

And that was the easiest ssl I have ever done.  Trinidad is nice!


Please log in before posting. Registration is free and takes only a minute.
Existing account

NEW: Do you have a Google/GoogleMail, Yahoo or Facebook account? No registration required!
Log in with Google account | Log in with Yahoo account | Log in with Facebook account
No account? Register here.