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