wavefront-cli 2.15.2 → 2.16.0

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: d23d72573c71a3c0fdfc1277b6a8f1544fe38536dfa6c72199d47a15833613db
4
- data.tar.gz: d212aa09f8bbe2bb3377f00be4a5fa6e4f6f64870e92d4e8130905cf190848b4
3
+ metadata.gz: ce414a92ff374362682499450746072dbe34c460c189bd66d65013286baf3f29
4
+ data.tar.gz: 138bfc2d8a0a9bdc1b295c89e65b076fbfbcb546ea1431d8e1f00b22c8811164
5
5
  SHA512:
6
- metadata.gz: 2df4d1cc0fd0ff924fd4d1f4271e00600b5448d332db1b65213e31944499c4aaece08944c719c0fcc5bd2603f1bdc5ddedeeb02aeb96ff054d33b227f46097ba
7
- data.tar.gz: 41f5a4aae62c21c9729b73f8581fcb0a1da3538d83278b55baee5321b2ba5732fbaa9f63ebe68f3bf90821958dabdb75c65a1595e131534cc0ba970b809db295
6
+ metadata.gz: e68d2827509748ccb6b5694c95c1b33eab50c0cf093332f6dbb3acc4e41586a9949b490dc3e6017edf3b788b029bb5dd1ac38b1b29e33aa3943591324340a93c
7
+ data.tar.gz: 2da872908d448dfd09624aa5200b7189ff8badf1f2361733cf90739135b4a2e85d1bfb25b7ffa53d303fb55bd90b62a39b87b8307fa3259f4ec58d44b333714d
data/.travis.yml CHANGED
@@ -2,9 +2,9 @@ language: ruby
2
2
  cache: bundler
3
3
  rvm:
4
4
  - 2.2.10
5
- - 2.3.7
6
- - 2.4.4
7
- - 2.5.1
5
+ - 2.3.8
6
+ - 2.4.5
7
+ - 2.5.3
8
8
  before_install: gem install bundler --no-rdoc --no-ri
9
9
  deploy:
10
10
  provider: rubygems
@@ -14,7 +14,7 @@ deploy:
14
14
  on:
15
15
  tags: true
16
16
  repo: snltd/wavefront-cli
17
- ruby: 2.5.1
17
+ ruby: 2.5.3
18
18
  notifications:
19
19
  email: false
20
20
  slack:
data/HISTORY.md CHANGED
@@ -1,5 +1,8 @@
1
1
  # Changelog
2
2
 
3
+ ## 2.16.0 (23/12/2018)
4
+ * Add `config` command to quickly set up and manage profiles.
5
+
3
6
  ## 2.15.2 (21/12/2018)
4
7
  * Fix bug which caused an unhandled exception if CSV or Wavefront
5
8
  query outputs tried to process an empty data set.
@@ -85,15 +85,22 @@ class WavefrontCommandBase
85
85
  # testing far simpler.
86
86
  # @return [String] the options the command understands.
87
87
  #
88
- #
88
+ # rubocop:disable Metrics/AbcSize
89
89
  def options(term_width = TW)
90
90
  width = option_column_width
91
- ret = "Global options:\n"
92
- global_options.each { |o| ret.<< opt_row(o, width, term_width) }
93
- ret.<< "\nOptions:\n"
91
+ ret = ''
92
+
93
+ unless global_options.empty?
94
+ ret.<< "Global options:\n"
95
+ global_options.each { |o| ret.<< opt_row(o, width, term_width) }
96
+ ret.<< "\n"
97
+ end
98
+
99
+ ret.<< "Options:\n"
94
100
  _options.flatten.each { |o| ret.<< opt_row(o, width, term_width) }
95
101
  ret
96
102
  end
103
+ # rubocop:enable Metrics/AbcSize
97
104
 
98
105
  # Formats an option string.
99
106
  #
@@ -0,0 +1,27 @@
1
+ require_relative 'base'
2
+
3
+ # Define the Configure command
4
+ #
5
+ class WavefrontCommandConfig < WavefrontCommandBase
6
+ def description
7
+ 'create and manage local configuration'
8
+ end
9
+
10
+ def _commands
11
+ ['location',
12
+ 'profiles [-D] [-c file]',
13
+ 'show [-D] [-c file] [<profile>]',
14
+ 'setup [-D] [-c file] [<profile>]',
15
+ 'delete [-D] [-c file] <profile>',
16
+ 'envvars']
17
+ end
18
+
19
+ def _options
20
+ ['-c, --config=FILE path to configuration file',
21
+ '-D, --debug enable debug mode']
22
+ end
23
+
24
+ def global_options
25
+ []
26
+ end
27
+ end
@@ -0,0 +1,165 @@
1
+ require 'inifile'
2
+ require_relative 'exception'
3
+ require_relative 'base'
4
+
5
+ module WavefrontCli
6
+ #
7
+ # Create and manage a local configuration file. This class doesn't
8
+ # fit many of the assumptions made by the Base class. (Primarily,
9
+ # that it will consume the SDK.) Rather than split everything up,
10
+ # we're going to do some bad programming and override a couple of
11
+ # methods in the parent class to force different behaviour.
12
+ #
13
+ class Config < WavefrontCli::Base
14
+ attr_reader :config_file, :profile
15
+
16
+ CONFIGURABLES = [
17
+ { key: :token,
18
+ text: 'Wavefront API token',
19
+ default: nil,
20
+ test: proc { |v| v =~ RX } },
21
+ { key: :endpoint,
22
+ text: 'Wavefront API endpoint',
23
+ default: 'metrics.wavefront.com',
24
+ test: proc { |v| v.end_with?('.wavefront.com') } },
25
+ { key: :proxy,
26
+ text: 'Wavefront proxy endpoint',
27
+ default: 'wavefront',
28
+ test: proc { true } },
29
+ { key: :format,
30
+ text: 'default output format',
31
+ default: 'human',
32
+ test: proc { |v| %w[human json yaml].include?(v) } }
33
+ ].freeze
34
+
35
+ RX = /^[\da-f]{8}-[\da-f]{4}-[\da-f]{4}-[\da-f]{4}-[\da-f]{12}$/
36
+
37
+ def initialize(options)
38
+ @options = options
39
+ @config_file = _config_file
40
+ @profile = options[:'<profile>'] || 'default'
41
+ end
42
+
43
+ def do_location
44
+ puts config_file
45
+ end
46
+
47
+ def do_profiles
48
+ read_config.sections.each { |s| puts s }
49
+ end
50
+
51
+ def do_show
52
+ present?
53
+ puts IO.read(config_file)
54
+ end
55
+
56
+ def base_config
57
+ return read_config if config_file.exist?
58
+
59
+ puts "Creating new configuration file at #{config_file}."
60
+ IniFile.new
61
+ end
62
+
63
+ def do_setup
64
+ config = base_config
65
+
66
+ if config.has_section?(profile)
67
+ raise(WavefrontCli::Exception::ProfileExists, profile)
68
+ end
69
+
70
+ new_section = create_profile(profile)
71
+
72
+ config = config.merge(new_section)
73
+ config.write(filename: config_file)
74
+ end
75
+
76
+ def create_profile(profile)
77
+ puts "Creating profile '#{profile}'."
78
+
79
+ str = CONFIGURABLES.each_with_object("[#{profile}]") do |t, a|
80
+ a.<< format("\n%s=%s", t[:key], read_thing(t))
81
+ end
82
+
83
+ IniFile.new(content: str)
84
+ end
85
+
86
+ def do_delete
87
+ delete_section(profile, config_file)
88
+ end
89
+
90
+ def delete_section(profile, file)
91
+ raw = read_config
92
+
93
+ unless raw.has_section?(profile)
94
+ raise(WavefrontCli::Exception::ProfileNotFound, profile)
95
+ end
96
+
97
+ raw.delete_section(profile)
98
+ raw.write(filename: file)
99
+ end
100
+
101
+ def do_envvars
102
+ %w[WAVEFRONT_ENDPOINT WAVEFRONT_TOKEN WAVEFRONT_PROXY].each do |v|
103
+ puts format('%-20s %s', v, ENV[v] || 'unset')
104
+ end
105
+ end
106
+
107
+ def validate_opts; end
108
+
109
+ def display(_data, _method); end
110
+
111
+ def run
112
+ dispatch
113
+ end
114
+
115
+ def input_prompt(label, default)
116
+ ret = format(' %s', label)
117
+ ret.<< format(' [%s]', default) unless default.nil?
118
+ ret + ':> '
119
+ end
120
+
121
+ # Read STDIN and strip the whitespace. The rescue is there to
122
+ # catch a ctrl-d
123
+ #
124
+ def read_input
125
+ STDIN.gets.strip
126
+ rescue NoMethodError
127
+ abort "\nInput aborted at user request."
128
+ end
129
+
130
+ # Read something, and return its checked, sanitized value
131
+ # @return [String]
132
+ #
133
+ def read_thing(thing)
134
+ print input_prompt(thing[:text], thing[:default])
135
+ validate_input(read_input, thing[:default], thing[:test])
136
+ end
137
+
138
+ def validate_input(input, default, test)
139
+ if input.empty?
140
+ raise WavefrontCli::Exception::MandatoryValue if default.nil?
141
+ input = default
142
+ end
143
+
144
+ return input if test.call(input)
145
+ raise WavefrontCli::Exception::InvalidValue
146
+ end
147
+
148
+ def present?
149
+ return true if config_file.exist?
150
+ raise WavefrontCli::Exception::ConfigFileNotFound
151
+ end
152
+
153
+ # @return [Pathname] path to config file, from options, or from
154
+ # a constant if not supplied.
155
+ #
156
+ def _config_file
157
+ Pathname.new(options[:config] || DEFAULT_CONFIG)
158
+ end
159
+
160
+ def read_config(_nocheck = false)
161
+ present?
162
+ IniFile.load(config_file)
163
+ end
164
+ end
165
+ end
@@ -1,3 +1,5 @@
1
+ require 'pathname'
2
+
1
3
  module WavefrontCli
2
4
  # Universal truths
3
5
  #
@@ -17,5 +19,9 @@ module WavefrontCli
17
19
  # --all
18
20
  #
19
21
  ALL_PAGE_SIZE = 999
22
+
23
+ # Default configuration file
24
+ #
25
+ DEFAULT_CONFIG = (Pathname.new(ENV['HOME']) + '.wavefront').freeze
20
26
  end
21
27
  end
@@ -13,8 +13,10 @@ require 'pathname'
13
13
  require 'pp'
14
14
  require 'docopt'
15
15
  require_relative 'version'
16
+ require_relative 'constants'
16
17
  require_relative 'exception'
17
18
  require_relative 'opt_handler'
19
+ require_relative 'stdlib/string'
18
20
 
19
21
  CMD_DIR = Pathname.new(__FILE__).dirname + 'commands'
20
22
 
@@ -24,6 +26,8 @@ CMD_DIR = Pathname.new(__FILE__).dirname + 'commands'
24
26
  class WavefrontCliController
25
27
  attr_reader :args, :usage, :opts, :cmds, :tw
26
28
 
29
+ include WavefrontCli::Constants
30
+
27
31
  def initialize(args)
28
32
  @args = args
29
33
  @cmds = load_commands
@@ -104,26 +108,32 @@ class WavefrontCliController
104
108
  cli_class_obj.run
105
109
  rescue Interrupt
106
110
  abort "\nOperation aborted at user request."
111
+ rescue WavefrontCli::Exception::ConfigFileNotFound => e
112
+ abort "Configuration file '#{e}' not found."
107
113
  rescue WavefrontCli::Exception::CredentialError => e
108
- abort "Credential error. #{e.message}"
109
- rescue WavefrontCli::Exception::UnsupportedOutput => e
110
- abort e.message
111
- rescue WavefrontCli::Exception::InsufficientData => e
112
- abort "Insufficient data. #{e.message}"
113
- rescue WavefrontCli::Exception::UnsupportedFileFormat
114
- abort 'Unsupported file format.'
115
- rescue WavefrontCli::Exception::UnparseableInput => e
116
- abort "Cannot parse input. #{e.message}"
117
- rescue WavefrontCli::Exception::UnparseableResponse => e
118
- abort "Bad response from Wavefront. #{e.message}"
114
+ handle_missing_credentials(e)
115
+ rescue WavefrontCli::Exception::MandatoryValue
116
+ abort 'A value must be supplied.'
117
+ rescue WavefrontCli::Exception::InvalidValue => e
118
+ abort "Invalid value for #{e}."
119
+ rescue WavefrontCli::Exception::ProfileExists => e
120
+ abort "Profile '#{e}' already exists."
121
+ rescue WavefrontCli::Exception::ProfileNotFound => e
122
+ abort "Profile '#{e}' not found."
119
123
  rescue WavefrontCli::Exception::FileNotFound
120
124
  abort 'File not found.'
121
- rescue WavefrontCli::Exception::UnparseableInput
122
- abort 'Cannot parse input.'
125
+ rescue WavefrontCli::Exception::InsufficientData => e
126
+ abort "Insufficient data. #{e.message}"
123
127
  rescue WavefrontCli::Exception::SystemError => e
124
128
  abort "Host system error. #{e.message}"
129
+ rescue WavefrontCli::Exception::UnparseableInput => e
130
+ abort "Cannot parse input. #{e.message}"
131
+ rescue WavefrontCli::Exception::UnsupportedFileFormat
132
+ abort 'Unsupported file format.'
125
133
  rescue WavefrontCli::Exception::UnsupportedOperation => e
126
134
  abort "Unsupported operation.\n#{e.message}"
135
+ rescue WavefrontCli::Exception::UnsupportedOutput => e
136
+ abort e.message
127
137
  rescue Wavefront::Exception::UnsupportedWriter => e
128
138
  abort "Unsupported writer '#{e.message}'."
129
139
  rescue StandardError => e
@@ -135,6 +145,21 @@ class WavefrontCliController
135
145
  # rubocop:enable Metrics/MethodLength
136
146
  # rubocop:enable Metrics/AbcSize
137
147
 
148
+ #
149
+ # @param error [WavefrontCli::Exception::CredentialError]
150
+ #
151
+ def handle_missing_credentials(error)
152
+ if DEFAULT_CONFIG.exist?
153
+ abort "Credential error. #{error.message}"
154
+ else
155
+ puts 'No credentials supplied on the command line or via ' \
156
+ 'environment variables, and no configuration file found. ' \
157
+ "Please run 'wf config setup' to create configuration."
158
+ .fold(TW, 0)
159
+ exit 1
160
+ end
161
+ end
162
+
138
163
  # Each command is defined in its own file. Dynamically load all
139
164
  # those commands.
140
165
  # @return [Hash] :command => CommandClass
@@ -1,9 +1,14 @@
1
1
  module WavefrontCli
2
2
  class Exception
3
3
  class CredentialError < RuntimeError; end
4
+ class MandatoryValue < RuntimeError; end
5
+ class ConfigFileNotFound < IOError; end
4
6
  class FileNotFound < IOError; end
5
7
  class InsufficientData < RuntimeError; end
6
8
  class InvalidInput < RuntimeError; end
9
+ class InvalidValue < RuntimeError; end
10
+ class ProfileExists < RuntimeError; end
11
+ class ProfileNotFound < RuntimeError; end
7
12
  class SystemError < RuntimeError; end
8
13
  class UnhandledCommand < RuntimeError; end
9
14
  class UnparseableInput < RuntimeError; end
@@ -1,4 +1,3 @@
1
- require 'inifile'
2
1
  require 'pathname'
3
2
  require 'wavefront-sdk/credentials'
4
3
  require_relative 'constants.rb'
@@ -1 +1 @@
1
- WF_CLI_VERSION = '2.15.2'.freeze
1
+ WF_CLI_VERSION = '2.16.0'.freeze
data/spec/.rubocop.yml CHANGED
@@ -1,6 +1,9 @@
1
1
  AllCops:
2
2
  TargetRubyVersion: 2.2
3
3
 
4
+ Style/FormatStringToken:
5
+ Enabled: false
6
+
4
7
  # Allow long blocks of tests
5
8
  #
6
9
  Metrics/BlockLength:
data/spec/spec_helper.rb CHANGED
@@ -31,6 +31,7 @@ unless defined?(CMD)
31
31
  CMDS = all_commands.freeze
32
32
  BAD_TAG = '*BAD_TAG*'.freeze
33
33
  TW = 80
34
+ HOME_CONFIG = Pathname.new(ENV['HOME']) + '.wavefront'
34
35
  end
35
36
 
36
37
  # Return an array of CLI permutations and the values to which they relate
@@ -160,16 +161,23 @@ def invalid_ids(cmd, subcmds)
160
161
  end
161
162
  end
162
163
 
163
- # Without a token, you should get an error. If you don't supply an endpoint, it
164
- # will default to 'metrics.wavefront.com'.
164
+ # Without a token, you should get an error. If you don't supply an
165
+ # endpoint, it will default to 'metrics.wavefront.com'. The
166
+ # behaviour is different now, depending on whether you have
167
+ # ~/.wavefront or not.
165
168
  #
166
169
  def missing_creds(cmd, subcmds)
167
170
  describe 'commands with missing credentials' do
168
171
  subcmds.each do |subcmd|
169
172
  it "'#{subcmd}' errors and tells the user to use a token" do
170
173
  out, err = fail_command("#{cmd} #{subcmd} -c /f")
171
- assert_equal("Credential error. Missing API token.\n", err)
172
- assert_match(%r{config file '/f' not found.}, out)
174
+
175
+ if HOME_CONFIG.exist?
176
+ assert_equal("Credential error. Missing API token.\n", err)
177
+ assert_match(%r{config file '/f' not found.}, out)
178
+ else
179
+ assert_match(/Please run 'wf config setup'/, out)
180
+ end
173
181
  end
174
182
  end
175
183
  end
@@ -0,0 +1,49 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'pathname'
4
+ require_relative(File.join('../../../lib/wavefront-cli/commands',
5
+ Pathname.new(__FILE__).basename
6
+ .to_s.sub('_spec.rb', '')))
7
+ require_relative 'base_spec'
8
+
9
+ # Test config commands and options. These are different from
10
+ # everything else, so we crudely override some of the test methods.
11
+ #
12
+ class WavefrontCommmandConfigTest < WavefrontCommmandBaseTest
13
+ def setup
14
+ @wf = WavefrontCommandConfig.new
15
+ @col_width = 17
16
+ end
17
+
18
+ def test_options
19
+ refute wf.options(600).start_with?("Global options:\n")
20
+ assert_match(/Options:\n/, wf.options)
21
+
22
+ wf.options(600).split("\n")[1..-1].each do |o|
23
+ next if o == 'Global options:' || o == 'Options:' || o.empty?
24
+ assert_instance_of(String, o)
25
+ assert_match(/^ -\w, --\w+/, o)
26
+ refute o.end_with?('.')
27
+ end
28
+
29
+ assert_equal(wf.options.split("\n").select(&:empty?).size, 0)
30
+ end
31
+
32
+ def test_commands
33
+ assert wf.commands.start_with?("Usage:\n")
34
+ assert wf.commands.match(/ --help$/)
35
+
36
+ wf.commands(600).split("\n")[1..-1].each do |c|
37
+ next if skip_cmd && c.match(skip_cmd)
38
+ assert_match(/^ \w+/, c)
39
+ end
40
+ end
41
+
42
+ def test_docopt
43
+ x = wf.docopt
44
+ assert x.start_with?("Usage:\n")
45
+ refute_match("\nGlobal options:\n", x)
46
+ assert_match("--help\n", x)
47
+ assert_instance_of(String, x)
48
+ end
49
+ end
@@ -0,0 +1,214 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require_relative '../spec_helper'
4
+ require_relative '../../lib/wavefront-cli/config'
5
+
6
+ DEF_CF = Pathname.new(ENV['HOME']) + '.wavefront'
7
+ CONF_TMP = Pathname.new('/tmp/outfile')
8
+
9
+ # Test base writer
10
+ #
11
+ class WavefrontCliConfigTest < MiniTest::Test
12
+ attr_reader :wf, :wfo, :wfn
13
+
14
+ def setup
15
+ @wf = WavefrontCli::Config.new({})
16
+ @wfo = WavefrontCli::Config.new(config: CF)
17
+ @wfn = WavefrontCli::Config.new(config: '/no/file')
18
+ end
19
+
20
+ def test_do_location
21
+ assert_output(format("%s\n", CF)) { wfo.do_location }
22
+ assert_output("/no/file\n") { wfn.do_location }
23
+ assert_output(format("%s\n", DEF_CF)) { wf.do_location }
24
+ end
25
+
26
+ def test_do_profiles
27
+ assert_output("default\nother\n") { wfo.do_profiles }
28
+
29
+ assert_raises(WavefrontCli::Exception::ConfigFileNotFound) do
30
+ wfn.do_profiles
31
+ end
32
+ end
33
+
34
+ def test_do_show
35
+ out, err = capture_io { wfo.do_show }
36
+ assert_empty(err)
37
+ assert out.start_with?("[default]\n")
38
+ assert_equal(10, out.split("\n").size)
39
+ end
40
+
41
+ def test_input_prompt
42
+ assert_equal(' Token:> ', wf.input_prompt('Token', nil))
43
+ assert_equal(' Proxy [proxy]:> ', wf.input_prompt('Proxy', 'proxy'))
44
+ end
45
+
46
+ def test_read_input
47
+ ["value \n", " value\n", " value \t\n", "value\n"].each do |v|
48
+ STDIN.stub(:gets, v) do
49
+ assert_equal('value', wf.read_input)
50
+ end
51
+ end
52
+ end
53
+
54
+ def test_base_config
55
+ assert_instance_of(IniFile, wfo.base_config)
56
+ assert_instance_of(IniFile, wf.base_config)
57
+
58
+ assert_output('') { wfo.base_config }
59
+ assert_output("Creating new configuration file at /no/file.\n") do
60
+ wfn.base_config
61
+ end
62
+ end
63
+
64
+ def test_validate_input
65
+ assert_equal('str', wf.validate_input('str', nil,
66
+ proc { |v| v.is_a?(String) }))
67
+
68
+ assert_equal('defval', wf.validate_input('', 'defval',
69
+ proc { |v| v.is_a?(String) }))
70
+
71
+ assert_raises(WavefrontCli::Exception::MandatoryValue) do
72
+ wf.validate_input('', nil, proc { |v| v.is_a?(String) })
73
+ end
74
+
75
+ assert_raises(WavefrontCli::Exception::InvalidValue) do
76
+ wf.validate_input(:symbol, nil, proc { |v| v.is_a?(String) })
77
+ end
78
+
79
+ assert_raises(WavefrontCli::Exception::InvalidValue) do
80
+ wf.validate_input('', 123, proc { |v| v.is_a?(String) })
81
+ end
82
+ end
83
+
84
+ def test_create_profile_1
85
+ input_list = %w[2501b9c3-61e3-4f07-bee2-250aa06a9cab
86
+ test.wavefront.com myproxy json]
87
+
88
+ x = wfo.stub(:read_input, proc { input_list.shift }) do
89
+ wfo.create_profile('prof')
90
+ end
91
+
92
+ assert_instance_of(IniFile, x)
93
+ assert_equal('2501b9c3-61e3-4f07-bee2-250aa06a9cab', x[:prof]['token'])
94
+ assert_equal('test.wavefront.com', x[:prof]['endpoint'])
95
+ assert_equal('myproxy', x[:prof]['proxy'])
96
+ assert_equal('json', x[:prof]['format'])
97
+ end
98
+
99
+ def test_create_profile_2
100
+ input_list = ['2501b9c3-61e3-4f07-bee2-250aa06a9cab', '', '', '']
101
+
102
+ x = wfo.stub(:read_input, proc { input_list.shift }) do
103
+ wfo.create_profile('prof')
104
+ end
105
+
106
+ assert_instance_of(IniFile, x)
107
+ assert_equal('2501b9c3-61e3-4f07-bee2-250aa06a9cab', x[:prof]['token'])
108
+ assert_equal('metrics.wavefront.com', x[:prof]['endpoint'])
109
+ assert_equal('wavefront', x[:prof]['proxy'])
110
+ assert_equal('human', x[:prof]['format'])
111
+ end
112
+
113
+ def test_create_profile_3
114
+ input_list = ['X501b9c3-61e3-4f07-bee2-250aa06a9cab', '', '', '']
115
+
116
+ assert_raises(WavefrontCli::Exception::InvalidValue) do
117
+ wfo.stub(:read_input, proc { input_list.shift }) do
118
+ wfo.create_profile('prof')
119
+ end
120
+ end
121
+ end
122
+
123
+ def test_create_profile_4
124
+ input_list = ['2501b9c3-61e3-4f07-bee2-250aa06a9cab', 'end', '', '']
125
+
126
+ assert_raises(WavefrontCli::Exception::InvalidValue) do
127
+ wfo.stub(:read_input, proc { input_list.shift }) do
128
+ wfo.create_profile('prof')
129
+ end
130
+ end
131
+ end
132
+
133
+ def test_create_profile_5
134
+ input_list = ['', '', '', '']
135
+
136
+ assert_raises(WavefrontCli::Exception::MandatoryValue) do
137
+ wfo.stub(:read_input, proc { input_list.shift }) do
138
+ wfo.create_profile('prof')
139
+ end
140
+ end
141
+ end
142
+
143
+ def test_do_setup; end
144
+
145
+ def test_delete_section
146
+ wfo.delete_section('default', CONF_TMP)
147
+ assert_equal(
148
+ "[other]\ntoken = abcdefab-0123-abcd-0123-abcdefabcdef\n" \
149
+ "endpoint = other.wavefront.com\nproxy = otherwf.localnet\n\n",
150
+ IO.read(CONF_TMP)
151
+ )
152
+
153
+ assert_raises(WavefrontCli::Exception::ProfileNotFound) do
154
+ wfo.delete_section('nosuchprofile', CONF_TMP)
155
+ end
156
+ end
157
+
158
+ def test_do_envvars_1
159
+ blank_envvars
160
+ out, err = capture_io { wfo.do_envvars }
161
+ assert_empty(err)
162
+ out.each_line { |l| assert_match(/WAVEFRONT_[A-Z]+\s+unset$/, l) }
163
+ blank_envvars
164
+ end
165
+
166
+ def test_do_envvars_2
167
+ blank_envvars
168
+ ENV['WAVEFRONT_PROXY'] = 'myproxy'
169
+
170
+ out, err = capture_io { wfo.do_envvars }
171
+ assert_empty(err)
172
+ assert_match(/WAVEFRONT_ENDPOINT+\s+unset$/, out)
173
+ assert_match(/WAVEFRONT_TOKEN+\s+unset$/, out)
174
+ assert_match(/WAVEFRONT_PROXY+\s+myproxy$/, out)
175
+ blank_envvars
176
+ end
177
+
178
+ def test_do_envvars_3
179
+ blank_envvars
180
+ ENV['WAVEFRONT_PROXY'] = 'myproxy'
181
+ ENV['WAVEFRONT_TOKEN'] = 'token'
182
+
183
+ out, err = capture_io { wfo.do_envvars }
184
+ assert_empty(err)
185
+ assert_match(/WAVEFRONT_ENDPOINT+\s+unset$/, out)
186
+ assert_match(/WAVEFRONT_TOKEN+\s+token$/, out)
187
+ assert_match(/WAVEFRONT_PROXY+\s+myproxy$/, out)
188
+ blank_envvars
189
+ end
190
+
191
+ def test_read_thing; end
192
+
193
+ def test_present?
194
+ assert wfo.present?
195
+ assert_raises(WavefrontCli::Exception::ConfigFileNotFound) do
196
+ wfn.present?
197
+ end
198
+ end
199
+
200
+ def test__config_file
201
+ assert_equal(DEF_CF, wf._config_file)
202
+ assert_equal(Pathname.new(CF), wfo._config_file)
203
+ end
204
+
205
+ def test_read_config
206
+ assert_instance_of(IniFile, wfo.read_config)
207
+ end
208
+
209
+ def blank_envvars
210
+ %w[WAVEFRONT_ENDPOINT WAVEFRONT_PROXY WAVEFRONT_TOKEN].each do |v|
211
+ ENV[v] = nil
212
+ end
213
+ end
214
+ end
@@ -23,7 +23,8 @@ Gem::Specification.new do |gem|
23
23
  gem.require_paths = %w[lib]
24
24
 
25
25
  gem.add_runtime_dependency 'docopt', '~> 0.6.0'
26
- gem.add_runtime_dependency 'wavefront-sdk', '~> 2.2', '>= 2.2.0'
26
+ gem.add_runtime_dependency 'inifile', '~> 3.0'
27
+ gem.add_runtime_dependency 'wavefront-sdk', '~> 2.2', '>= 2.2.1'
27
28
 
28
29
  gem.add_development_dependency 'bundler', '~> 1.3'
29
30
  gem.add_development_dependency 'minitest', '~> 5.11', '>= 5.11.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: 2.15.2
4
+ version: 2.16.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Robert Fisher
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-12-21 00:00:00.000000000 Z
11
+ date: 2018-12-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: docopt
@@ -25,25 +25,39 @@ dependencies:
25
25
  - !ruby/object:Gem::Version
26
26
  version: 0.6.0
27
27
  - !ruby/object:Gem::Dependency
28
- name: wavefront-sdk
28
+ name: inifile
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - ">="
32
- - !ruby/object:Gem::Version
33
- version: 2.2.0
34
31
  - - "~>"
35
32
  - !ruby/object:Gem::Version
36
- version: '2.2'
33
+ version: '3.0'
37
34
  type: :runtime
38
35
  prerelease: false
39
36
  version_requirements: !ruby/object:Gem::Requirement
40
37
  requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '3.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: wavefront-sdk
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '2.2'
41
48
  - - ">="
42
49
  - !ruby/object:Gem::Version
43
- version: 2.2.0
50
+ version: 2.2.1
51
+ type: :runtime
52
+ prerelease: false
53
+ version_requirements: !ruby/object:Gem::Requirement
54
+ requirements:
44
55
  - - "~>"
45
56
  - !ruby/object:Gem::Version
46
57
  version: '2.2'
58
+ - - ">="
59
+ - !ruby/object:Gem::Version
60
+ version: 2.2.1
47
61
  - !ruby/object:Gem::Dependency
48
62
  name: bundler
49
63
  requirement: !ruby/object:Gem::Requirement
@@ -174,6 +188,7 @@ files:
174
188
  - lib/wavefront-cli/commands/alert.rb
175
189
  - lib/wavefront-cli/commands/base.rb
176
190
  - lib/wavefront-cli/commands/cloudintegration.rb
191
+ - lib/wavefront-cli/commands/config.rb
177
192
  - lib/wavefront-cli/commands/dashboard.rb
178
193
  - lib/wavefront-cli/commands/derivedmetric.rb
179
194
  - lib/wavefront-cli/commands/event.rb
@@ -191,6 +206,7 @@ files:
191
206
  - lib/wavefront-cli/commands/webhook.rb
192
207
  - lib/wavefront-cli/commands/window.rb
193
208
  - lib/wavefront-cli/commands/write.rb
209
+ - lib/wavefront-cli/config.rb
194
210
  - lib/wavefront-cli/constants.rb
195
211
  - lib/wavefront-cli/controller.rb
196
212
  - lib/wavefront-cli/dashboard.rb
@@ -263,6 +279,7 @@ files:
263
279
  - spec/wavefront-cli/commands/alert_spec.rb
264
280
  - spec/wavefront-cli/commands/base_spec.rb
265
281
  - spec/wavefront-cli/commands/cloudintegration_spec.rb
282
+ - spec/wavefront-cli/commands/config_spec.rb
266
283
  - spec/wavefront-cli/commands/dashboard_spec.rb
267
284
  - spec/wavefront-cli/commands/derivedmetric_spec.rb
268
285
  - spec/wavefront-cli/commands/event_spec.rb
@@ -275,6 +292,7 @@ files:
275
292
  - spec/wavefront-cli/commands/webhook_spec.rb
276
293
  - spec/wavefront-cli/commands/window_spec.rb
277
294
  - spec/wavefront-cli/commands/write_spec.rb
295
+ - spec/wavefront-cli/config_spec.rb
278
296
  - spec/wavefront-cli/controller_spec.rb
279
297
  - spec/wavefront-cli/dashboard_spec.rb
280
298
  - spec/wavefront-cli/derivedmetric_spec.rb
@@ -329,7 +347,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
329
347
  - !ruby/object:Gem::Version
330
348
  version: '0'
331
349
  requirements: []
332
- rubygems_version: 3.0.0
350
+ rubygems_version: 3.0.1
333
351
  signing_key:
334
352
  specification_version: 4
335
353
  summary: CLI for Wavefront API v2
@@ -342,6 +360,7 @@ test_files:
342
360
  - spec/wavefront-cli/commands/alert_spec.rb
343
361
  - spec/wavefront-cli/commands/base_spec.rb
344
362
  - spec/wavefront-cli/commands/cloudintegration_spec.rb
363
+ - spec/wavefront-cli/commands/config_spec.rb
345
364
  - spec/wavefront-cli/commands/dashboard_spec.rb
346
365
  - spec/wavefront-cli/commands/derivedmetric_spec.rb
347
366
  - spec/wavefront-cli/commands/event_spec.rb
@@ -354,6 +373,7 @@ test_files:
354
373
  - spec/wavefront-cli/commands/webhook_spec.rb
355
374
  - spec/wavefront-cli/commands/window_spec.rb
356
375
  - spec/wavefront-cli/commands/write_spec.rb
376
+ - spec/wavefront-cli/config_spec.rb
357
377
  - spec/wavefront-cli/controller_spec.rb
358
378
  - spec/wavefront-cli/dashboard_spec.rb
359
379
  - spec/wavefront-cli/derivedmetric_spec.rb