简体   繁体   中英

Declaring In-Line Secret Keys in Ruby On Rails

I'm learning Ruby On Rails. I'm trying to use the aws-s3 gem to access Amazon S3. One line of my controller code reads:

AWS::S3::Base.establish_connection!(
      :access_key_id     => 'myrealaccesskeyishere',
      :secret_access_key => 'myrealsecretkeyishere'
)

I've noticed that if I make an error, sometimes rails will come back and show a few lines of code where it thinks the error might be. Should I not be writing these out in the .rb controller files like this? Am I potentially risking my secret key? If so, how should I be doing this instead?

You should put this in an initializer. Place it in config/intializers/amazon_s3.rb

Is there a reason you are putting this code directly in the controller?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM