Obtaining the Trinidad config for SSL

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::CommandLineParser.parse(ARGV)
$trinidad_config = Trinidad.configuration

This will allow me hash like access to the yaml file, next I add to a
library:

module TrinidadHelper
def trinidad_ssl_enforcer(action_array)
if (!$trinidad_config[:ssl].nil? &&
!$trinidad_config[:ssl][:port].nil?)
force_ssl only: action_array, port: $trinidad_config[:ssl][:port]
else
#take the default of 443
force_ssl only: action_array unless $trinidad_config[:ssl].nil?
end
end
end

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…

Thanks,

Cris

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
parsed
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 }
else
config.port = 3003 # only start HTTP
end
end

K.

Karol,

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’]}”%>
#@see https://github.com/trinidad/trinidad/wiki/Secure-Socket-Layer
#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
ENV[‘SSL_PORT’].nil?

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

Thanks,

Cris

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs