env-checker 0.1.1 → 0.1.2
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/.rubocop_todo.yml +30 -13
- data/Gemfile.lock +2 -1
- data/README.md +37 -8
- data/env-checker.gemspec +14 -2
- data/exe/env-checker +5 -0
- data/lib/env_checker.rb +52 -17
- data/lib/env_checker/cli.rb +21 -0
- data/lib/env_checker/configuration.rb +2 -1
- data/lib/env_checker/version.rb +1 -1
- metadata +27 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3b69d2729808eb8df421332bd614066c161fdeda
|
4
|
+
data.tar.gz: 6a78a5b6c6e31ba5e25f7e8f52d0e92797f46197
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6377aec544e2d13020113253fdf63eb35fefa0a008ce0067e99c96599bb2bb81a7894bfc9eaf00ff109e5e23d1d64a8ff7663539d7be8be8ccb2c71d06b6b0a1
|
7
|
+
data.tar.gz: c38c14c7ea5b277e1658718c47e70d1a1f2b6d50cfac3f66e1d3578bf24ac6c40273353f05fc599f890c026b8e1cfb3ab47240ab607cb8b220111974c689bc91
|
data/.rubocop_todo.yml
CHANGED
@@ -1,18 +1,39 @@
|
|
1
1
|
# This configuration was generated by
|
2
2
|
# `rubocop --auto-gen-config`
|
3
|
-
# on 2016-11-
|
3
|
+
# on 2016-11-08 20:21:40 +0100 using RuboCop version 0.45.0.
|
4
4
|
# The point is for the user to remove these configuration records
|
5
5
|
# one by one as the offenses are removed from the code base.
|
6
6
|
# Note that changes in the inspected code, or installation of new
|
7
7
|
# versions of RuboCop, may require this file to be generated again.
|
8
8
|
|
9
9
|
# Offense count: 2
|
10
|
+
Metrics/AbcSize:
|
11
|
+
Max: 16
|
12
|
+
|
13
|
+
# Offense count: 1
|
14
|
+
# Configuration parameters: CountComments.
|
15
|
+
Metrics/BlockLength:
|
16
|
+
Max: 30
|
17
|
+
|
18
|
+
# Offense count: 1
|
10
19
|
# Configuration parameters: AllowHeredoc, AllowURI, URISchemes, IgnoreCopDirectives.
|
11
20
|
# URISchemes: http, https
|
12
21
|
Metrics/LineLength:
|
13
|
-
Max:
|
22
|
+
Max: 81
|
23
|
+
|
24
|
+
# Offense count: 2
|
25
|
+
# Configuration parameters: CountComments.
|
26
|
+
Metrics/MethodLength:
|
27
|
+
Max: 11
|
14
28
|
|
15
|
-
# Offense count:
|
29
|
+
# Offense count: 1
|
30
|
+
# Cop supports --auto-correct.
|
31
|
+
# Configuration parameters: AllowForAlignment, ForceEqualSignAlignment.
|
32
|
+
Style/ExtraSpacing:
|
33
|
+
Exclude:
|
34
|
+
- 'env-checker.gemspec'
|
35
|
+
|
36
|
+
# Offense count: 15
|
16
37
|
# Cop supports --auto-correct.
|
17
38
|
# Configuration parameters: EnforcedStyle, SupportedStyles.
|
18
39
|
# SupportedStyles: when_needed, always
|
@@ -22,7 +43,9 @@ Style/FrozenStringLiteralComment:
|
|
22
43
|
- 'Rakefile'
|
23
44
|
- 'bin/console'
|
24
45
|
- 'env-checker.gemspec'
|
46
|
+
- 'exe/env-checker'
|
25
47
|
- 'lib/env_checker.rb'
|
48
|
+
- 'lib/env_checker/cli.rb'
|
26
49
|
- 'lib/env_checker/configuration.rb'
|
27
50
|
- 'lib/env_checker/missing_keys_error.rb'
|
28
51
|
- 'lib/env_checker/version.rb'
|
@@ -32,7 +55,7 @@ Style/FrozenStringLiteralComment:
|
|
32
55
|
- 'spec/env_checker_spec.rb'
|
33
56
|
- 'spec/spec_helper.rb'
|
34
57
|
|
35
|
-
# Offense count:
|
58
|
+
# Offense count: 5
|
36
59
|
# Cop supports --auto-correct.
|
37
60
|
# Configuration parameters: SupportedStyles, UseHashRocketsWithSymbolValues, PreferHashRocketsForNonAlnumEndingSymbols.
|
38
61
|
# SupportedStyles: ruby19, hash_rockets, no_mixed_keys, ruby19_no_mixed_keys
|
@@ -45,13 +68,6 @@ Style/MutableConstant:
|
|
45
68
|
Exclude:
|
46
69
|
- 'lib/env_checker/version.rb'
|
47
70
|
|
48
|
-
# Offense count: 2
|
49
|
-
# Cop supports --auto-correct.
|
50
|
-
# Configuration parameters: PreferredDelimiters.
|
51
|
-
Style/PercentLiteralDelimiters:
|
52
|
-
Exclude:
|
53
|
-
- 'env-checker.gemspec'
|
54
|
-
|
55
71
|
# Offense count: 1
|
56
72
|
# Cop supports --auto-correct.
|
57
73
|
# Configuration parameters: SupportedStyles.
|
@@ -59,8 +75,9 @@ Style/PercentLiteralDelimiters:
|
|
59
75
|
Style/RaiseArgs:
|
60
76
|
EnforcedStyle: compact
|
61
77
|
|
62
|
-
# Offense count:
|
78
|
+
# Offense count: 1
|
63
79
|
# Cop supports --auto-correct.
|
64
|
-
|
80
|
+
# Configuration parameters: AllowForAlignment.
|
81
|
+
Style/SpaceAroundOperators:
|
65
82
|
Exclude:
|
66
83
|
- 'env-checker.gemspec'
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -8,10 +8,21 @@
|
|
8
8
|
[](https://github.com/ryanfox1985/env-checker/blob/master/LICENSE)
|
9
9
|
|
10
10
|
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
11
|
+
Don't forget your environment variables when your app changes the environment.
|
12
|
+
When you are developing a new feature if your app have some environments like
|
13
|
+
test, staging and production is easy to forget an environment variable in the
|
14
|
+
middle of the process. Also when you migrate the app to another server is easy
|
15
|
+
to forget an environment variable.
|
16
|
+
|
17
|
+
You can define two variable lists:
|
18
|
+
- **required_variables:** These variables are mandatory (Your app cannot run
|
19
|
+
without these variables, like `DATABASE_URL`)
|
20
|
+
- **optional_variables:** These variables are from secondary services (Your app
|
21
|
+
can run without these variables, like some `THRESHOLD`)
|
22
|
+
|
23
|
+
All the missing variables are notified by default in the `STDERR`. When a
|
24
|
+
required variable is missing the gem raises an error `MissingKeysError` and
|
25
|
+
stops the application.
|
15
26
|
|
16
27
|
## Installation
|
17
28
|
|
@@ -44,8 +55,16 @@ environment variables. Example:
|
|
44
55
|
require 'env_checker'
|
45
56
|
|
46
57
|
EnvChecker.configure do |config|
|
47
|
-
config.optional_variables = %w(
|
48
|
-
config.required_variables = %w(
|
58
|
+
config.optional_variables = %w(MyOptVar1 MyOptVar2)
|
59
|
+
config.required_variables = %w(MyReqVar1 MyReqVar2)
|
60
|
+
|
61
|
+
# ENVIRONMENT
|
62
|
+
# ===========
|
63
|
+
# Default is:
|
64
|
+
# environment = ENV['RACK_ENV'] || ENV['RAILS_ENV']
|
65
|
+
#
|
66
|
+
# Other possible value
|
67
|
+
# config.environment = 'MyEnv'
|
49
68
|
|
50
69
|
# LOGGER
|
51
70
|
# ======
|
@@ -73,9 +92,19 @@ end
|
|
73
92
|
```
|
74
93
|
|
75
94
|
|
76
|
-
### Standalone and CLI
|
95
|
+
### Standalone and CLI usages
|
96
|
+
|
97
|
+
#### Check optional and required variables
|
98
|
+
|
99
|
+
$ env-checker check --optional MyOptVar1 MyOptVar2 --required MyReqVar1 MyReqVar2
|
100
|
+
|
101
|
+
#### Show help
|
102
|
+
|
103
|
+
$ env-checker help
|
104
|
+
|
105
|
+
#### Show version
|
77
106
|
|
78
|
-
|
107
|
+
$ env-checker version
|
79
108
|
|
80
109
|
|
81
110
|
## Contributing
|
data/env-checker.gemspec
CHANGED
@@ -9,8 +9,18 @@ Gem::Specification.new do |spec|
|
|
9
9
|
spec.authors = ['Guillermo Guerrero Ibarra']
|
10
10
|
spec.email = ['guillermo@guerreroibarra.com']
|
11
11
|
|
12
|
-
spec.summary =
|
13
|
-
|
12
|
+
spec.summary = <<-EOF
|
13
|
+
Don't forget your environment variables when your app changes the
|
14
|
+
environment.
|
15
|
+
EOF
|
16
|
+
|
17
|
+
spec.description = <<-EOF
|
18
|
+
When you are developing a new feature if your app have some environments
|
19
|
+
like test, staging and production is easy to forget an environment variable
|
20
|
+
in the middle of the process. Also when you migrate the app to another
|
21
|
+
server is easy to forget an environment variable.
|
22
|
+
EOF
|
23
|
+
|
14
24
|
spec.homepage = 'https://github.com/ryanfox1985/env-checker'
|
15
25
|
spec.license = 'MIT'
|
16
26
|
|
@@ -20,7 +30,9 @@ Gem::Specification.new do |spec|
|
|
20
30
|
spec.bindir = 'exe'
|
21
31
|
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
22
32
|
spec.require_paths = ['lib']
|
33
|
+
spec.required_ruby_version = '>= 2.0.0'
|
23
34
|
|
35
|
+
spec.add_runtime_dependency 'thor', '~> 0'
|
24
36
|
spec.add_development_dependency 'bundler', '~> 1.13'
|
25
37
|
spec.add_development_dependency 'rake', '~> 10.0'
|
26
38
|
spec.add_development_dependency 'rspec', '~> 3.0'
|
data/exe/env-checker
ADDED
data/lib/env_checker.rb
CHANGED
@@ -3,12 +3,15 @@ $LOAD_PATH.unshift(File.dirname(__FILE__))
|
|
3
3
|
require 'env_checker/version'
|
4
4
|
require 'env_checker/missing_keys_error'
|
5
5
|
require 'env_checker/configuration'
|
6
|
+
require 'env_checker/cli'
|
6
7
|
|
7
8
|
module EnvChecker
|
8
9
|
class << self
|
9
10
|
attr_accessor :configuration
|
10
11
|
|
11
12
|
def check_environment_variables
|
13
|
+
return true unless configuration
|
14
|
+
|
12
15
|
bov = check_optional_variables
|
13
16
|
brv = check_required_variables
|
14
17
|
|
@@ -20,40 +23,64 @@ module EnvChecker
|
|
20
23
|
yield(configuration)
|
21
24
|
end
|
22
25
|
|
26
|
+
def cli_configure_and_check(options)
|
27
|
+
return if !options[:optional] && !options[:required]
|
28
|
+
|
29
|
+
self.configuration = create_config_from_parameters(options)
|
30
|
+
|
31
|
+
begin
|
32
|
+
check_environment_variables ? exit(true) : exit(1)
|
33
|
+
rescue EnvChecker::MissingKeysError
|
34
|
+
exit 2
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
23
38
|
private
|
24
39
|
|
40
|
+
def create_config_from_parameters(options)
|
41
|
+
config = Configuration.new
|
42
|
+
config.optional_variables = options[:optional] if options[:optional]
|
43
|
+
config.required_variables = options[:required] if options[:required]
|
44
|
+
|
45
|
+
config
|
46
|
+
end
|
47
|
+
|
25
48
|
def check_optional_variables
|
26
|
-
if
|
27
|
-
|
28
|
-
|
29
|
-
variables: [#{missing_keys}]")
|
49
|
+
return true if
|
50
|
+
!configuration.optional_variables ||
|
51
|
+
configuration.optional_variables.empty?
|
30
52
|
|
31
|
-
|
32
|
-
|
53
|
+
missing_keys = missing_keys_env(configuration.optional_variables)
|
54
|
+
log_message(:warning,
|
55
|
+
configuration.environment,
|
56
|
+
"Warning! Missing these optional variables: #{missing_keys}")
|
33
57
|
|
34
|
-
|
58
|
+
missing_keys.empty?
|
35
59
|
end
|
36
60
|
|
37
61
|
def check_required_variables
|
38
|
-
if
|
39
|
-
|
62
|
+
return true if
|
63
|
+
!configuration.required_variables ||
|
64
|
+
configuration.required_variables.empty?
|
65
|
+
|
66
|
+
missing_keys = missing_keys_env(configuration.required_variables)
|
40
67
|
|
41
|
-
|
42
|
-
|
43
|
-
|
68
|
+
if missing_keys.any?
|
69
|
+
log_message(:error,
|
70
|
+
configuration.environment,
|
71
|
+
"Error! Missing these required variables: #{missing_keys}")
|
44
72
|
|
45
|
-
|
46
|
-
end
|
73
|
+
raise MissingKeysError.new(missing_keys)
|
47
74
|
end
|
48
75
|
|
49
76
|
true
|
50
77
|
end
|
51
78
|
|
52
|
-
def log_message(type,
|
53
|
-
return unless
|
79
|
+
def log_message(type, environment, error_message)
|
80
|
+
return unless error_message
|
54
81
|
|
82
|
+
message = format_error_message(environment, error_message)
|
55
83
|
# TODO: add other integrations like slack, email...
|
56
|
-
|
57
84
|
return unless configuration.logger
|
58
85
|
|
59
86
|
case type
|
@@ -66,6 +93,14 @@ module EnvChecker
|
|
66
93
|
end
|
67
94
|
end
|
68
95
|
|
96
|
+
def format_error_message(environment, error_message)
|
97
|
+
messages = []
|
98
|
+
messages << '[EnvChecker]'
|
99
|
+
messages << "[#{environment}]" if environment
|
100
|
+
messages << error_message
|
101
|
+
messages.join(' ')
|
102
|
+
end
|
103
|
+
|
69
104
|
def missing_keys_env(keys)
|
70
105
|
keys.flatten - ::ENV.keys
|
71
106
|
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
require 'thor'
|
2
|
+
|
3
|
+
class CLI < Thor
|
4
|
+
desc 'version', 'EnvChecker version.'
|
5
|
+
def version
|
6
|
+
puts "EnvChecker #{EnvChecker::VERSION}"
|
7
|
+
end
|
8
|
+
|
9
|
+
option :required, :aliases => :r, :type => :array
|
10
|
+
option :optional, :aliases => :o, :type => :array
|
11
|
+
desc 'check', 'check environment variables'
|
12
|
+
def check
|
13
|
+
output = []
|
14
|
+
output << 'Variables: '
|
15
|
+
output << "- Optional: #{options[:optional]}" if options[:optional]
|
16
|
+
output << "- Required: #{options[:required]}" if options[:required]
|
17
|
+
puts output.join("\n")
|
18
|
+
|
19
|
+
EnvChecker.cli_configure_and_check(options)
|
20
|
+
end
|
21
|
+
end
|
@@ -2,10 +2,11 @@ require 'logger'
|
|
2
2
|
|
3
3
|
module EnvChecker
|
4
4
|
class Configuration
|
5
|
-
attr_accessor :required_variables, :optional_variables, :logger
|
5
|
+
attr_accessor :required_variables, :optional_variables, :logger, :environment
|
6
6
|
|
7
7
|
# Has default settings, which can be overridden in the initializer.
|
8
8
|
def initialize
|
9
|
+
@environment = ENV['RACK_ENV'] || ENV['RAILS_ENV']
|
9
10
|
@required_variables = []
|
10
11
|
@optional_variables = []
|
11
12
|
@logger = Logger.new(STDERR)
|
data/lib/env_checker/version.rb
CHANGED
metadata
CHANGED
@@ -1,15 +1,29 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: env-checker
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Guillermo Guerrero Ibarra
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-11-
|
11
|
+
date: 2016-11-08 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: thor
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
13
27
|
- !ruby/object:Gem::Dependency
|
14
28
|
name: bundler
|
15
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -94,10 +108,15 @@ dependencies:
|
|
94
108
|
- - "~>"
|
95
109
|
- !ruby/object:Gem::Version
|
96
110
|
version: '0'
|
97
|
-
description:
|
111
|
+
description: |2
|
112
|
+
When you are developing a new feature if your app have some environments
|
113
|
+
like test, staging and production is easy to forget an environment variable
|
114
|
+
in the middle of the process. Also when you migrate the app to another
|
115
|
+
server is easy to forget an environment variable.
|
98
116
|
email:
|
99
117
|
- guillermo@guerreroibarra.com
|
100
|
-
executables:
|
118
|
+
executables:
|
119
|
+
- env-checker
|
101
120
|
extensions: []
|
102
121
|
extra_rdoc_files: []
|
103
122
|
files:
|
@@ -115,7 +134,9 @@ files:
|
|
115
134
|
- bin/console
|
116
135
|
- bin/setup
|
117
136
|
- env-checker.gemspec
|
137
|
+
- exe/env-checker
|
118
138
|
- lib/env_checker.rb
|
139
|
+
- lib/env_checker/cli.rb
|
119
140
|
- lib/env_checker/configuration.rb
|
120
141
|
- lib/env_checker/missing_keys_error.rb
|
121
142
|
- lib/env_checker/version.rb
|
@@ -131,7 +152,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
131
152
|
requirements:
|
132
153
|
- - ">="
|
133
154
|
- !ruby/object:Gem::Version
|
134
|
-
version:
|
155
|
+
version: 2.0.0
|
135
156
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
136
157
|
requirements:
|
137
158
|
- - ">="
|
@@ -142,5 +163,5 @@ rubyforge_project:
|
|
142
163
|
rubygems_version: 2.5.1
|
143
164
|
signing_key:
|
144
165
|
specification_version: 4
|
145
|
-
summary:
|
166
|
+
summary: Don't forget your environment variables when your app changes the environment.
|
146
167
|
test_files: []
|