fat-settings-yml

83899fe2d00874176098a3bb71b043be?s=47 TAKAHASHI Kazunari
August 24, 2016
320

 fat-settings-yml

83899fe2d00874176098a3bb71b043be?s=128

TAKAHASHI Kazunari

August 24, 2016
Tweet

Transcript

  1. 'BUTFUUJOHTZNMͱ ޲͖߹͏

  2. ࣗݾ঺հ w ߴڮҰੜ w UXJUUFSDPNTZP w HJUIVCDPNTZP w 3BJMTϓϩάϥϚʔ w

    ,BXBTBLJSC༓ྶ෦һ
  3. લఏͱ͔ w 3BJMT੡ͷ΢ΣϒΞϓϦέʔγϣϯ w ʙ೥ӡ༻͍ͯ͠Δ w 8FCαʔόʔʙ୆ w %#αʔόʔ୆ w

    "1*Ωʔ΍ύεϫʔυ͸ίϛοτʹؚΊͳ͍
  4. TFUUJOHTZNMͱ͸ w $POpHVSBUJPO.BOBHNFOU w 4FUUJOHT-PHJDT w $POpH w (MPCBM

  5. DPOpHTFUUJOHTZNM 1 development: 2 smtp: 3 host: smtp.gmail.com 4 username:

    development_user 5 password: password 6 test: 7 smtp: 8 host: smtp.gmail.com 9 username: test_user 10 password: password 11 production: 12 smtp: 13 host: smtp.gmail.com 14 username: production_user 15 password: <%= ENV['SMTP_PASSWORD'] %>
  6. BQQNPEFMTTFUUJOHTSC 1 class Settings < Settingslogic 2 source Rails.root.join('config/settings.yml') 3

    namespace Rails.env 4 suppress_errors Rails.env.production? 5 end 6 7 #=> Settings.smtp.username 8 #=> development_user
  7. ӡ༻ํ๏ w ίϛοτʹ͸ؚΊͳ͍ w ຊ൪؀ڥͷTIBSFEDPOpHTFUUJOHTZNMͷΈ w EFQMPZ࣌ʹDVSSFOUDPOpHTFUUJOHTZNMʹϦϯΫ

  8. ઃఆΛ௥Ճ͢Δ࣌͸֤΢Σ ϒαʔόʔͰઃఆΛ௥Ճ͢Δ

  9. ઃఆ͕ଟ͘ͳͬͨ࣌ͷ՝୊ w ઃఆͷ௥Ճมߋ w ઃఆ࿙Ε w ஋͕Χϥ w 3BJMTFOW͕૿͑ͨ࣌ͷରԠ

  10. ઃఆͷ௥Ճมߋ

  11. 1 development: 2 aws: 3 access_key_id: DEVELOPMENT_ACCESS_KEY_ID 4 secret_access_key: DEVELOPMENT_SECRET_ACCESS_KEY

    5 google: 6 client_id: DEVELOPMENT_GOOGLE_CLIENT_ID.apps.googleusercontent.com 7 secret_key: DEVELOPMENT_SECRET_KEY 8 token_filename: google_drive.json 9 callback_url: http://localhost:3000/oauth/callback 10 foobar_ftp: 11 host: ftp.example.com 12 user: ftp_user 13 password: Ohyee7ak2She 14 export_dirs: 15 shipments: <%= Rails.root.join('tmp', 'shipments') %> 16 products: <%= Rails.root.join('tmp', 'products') %> 17 suppliers: <%= Rails.root.join('tmp', 'suppliers') %> 18 stocks: <%= Rails.root.join('tmp', 'stocks') %> 19 airbrake: 20 project_id: DEVELPMENT_PROJECT_ID 21 project_key: DEVELOPMENT_PROJECT_KEY 22 test: 23 aws: 24 access_key_id: TEST_ACCESS_KEY_ID 25 secret_access_key: TEST_SECRET_ACCESS_KEY 26 google: 27 client_id: TEST_GOOGLE_CLIENT_ID.apps.googleusercontent.com 28 secret_key: TEST_SECRET_KEY 29 token_filename: google_drive.json 30 callback_url: http://localhost:3000/oauth/callback 31 foobar_ftp: 32 host: ftp.example.com 33 user: ftp_user 34 password: Ohyee7ak2She 35 export_dirs: 36 shipments: <%= Rails.root.join('tmp', 'shipments') %> 37 products: <%= Rails.root.join('tmp', 'products') %> 1 production: 2 aws: 3 access_key_id: PRODUCTION_ACCESS_KEY_ID 4 secret_access_key: PRODUCTION_SECRET_ACCESS_KEY 5 google: 6 client_id: PRODUCTION_GOOGLE_CLIENT_ID.apps.googleusercontent.com 7 secret_key: PRODUCTION_SECRET_KEY 8 token_filename: google_drive.json 9 callback_url: http://localhost:3000/oauth/callback 10 foobar_ftp: 11 host: ftp.example.com 12 user: ftp_user 13 password: Ohyee7ak2She --------------------------------------------------------- --------------------------------------------------------- --------------------------------------------------------- ------------------------------ --------------------------------------------------------- --------------------------------------------------------- --------------------------------------------------------- ------------------------------ --------------------------------------------------------- --------------------------------------------------------- --------------------------------------------------------- ------------------------------ --------------------------------------------------------- --------------------------------------------------------- --------------------------------------------------------- ------------------------------ --------------------------------------------------------- --------------------------------------------------------- --------------------------------------------------------- ------------------------------ --------------------------------------------------------- --------------------------------------------------------- --------------------------------------------------------- ------------------------------
  12. ઃఆ࿙Ε

  13. NFUIPE֎Ͱݺͼग़͠ 1 class AdministratorsController < ApplicationController 2 USER = Settings.basic_auth.username

    #=> username͸ະఆٛ 3 PASSWORD = Settings.basic_auth.password 4 5 def index 6 end 7 end
  14. BQQαʔόʔىಈ࣌ʹΤϥʔ $ RAILS_ENV=production bundle exec rails s => Booting Puma

    => Rails 5.0.0.1 application starting in production on http://0.0.0.0:3000 => Run `rails server -h` for more startup options Exiting /usr/local/lib/ruby/gems/2.3.0/gems/ settingslogic-2.0.9/lib/settingslogic.rb:189:in `missing_key': Missing setting 'username' in 'basic_auth' section in /path/to/app/config/ settings.yml (Settingslogic::MissingSetting)
  15. NFUIPE಺Ͱݺͼग़͠ 1 class AdministratorsController < ApplicationController 2 def index 3

    user = Settings.basic_auth.username #=> username͸ະఆٛ 4 password = Settings.basic_auth.password 5 end 6 end
  16. NFUIPEݺͼग़࣌͠ʹΤϥʔ 4UBSUFE(&5BENJOJTUSBUPSTGPSBU   1SPDFTTJOHCZ"ENJOJTUSBUPST$POUSPMMFSJOEFYBT)5.- $PNQMFUFE*OUFSOBM4FSWFS&SSPSJONT "DUJWF3FDPSE NT  4FUUJOHTMPHJD.JTTJOH4FUUJOH

    .JTTJOHTFUUJOHVTFSOBNFJO CBTJD@BVUITFDUJPOJOQBUIUPBQQDPOpHTFUUJOHTZNM 
  17. όονͰར༻͢Δͷ͔ʁ

  18. ஋͕Χϥ w &3#ͷॲཧʹ໰୊͕͋Δ w ؀ڥม਺Λࢀর͍ͯ͠Δ

  19. 3BJMTFOW͕ ૿͑ͨ࣌ͷରԠ

  20. ΄ͱΜͲಉ͡ઃఆΛ࢖͍͍ͨ w 4UBHJOH 4UBHJOH w "ENJO

  21. ઃఆ͕ଟ͘ͳͬͨ࣌ͷ՝୊ w ઃఆͷ௥Ճมߋ w ઃఆ࿙Ε w ஋͕ۭ w 3BJMTFOW͕૿͑ͨ࣌ͷରԠ

  22. ղܾʹ޲͚ͯͷࢥ͍ w ҆શʹղܾ͍ͨ͠ w ͳΔ΂͘ଟ͘ͷઃఆΛίϛοτʹؚΊ͍ͨ w ΞϓϦέʔγϣϯαʔόʔͷ࠶ىಈΑΓલʹ໰୊Λ ݕ஌͍ͨ͠ w 3BJMTFOWͷϑΥʔϧόοΫతͳ࢓૊Έ͕΄͍͠

  23. ղܾ΁ͷΞΠσΟΞ w TFUUJOHTZNMΛҙຯຖʹ෼ׂ͢Δ w "1*Ωʔ΍ύεϫʔυͳͲ͸؀ڥม਺ʹҠߦ w 4FUUJOHTϞσϧ͸Ϋϥεఆ਺ܦ༝Ͱࢀর͢Δ w ۭͷ஋ͷνΣοΫ༻λεΫͷ࡞੒ w

    ΦϨΦϨ3BJMTFOW
  24. TFUUJOHTZNM 1 development: 2 aws: 3 access_key_id: DEVELOPMENT_ACCESS_KEY_ID 4 secret_access_key:

    DEVELOPMENT_SECRET_ACCESS_KEY 5 google: 6 client_id: DEVELOPMENT_GOOGLE_CLIENT_ID.apps.googleusercontent.com 7 secret_key: DEVELOPMENT_SECRET_KEY 8 token_filename: google_drive.json 9 callback_url: http://localhost:3000/oauth/callback 10 foobar_ftp: 11 host: ftp.example.com 12 user: ftp_user 13 password: Ohyee7ak2She 14 export_dirs: 15 shipments: <%= Rails.root.join('tmp', 'shipments') %> 16 products: <%= Rails.root.join('tmp', 'products') %> 17 suppliers: <%= Rails.root.join('tmp', 'suppliers') %> 18 stocks: <%= Rails.root.join('tmp', 'stocks') %> 19 airbrake: 20 project_id: DEVELPMENT_PROJECT_ID 21 project_key: DEVELOPMENT_PROJECT_KEY
  25. TFUUJOHTZNMΛҙຯ ຖʹ෼ׂ͢Δ

  26. DPOpHTFUUJOHT ZNM $ tree config/settings config/settings ├── airbrake.yml ├── aws.yml

    ├── basic_auth.yml ├── export_dirs.yml ├── foobar_ftp.yml └── smtp.yml
  27. DPOpHTFUUJOHTTNUQZNM 1 development: 2 host: smtp.gmail.com 3 username: development_user 4

    password: password 5 test: 6 host: smtp.gmail.com 7 username: test_user 8 password: password 9 staging: 10 host: smtp.gmail.com 11 username: staging_user 12 password: <%= ENV['SMTP_PASSWORD'] %> 13 production: 14 host: smtp.gmail.com 15 username: production_user 16 password: <%= ENV['SMTP_PASSWORD'] %>
  28. BQQNPEFMTTFUUJOHT SC $ tree app/models/settings app/models/settings ├── airbrake.rb ├── aws.rb

    ├── basic_auth.rb ├── foobar_ftp.rb └── smtp.rb
  29. BQQNPEFMTTFUUJOHTTNUQSC 1 class Settings::Smtp < Settingslogic 2 source Rails.root.join('config/settings/smtp.yml') 3

    namespace Rails.env 4 end 5 6 #=> Settings::Smtp.username 7 #=> development_user
  30. "1*Ωʔ΍ύεϫʔυ ͳͲ͸؀ڥม਺ʹҠߦ

  31. DPOpHTFUUJOHTTNUQZNM 1 development: 2 host: smtp.gmail.com 3 username: development_user 4

    password: password 5 test: 6 host: smtp.gmail.com 7 username: test_user 8 password: password 9 staging: 10 host: smtp.gmail.com 11 username: staging_user 12 password: <%= ENV['SMTP_PASSWORD'] %> 13 production: 14 host: smtp.gmail.com 15 username: production_user 16 password: <%= ENV['SMTP_PASSWORD'] %>
  32. 4FUUJOHTϞσϧ͸Ϋϥ εఆ਺ܦ༝Ͱࢀর͢Δ

  33. NFUIPE֎Ͱݺͼग़͠ 1 class AdministratorsController < ApplicationController 2 USER = Settings::BasicAuth.user

    3 PASSWORD = Settings::BasicAuth.password 4 5 def index 6 end 7 end
  34. ۭͷ஋ͷνΣοΫ༻λ εΫͷ࡞੒

  35. 1 namespace :settings do 2 task check: :environment do 3

    Dir.glob(Rails.root.join('app', 'models', 'settings', '*.rb')) { |f| require f } 4 Settingslogic.subclasses.all? do |klass| 5 klass.keys.all? { |m| klass.send(m).present? } 6 end 7 end 8 end
  36. ΦϨΦϨ3BJMTFOW

  37. 1 class RailsEnvDetector 2 def self.detect(env = Rails.env) 3 case

    env 4 when /\Astaging/ 5 'staging' 6 else 7 env 8 end 9 end 10 end
  38. BQQNPEFMTTFUUJOHTTNUQSC 1 class Settings::Smtp < Settingslogic 2 source Rails.root.join('config/settings/smtp.yml') 3

    namespace RailsEnvDetector.detect 4 end 5 6 #=> Settings::Smtp.username 7 #=> development_user
  39. ͓ΘΓʹ w ͠͹Βͨ͘͠Βผͷ՝୊͕Ͱ͖ͯͦ͏ɻܧଓతʹվળ͠ ͍͖͍ͯͨ w ؅ཧը໘͔Β؀ڥม਺ΛઃఆͰ͖ΔIFSPLVͬͯ࠷ߴͩͳ w ଟ͘ͷΞΠσΟΞΛHMPCBM͔Βഈआͨ͠ͷͰ࣍ճ͸HMPCBM Λར༻͍ͨ͠ w

    HMPCBMΛ঺հͯ͘͠ΕͨTVF͞Μ͋Γ͕ͱ͏ w Έͳ͞Μͷӡ༻ࣄྫ͕஌Γ͍ͨͰ͢