env-checker 0.1.4 → 0.1.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rubocop_todo.yml +14 -16
- data/Gemfile.lock +2 -2
- data/README.md +0 -12
- data/env-checker.gemspec +1 -1
- data/lib/env_checker.rb +28 -24
- data/lib/env_checker/cli.rb +2 -2
- data/lib/env_checker/configuration.rb +21 -5
- data/lib/env_checker/version.rb +1 -1
- metadata +4 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 787f95fa9585bada75c7b3343ecde721a5a71ca0
|
4
|
+
data.tar.gz: d33b2fbd2ee5c321e9134ac2a37df57bd84924b7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4c6ba33bc106c8c27f3fa7678c2defe258646aa270de98db4d3494a62709854414763d0268dec3d2478c1cde877da64ad489194cf579376ec0bc6a41d89ef242
|
7
|
+
data.tar.gz: 867efafdfb59b5232bf0fe6cb79be37a0857018a8e404e8d14251a4cc13f7bd7cfe232ccda7ccd6ce9f5dad9aac1cab132f81a982efc71014bd244d493218b2e
|
data/.rubocop_todo.yml
CHANGED
@@ -1,36 +1,34 @@
|
|
1
1
|
# This configuration was generated by
|
2
2
|
# `rubocop --auto-gen-config`
|
3
|
-
# on 2016-11-
|
3
|
+
# on 2016-11-12 02:10:52 +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: 4
|
10
10
|
Metrics/AbcSize:
|
11
|
-
Max:
|
11
|
+
Max: 23
|
12
12
|
|
13
13
|
# Offense count: 1
|
14
14
|
# Configuration parameters: CountComments.
|
15
15
|
Metrics/BlockLength:
|
16
|
-
Max:
|
16
|
+
Max: 32
|
17
17
|
|
18
|
-
# Offense count:
|
18
|
+
# Offense count: 1
|
19
|
+
Metrics/CyclomaticComplexity:
|
20
|
+
Max: 7
|
21
|
+
|
22
|
+
# Offense count: 3
|
19
23
|
# Configuration parameters: AllowHeredoc, AllowURI, URISchemes, IgnoreCopDirectives.
|
20
24
|
# URISchemes: http, https
|
21
25
|
Metrics/LineLength:
|
22
|
-
Max:
|
26
|
+
Max: 95
|
23
27
|
|
24
|
-
# Offense count:
|
28
|
+
# Offense count: 4
|
25
29
|
# Configuration parameters: CountComments.
|
26
30
|
Metrics/MethodLength:
|
27
|
-
Max:
|
28
|
-
|
29
|
-
# Offense count: 1
|
30
|
-
# Cop supports --auto-correct.
|
31
|
-
Style/EmptyLines:
|
32
|
-
Exclude:
|
33
|
-
- 'spec/env_checker/cli_spec.rb'
|
31
|
+
Max: 13
|
34
32
|
|
35
33
|
# Offense count: 1
|
36
34
|
# Cop supports --auto-correct.
|
@@ -46,7 +44,7 @@ Style/ExtraSpacing:
|
|
46
44
|
Style/FrozenStringLiteralComment:
|
47
45
|
Enabled: false
|
48
46
|
|
49
|
-
# Offense count:
|
47
|
+
# Offense count: 9
|
50
48
|
# Cop supports --auto-correct.
|
51
49
|
# Configuration parameters: EnforcedStyle, SupportedStyles, UseHashRocketsWithSymbolValues, PreferHashRocketsForNonAlnumEndingSymbols.
|
52
50
|
# SupportedStyles: ruby19, hash_rockets, no_mixed_keys, ruby19_no_mixed_keys
|
@@ -61,7 +59,7 @@ Style/MutableConstant:
|
|
61
59
|
Exclude:
|
62
60
|
- 'lib/env_checker/version.rb'
|
63
61
|
|
64
|
-
# Offense count:
|
62
|
+
# Offense count: 4
|
65
63
|
# Cop supports --auto-correct.
|
66
64
|
# Configuration parameters: SupportedStyles.
|
67
65
|
# SupportedStyles: compact, exploded
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -78,18 +78,6 @@ EnvChecker.configure do |config|
|
|
78
78
|
# config.logger = Logger.new('log/env_checker.log') # Use this file
|
79
79
|
# config.logger = Logger.new('/dev/null') # Don't log at all (on a Unix system)
|
80
80
|
end
|
81
|
-
|
82
|
-
# Example to run always
|
83
|
-
[YOUR_APP]::Application.config.after_initialize do
|
84
|
-
EnvChecker.check_environment_variables
|
85
|
-
end
|
86
|
-
|
87
|
-
# Example to run in specific environments
|
88
|
-
if Rails.env.production? || Rails.env.test?
|
89
|
-
[YOUR_APP]::Application.config.after_initialize do
|
90
|
-
EnvChecker.check_environment_variables
|
91
|
-
end
|
92
|
-
end
|
93
81
|
```
|
94
82
|
|
95
83
|
|
data/env-checker.gemspec
CHANGED
@@ -33,7 +33,7 @@ Gem::Specification.new do |spec|
|
|
33
33
|
spec.required_ruby_version = '>= 2.0.0'
|
34
34
|
|
35
35
|
spec.add_runtime_dependency 'thor', '~> 0.19.1'
|
36
|
-
spec.add_runtime_dependency 'slack-notifier', '~> 1.5
|
36
|
+
spec.add_runtime_dependency 'slack-notifier', '~> 1.5'
|
37
37
|
spec.add_development_dependency 'bundler', '~> 1.13'
|
38
38
|
spec.add_development_dependency 'rake', '~> 11.3'
|
39
39
|
spec.add_development_dependency 'rspec', '~> 3.5'
|
data/lib/env_checker.rb
CHANGED
@@ -8,23 +8,13 @@ require 'env_checker/cli'
|
|
8
8
|
|
9
9
|
module EnvChecker
|
10
10
|
class << self
|
11
|
-
attr_accessor :
|
12
|
-
|
13
|
-
def check_environment_variables
|
14
|
-
return true unless configuration
|
15
|
-
|
16
|
-
bov = check_optional_variables
|
17
|
-
brv = check_required_variables
|
18
|
-
|
19
|
-
bov & brv
|
20
|
-
end
|
11
|
+
attr_accessor :configurations
|
21
12
|
|
22
13
|
def configure
|
23
|
-
self.
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
configuration.after_initialize
|
14
|
+
self.configurations ||= {}
|
15
|
+
configurations['global'] = Configuration.new
|
16
|
+
yield(configurations['global'])
|
17
|
+
after_configure_and_check(configurations['global'])
|
28
18
|
end
|
29
19
|
|
30
20
|
def cli_configure_and_check(options)
|
@@ -32,17 +22,29 @@ module EnvChecker
|
|
32
22
|
!options[:required] &&
|
33
23
|
!options[:config_file]
|
34
24
|
|
35
|
-
self.
|
25
|
+
self.configurations = create_config_from_parameters(options)
|
36
26
|
|
37
27
|
begin
|
38
|
-
|
28
|
+
exit(1) unless after_configure_and_check(configurations['global'])
|
29
|
+
exit(true)
|
39
30
|
rescue EnvChecker::MissingKeysError
|
40
31
|
exit 2
|
32
|
+
rescue EnvChecker::ConfigurationError
|
33
|
+
exit 3
|
41
34
|
end
|
42
35
|
end
|
43
36
|
|
44
37
|
private
|
45
38
|
|
39
|
+
def after_configure_and_check(configuration)
|
40
|
+
configuration.after_initialize
|
41
|
+
|
42
|
+
bov = check_optional_variables(configuration)
|
43
|
+
brv = check_required_variables(configuration)
|
44
|
+
|
45
|
+
bov & brv
|
46
|
+
end
|
47
|
+
|
46
48
|
def create_config_from_parameters(options)
|
47
49
|
config = Configuration.new
|
48
50
|
|
@@ -52,17 +54,17 @@ module EnvChecker
|
|
52
54
|
config.required_variables = from_file['required_variables']
|
53
55
|
config.slack_webhook_url = from_file['slack_webhook_url']
|
54
56
|
|
55
|
-
return config
|
57
|
+
return { 'global' => config }
|
56
58
|
end
|
57
59
|
|
58
60
|
config.optional_variables = options[:optional] if options[:optional]
|
59
61
|
config.required_variables = options[:required] if options[:required]
|
60
62
|
config.slack_webhook_url = options[:slack] if options[:slack]
|
61
63
|
|
62
|
-
config
|
64
|
+
{ 'global' => config }
|
63
65
|
end
|
64
66
|
|
65
|
-
def check_optional_variables
|
67
|
+
def check_optional_variables(configuration)
|
66
68
|
return true if
|
67
69
|
!configuration.optional_variables ||
|
68
70
|
configuration.optional_variables.empty?
|
@@ -70,14 +72,15 @@ module EnvChecker
|
|
70
72
|
missing_keys = missing_keys_env(configuration.optional_variables)
|
71
73
|
return true if missing_keys.empty?
|
72
74
|
|
73
|
-
log_message(
|
75
|
+
log_message(configuration,
|
76
|
+
:warning,
|
74
77
|
configuration.environment,
|
75
78
|
"Warning! Missing optional variables: #{missing_keys}")
|
76
79
|
|
77
80
|
false
|
78
81
|
end
|
79
82
|
|
80
|
-
def check_required_variables
|
83
|
+
def check_required_variables(configuration)
|
81
84
|
return true if
|
82
85
|
!configuration.required_variables ||
|
83
86
|
configuration.required_variables.empty?
|
@@ -85,7 +88,8 @@ module EnvChecker
|
|
85
88
|
missing_keys = missing_keys_env(configuration.required_variables)
|
86
89
|
|
87
90
|
if missing_keys.any?
|
88
|
-
log_message(
|
91
|
+
log_message(configuration,
|
92
|
+
:error,
|
89
93
|
configuration.environment,
|
90
94
|
"Error! Missing required variables: #{missing_keys}")
|
91
95
|
|
@@ -95,7 +99,7 @@ module EnvChecker
|
|
95
99
|
true
|
96
100
|
end
|
97
101
|
|
98
|
-
def log_message(type, environment, error_message)
|
102
|
+
def log_message(configuration, type, environment, error_message)
|
99
103
|
return unless error_message
|
100
104
|
|
101
105
|
message = format_error_message(environment, error_message)
|
data/lib/env_checker/cli.rb
CHANGED
@@ -18,9 +18,9 @@ module EnvChecker
|
|
18
18
|
|
19
19
|
variables = %w(config_file slack_webhook_url optional required)
|
20
20
|
variables.each do |v|
|
21
|
-
#
|
21
|
+
# TODO: get config variables from current environment
|
22
22
|
# options[v.to_sym] ||= ENV[v.to_sym] if ENV[v.to_sym]
|
23
|
-
output << "-
|
23
|
+
output << "- #{v}: #{options[v.to_sym]}" if options[v.to_sym]
|
24
24
|
end
|
25
25
|
puts output.join("\n")
|
26
26
|
|
@@ -1,5 +1,6 @@
|
|
1
1
|
require 'logger'
|
2
2
|
require 'slack-notifier'
|
3
|
+
require 'uri'
|
3
4
|
|
4
5
|
module EnvChecker
|
5
6
|
class ConfigurationError < StandardError; end
|
@@ -18,17 +19,32 @@ module EnvChecker
|
|
18
19
|
@logger = Logger.new(STDERR)
|
19
20
|
end
|
20
21
|
|
21
|
-
def valid?
|
22
|
-
# TODO: check types and raise invalid config
|
23
|
-
true
|
24
|
-
end
|
25
|
-
|
26
22
|
def after_initialize
|
23
|
+
valid?
|
24
|
+
|
27
25
|
@slack_webhook_url &&
|
28
26
|
@slack_webhook_url != '' &&
|
29
27
|
@slack_notifier = Slack::Notifier.new(@slack_webhook_url)
|
30
28
|
|
31
29
|
true
|
32
30
|
end
|
31
|
+
|
32
|
+
private
|
33
|
+
|
34
|
+
def valid?
|
35
|
+
if required_variables && required_variables.class != Array
|
36
|
+
raise ConfigurationError.new("Invalid value required_variables: #{required_variables}")
|
37
|
+
end
|
38
|
+
|
39
|
+
if optional_variables && optional_variables.class != Array
|
40
|
+
raise ConfigurationError.new("Invalid value optional_variables: #{optional_variables}")
|
41
|
+
end
|
42
|
+
|
43
|
+
if slack_webhook_url && slack_webhook_url != ~ URI.regexp
|
44
|
+
raise ConfigurationError.new("Invalid value slack_webhook_url: #{slack_webhook_url}")
|
45
|
+
end
|
46
|
+
|
47
|
+
true
|
48
|
+
end
|
33
49
|
end
|
34
50
|
end
|
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.5
|
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-15 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: thor
|
@@ -30,14 +30,14 @@ dependencies:
|
|
30
30
|
requirements:
|
31
31
|
- - "~>"
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version: 1.5
|
33
|
+
version: '1.5'
|
34
34
|
type: :runtime
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
38
|
- - "~>"
|
39
39
|
- !ruby/object:Gem::Version
|
40
|
-
version: 1.5
|
40
|
+
version: '1.5'
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: bundler
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|