wavefront-cli 3.1.1 → 3.1.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 83c302c633dd23f3749b0afc4b6459c07352a627a6446bba2d692e323c24a1ed
4
- data.tar.gz: b9a62872d2961ba16e4328fa4841a382e7a78d788c473df6c4b13518aa26eb67
3
+ metadata.gz: bfee50381c5609e38fdefab8aa7db8b7daf58fbbc547437d3a09654c65060f0b
4
+ data.tar.gz: 9fa8ef583e2e0e5547cbd81a84ab5fafe56e1e26b7738918f20d092187e332f6
5
5
  SHA512:
6
- metadata.gz: 6bd512328c814a40ffc3f4e8cb3384e3bdba1d5d58f5df08f311ae2a4dece9686a38bd3ff13f11ac0fdf11e971dc8dc85b0f9f31558bf25194b021035a5c41b8
7
- data.tar.gz: 72e59111e5394b44fc7177dbb9bd38e2a6baa4ee0c388768f2a3d6f5c5803b2a19840db4948b113b3775189dbb50fe4155f6ecd9acd147f035deb83cacfb078f
6
+ metadata.gz: 2d4c4b99f8e0bdc57fd43f7813b47830e17dfdf4349f9c6ae2fc27b97474ccd3db2db0bc23dd368e937ccdd281c6982489f47438d4cdaad43d8f484cf53f956f
7
+ data.tar.gz: 2a12e2a4af8f144d3f0dca74265b98dac65d0187320d6d26557725bd559d5c07b965e0987f3232b23d7597df67e31711bf1f22dd01f7cd2e2008dba8396c7aba
data/HISTORY.md CHANGED
@@ -1,5 +1,11 @@
1
1
  # Changelog
2
2
 
3
+ ## 3.1.2 (06/04/2019)
4
+ * Bugfix on handling of invalid config files.
5
+ * Explicitly specifying a missing config file now causes an error
6
+ whether or not credentials available from other mechanisms.
7
+ * Require 3.0.2 of [the SDK](https://github.com/snltd/wavefront-sdk).
8
+
3
9
  ## 3.1.1 (05/04/2019)
4
10
  * Usernames do not have to be e-mail addresses.
5
11
  * Require 3.0.1 of [the SDK](https://github.com/snltd/wavefront-sdk).
@@ -161,7 +161,7 @@ module WavefrontCli
161
161
 
162
162
  def present?
163
163
  return true if config_file.exist?
164
- raise WavefrontCli::Exception::ConfigFileNotFound
164
+ raise WavefrontCli::Exception::ConfigFileNotFound, config_file
165
165
  end
166
166
 
167
167
  # @return [Pathname] path to config file, from options, or from
@@ -72,7 +72,7 @@ class WavefrontCliController
72
72
  begin
73
73
  [cmd, sanitize_keys(Docopt.docopt(usage[cmd], argv: args))]
74
74
  rescue Docopt::DocoptLanguageError => e
75
- abort "mangled command description:\n#{e.message}"
75
+ abort "Mangled command description:\n#{e.message}"
76
76
  rescue Docopt::Exit => e
77
77
  abort e.message
78
78
  end
@@ -109,7 +109,7 @@ class WavefrontCliController
109
109
  rescue Interrupt
110
110
  abort "\nOperation aborted at user request."
111
111
  rescue WavefrontCli::Exception::ConfigFileNotFound => e
112
- abort "Configuration file '#{e}' not found."
112
+ abort "Configuration file #{e}' not found."
113
113
  rescue WavefrontCli::Exception::CredentialError => e
114
114
  handle_missing_credentials(e)
115
115
  rescue WavefrontCli::Exception::MandatoryValue
@@ -153,7 +153,7 @@ class WavefrontCliController
153
153
  # @param error [WavefrontCli::Exception::CredentialError]
154
154
  #
155
155
  def handle_missing_credentials(error)
156
- if DEFAULT_CONFIG.exist?
156
+ if DEFAULT_CONFIG.exist? && DEFAULT_CONFIG.file?
157
157
  abort "Credential error. #{error.message}"
158
158
  else
159
159
  puts 'No credentials supplied on the command line or via ' \
@@ -1,4 +1,8 @@
1
1
  module WavefrontCli
2
+ #
3
+ # CLI-specific exceptions. These should generally be caught in the
4
+ # controller.
5
+ #
2
6
  class Exception
3
7
  class CredentialError < RuntimeError; end
4
8
  class MandatoryValue < RuntimeError; end
@@ -29,6 +29,10 @@ module WavefrontCli
29
29
  cred_opts = setup_cred_opts(cli_opts)
30
30
  cli_opts.reject! { |_k, v| v.nil? }
31
31
  @opts = DEFAULT_OPTS.merge(load_profile(cred_opts)).merge(cli_opts)
32
+ rescue WavefrontCli::Exception::ConfigFileNotFound => e
33
+ abort "Configuration file '#{e}' not found."
34
+ rescue Wavefront::Exception::InvalidConfigFile => e
35
+ abort "Could not load configuration file '#{e.message}'."
32
36
  end
33
37
 
34
38
  # Create an options hash to pass to the Wavefront::Credentials
@@ -45,7 +49,7 @@ module WavefrontCli
45
49
  cred_opts[:file] = Pathname.new(cli_opts[:config])
46
50
 
47
51
  unless cred_opts[:file].exist?
48
- puts "config file '#{cred_opts[:file]}' not found."
52
+ raise WavefrontCli::Exception::ConfigFileNotFound, cred_opts[:file]
49
53
  end
50
54
  end
51
55
 
@@ -1 +1 @@
1
- WF_CLI_VERSION = '3.1.1'.freeze
1
+ WF_CLI_VERSION = '3.1.2'.freeze
data/spec/spec_helper.rb CHANGED
@@ -248,15 +248,20 @@ end
248
248
  def missing_creds(cmd, subcmds)
249
249
  describe 'commands with missing credentials' do
250
250
  subcmds.each do |subcmd|
251
- it "'#{subcmd}' errors and tells the user to use a token" do
252
- out, err = fail_command("#{cmd} #{subcmd} -c /f")
253
-
254
- if HOME_CONFIG.exist?
255
- assert_equal("Credential error. Missing API token.\n", err)
256
- assert_match(%r{config file '/f' not found.}, out)
257
- else
258
- assert_match(/Please run 'wf config setup'/, out)
259
- end
251
+ it "'#{subcmd}' tells the user config file not found" do
252
+ _out, err = fail_command("#{cmd} #{subcmd} -c /f")
253
+ assert_equal("Configuration file '/f' not found.\n", err)
254
+ end
255
+
256
+ # I've generally got a config file on my dev box, but Travis
257
+ # won't have one. Therefore this test probably won't get run
258
+ # locally, but it will get run in CI, which is what counts.
259
+ #
260
+ next if HOME_CONFIG.exist?
261
+
262
+ it "'#{subcmd}' errors and tells the user to generate config" do
263
+ out, _err = fail_command("#{cmd} #{subcmd}")
264
+ assert_match(/Please run 'wf config setup'/, out)
260
265
  end
261
266
  end
262
267
  end
@@ -44,6 +44,21 @@ class WavefrontCliHelpTest < MiniTest::Test
44
44
  end
45
45
  end
46
46
  end
47
+
48
+ def test_malformed_config
49
+ WavefrontCliController.new(['alert', 'list',
50
+ "--config=#{RES_DIR}/malformed.conf"])
51
+ rescue SystemExit => e
52
+ assert_equal(1, e.status)
53
+ assert e.message.start_with?('Could not load configuration file')
54
+ end
55
+
56
+ def test_missing_config
57
+ WavefrontCliController.new(%w[alert list --config=/no/such/file])
58
+ rescue SystemExit => e
59
+ assert_equal(1, e.status)
60
+ assert_equal("Configuration file '/no/such/file' not found.", e.message)
61
+ end
47
62
  end
48
63
 
49
64
  # To test internal methods, make a subclass with no initializer,
@@ -3,13 +3,15 @@
3
3
  require_relative '../spec_helper'
4
4
  require_relative '../../lib/wavefront-cli/opt_handler'
5
5
 
6
+ # Some of these tests will be skipped if you have a ~/.wavefront
7
+ # config file. CI will never have that.
8
+ #
9
+ INTERFERING_FILE = Pathname.new(ENV['HOME']) + '.wavefront'
10
+
6
11
  # Test option handler class. End to end tests because the work is
7
12
  # always done in the constructor
8
13
  #
9
14
  class OptHandlerTest < MiniTest::Test
10
- # This one has to be kind of vague because I have a config file on
11
- # the box I develop on, which will always be picked up. Other
12
- # tests are more specific
13
15
  def test_no_opts
14
16
  x = WavefrontCli::OptHandler.new
15
17
  assert x.is_a?(WavefrontCli::OptHandler)
@@ -17,37 +19,37 @@ class OptHandlerTest < MiniTest::Test
17
19
  assert x.opts.keys.include?(:endpoint)
18
20
  end
19
21
 
22
+ def test_missing_config
23
+ WavefrontCli::OptHandler.new(config: '/no/such/file')
24
+ rescue SystemExit => e
25
+ assert_equal(1, e.status)
26
+ assert_match("Configuration file '/no/such/file' not found.", e.message)
27
+ end
28
+
20
29
  def test_no_config_no_env
21
- opts = { config: '/nosuchfile' }
22
- x = WavefrontCli::OptHandler.new(opts)
30
+ return if INTERFERING_FILE.exist?
31
+
32
+ x = WavefrontCli::OptHandler.new({})
23
33
  o = x.opts
24
34
  assert x.is_a?(WavefrontCli::OptHandler)
25
35
  assert o.is_a?(Hash)
26
36
  refute o.keys.include?(:token)
27
- assert_equal(o[:config], '/nosuchfile')
28
37
  assert_equal(o[:endpoint], 'metrics.wavefront.com')
29
-
30
- assert_output("config file '/nosuchfile' not found.\n") do
31
- WavefrontCli::OptHandler.new(opts)
32
- end
33
38
  end
34
39
 
35
40
  def test_no_config_env
41
+ return if INTERFERING_FILE.exist?
42
+
36
43
  ENV['WAVEFRONT_TOKEN'] = 'abcd1234'
37
44
  ENV['WAVEFRONT_ENDPOINT'] = 'myendpoint.wavefront.com'
38
- opts = { config: '/nosuchfile' }
39
- x = WavefrontCli::OptHandler.new(opts)
45
+ x = WavefrontCli::OptHandler.new({})
40
46
  o = x.opts
41
47
  assert x.is_a?(WavefrontCli::OptHandler)
42
48
  assert o.is_a?(Hash)
43
49
  assert_equal(o[:token], 'abcd1234')
44
- assert_equal(o[:config], '/nosuchfile')
50
+ assert_nil o[:config]
45
51
  assert_equal(o[:endpoint], 'myendpoint.wavefront.com')
46
52
  refute o.keys.include?(:proxy)
47
-
48
- assert_output("config file '/nosuchfile' not found.\n") do
49
- WavefrontCli::OptHandler.new(opts)
50
- end
51
53
  ENV['WAVEFRONT_TOKEN'] = nil
52
54
  ENV['WAVEFRONT_ENDPOINT'] = nil
53
55
  end
@@ -0,0 +1 @@
1
+ this is not a valid config file
@@ -24,7 +24,7 @@ Gem::Specification.new do |gem|
24
24
 
25
25
  gem.add_runtime_dependency 'docopt', '~> 0.6.0'
26
26
  gem.add_runtime_dependency 'inifile', '~> 3.0'
27
- gem.add_runtime_dependency 'wavefront-sdk', '~> 3.0', '>= 3.0.1'
27
+ gem.add_runtime_dependency 'wavefront-sdk', '~> 3.0', '>= 3.0.2'
28
28
 
29
29
  gem.add_development_dependency 'minitest', '~> 5.11', '>= 5.11.0'
30
30
  gem.add_development_dependency 'rake', '~> 12.0'
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: wavefront-cli
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.1.1
4
+ version: 3.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Robert Fisher
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-04-05 00:00:00.000000000 Z
11
+ date: 2019-04-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: docopt
@@ -47,7 +47,7 @@ dependencies:
47
47
  version: '3.0'
48
48
  - - ">="
49
49
  - !ruby/object:Gem::Version
50
- version: 3.0.1
50
+ version: 3.0.2
51
51
  type: :runtime
52
52
  prerelease: false
53
53
  version_requirements: !ruby/object:Gem::Requirement
@@ -57,7 +57,7 @@ dependencies:
57
57
  version: '3.0'
58
58
  - - ">="
59
59
  - !ruby/object:Gem::Version
60
- version: 3.0.1
60
+ version: 3.0.2
61
61
  - !ruby/object:Gem::Dependency
62
62
  name: minitest
63
63
  requirement: !ruby/object:Gem::Requirement
@@ -311,6 +311,7 @@ files:
311
311
  - spec/wavefront-cli/resources/display/user-human-long
312
312
  - spec/wavefront-cli/resources/display/user-human-long-no_sep
313
313
  - spec/wavefront-cli/resources/display/user-input.json
314
+ - spec/wavefront-cli/resources/malformed.conf
314
315
  - spec/wavefront-cli/resources/responses/README.md
315
316
  - spec/wavefront-cli/resources/responses/alert-list.json
316
317
  - spec/wavefront-cli/resources/responses/backups.json
@@ -418,6 +419,7 @@ test_files:
418
419
  - spec/wavefront-cli/resources/display/user-human-long
419
420
  - spec/wavefront-cli/resources/display/user-human-long-no_sep
420
421
  - spec/wavefront-cli/resources/display/user-input.json
422
+ - spec/wavefront-cli/resources/malformed.conf
421
423
  - spec/wavefront-cli/resources/responses/README.md
422
424
  - spec/wavefront-cli/resources/responses/alert-list.json
423
425
  - spec/wavefront-cli/resources/responses/backups.json