envied 0.11.0 → 2.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +0 -55
- data/lib/envied/coercer/envied_string.rb +2 -2
- data/lib/envied/version.rb +1 -1
- data/lib/envied.rb +1 -2
- metadata +9 -35
- data/exe/envied +0 -4
- data/lib/envied/cli.rb +0 -130
- data/lib/envied/env_var_extractor.rb +0 -76
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 2c87382598e109db129b09fd818ed11b729fc427e098e24c05fb3ff8a79e2467
|
4
|
+
data.tar.gz: 314e2eb1c0f14d79746d8f539ac01be80bf341934ab97c031a81ad9eb5f7e478
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8bae1042bb3ca7ed0c245271cd5f52484185062e60aebf3a7a290e1e54c1ddededbf6ab573ec21e69c8991f4b2368a7be88ca43f2c9efbfc59fdcd85ad002a44
|
7
|
+
data.tar.gz: 8bef2ba41094a5ee2f9fa5cee130a85ba99a7a803ffe54700e00a0775b533d425bcbd26ac12845c7065c982b3efd309f56997d2ab69712e4bb985a52a4b47651
|
data/README.md
CHANGED
@@ -8,7 +8,6 @@ For the rationale behind this project, see this [blogpost](http://www.gertgoet.c
|
|
8
8
|
|
9
9
|
* check for presence and correctness of ENV-variables
|
10
10
|
* access to typed ENV-variables (integers, booleans etc. instead of just strings)
|
11
|
-
* check the presence and correctness of a Heroku config
|
12
11
|
|
13
12
|
## Contents
|
14
13
|
|
@@ -19,8 +18,6 @@ For the rationale behind this project, see this [blogpost](http://www.gertgoet.c
|
|
19
18
|
* [Groups](#groups)
|
20
19
|
* [Defaults](#defaults)
|
21
20
|
* [More examples](#more-examples)
|
22
|
-
* [Command-line interface](#command-line-interface)
|
23
|
-
* [How do I...?](#how-do-i)
|
24
21
|
* [Development](#development)
|
25
22
|
|
26
23
|
## Quickstart
|
@@ -183,58 +180,6 @@ As a rule of thumb you should only use defaults:
|
|
183
180
|
* See the [examples](/examples)-folder for a more extensive Envfile
|
184
181
|
* See [the Envfile](https://github.com/eval/bunny_drain/blob/c54d7d977afb5e23a92da7a2fd0d39f6a7e29bf1/Envfile) for the bunny_drain application
|
185
182
|
|
186
|
-
## Command-line interface
|
187
|
-
|
188
|
-
For help on a specific command, use `envied help <command>`.
|
189
|
-
|
190
|
-
```bash
|
191
|
-
$ envied help
|
192
|
-
Commands:
|
193
|
-
envied check # Checks whether you environment contains required variables
|
194
|
-
envied check:heroku # Checks whether a Heroku config contains required variables
|
195
|
-
envied check:heroku:binstub # Generates a shell script for the check:heroku-task
|
196
|
-
envied extract # Grep code to find ENV-variables
|
197
|
-
envied help [COMMAND] # Describe available commands or one specific command
|
198
|
-
envied init # Generates a default Envfile in the current working directory
|
199
|
-
envied init:rails # Generate all files needed for a Rails project
|
200
|
-
envied version, --version, -v # Shows version number
|
201
|
-
```
|
202
|
-
|
203
|
-
## How do I
|
204
|
-
|
205
|
-
### ...find all ENV-variables my app is currently using?
|
206
|
-
|
207
|
-
```
|
208
|
-
$ bundle exec envied extract
|
209
|
-
```
|
210
|
-
|
211
|
-
This comes in handy when you're not using ENVied yet. It will find all `ENV['KEY']` and `ENV.fetch('KEY')` statements in your project.
|
212
|
-
|
213
|
-
It assumes a standard project layout (see the default value for the globs-option).
|
214
|
-
|
215
|
-
### ...check the config of a Heroku app?
|
216
|
-
|
217
|
-
The easiest/quickest is to run:
|
218
|
-
|
219
|
-
```
|
220
|
-
$ heroku config --json | bundle exec envied check:heroku
|
221
|
-
```
|
222
|
-
|
223
|
-
This is equivalent to having the heroku config as your local environment and running `envied check:heroku --groups default production`.
|
224
|
-
|
225
|
-
You want to run this right before a deploy to Heroku. This prevents that your app will crash during bootup because ENV-variables are missing from heroku config.
|
226
|
-
|
227
|
-
You can turn the above into a handy binstub like so:
|
228
|
-
```
|
229
|
-
$ bundle exec envied check:heroku:binstub
|
230
|
-
# created bin/heroku-env-check
|
231
|
-
```
|
232
|
-
|
233
|
-
This way you can do stuff like:
|
234
|
-
```
|
235
|
-
$ ./bin/heroku-env-check && git push live master
|
236
|
-
```
|
237
|
-
|
238
183
|
## Development
|
239
184
|
|
240
185
|
- `bin/setup`
|
@@ -27,8 +27,8 @@ class ENVied::Coercer::ENViedString
|
|
27
27
|
end
|
28
28
|
|
29
29
|
def to_hash(str)
|
30
|
-
require '
|
31
|
-
::
|
30
|
+
require 'uri'
|
31
|
+
::URI.decode_www_form(str).map { |key, values| [key, values[0]] }.to_h
|
32
32
|
end
|
33
33
|
|
34
34
|
def to_string(str)
|
data/lib/envied/version.rb
CHANGED
data/lib/envied.rb
CHANGED
@@ -1,5 +1,4 @@
|
|
1
1
|
require 'envied/version'
|
2
|
-
require 'envied/cli'
|
3
2
|
require 'envied/env_proxy'
|
4
3
|
require 'envied/coercer'
|
5
4
|
require 'envied/coercer/envied_string'
|
@@ -62,7 +61,7 @@ class ENVied
|
|
62
61
|
if defined?(ActiveSupport::Deprecation.warn) && !required?
|
63
62
|
ActiveSupport::Deprecation.warn(<<~MSG)
|
64
63
|
It's no longer recommended to `ENVied.require` within ENVied.springify's
|
65
|
-
block.
|
64
|
+
block.
|
66
65
|
MSG
|
67
66
|
end
|
68
67
|
if spring_enabled?
|
metadata
CHANGED
@@ -1,67 +1,42 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: envied
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 2.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Gert Goet
|
8
8
|
- Javier Julio
|
9
|
-
|
10
|
-
bindir: exe
|
9
|
+
bindir: bin
|
11
10
|
cert_chain: []
|
12
|
-
date:
|
13
|
-
dependencies:
|
14
|
-
- !ruby/object:Gem::Dependency
|
15
|
-
name: thor
|
16
|
-
requirement: !ruby/object:Gem::Requirement
|
17
|
-
requirements:
|
18
|
-
- - ">="
|
19
|
-
- !ruby/object:Gem::Version
|
20
|
-
version: '0.15'
|
21
|
-
- - "<"
|
22
|
-
- !ruby/object:Gem::Version
|
23
|
-
version: '2.0'
|
24
|
-
type: :runtime
|
25
|
-
prerelease: false
|
26
|
-
version_requirements: !ruby/object:Gem::Requirement
|
27
|
-
requirements:
|
28
|
-
- - ">="
|
29
|
-
- !ruby/object:Gem::Version
|
30
|
-
version: '0.15'
|
31
|
-
- - "<"
|
32
|
-
- !ruby/object:Gem::Version
|
33
|
-
version: '2.0'
|
11
|
+
date: 1980-01-02 00:00:00.000000000 Z
|
12
|
+
dependencies: []
|
34
13
|
description: Ensure presence and type of your app's ENV-variables.
|
35
14
|
email:
|
36
15
|
- gert@thinkcreate.nl
|
37
16
|
- jjfutbol@gmail.com
|
38
|
-
executables:
|
39
|
-
- envied
|
17
|
+
executables: []
|
40
18
|
extensions: []
|
41
19
|
extra_rdoc_files: []
|
42
20
|
files:
|
43
21
|
- LICENSE.txt
|
44
22
|
- README.md
|
45
|
-
- exe/envied
|
46
23
|
- lib/envied.rb
|
47
|
-
- lib/envied/cli.rb
|
48
24
|
- lib/envied/coercer.rb
|
49
25
|
- lib/envied/coercer/envied_string.rb
|
50
26
|
- lib/envied/configuration.rb
|
51
27
|
- lib/envied/env_proxy.rb
|
52
|
-
- lib/envied/env_var_extractor.rb
|
53
28
|
- lib/envied/variable.rb
|
54
29
|
- lib/envied/version.rb
|
55
30
|
homepage: https://github.com/javierjulio/envied
|
56
31
|
licenses:
|
57
32
|
- MIT
|
58
33
|
metadata:
|
59
|
-
|
34
|
+
homepage_uri: https://github.com/javierjulio/envied
|
35
|
+
source_code_uri: https://github.com/javierjulio/envied.git
|
60
36
|
bug_tracker_uri: https://github.com/javierjulio/envied/issues
|
61
37
|
changelog_uri: https://github.com/javierjulio/envied/blob/master/CHANGELOG.md
|
62
38
|
wiki_uri: https://github.com/javierjulio/envied/wiki
|
63
39
|
rubygems_mfa_required: 'true'
|
64
|
-
post_install_message:
|
65
40
|
rdoc_options: []
|
66
41
|
require_paths:
|
67
42
|
- lib
|
@@ -69,15 +44,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
69
44
|
requirements:
|
70
45
|
- - ">="
|
71
46
|
- !ruby/object:Gem::Version
|
72
|
-
version: '3.
|
47
|
+
version: '3.2'
|
73
48
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
74
49
|
requirements:
|
75
50
|
- - ">="
|
76
51
|
- !ruby/object:Gem::Version
|
77
52
|
version: '0'
|
78
53
|
requirements: []
|
79
|
-
rubygems_version: 3.
|
80
|
-
signing_key:
|
54
|
+
rubygems_version: 3.6.9
|
81
55
|
specification_version: 4
|
82
56
|
summary: Ensure presence and type of ENV-variables
|
83
57
|
test_files: []
|
data/exe/envied
DELETED
data/lib/envied/cli.rb
DELETED
@@ -1,130 +0,0 @@
|
|
1
|
-
require 'thor'
|
2
|
-
require 'json'
|
3
|
-
require 'envied/env_var_extractor'
|
4
|
-
|
5
|
-
class ENVied
|
6
|
-
class Cli < Thor
|
7
|
-
include Thor::Actions
|
8
|
-
source_root File.expand_path('../templates', __FILE__)
|
9
|
-
|
10
|
-
desc "version, --version, -v", "Shows version number"
|
11
|
-
def version
|
12
|
-
puts ENVied::VERSION
|
13
|
-
end
|
14
|
-
map %w(-v --version) => :version
|
15
|
-
|
16
|
-
desc "extract", "Grep code to find ENV-variables"
|
17
|
-
long_desc <<-LONG
|
18
|
-
Greps source-files to find all ENV-variables your code is using.
|
19
|
-
|
20
|
-
This task helps you find variables to put in your Envfile.
|
21
|
-
|
22
|
-
By default the test/spec-folders are excluded. Use `--tests` to include them.
|
23
|
-
LONG
|
24
|
-
option :globs, type: :array, default: ENVied::EnvVarExtractor.defaults[:globs], banner: "*.* lib/*"
|
25
|
-
option :tests, type: :boolean, default: false, desc: "include tests/specs"
|
26
|
-
def extract
|
27
|
-
globs = options[:globs]
|
28
|
-
globs << "{test,spec}/*" if options[:tests]
|
29
|
-
var_occurrences = ENVied::EnvVarExtractor.new(globs: globs).extract
|
30
|
-
|
31
|
-
puts "Found %d occurrences of %d variables:" % [var_occurrences.values.flatten.size, var_occurrences.size]
|
32
|
-
var_occurrences.sort.each do |var, occs|
|
33
|
-
puts var
|
34
|
-
occs.sort_by{|i| i[:path].size }.each do |occ|
|
35
|
-
puts "* %s:%s" % occ.values_at(:path, :line)
|
36
|
-
end
|
37
|
-
puts
|
38
|
-
end
|
39
|
-
end
|
40
|
-
|
41
|
-
desc "init", "Generates a default Envfile in the current working directory"
|
42
|
-
def init
|
43
|
-
puts "Writing Envfile to #{File.expand_path('Envfile')}"
|
44
|
-
template("Envfile.tt")
|
45
|
-
|
46
|
-
puts "Add the following snippet (or similar) to your app's initialization:"
|
47
|
-
puts "ENVied.require(*ENV['ENVIED_GROUPS'] || [:default, ENV['RACK_ENV']])"
|
48
|
-
end
|
49
|
-
|
50
|
-
desc "init:rails", "Generate all files needed for a Rails project"
|
51
|
-
define_method "init:rails" do
|
52
|
-
puts "Writing Envfile to #{File.expand_path('Envfile')}"
|
53
|
-
template("Envfile.tt")
|
54
|
-
inject_into_file "config/application.rb", "\nENVied.require(*ENV['ENVIED_GROUPS'] || Rails.groups)", after: /^ *Bundler.require.+$/
|
55
|
-
legacy_initializer = Dir['config/initializers/*envied*.rb'].first
|
56
|
-
if legacy_initializer && File.exists?(legacy_initializer)
|
57
|
-
puts "Removing 'ENVied.require' from #{legacy_initializer.inspect}."
|
58
|
-
puts "(you might want to remove the whole file)"
|
59
|
-
comment_lines legacy_initializer, /ENVied.require/
|
60
|
-
end
|
61
|
-
end
|
62
|
-
|
63
|
-
desc "check", "Checks whether you environment contains required variables"
|
64
|
-
long_desc <<-LONG
|
65
|
-
Checks whether required variables are present and valid in your shell.
|
66
|
-
|
67
|
-
On success the process will exit with status 0.
|
68
|
-
Else the missing/invalid variables will be shown, and the process will exit with status 1.
|
69
|
-
LONG
|
70
|
-
option :groups, type: :array, desc: "uses ENV['ENVIED_GROUPS'] as default if present", default: ENV['ENVIED_GROUPS'] || %w(default), banner: 'default production'
|
71
|
-
option :quiet, type: :boolean, desc: 'Communicate success of the check only via the exit status.'
|
72
|
-
def check
|
73
|
-
ENVied.require(*options[:groups])
|
74
|
-
unless options[:quiet]
|
75
|
-
puts "All variables for group(s) #{options[:groups]} are present and valid"
|
76
|
-
end
|
77
|
-
end
|
78
|
-
|
79
|
-
desc "check:heroku", "Checks whether a Heroku config contains required variables"
|
80
|
-
long_desc <<-LONG
|
81
|
-
Checks the config of your Heroku app against the local Envfile.
|
82
|
-
|
83
|
-
The Heroku config should be piped to this task:
|
84
|
-
|
85
|
-
heroku config --json | bundle exec envied check:heroku
|
86
|
-
|
87
|
-
Use the check:heroku:binstub-task to turn this into a bash-script.
|
88
|
-
|
89
|
-
On success the process will exit with status 0.
|
90
|
-
Else the missing/invalid variables will be shown, and the process will exit with status 1.
|
91
|
-
LONG
|
92
|
-
option :groups, type: :array, default: %w(default production), banner: 'default production'
|
93
|
-
option :quiet, type: :boolean, desc: 'Communicate success of the check only via the exit status.'
|
94
|
-
define_method "check:heroku" do
|
95
|
-
if STDIN.tty?
|
96
|
-
error "Please pipe to this task i.e. `heroku config --json | bundle exec envied check:heroku`"
|
97
|
-
exit 1
|
98
|
-
end
|
99
|
-
heroku_env = JSON.parse(STDIN.read)
|
100
|
-
ENV.replace(heroku_env)
|
101
|
-
|
102
|
-
requested_groups = ENV['ENVIED_GROUPS'] || options[:groups]
|
103
|
-
ENVied.require(*requested_groups)
|
104
|
-
unless options[:quiet]
|
105
|
-
puts "All variables for group(s) #{requested_groups} are present and valid in your Heroku app"
|
106
|
-
end
|
107
|
-
end
|
108
|
-
|
109
|
-
desc "check:heroku:binstub", "Generates a shell script for the check:heroku-task"
|
110
|
-
long_desc <<-LONG
|
111
|
-
Generates a shell script to check the Heroku config against the local Envfile.
|
112
|
-
|
113
|
-
The same as the check:heroku-task, but all in one script (no need to pipe `heroku config --json` to it etc.).
|
114
|
-
LONG
|
115
|
-
option :dest, banner: "where to put the script", desc: "Default: bin/<app>-env-check or bin/heroku-env-check"
|
116
|
-
option :app, banner: "name of Heroku app", desc: "uses ENV['HEROKU_APP'] as default if present", default: ENV['HEROKU_APP']
|
117
|
-
option :groups, type: :array, default: %w(default production), banner: 'default production'
|
118
|
-
define_method "check:heroku:binstub" do
|
119
|
-
require 'fileutils'
|
120
|
-
@app = options[:app]
|
121
|
-
@dest = options[:dest]
|
122
|
-
@dest ||= File.join(*%W(bin #{(@app || 'heroku')}-env-check))
|
123
|
-
@groups = options[:groups]
|
124
|
-
|
125
|
-
full_dest = File.expand_path(@dest)
|
126
|
-
template("heroku-env-check.tt", full_dest)
|
127
|
-
FileUtils.chmod 0755, full_dest
|
128
|
-
end
|
129
|
-
end
|
130
|
-
end
|
@@ -1,76 +0,0 @@
|
|
1
|
-
class ENVied
|
2
|
-
class EnvVarExtractor
|
3
|
-
def self.defaults
|
4
|
-
@defaults ||= begin
|
5
|
-
{
|
6
|
-
extensions: %w(ru thor rake rb yml ruby yaml erb builder markerb haml),
|
7
|
-
globs: %w(*.* Thorfile Rakefile {app,config,db,lib,script}/*)
|
8
|
-
}
|
9
|
-
end
|
10
|
-
end
|
11
|
-
|
12
|
-
def defaults
|
13
|
-
self.class.defaults
|
14
|
-
end
|
15
|
-
|
16
|
-
attr_reader :globs, :extensions
|
17
|
-
|
18
|
-
def initialize(**options)
|
19
|
-
@globs = options.fetch(:globs, self.defaults[:globs])
|
20
|
-
@extensions = options.fetch(:extensions, self.defaults[:extensions])
|
21
|
-
end
|
22
|
-
|
23
|
-
def self.extract_from(globs, **options)
|
24
|
-
new(options.merge(globs: Array(globs))).extract
|
25
|
-
end
|
26
|
-
|
27
|
-
# Greps all ENV-variables from a line of text.
|
28
|
-
# Captures 'A' in lines like `ENV['A']`, but also `ENV.fetch('A')`.
|
29
|
-
#
|
30
|
-
# @param line [String] the line to grep
|
31
|
-
#
|
32
|
-
# @example
|
33
|
-
# extractor.new.capture_variables("config.force_ssl = ENV['FORCE_SSL']")
|
34
|
-
# # => ["FORCE_SSL"]
|
35
|
-
#
|
36
|
-
# @return [Array<String>] the names o
|
37
|
-
def capture_variables(line)
|
38
|
-
line.scan(/ENV(?:\[|\.fetch\()['"]([^'"]+)['"]/).flatten
|
39
|
-
end
|
40
|
-
|
41
|
-
# Extract all keys recursively from files found via `globs`.
|
42
|
-
# Any occurrence of `ENV['A']` or `ENV.fetch('A')`, will result
|
43
|
-
# in 'A' being extracted.
|
44
|
-
#
|
45
|
-
# @param globs [Array<String>] the collection of globs
|
46
|
-
#
|
47
|
-
# @example
|
48
|
-
# EnvVarExtractor.new.extract(*%w(app lib))
|
49
|
-
# # => {'A' => [{:path => 'app/models/user.rb', :line => 2}, {:path => ..., :line => ...}],
|
50
|
-
# 'B' => [{:path => 'config/application.rb', :line => 12}]}
|
51
|
-
#
|
52
|
-
# @return [<Hash{String => Array<String => Array>}>] the list of items.
|
53
|
-
def extract(globs = self.globs)
|
54
|
-
results = Hash.new { |hash, key| hash[key] = [] }
|
55
|
-
|
56
|
-
Array(globs).each do |glob|
|
57
|
-
Dir.glob(glob).each do |item|
|
58
|
-
next if File.basename(item)[0] == ?.
|
59
|
-
|
60
|
-
if File.directory?(item)
|
61
|
-
results.merge!(extract("#{item}/*"))
|
62
|
-
else
|
63
|
-
next unless extensions.detect {|ext| File.extname(item)[ext] }
|
64
|
-
File.readlines(item).each_with_index do |line, ix|
|
65
|
-
capture_variables(line).each do |variable|
|
66
|
-
results[variable] << { :path => item, :line => ix.succ }
|
67
|
-
end
|
68
|
-
end
|
69
|
-
end
|
70
|
-
end
|
71
|
-
end
|
72
|
-
|
73
|
-
results
|
74
|
-
end
|
75
|
-
end
|
76
|
-
end
|