env-checker 0.1.3 → 0.1.4

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 157bc8d87b47465463bf92d1f36cabd512383af7
4
- data.tar.gz: 38eb8608f2b9ec6bc737da8150eecddc4a0c7d65
3
+ metadata.gz: 1f0f0740e16308b5524249cb91466b74335522f0
4
+ data.tar.gz: 54bf8b5c0295e8e77c65186a59f996e4391b82cd
5
5
  SHA512:
6
- metadata.gz: 5207f2040ab213eb3fae659885f674ea09f04d2f19271a21b52d3aa531ce310fd7928f2a57e11506e4b044ee0d3d432098696ee0798b12bf4a510cae139cc359
7
- data.tar.gz: dc18440c297ef31674862717097829cd008526492f5fc7e25a16ea7cef02484b04f1630e48da427e17ade50bf40e66c5ac48e1f939c24e268a73ca084aac1b6b
6
+ metadata.gz: c81fc0e2b03c48cef8e37d6800362aa3e6f35d02109f17f2599d3f330a712cbcc298c8bbb75fce557725c2f36b7bdc8e056b48051ada02170742da61629bde7d
7
+ data.tar.gz: 38ed741d13ca139d1012450271dab20479e1252114e8c4928bd0cf1df035e3891ef6c07a46c6f12918112004435497a748bc42317eb7ad0ba076ff587c9511ed
@@ -1,8 +1,9 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- env-checker (0.1.3)
5
- thor
4
+ env-checker (0.1.4)
5
+ slack-notifier (~> 1.5.1)
6
+ thor (~> 0.19.1)
6
7
 
7
8
  GEM
8
9
  remote: https://rubygems.org/
@@ -48,6 +49,7 @@ GEM
48
49
  json (>= 1.8, < 3)
49
50
  simplecov-html (~> 0.10.0)
50
51
  simplecov-html (0.10.0)
52
+ slack-notifier (1.5.1)
51
53
  term-ansicolor (1.4.0)
52
54
  tins (~> 1.0)
53
55
  thor (0.19.1)
@@ -58,14 +60,14 @@ PLATFORMS
58
60
  ruby
59
61
 
60
62
  DEPENDENCIES
61
- bundler (>= 1.13)
62
- byebug (>= 9.0.5)
63
- coveralls
63
+ bundler (~> 1.13)
64
+ byebug (~> 9.0)
65
+ coveralls (~> 0.8)
64
66
  env-checker!
65
- rake (>= 10.0)
66
- rspec (>= 3.0)
67
- rubocop
68
- simplecov
67
+ rake (~> 11.3)
68
+ rspec (~> 3.5)
69
+ rubocop (~> 0.45)
70
+ simplecov (~> 0.12)
69
71
 
70
72
  BUNDLED WITH
71
73
  1.13.6
data/README.md CHANGED
@@ -55,6 +55,7 @@ environment variables. Example:
55
55
  require 'env_checker'
56
56
 
57
57
  EnvChecker.configure do |config|
58
+ config.slack_webhook_url = 'https://hooks.slack.com/services/.../.../.../'
58
59
  config.optional_variables = %w(MyOptVar1 MyOptVar2)
59
60
  config.required_variables = %w(MyReqVar1 MyReqVar2)
60
61
 
@@ -32,12 +32,13 @@ Gem::Specification.new do |spec|
32
32
  spec.require_paths = ['lib']
33
33
  spec.required_ruby_version = '>= 2.0.0'
34
34
 
35
- spec.add_runtime_dependency 'thor', '>= 0'
36
- spec.add_development_dependency 'bundler', '>= 1.13'
37
- spec.add_development_dependency 'rake', '>= 10.0'
38
- spec.add_development_dependency 'rspec', '>= 3.0'
39
- spec.add_development_dependency 'rubocop', '>= 0'
40
- spec.add_development_dependency 'coveralls', '>= 0'
41
- spec.add_development_dependency 'simplecov', '>= 0'
42
- spec.add_development_dependency 'byebug', '>= 9.0.5'
35
+ spec.add_runtime_dependency 'thor', '~> 0.19.1'
36
+ spec.add_runtime_dependency 'slack-notifier', '~> 1.5.1'
37
+ spec.add_development_dependency 'bundler', '~> 1.13'
38
+ spec.add_development_dependency 'rake', '~> 11.3'
39
+ spec.add_development_dependency 'rspec', '~> 3.5'
40
+ spec.add_development_dependency 'rubocop', '~> 0.45'
41
+ spec.add_development_dependency 'coveralls', '~> 0.8'
42
+ spec.add_development_dependency 'simplecov', '~> 0.12'
43
+ spec.add_development_dependency 'byebug', '~> 9.0'
43
44
  end
@@ -22,6 +22,9 @@ module EnvChecker
22
22
  def configure
23
23
  self.configuration = Configuration.new
24
24
  yield(configuration)
25
+
26
+ configuration.valid? &&
27
+ configuration.after_initialize
25
28
  end
26
29
 
27
30
  def cli_configure_and_check(options)
@@ -47,12 +50,14 @@ module EnvChecker
47
50
  from_file = YAML.load_file(options[:config_file])
48
51
  config.optional_variables = from_file['optional_variables']
49
52
  config.required_variables = from_file['required_variables']
53
+ config.slack_webhook_url = from_file['slack_webhook_url']
50
54
 
51
55
  return config
52
56
  end
53
57
 
54
58
  config.optional_variables = options[:optional] if options[:optional]
55
59
  config.required_variables = options[:required] if options[:required]
60
+ config.slack_webhook_url = options[:slack] if options[:slack]
56
61
 
57
62
  config
58
63
  end
@@ -63,11 +68,13 @@ module EnvChecker
63
68
  configuration.optional_variables.empty?
64
69
 
65
70
  missing_keys = missing_keys_env(configuration.optional_variables)
71
+ return true if missing_keys.empty?
72
+
66
73
  log_message(:warning,
67
74
  configuration.environment,
68
- "Warning! Missing these optional variables: #{missing_keys}")
75
+ "Warning! Missing optional variables: #{missing_keys}")
69
76
 
70
- missing_keys.empty?
77
+ false
71
78
  end
72
79
 
73
80
  def check_required_variables
@@ -80,7 +87,7 @@ module EnvChecker
80
87
  if missing_keys.any?
81
88
  log_message(:error,
82
89
  configuration.environment,
83
- "Error! Missing these required variables: #{missing_keys}")
90
+ "Error! Missing required variables: #{missing_keys}")
84
91
 
85
92
  raise MissingKeysError.new(missing_keys)
86
93
  end
@@ -92,20 +99,25 @@ module EnvChecker
92
99
  return unless error_message
93
100
 
94
101
  message = format_error_message(environment, error_message)
95
- # TODO: add other integrations like slack, email...
96
- return unless configuration.logger
97
-
98
- case type
99
- when :warning
100
- configuration.logger.warn(message)
101
- when :error
102
- configuration.logger.error(message)
103
- else
104
- configuration.logger.info(message)
105
- end
102
+
103
+ configuration.slack_notifier &&
104
+ configuration.slack_notifier.ping(message)
105
+ # TODO: add other integrations like email...
106
+
107
+ configuration.logger &&
108
+ case type
109
+ when :warning
110
+ configuration.logger.warn(message)
111
+ when :error
112
+ configuration.logger.error(message)
113
+ else
114
+ configuration.logger.info(message)
115
+ end
106
116
  end
107
117
 
108
118
  def format_error_message(environment, error_message)
119
+ return [] unless error_message
120
+
109
121
  messages = []
110
122
  messages << '[EnvChecker]'
111
123
  messages << "[#{environment}]" if environment
@@ -10,13 +10,18 @@ module EnvChecker
10
10
  option :config_file, :aliases => :cf, :type => :string
11
11
  option :required, :aliases => :r, :type => :array
12
12
  option :optional, :aliases => :o, :type => :array
13
+ option :slack_webhook_url, :aliases => :slack, :type => :string
13
14
  desc 'check', 'Check optional and required environment variables.'
14
15
  def check
15
16
  output = []
16
17
  output << 'Variables: '
17
- output << "- Config file: #{options[:config_file]}" if options[:config_file]
18
- output << "- Optional: #{options[:optional]}" if options[:optional]
19
- output << "- Required: #{options[:required]}" if options[:required]
18
+
19
+ variables = %w(config_file slack_webhook_url optional required)
20
+ variables.each do |v|
21
+ # TODO: get config variables from current environment
22
+ # options[v.to_sym] ||= ENV[v.to_sym] if ENV[v.to_sym]
23
+ output << "- Config file: #{options[v.to_sym]}" if options[v.to_sym]
24
+ end
20
25
  puts output.join("\n")
21
26
 
22
27
  EnvChecker.cli_configure_and_check(options)
@@ -1,15 +1,34 @@
1
1
  require 'logger'
2
+ require 'slack-notifier'
2
3
 
3
4
  module EnvChecker
5
+ class ConfigurationError < StandardError; end
6
+
4
7
  class Configuration
5
- attr_accessor :required_variables, :optional_variables, :logger, :environment
8
+ attr_accessor :required_variables, :optional_variables, :logger,
9
+ :environment, :slack_webhook_url, :slack_notifier
6
10
 
7
11
  # Has default settings, which can be overridden in the initializer.
8
12
  def initialize
9
13
  @environment = ENV['RACK_ENV'] || ENV['RAILS_ENV']
10
14
  @required_variables = []
11
15
  @optional_variables = []
16
+ @slack_webhook_url = nil
17
+ @slack_notifier = nil
12
18
  @logger = Logger.new(STDERR)
13
19
  end
20
+
21
+ def valid?
22
+ # TODO: check types and raise invalid config
23
+ true
24
+ end
25
+
26
+ def after_initialize
27
+ @slack_webhook_url &&
28
+ @slack_webhook_url != '' &&
29
+ @slack_notifier = Slack::Notifier.new(@slack_webhook_url)
30
+
31
+ true
32
+ end
14
33
  end
15
34
  end
@@ -1,3 +1,3 @@
1
1
  module EnvChecker
2
- VERSION = '0.1.3'
2
+ VERSION = '0.1.4'
3
3
  end
@@ -3,4 +3,6 @@ optional_variables:
3
3
  - MyOptVar2
4
4
  required_variables:
5
5
  - MyReqVar1
6
- - MyReqVar2
6
+ - MyReqVar2
7
+
8
+ slack_webhook_url: https://hooks.slack.com/services/.../.../...
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: env-checker
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.3
4
+ version: 0.1.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Guillermo Guerrero Ibarra
@@ -14,114 +14,128 @@ dependencies:
14
14
  name: thor
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - ">="
17
+ - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: '0'
19
+ version: 0.19.1
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: '0'
26
+ version: 0.19.1
27
+ - !ruby/object:Gem::Dependency
28
+ name: slack-notifier
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: 1.5.1
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: 1.5.1
27
41
  - !ruby/object:Gem::Dependency
28
42
  name: bundler
29
43
  requirement: !ruby/object:Gem::Requirement
30
44
  requirements:
31
- - - ">="
45
+ - - "~>"
32
46
  - !ruby/object:Gem::Version
33
47
  version: '1.13'
34
48
  type: :development
35
49
  prerelease: false
36
50
  version_requirements: !ruby/object:Gem::Requirement
37
51
  requirements:
38
- - - ">="
52
+ - - "~>"
39
53
  - !ruby/object:Gem::Version
40
54
  version: '1.13'
41
55
  - !ruby/object:Gem::Dependency
42
56
  name: rake
43
57
  requirement: !ruby/object:Gem::Requirement
44
58
  requirements:
45
- - - ">="
59
+ - - "~>"
46
60
  - !ruby/object:Gem::Version
47
- version: '10.0'
61
+ version: '11.3'
48
62
  type: :development
49
63
  prerelease: false
50
64
  version_requirements: !ruby/object:Gem::Requirement
51
65
  requirements:
52
- - - ">="
66
+ - - "~>"
53
67
  - !ruby/object:Gem::Version
54
- version: '10.0'
68
+ version: '11.3'
55
69
  - !ruby/object:Gem::Dependency
56
70
  name: rspec
57
71
  requirement: !ruby/object:Gem::Requirement
58
72
  requirements:
59
- - - ">="
73
+ - - "~>"
60
74
  - !ruby/object:Gem::Version
61
- version: '3.0'
75
+ version: '3.5'
62
76
  type: :development
63
77
  prerelease: false
64
78
  version_requirements: !ruby/object:Gem::Requirement
65
79
  requirements:
66
- - - ">="
80
+ - - "~>"
67
81
  - !ruby/object:Gem::Version
68
- version: '3.0'
82
+ version: '3.5'
69
83
  - !ruby/object:Gem::Dependency
70
84
  name: rubocop
71
85
  requirement: !ruby/object:Gem::Requirement
72
86
  requirements:
73
- - - ">="
87
+ - - "~>"
74
88
  - !ruby/object:Gem::Version
75
- version: '0'
89
+ version: '0.45'
76
90
  type: :development
77
91
  prerelease: false
78
92
  version_requirements: !ruby/object:Gem::Requirement
79
93
  requirements:
80
- - - ">="
94
+ - - "~>"
81
95
  - !ruby/object:Gem::Version
82
- version: '0'
96
+ version: '0.45'
83
97
  - !ruby/object:Gem::Dependency
84
98
  name: coveralls
85
99
  requirement: !ruby/object:Gem::Requirement
86
100
  requirements:
87
- - - ">="
101
+ - - "~>"
88
102
  - !ruby/object:Gem::Version
89
- version: '0'
103
+ version: '0.8'
90
104
  type: :development
91
105
  prerelease: false
92
106
  version_requirements: !ruby/object:Gem::Requirement
93
107
  requirements:
94
- - - ">="
108
+ - - "~>"
95
109
  - !ruby/object:Gem::Version
96
- version: '0'
110
+ version: '0.8'
97
111
  - !ruby/object:Gem::Dependency
98
112
  name: simplecov
99
113
  requirement: !ruby/object:Gem::Requirement
100
114
  requirements:
101
- - - ">="
115
+ - - "~>"
102
116
  - !ruby/object:Gem::Version
103
- version: '0'
117
+ version: '0.12'
104
118
  type: :development
105
119
  prerelease: false
106
120
  version_requirements: !ruby/object:Gem::Requirement
107
121
  requirements:
108
- - - ">="
122
+ - - "~>"
109
123
  - !ruby/object:Gem::Version
110
- version: '0'
124
+ version: '0.12'
111
125
  - !ruby/object:Gem::Dependency
112
126
  name: byebug
113
127
  requirement: !ruby/object:Gem::Requirement
114
128
  requirements:
115
- - - ">="
129
+ - - "~>"
116
130
  - !ruby/object:Gem::Version
117
- version: 9.0.5
131
+ version: '9.0'
118
132
  type: :development
119
133
  prerelease: false
120
134
  version_requirements: !ruby/object:Gem::Requirement
121
135
  requirements:
122
- - - ">="
136
+ - - "~>"
123
137
  - !ruby/object:Gem::Version
124
- version: 9.0.5
138
+ version: '9.0'
125
139
  description: |2
126
140
  When you are developing a new feature if your app have some environments
127
141
  like test, staging and production is easy to forget an environment variable