-
Notifications
You must be signed in to change notification settings - Fork 1
/
environment.rb
64 lines (52 loc) · 1.7 KB
/
environment.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
module Environment
REQUIRED_ENV_VARS = %w(
DATABASE_URL
ALLOWED_USERS
SESSION_SECRET
SESSION_DOMAIN
PORT
).freeze
OPTIONAL_ENV_VARS = %w(
AUTHY_API_KEY
GOOGLE_ANALYTICS_KEY
GOOGLE_CLIENT_ID
GOOGLE_CLIENT_SECRET
ROLLBAR_ACCESS_TOKEN
ROLLBAR_ENDPOINT
SENDGRID_PASSWORD
SENDGRID_USERNAME
TWILIO_ACCOUNT_SID
TWILIO_AUTH_TOKEN
TWILIO_FROM_NUMBER
).freeze
ENV_VARS_TO_CHANGE = {
'PORT' => '4567',
'SESSION_DOMAIN' => 'localhost'
'SESSION_SECRET' => '52ea5dabe17d8263d5381a54920f55baa9b025fbdefd65fc605cd6d63bb08f60b6329fbbaf0d6c7718bfb350b6068743ddff1c2772cd7dc7a1177a8a7c2e2f91',
}.freeze
def self.check_env
unless File.exists?('./.env')
warn "You need a .env file - copy over .env.defaults and customize from there."
exit 1
end
missing_required = REQUIRED_ENV_VARS.select { |key| ENV[key].blank? }
unless missing_required.empty?
warn "MISSING REQUIRED ENV VARIABLES:\n\t#{missing_required.join("\n\t")}"
end
missing_optional = OPTIONAL_ENV_VARS.select { |key| ENV[key].blank? }
unless missing_optional.empty?
warn "MISSING OPTIONAL ENV VARIABLES (not required for local development, probably necessary in prod):\n\t#{missing_optional.join("\n\t")}"
end
to_change = ENV_VARS_TO_CHANGE.select { |key, value| ENV[key] == value }
unless to_change.empty?
warn "DEFAULT VARIABlES (these are fine in local development, but should be changed in production):\n\t#{to_change.keys.join("\n\t")}"
end
unless REQUIRED_ENV_VARS.select { |key| ENV[key] }
.blank?
exit 1
end
end
def self.new_session_secret
SecureRandom.hex(64)
end
end