adamthedeveloper / wepay-rails

Collect payments from wepay in your rails application.
MIT License
32 stars 24 forks source link

Store sensitive data in wepay.yml using embedded Ruby (.erb) #15

Closed SteveAquino closed 12 years ago

SteveAquino commented 12 years ago

Not sure the best way to handle this one, but I'd like to store sensitive data (namely production client_id and client_secret) in a variable and call it in wepay.yml with ruby. This is trivial using yml.erb, however the initialization mechanism for WepayRails only looks for "wepay.yml" and thus fails when you add .erb to the file name.

I don't have much experience messing with YAML loading and such, but I found out how to load the file with .erb. I'm sure there is a more elegant way to solve this but my proposed solution is to edit wepay-rails.rb as follows:

class Engine < Rails::Engine
    # Initializers
    initializer "WepayRails.initialize_wepay_rails" do |app|
      yml = Rails.root.join('config', 'wepay.yml').to_s
      if File.exists?(yml)
        settings = YAML.load_file(yml)[Rails.env].symbolize_keys
      elsif File.exists?(yml+".erb")
        settings = YAML::load(ERB.new(IO.read(yml+".erb")).result)[Rails.env].symbolize_keys
      end
      Configuration.init_conf(settings) unless settings.nil?
    end

    ...
end
SteveAquino commented 12 years ago

I've updated my personal fork and things are working. I think it makes sense to add some tests before we bump to version 2.3.0, so I will do that before pushing out changes.

adamthedeveloper commented 12 years ago

Your erb solution looks good to me.

SteveAquino commented 12 years ago

Ok I've pushed the update and added some basic tests. It's pretty self explanatory but let me know if you think there should be a wiki entry for this.