env-checker 0.1.6 → 0.1.7
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 +11 -10
- data/Gemfile.lock +1 -1
- data/README.md +18 -0
- data/lib/env_checker.rb +27 -9
- data/lib/env_checker/cli.rb +19 -5
- data/lib/env_checker/configuration.rb +6 -0
- data/lib/env_checker/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f282676d3c5ae43ac48a7f113ee2b431bcc99b8a
|
4
|
+
data.tar.gz: 0eb4785314b9a54a23f18d0f34d8f5e02f11b05b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e8b80854cb56561b72c4392f6b54ba8325e095333822904ccab9258176acce7d07c96a9faaaa2a80678c33e2fda69affdd9174afcebf6e4d825ecc608057422b
|
7
|
+
data.tar.gz: 84f4880d192b258c34b3c3b95d9f74e800fe84c4768cd2be0448110275e340c29c2e861e1abdfea52a4445bf26060b532e8eeaf279bf3e6ff52bbf6b68a12c65
|
data/.rubocop_todo.yml
CHANGED
@@ -1,34 +1,35 @@
|
|
1
1
|
# This configuration was generated by
|
2
2
|
# `rubocop --auto-gen-config`
|
3
|
-
# on 2016-11-
|
3
|
+
# on 2016-11-17 20:42:19 +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
|
-
# Offense count:
|
9
|
+
# Offense count: 3
|
10
10
|
Metrics/AbcSize:
|
11
|
-
Max:
|
11
|
+
Max: 29
|
12
12
|
|
13
13
|
# Offense count: 1
|
14
14
|
# Configuration parameters: CountComments.
|
15
15
|
Metrics/BlockLength:
|
16
16
|
Max: 32
|
17
17
|
|
18
|
-
# Offense count: 1
|
19
|
-
Metrics/CyclomaticComplexity:
|
20
|
-
Max: 7
|
21
|
-
|
22
18
|
# Offense count: 3
|
23
19
|
# Configuration parameters: AllowHeredoc, AllowURI, URISchemes, IgnoreCopDirectives.
|
24
20
|
# URISchemes: http, https
|
25
21
|
Metrics/LineLength:
|
26
22
|
Max: 95
|
27
23
|
|
28
|
-
# Offense count:
|
24
|
+
# Offense count: 5
|
29
25
|
# Configuration parameters: CountComments.
|
30
26
|
Metrics/MethodLength:
|
31
|
-
Max:
|
27
|
+
Max: 22
|
28
|
+
|
29
|
+
# Offense count: 1
|
30
|
+
# Configuration parameters: CountComments.
|
31
|
+
Metrics/ModuleLength:
|
32
|
+
Max: 109
|
32
33
|
|
33
34
|
# Offense count: 1
|
34
35
|
# Cop supports --auto-correct.
|
@@ -44,7 +45,7 @@ Style/ExtraSpacing:
|
|
44
45
|
Style/FrozenStringLiteralComment:
|
45
46
|
Enabled: false
|
46
47
|
|
47
|
-
# Offense count:
|
48
|
+
# Offense count: 12
|
48
49
|
# Cop supports --auto-correct.
|
49
50
|
# Configuration parameters: EnforcedStyle, SupportedStyles, UseHashRocketsWithSymbolValues, PreferHashRocketsForNonAlnumEndingSymbols.
|
50
51
|
# SupportedStyles: ruby19, hash_rockets, no_mixed_keys, ruby19_no_mixed_keys
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -20,10 +20,16 @@ You can define two variable lists:
|
|
20
20
|
- **optional_variables:** These variables are from secondary services (Your app
|
21
21
|
can run without these variables, like some `THRESHOLD`)
|
22
22
|
|
23
|
+
By default `EnvChecker` checks the global environment and after the current
|
24
|
+
or set environment.
|
25
|
+
|
23
26
|
All the missing variables are notified by default in the `STDERR`. When a
|
24
27
|
required variable is missing the gem raises an error `MissingKeysError` and
|
25
28
|
stops the application.
|
26
29
|
|
30
|
+
By convention all the environment variable names must be in up case, the gem
|
31
|
+
internally parse the required_variables and optional_variables to up case.
|
32
|
+
|
27
33
|
## Installation
|
28
34
|
|
29
35
|
Add this line to your application's Gemfile:
|
@@ -89,6 +95,18 @@ Inline passing the variables with the shell:
|
|
89
95
|
|
90
96
|
$ env-checker check --optional MyOptVar1 MyOptVar2 --required MyReqVar1 MyReqVar2
|
91
97
|
|
98
|
+
Usage:
|
99
|
+
env-checker check
|
100
|
+
|
101
|
+
Options:
|
102
|
+
e, [--environment=ENVIRONMENT]
|
103
|
+
cf, [--config-file=CONFIG_FILE]
|
104
|
+
r, required, [--required-variables=one two three]
|
105
|
+
o, optional, [--optional-variables=one two three]
|
106
|
+
slack, [--slack-webhook-url=SLACK_WEBHOOK_URL]
|
107
|
+
[--run=RUN]
|
108
|
+
|
109
|
+
|
92
110
|
Example with a `.yml` [example file](https://raw.githubusercontent.com/ryanfox1985/env-checker/master/sample_config.yml):
|
93
111
|
|
94
112
|
$ env-checker check --config_file sample_config.yml
|
data/lib/env_checker.rb
CHANGED
@@ -5,6 +5,7 @@ require 'env_checker/version'
|
|
5
5
|
require 'env_checker/missing_keys_error'
|
6
6
|
require 'env_checker/configuration'
|
7
7
|
require 'env_checker/cli'
|
8
|
+
require 'byebug'
|
8
9
|
|
9
10
|
module EnvChecker
|
10
11
|
class << self
|
@@ -18,23 +19,32 @@ module EnvChecker
|
|
18
19
|
end
|
19
20
|
|
20
21
|
def cli_configure_and_check(options)
|
21
|
-
|
22
|
-
|
23
|
-
|
22
|
+
if run_configure_and_check(options) && options[:run]
|
23
|
+
exit(system(options[:run]))
|
24
|
+
end
|
25
|
+
|
26
|
+
exit(true)
|
27
|
+
end
|
28
|
+
|
29
|
+
private
|
30
|
+
|
31
|
+
def run_configure_and_check(options)
|
32
|
+
return true if !options[:optional_variables] &&
|
33
|
+
!options[:required_variables] &&
|
34
|
+
!options[:config_file]
|
24
35
|
|
25
36
|
self.configurations = create_config_from_parameters(options)
|
26
37
|
|
27
38
|
begin
|
28
39
|
exit(1) unless after_configure_and_check(configurations['global'])
|
29
|
-
exit(true)
|
30
40
|
rescue EnvChecker::MissingKeysError
|
31
41
|
exit 2
|
32
42
|
rescue EnvChecker::ConfigurationError
|
33
43
|
exit 3
|
34
44
|
end
|
35
|
-
end
|
36
45
|
|
37
|
-
|
46
|
+
true
|
47
|
+
end
|
38
48
|
|
39
49
|
def after_configure_and_check(configuration)
|
40
50
|
configuration.after_initialize
|
@@ -58,9 +68,17 @@ module EnvChecker
|
|
58
68
|
end
|
59
69
|
|
60
70
|
config.environment = options[:environment] if options[:environment]
|
61
|
-
|
62
|
-
|
63
|
-
|
71
|
+
if options[:optional_variables]
|
72
|
+
config.optional_variables = options[:optional_variables]
|
73
|
+
end
|
74
|
+
|
75
|
+
if options[:required_variables]
|
76
|
+
config.required_variables = options[:required_variables]
|
77
|
+
end
|
78
|
+
|
79
|
+
if options[:slack_webhook_url]
|
80
|
+
config.slack_webhook_url = options[:slack_webhook_url]
|
81
|
+
end
|
64
82
|
|
65
83
|
{ 'global' => config }
|
66
84
|
end
|
data/lib/env_checker/cli.rb
CHANGED
@@ -12,20 +12,34 @@ module EnvChecker
|
|
12
12
|
option :required_variables, :aliases => [:r, :required], :type => :array
|
13
13
|
option :optional_variables, :aliases => [:o, :optional], :type => :array
|
14
14
|
option :slack_webhook_url, :aliases => :slack, :type => :string
|
15
|
+
option :run, :type => :string
|
15
16
|
desc 'check', 'Check optional and required environment variables.'
|
16
17
|
def check
|
17
18
|
output = []
|
18
19
|
output << 'Variables: '
|
19
20
|
|
20
|
-
variables = %w(config_file
|
21
|
+
variables = %w(config_file
|
22
|
+
slack_webhook_url
|
23
|
+
environment
|
24
|
+
run
|
25
|
+
optional_variables
|
26
|
+
required_variables)
|
27
|
+
|
28
|
+
my_options = {}
|
21
29
|
variables.each do |v|
|
22
|
-
|
23
|
-
|
24
|
-
|
30
|
+
if ENV[v.upcase]
|
31
|
+
my_options[v.to_sym] ||= if v.upcase.include?('VARIABLES')
|
32
|
+
ENV[v.upcase].split(' ')
|
33
|
+
else
|
34
|
+
ENV[v.upcase]
|
35
|
+
end
|
36
|
+
end
|
37
|
+
my_options[v.to_sym] = options[v.to_sym] if options[v.to_sym]
|
38
|
+
output << "- #{v}: #{my_options[v.to_sym]}" if my_options[v.to_sym]
|
25
39
|
end
|
26
40
|
puts output.join("\n")
|
27
41
|
|
28
|
-
EnvChecker.cli_configure_and_check(
|
42
|
+
EnvChecker.cli_configure_and_check(my_options)
|
29
43
|
end
|
30
44
|
end
|
31
45
|
end
|
@@ -26,6 +26,12 @@ module EnvChecker
|
|
26
26
|
@slack_webhook_url != '' &&
|
27
27
|
@slack_notifier = Slack::Notifier.new(@slack_webhook_url)
|
28
28
|
|
29
|
+
@required_variables &&
|
30
|
+
@required_variables = @required_variables.map(&:upcase)
|
31
|
+
|
32
|
+
@optional_variables &&
|
33
|
+
@optional_variables = @optional_variables.map(&:upcase)
|
34
|
+
|
29
35
|
true
|
30
36
|
end
|
31
37
|
|
data/lib/env_checker/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
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.7
|
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-17 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: thor
|