How to see ENV vars in a Rails application?

I am using an old Rails application. No one touched him after a year. The last developer left in April 2015, and I have no way to contact him. I have ssh access to the server and I have access to the Github repository.

I do not know any of the usernames / passwords.

If I ssh on the server and I have a cat database.yml file, I see things like:

staging: adapter: mysql2 encoding: utf8 pool: 5 socket: /var/lib/mysql/mysql.sock database: o_wawa_stage username: wawa_stage password: <%= ENV['STAGE_DATABASE_PASSWORD'] %> host: access.dmedia.com 

If I run the command "printenv", then I do not see any of these vars. I assume that they are loaded only by the Rails environment.

I suppose I can edit templates to spit out values ​​using empty put statements, but I think there should be a more obvious way to do this, other than printing the data that the public could see. This?

If I try to run the "rails console", I get:

  Rails Error: Unable to access log file. Please ensure that /var/www/haha/production/releases/20150118213616/log/development.log exists and is writable (ie, make it writable for user and group: chmod 0664 /var/www/haha/production/releases/20150118213616/log/development.log). The log level has been raised to WARN and the output directed to STDERR until the problem is fixed. 

I do not have sudo in this field, so I can not fix the error.

+6
source share
2 answers

Assuming an intermediate environment, as your example points out. You want to load the console by adding the RAILS_ENV environment variable to the rails console command.

 RAILS_ENV=staging rails console 

This should introduce you. Once you are logged in, you can simply access the ENV variable.

 2.2.2 (main):0 > ENV 

And that will bring out environment variables for you. Please note: your invitation may look different. If you want to access a specific value, for example, a database password, you can:

 2.2.2 (main):0 > ENV['STAGE_DATABASE_PASSWORD'] 
+5
source

yourapp / config / env.yml or application.yml etc.

Look at the code that looks like

 AWS_KEY_ID: blahblah23rkjewfojerflbah AWS_SECRET_KEY_ID: blahblah2394082fkwejfoblah 
0
source

All Articles