2013-07-14 5 views
-1

나는 사용자가 등록 할 때 환영 이메일을 보내는 매우 간단한 Rails 앱을 가지고있다. 나는 메시지를 보내 내 Gmail 계정을 사용하고, 아래와 같이 나는 응용 프로그램에 저장 내 Gmail 계정에 대한 암호를 가지고 :git 저장소에서 비밀번호를 숨기는 방법은 무엇입니까?

application.rb

require File.expand_path('../boot', __FILE__) 

require 'rails/all' 

if defined?(Bundler) 
    # If you precompile assets before deploying to production, use this line 
    Bundler.require(*Rails.groups(:assets => %w(development test))) 
    # If you want your assets lazily compiled in production, use this line 
    # Bundler.require(:default, :assets, Rails.env) 
end 

ENV.update YAML.load(File.read(File.expand_path('../application.yml', __FILE__))) 

module TestMailApp 
    class Application < Rails::Application 

    config.action_mailer.smtp_settings = { 
     :address    => "smtp.gmail.com", 
     :port     => 587, 
     :domain    => "my address", 
     :user_name   => "my_gmail_name", 
     :password    => ENV["MAIL_PASSWORD"], 
     :authentication  => :plain, 
     :enable_starttls_auto => true 
    } 

    config.action_mailer.default_url_options = { 
     :host => "my address" 
    } 


application.yml

MAIL_PASSWORD: "my_password" 


내 git 저장소의 application.yml 파일에 저장된 비밀번호를 숨기고 싶습니다. 내 gitignore 파일에 application.yml을 추가하려고했지만 내 응용 프로그램이 충돌합니다.

내 앱이 여전히 작동하고 개인용 저장소에 앱을 넣지 않아도되도록이 비밀번호를 내 git 저장소에서 숨기려면 어떻게해야하나요?

+0

duplicate of duplicates =] http://stackoverflow.com/questions/3605866/hide-password-when-checking-config-file-in-git (또한, off of stackoverflow : http://ejohn.org/) 블로그/유지 - 패스워드 - 소스 제어 /) –

+0

[this] (http://stackoverflow.com/questions/15978253/rails-how-to-store-passwords-for-other-services) –

+0

'application.yml'을 추가하는 것은 저에게 당신이해야 할 일처럼 보입니다. 그 앱이 어떻게 깨지나요? 나는 그 앱이 git repo에 완전히 불가 지론이라고 생각했을 것이다 ... –

답변

4

기본적으로 할 수 없습니다. 그 종류의 정보는 서버 또는 git에 추가하지 않는 설정 파일에 환경 변수로 저장하는 것이 가장 좋습니다. sendgrid에 대한

+0

git repo에 저장하고 repo의 다른 사용자로부터 숨길 수는 없습니다. 그것은 사실입니다. 그러나 당신은 .gitingore에 파일을 가지고 있고 (서버상의) repo의 클론에 주위에있는 로컬 버전이있다. 그것은 버전 제어되지 않을 것이지만 이것은 아마도 당신이 자격 증명에 대해 원하는 것일 것입니다. http://stackoverflow.com/a/17484565/2536029를 참조하십시오. – mnagel

1

내 exemple :

development.rb 서버 편집 bash는 프로필에

if ENV['SENDGRID_USERNAME'] 
    config.action_mailer.smtp_settings = { 
     :address => 'smtp.sendgrid.net', 
     :domain => 'heroku.com', 
     :port => '587', 
     :authentication => :plain, 
     :user_name => ENV['SENDGRID_USERNAME'], 
     :password => ENV['SENDGRID_PASSWORD'] 
    } 
    end 

:

nano .bash_profile 

하고 값을 추가합니다

export SENDGRID_USERNAME=yourusername 
export SENDGRID_PASSWORD=yourpassword 
에게

내 로컬 컴퓨터에서이 모든 작업을 마친 후에는 모든 콘솔 창을 닫은 다음 다시 열어서 env variables을 초기화해야합니다. vps에서 이렇게하면 vps를 다시 시작해야 할 수도 있습니다.

0

dotenv 보석 https://rubygems.org/gems/dotenv을 사용해보세요. .gitignore에서 .env 파일을 언급하면 ​​원하는 결과를 얻을 수 있습니다.

관련 문제