Back-End /Ruby On Rails

[rails] 5.2부터 암호화인증서

rootkaien 2019. 8. 13. 16:58

5.2 버전부터 credentials.yml.enc 지원된다. 

 

- ./config/ 폴더안에 존재하며

- master.key파일이 존재해야 열수 있다. 

 

즉~~ 

./config/credentials.yml.enc

./config/master.key

 

두파일이 있어야됨 

 

수정 방법 

 

$ EDITOR=vim rails credentials:edit

 

실행하면 된다. 

 

development:
        database_url: mysql2://db:3306/hellorails_dev

test:
        database_url: mysql2://db:3306/hellorails_test

production:
        database_url: mysql2://hellorails:hellorails123@1.1.1.1:3306/hellorailsdev

파일에 위와같이 정의해줄수 있다. 

config/database.yml 안에 아래와같이 해주면 사용할수 있다. 

default: &default
  adapter: mysql2
  encoding: utf8mb4
  pool: <%= ENV.fetch("RAILS_MAX_THREADS") { 5 } %>
  socket: /tmp/mysql.sock

development:
  <<: *default
  url : <%= Rails.application.credentials.development[:database_url] %>

test:
  <<: *default
  url : <%= Rails.application.credentials.test[:database_url] %>

production:
  <<: *default
  url : <%= Rails.application.credentials.production[:database_url] %>%