cjm2671
cjm2671

Reputation: 19486

Where do I centrally configure the access credentials for the fog gem?

I don't want to place it in the code in situ where it is to be used; how/where should it be defined normally?

I want the connection to be accessible from all over the application, as follows:

connection = Fog::Storage.new({
  :provider                 => 'AWS',
  :aws_secret_access_key    => YOUR_SECRET_ACCESS_KEY,
  :aws_access_key_id        => YOUR_SECRET_ACCESS_KEY_ID
})

(from http://fog.io/1.0.0/about/getting_started.html)

Upvotes: 0

Views: 1329

Answers (1)

Benjamin Manns
Benjamin Manns

Reputation: 9148

You could set up a constant in an initializer.

config/initializers/fog.rb

FOG_CONNECTION = Fog::Storage.new({
  :provider                 => 'AWS',
  :aws_secret_access_key    => YOUR_SECRET_ACCESS_KEY,
  :aws_access_key_id        => YOUR_SECRET_ACCESS_KEY_ID
})

This will then be available within your application as FOG_CONNECTION.directories.get(...).

Upvotes: 2

Related Questions