dotenv-rails 2.2.0 → 2.7.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/README.md +82 -11
- data/lib/dotenv/rails.rb +6 -5
- metadata +7 -8
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 3995cb4fa7ede006c718bcd9391fca1d73470aafd60d503fe8ad7c3fa7b8deb6
|
4
|
+
data.tar.gz: 7dc12095713e14bf93fefe497168678dab88d7f839ccce43702885d5873e8900
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 53280479e8c0600acaebb33ccf435c0f696a9bde8a76dc76218ee8cc216c5c8c51a0278bdc89438ed2a02ea1652c179afcb10ed96393bac2a120727d6d105ca7
|
7
|
+
data.tar.gz: f0f62ccf99cbd0753b0f0ec0113877dc9d18f7239b480c9a1942144a84ff5563b0706fad663f8b16db3c24fceadecc36e20732dc0a5b5353f874b961daedd95f
|
data/README.md
CHANGED
@@ -1,6 +1,4 @@
|
|
1
|
-
# dotenv [![Build Status](https://secure.travis-ci.org/bkeepers/dotenv.
|
2
|
-
|
3
|
-
[![Join the chat at https://gitter.im/bkeepers/dotenv](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/bkeepers/dotenv?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
|
1
|
+
# dotenv [![Build Status](https://secure.travis-ci.org/bkeepers/dotenv.svg?branch=master)](https://travis-ci.org/bkeepers/dotenv) [![Gem Version](https://badge.fury.io/rb/dotenv.svg)](https://badge.fury.io/rb/dotenv) [![Join the chat at https://gitter.im/bkeepers/dotenv](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/bkeepers/dotenv?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
|
4
2
|
|
5
3
|
Shim to load environment variables from `.env` into `ENV` in *development*.
|
6
4
|
|
@@ -64,7 +62,7 @@ Dotenv.load
|
|
64
62
|
|
65
63
|
By default, `load` will look for a file called `.env` in the current working directory. Pass in multiple files and they will be loaded in order. The first value set for a variable will win.
|
66
64
|
|
67
|
-
```
|
65
|
+
```ruby
|
68
66
|
require 'dotenv'
|
69
67
|
Dotenv.load('file1.env', 'file2.env')
|
70
68
|
```
|
@@ -72,7 +70,13 @@ Dotenv.load('file1.env', 'file2.env')
|
|
72
70
|
Alternatively, you can use the `dotenv` executable to launch your application:
|
73
71
|
|
74
72
|
```shell
|
75
|
-
$ dotenv ./script.
|
73
|
+
$ dotenv ./script.rb
|
74
|
+
```
|
75
|
+
|
76
|
+
The `dotenv` executable also accepts a single flag, `-f`. Its value should be a comma-separated list of configuration files, in the order of most important to least. All of the files must exist. There _must_ be a space between the flag and its value.
|
77
|
+
|
78
|
+
```
|
79
|
+
$ dotenv -f ".env.local,.env" ./script.rb
|
76
80
|
```
|
77
81
|
|
78
82
|
To ensure `.env` is loaded in rake, load the tasks:
|
@@ -112,9 +116,21 @@ export SECRET_KEY=YOURSECRETKEYGOESHERE
|
|
112
116
|
If you need multiline variables, for example private keys, you can double quote strings and use the `\n` character for newlines:
|
113
117
|
|
114
118
|
```shell
|
115
|
-
PRIVATE_KEY="-----BEGIN RSA PRIVATE KEY-----\nHkVN9
|
119
|
+
PRIVATE_KEY="-----BEGIN RSA PRIVATE KEY-----\nHkVN9...\n-----END DSA PRIVATE KEY-----\n"
|
120
|
+
```
|
121
|
+
|
122
|
+
Alternatively, multi-line values with line breaks are now supported for quoted values.
|
123
|
+
|
124
|
+
```shell
|
125
|
+
PRIVATE_KEY="-----BEGIN RSA PRIVATE KEY-----
|
126
|
+
...
|
127
|
+
HkVN9...
|
128
|
+
...
|
129
|
+
-----END DSA PRIVATE KEY-----"
|
116
130
|
```
|
117
131
|
|
132
|
+
This is particularly helpful when using the Heroku command line plugin [`heroku-config`](https://github.com/xavdid/heroku-config) to pull configuration variables down that may have line breaks.
|
133
|
+
|
118
134
|
### Command Substitution
|
119
135
|
|
120
136
|
You need to add the output of a command in one of your variables? Simply add it with `$(your_command)`:
|
@@ -147,6 +163,31 @@ SECRET_KEY=YOURSECRETKEYGOESHERE # comment
|
|
147
163
|
SECRET_HASH="something-with-a-#-hash"
|
148
164
|
```
|
149
165
|
|
166
|
+
### Required Keys
|
167
|
+
|
168
|
+
If a particular configuration value is required but not set, it's appropriate to raise an error.
|
169
|
+
|
170
|
+
To require configuration keys:
|
171
|
+
|
172
|
+
```ruby
|
173
|
+
# config/initializers/dotenv.rb
|
174
|
+
|
175
|
+
Dotenv.require_keys("SERVICE_APP_ID", "SERVICE_KEY", "SERVICE_SECRET")
|
176
|
+
```
|
177
|
+
|
178
|
+
If any of the configuration keys above are not set, your application will raise an error during initialization. This method is preferred because it prevents runtime errors in a production application due to improper configuration.
|
179
|
+
|
180
|
+
### Parsing
|
181
|
+
|
182
|
+
To parse a list of env files for programmatic inspection without modifying the ENV:
|
183
|
+
|
184
|
+
```ruby
|
185
|
+
Dotenv.parse(".env.local", ".env")
|
186
|
+
# => {'S3_BUCKET' => 'YOURS3BUCKET', 'SECRET_KEY' => 'YOURSECRETKEYGOESHERE', ...}
|
187
|
+
```
|
188
|
+
|
189
|
+
This method returns a hash of the ENV var name/value pairs.
|
190
|
+
|
150
191
|
## Frequently Answered Questions
|
151
192
|
|
152
193
|
### Can I use dotenv in production?
|
@@ -159,17 +200,47 @@ If you use this gem to handle env vars for multiple Rails environments (developm
|
|
159
200
|
|
160
201
|
### What other .env* files can I use?
|
161
202
|
|
162
|
-
`dotenv-rails` will
|
203
|
+
`dotenv-rails` will override in the following order (highest defined variable overrides lower):
|
204
|
+
|
205
|
+
| Hierarchy Priority | Filename | Environment | Should I `.gitignore`it? | Notes |
|
206
|
+
| ------------------ | ------------------------ | -------------------- | --------------------------------------------------- | ------------------------------------------------------------ |
|
207
|
+
| 1st (highest) | `.env.development.local` | Development | Yes! | Local overrides of environment-specific settings. |
|
208
|
+
| 1st | `.env.test.local` | Test | Yes! | Local overrides of environment-specific settings. |
|
209
|
+
| 1st | `.env.production.local` | Production | Yes! | Local overrides of environment-specific settings. |
|
210
|
+
| 2nd | `.env.local` | Wherever the file is | Definitely. | Local overrides. This file is loaded for all environments _except_ `test`. |
|
211
|
+
| 3rd | `.env.development` | Development | No. | Shared environment-specific settings |
|
212
|
+
| 3rd | `.env.test` | Test | No. | Shared environment-specific settings |
|
213
|
+
| 3rd | `.env.production` | Production | No. | Shared environment-specific settings |
|
214
|
+
| Last | `.env` | All Environments | Depends (See [below](#should-i-commit-my-env-file)) | The Original® |
|
163
215
|
|
164
|
-
- `.env` - The Original®
|
165
|
-
- `.env.development`, `.env.test`, `.env.production` - Environment-specific settings.
|
166
|
-
- `.env.local` - Local overrides. This file is loaded for all environments _except_ `test`.
|
167
|
-
- `.env.development.local`, `.env.test.local`, `.env.production.local` - Local overrides of environment-specific settings.
|
168
216
|
|
169
217
|
### Should I commit my .env file?
|
170
218
|
|
171
219
|
Credentials should only be accessible on the machines that need access to them. Never commit sensitive information to a repository that is not needed by every development machine and server.
|
172
220
|
|
221
|
+
|
222
|
+
You can use the `-t` or `--template` flag on the dotenv cli to create a template of your `.env` file.
|
223
|
+
```shell
|
224
|
+
$ dotenv -t .env
|
225
|
+
```
|
226
|
+
A template will be created in your working directory named `{FINAME}.template`. So in the above example, it would create a `.env.template` file.
|
227
|
+
|
228
|
+
The template will contain all the environment variables in your `.env` file but with their values set to the variable names.
|
229
|
+
|
230
|
+
```shell
|
231
|
+
# .env
|
232
|
+
S3_BUCKET=YOURS3BUCKET
|
233
|
+
SECRET_KEY=YOURSECRETKEYGOESHERE
|
234
|
+
```
|
235
|
+
|
236
|
+
Would become
|
237
|
+
|
238
|
+
```shell
|
239
|
+
# .env.template
|
240
|
+
S3_BUCKET=S3_BUCKET
|
241
|
+
SECRET_KEY=SECRET_KEY
|
242
|
+
```
|
243
|
+
|
173
244
|
Personally, I prefer to commit the `.env` file with development-only settings. This makes it easy for other developers to get started on the project without compromising credentials for other environments. If you follow this advice, make sure that all the credentials for your development environment are different from your other deployments and that the development credentials do not have access to any confidential data.
|
174
245
|
|
175
246
|
### Why is it not overriding existing `ENV` variables?
|
data/lib/dotenv/rails.rb
CHANGED
@@ -9,8 +9,9 @@ require "dotenv"
|
|
9
9
|
#
|
10
10
|
# See https://github.com/bkeepers/dotenv/issues/219
|
11
11
|
if defined?(Rake.application)
|
12
|
-
|
13
|
-
|
12
|
+
if Rake.application.top_level_tasks.grep(/^(parallel:spec|spec(:|$))/).any?
|
13
|
+
Rails.env = ENV["RAILS_ENV"] ||= "test"
|
14
|
+
end
|
14
15
|
end
|
15
16
|
|
16
17
|
Dotenv.instrumenter = ActiveSupport::Notifications
|
@@ -22,7 +23,7 @@ begin
|
|
22
23
|
event = ActiveSupport::Notifications::Event.new(*args)
|
23
24
|
Spring.watch event.payload[:env].filename if Rails.application
|
24
25
|
end
|
25
|
-
rescue LoadError
|
26
|
+
rescue LoadError, ArgumentError
|
26
27
|
# Spring is not available
|
27
28
|
end
|
28
29
|
|
@@ -51,8 +52,6 @@ module Dotenv
|
|
51
52
|
instance.load
|
52
53
|
end
|
53
54
|
|
54
|
-
config.before_configuration { load }
|
55
|
-
|
56
55
|
private
|
57
56
|
|
58
57
|
def dotenv_files
|
@@ -63,5 +62,7 @@ module Dotenv
|
|
63
62
|
root.join(".env")
|
64
63
|
].compact
|
65
64
|
end
|
65
|
+
|
66
|
+
config.before_configuration { load }
|
66
67
|
end
|
67
68
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: dotenv-rails
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.
|
4
|
+
version: 2.7.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Brandon Keepers
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2019-07-31 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: dotenv
|
@@ -16,14 +16,14 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - '='
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: 2.
|
19
|
+
version: 2.7.5
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
24
|
- - '='
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: 2.
|
26
|
+
version: 2.7.5
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: railties
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -33,7 +33,7 @@ dependencies:
|
|
33
33
|
version: '3.2'
|
34
34
|
- - "<"
|
35
35
|
- !ruby/object:Gem::Version
|
36
|
-
version: '
|
36
|
+
version: '6.1'
|
37
37
|
type: :runtime
|
38
38
|
prerelease: false
|
39
39
|
version_requirements: !ruby/object:Gem::Requirement
|
@@ -43,7 +43,7 @@ dependencies:
|
|
43
43
|
version: '3.2'
|
44
44
|
- - "<"
|
45
45
|
- !ruby/object:Gem::Version
|
46
|
-
version: '
|
46
|
+
version: '6.1'
|
47
47
|
- !ruby/object:Gem::Dependency
|
48
48
|
name: spring
|
49
49
|
requirement: !ruby/object:Gem::Requirement
|
@@ -89,8 +89,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
89
89
|
- !ruby/object:Gem::Version
|
90
90
|
version: '0'
|
91
91
|
requirements: []
|
92
|
-
|
93
|
-
rubygems_version: 2.5.2
|
92
|
+
rubygems_version: 3.0.1
|
94
93
|
signing_key:
|
95
94
|
specification_version: 4
|
96
95
|
summary: Autoload dotenv in Rails.
|