wavefront-cli 2.1.2 → 2.1.3
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/lib/wavefront-cli/controller.rb +15 -21
- data/lib/wavefront-cli/opt_handler.rb +35 -27
- data/lib/wavefront-cli/version.rb +1 -1
- data/spec/spec_helper.rb +17 -15
- data/spec/wavefront-cli/commands/base_spec.rb +0 -2
- data/spec/wavefront-cli/commands/spec_helper.rb +0 -2
- data/spec/wavefront-cli/{cli_help_spec.rb → controller_spec.rb} +23 -1
- data/spec/wavefront-cli/display/base_spec.rb +0 -2
- data/spec/wavefront-cli/display/spec_helper.rb +0 -2
- data/spec/wavefront-cli/opt_handler_spec.rb +102 -0
- data/spec/wavefront-cli/resources/{conf.yaml → wavefront.conf} +0 -0
- metadata +7 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1098aac042355b553d4b5e6b1ae5bad73794a61a
|
4
|
+
data.tar.gz: 97495d06c18f86febbc78578bfae1c60eec8b260
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 178fe53faaad7d665bf497b35177884b37b03175788e0cf7a808a3a7430aa655efd5ba3bd1941ea122ffd5b5e85aa5e90039906775088aa52fe390f59928a25d
|
7
|
+
data.tar.gz: 0ce5b99c7cf2af4376a6a5750243bc06155dbad7ef9c2908fd7e220e344a95af84ef6adc7c6166022e446a4035c213d4967be072cfe1f42724269a60a3734c36
|
@@ -1,14 +1,17 @@
|
|
1
|
+
# For development against a local checkout of the SDK, uncomment
|
2
|
+
# this block
|
3
|
+
#
|
4
|
+
# dir = Pathname.new(__FILE__).dirname.realpath.parent.parent.parent
|
5
|
+
# $LOAD_PATH.<< dir + 'lib'
|
6
|
+
# $LOAD_PATH.<< dir + 'wavefront-sdk' + 'lib'
|
7
|
+
|
1
8
|
require 'pathname'
|
2
9
|
require 'pp'
|
3
10
|
require 'docopt'
|
4
11
|
require_relative './version'
|
5
|
-
require_relative './opt_handler'
|
6
12
|
require_relative './exception'
|
7
13
|
|
8
|
-
|
9
|
-
# .parent + 'lib'
|
10
|
-
# $LOAD_PATH.<< Pathname.new(__FILE__).dirname.realpath.parent.parent
|
11
|
-
# .parent + 'wavefront-sdk' + 'lib'
|
14
|
+
require_relative './opt_handler'
|
12
15
|
|
13
16
|
CMD_DIR = Pathname.new(__FILE__).dirname + 'commands'
|
14
17
|
|
@@ -29,7 +32,8 @@ class WavefrontCliController
|
|
29
32
|
run_command(hook)
|
30
33
|
end
|
31
34
|
|
32
|
-
# What you see when you do '
|
35
|
+
# What you see when you do 'wf --help'
|
36
|
+
# @return [String]
|
33
37
|
#
|
34
38
|
def default_help
|
35
39
|
s = "Wavefront CLI\n\nUsage:\n #{CMD} command [options]\n" \
|
@@ -39,7 +43,7 @@ class WavefrontCliController
|
|
39
43
|
s.<< "\nUse '#{CMD} <command> --help' for further information.\n"
|
40
44
|
end
|
41
45
|
|
42
|
-
#
|
46
|
+
# @return [Hash] command descriptions for docopt.
|
43
47
|
#
|
44
48
|
def docopt_hash
|
45
49
|
cmds.each_with_object(default: default_help) do |(k, v), ret|
|
@@ -67,11 +71,12 @@ class WavefrontCliController
|
|
67
71
|
end
|
68
72
|
|
69
73
|
def parse_opts(o)
|
70
|
-
WavefrontCli::OptHandler.new(
|
74
|
+
WavefrontCli::OptHandler.new(o).opts
|
71
75
|
end
|
72
76
|
|
73
77
|
# Get the SDK class we need to run the command we've been given.
|
74
78
|
#
|
79
|
+
# @param cmd [String]
|
75
80
|
def load_sdk(cmd, opts)
|
76
81
|
require_relative File.join('.', cmds[cmd].sdk_file)
|
77
82
|
Object.const_get('WavefrontCli').const_get(cmds[cmd].sdk_class).new(opts)
|
@@ -93,6 +98,7 @@ class WavefrontCliController
|
|
93
98
|
|
94
99
|
# Each command is defined in its own file. Dynamically load all
|
95
100
|
# those commands.
|
101
|
+
# @return [Hash] :command => CommandClass
|
96
102
|
#
|
97
103
|
def load_commands
|
98
104
|
CMD_DIR.children.each_with_object({}) do |f, ret|
|
@@ -113,24 +119,12 @@ class WavefrontCliController
|
|
113
119
|
Object.const_get("WavefrontCommand#{k_name.capitalize}").new
|
114
120
|
end
|
115
121
|
|
116
|
-
# The default config file path.
|
117
|
-
#
|
118
|
-
# @return [Pathname] where we excpect to find a config file
|
119
|
-
#
|
120
|
-
def conf_file
|
121
|
-
if ENV['HOME']
|
122
|
-
Pathname.new(ENV['HOME']) + '.wavefront'
|
123
|
-
else
|
124
|
-
Pathname.new('/etc/wavefront/client.conf')
|
125
|
-
end
|
126
|
-
end
|
127
|
-
|
128
122
|
# Symbolize, and remove dashes from option keys
|
129
123
|
#
|
130
124
|
# @param h [Hash] options hash
|
131
125
|
# return [Hash] h with modified keys
|
132
126
|
#
|
133
127
|
def sanitize_keys(h)
|
134
|
-
h.each_with_object({}) { |(k, v), r| r[k.delete('-').to_sym] = v }
|
128
|
+
h.each_with_object({}) { |(k, v), r| r[k.to_s.delete('-').to_sym] = v }
|
135
129
|
end
|
136
130
|
end
|
@@ -1,5 +1,6 @@
|
|
1
1
|
require 'inifile'
|
2
2
|
require 'pathname'
|
3
|
+
require 'wavefront-sdk/credentials'
|
3
4
|
require_relative './constants.rb'
|
4
5
|
|
5
6
|
module WavefrontCli
|
@@ -23,40 +24,47 @@ module WavefrontCli
|
|
23
24
|
class OptHandler
|
24
25
|
include WavefrontCli::Constants
|
25
26
|
|
26
|
-
attr_reader :opts
|
27
|
+
attr_reader :opts
|
27
28
|
|
28
|
-
def initialize(
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
conf_file
|
33
|
-
end
|
34
|
-
|
35
|
-
@cli_opts = cli_opts.reject { |_k, v| v.nil? }
|
36
|
-
|
37
|
-
@opts = DEFAULT_OPTS.merge(load_profile).merge(@cli_opts)
|
29
|
+
def initialize(cli_opts = {})
|
30
|
+
cred_opts = setup_cred_opts(cli_opts)
|
31
|
+
cli_opts.reject! { |_k, v| v.nil? }
|
32
|
+
@opts = DEFAULT_OPTS.merge(load_profile(cred_opts)).merge(cli_opts)
|
38
33
|
end
|
39
34
|
|
40
|
-
#
|
41
|
-
#
|
42
|
-
#
|
43
|
-
#
|
35
|
+
# Create an options hash to pass to the Wavefront::Credentials
|
36
|
+
# constructor.
|
37
|
+
# @param cli_opts [Hash] options from docopt, which may include
|
38
|
+
# the location of the config file and the stanza within it
|
39
|
+
# @return [Hash] keys are none, one, or both of :file and
|
40
|
+
# :profile
|
44
41
|
#
|
45
|
-
|
46
|
-
|
47
|
-
unless conf_file.exist?
|
48
|
-
puts "config file '#{conf_file}' not found. Taking options " \
|
49
|
-
'from command-line.'
|
50
|
-
return {}
|
51
|
-
end
|
42
|
+
def setup_cred_opts(cli_opts)
|
43
|
+
cred_opts = {}
|
52
44
|
|
53
|
-
|
45
|
+
if cli_opts[:config]
|
46
|
+
cred_opts[:file] = Pathname.new(cli_opts[:config])
|
54
47
|
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
memo[k.to_sym] = v
|
48
|
+
unless cred_opts[:file].exist?
|
49
|
+
puts "config file '#{cred_opts[:file]}' not found."
|
50
|
+
end
|
59
51
|
end
|
52
|
+
|
53
|
+
cred_opts[:profile] = cli_opts[:profile] if cli_opts[:profile]
|
54
|
+
cred_opts
|
55
|
+
end
|
56
|
+
|
57
|
+
# Load credentials (and other config) using the SDK Credentials
|
58
|
+
# class. This allows the user to override values with
|
59
|
+
# environment variables
|
60
|
+
#
|
61
|
+
# @param cred_opts [Hash] options to pass to
|
62
|
+
# Wavefront::Credentials constructor
|
63
|
+
# @return [Hash] keys are :token, :endpoint etc
|
64
|
+
#
|
65
|
+
def load_profile(cred_opts)
|
66
|
+
creds = Wavefront::Credentials.new(cred_opts).config
|
67
|
+
Hash[creds.map{ |k, v| [k.to_sym, v] }]
|
60
68
|
end
|
61
69
|
end
|
62
70
|
end
|
@@ -1 +1 @@
|
|
1
|
-
WF_CLI_VERSION = '2.1.
|
1
|
+
WF_CLI_VERSION = '2.1.3'.freeze
|
data/spec/spec_helper.rb
CHANGED
@@ -7,21 +7,23 @@ require 'minitest/spec'
|
|
7
7
|
require 'pathname'
|
8
8
|
require_relative '../lib/wavefront-cli/controller'
|
9
9
|
|
10
|
-
CMD
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
10
|
+
unless defined?(CMD)
|
11
|
+
CMD = 'wavefront'.freeze
|
12
|
+
ENDPOINT = 'metrics.wavefront.com'
|
13
|
+
TOKEN = '0123456789-ABCDEF'
|
14
|
+
RES_DIR = Pathname.new(__FILE__).dirname + 'wavefront-cli' + 'resources'
|
15
|
+
CF = RES_DIR + 'wavefront.conf'
|
16
|
+
CF_VAL = IniFile.load(CF)
|
17
|
+
JSON_POST_HEADERS = {
|
18
|
+
:'Content-Type' => 'application/json', :Accept => 'application/json'
|
19
|
+
}.freeze
|
20
|
+
|
21
|
+
CMDS = %w(alert integration dashboard event link message metric
|
22
|
+
proxy query savedsearch source user window webhook write).freeze
|
23
|
+
|
24
|
+
BAD_TAG="*BAD TAG*"
|
25
|
+
TW = 80
|
26
|
+
end
|
25
27
|
|
26
28
|
# Return an array of CLI permutations and the values to which they relate
|
27
29
|
#
|
@@ -1,7 +1,7 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
2
|
|
3
|
-
require_relative '../../lib/wavefront-cli/controller'
|
4
3
|
require_relative '../spec_helper'
|
4
|
+
require_relative '../../lib/wavefront-cli/controller'
|
5
5
|
|
6
6
|
# Be sure the CLI behaves properly when people ask for help
|
7
7
|
#
|
@@ -47,3 +47,25 @@ class WavefrontCliHelpTest < MiniTest::Test
|
|
47
47
|
end
|
48
48
|
end
|
49
49
|
end
|
50
|
+
|
51
|
+
# To test internal methods, make a subclass with no initializer,
|
52
|
+
# so we can get at the methods without triggering one of the things
|
53
|
+
# tested above.
|
54
|
+
#
|
55
|
+
class Giblets < WavefrontCliController
|
56
|
+
def initialize; end
|
57
|
+
end
|
58
|
+
|
59
|
+
class GibletsTest < MiniTest::Test
|
60
|
+
attr_reader :wfc
|
61
|
+
|
62
|
+
def setup
|
63
|
+
@wfc = Giblets.new
|
64
|
+
end
|
65
|
+
|
66
|
+
def test_sanitize_keys
|
67
|
+
h_in = { '--help': true, stuff: false, 'key' => 'value' }
|
68
|
+
assert_equal(wfc.sanitize_keys(h_in),
|
69
|
+
{ help: true, stuff: false, key: 'value' })
|
70
|
+
end
|
71
|
+
end
|
@@ -0,0 +1,102 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require_relative '../spec_helper'
|
4
|
+
require_relative '../../lib/wavefront-cli/opt_handler'
|
5
|
+
|
6
|
+
# Test option handler class. End to end tests because the work is
|
7
|
+
# always done in the constructor
|
8
|
+
#
|
9
|
+
class OptHandlerTest < MiniTest::Test
|
10
|
+
|
11
|
+
# This one has to be kind of vague because I have a config file on
|
12
|
+
# the box I develop on, which will always be picked up. Other
|
13
|
+
# tests are more specific
|
14
|
+
def test_no_opts
|
15
|
+
x = WavefrontCli::OptHandler.new
|
16
|
+
assert x.is_a?(WavefrontCli::OptHandler)
|
17
|
+
assert x.opts.is_a?(Hash)
|
18
|
+
assert x.opts.keys.include?(:endpoint)
|
19
|
+
end
|
20
|
+
|
21
|
+
def test_no_config_no_env
|
22
|
+
opts = { config: '/nosuchfile' }
|
23
|
+
x = WavefrontCli::OptHandler.new(opts)
|
24
|
+
o = x.opts
|
25
|
+
assert x.is_a?(WavefrontCli::OptHandler)
|
26
|
+
assert o.is_a?(Hash)
|
27
|
+
refute o.keys.include?(:token)
|
28
|
+
assert_equal(o[:config], '/nosuchfile')
|
29
|
+
assert_equal(o[:endpoint], 'metrics.wavefront.com')
|
30
|
+
|
31
|
+
assert_output("config file '/nosuchfile' not found.\n") do
|
32
|
+
WavefrontCli::OptHandler.new(opts)
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
def test_no_config_env
|
37
|
+
ENV['WAVEFRONT_TOKEN'] = 'abcd1234'
|
38
|
+
ENV['WAVEFRONT_ENDPOINT'] = 'myendpoint.wavefront.com'
|
39
|
+
opts = { config: '/nosuchfile' }
|
40
|
+
x = WavefrontCli::OptHandler.new(opts)
|
41
|
+
o = x.opts
|
42
|
+
assert x.is_a?(WavefrontCli::OptHandler)
|
43
|
+
assert o.is_a?(Hash)
|
44
|
+
assert_equal(o[:token], 'abcd1234')
|
45
|
+
assert_equal(o[:config], '/nosuchfile')
|
46
|
+
assert_equal(o[:endpoint], 'myendpoint.wavefront.com')
|
47
|
+
refute o.keys.include?(:proxy)
|
48
|
+
|
49
|
+
assert_output("config file '/nosuchfile' not found.\n") do
|
50
|
+
WavefrontCli::OptHandler.new(opts)
|
51
|
+
end
|
52
|
+
ENV['WAVEFRONT_TOKEN'] = nil
|
53
|
+
ENV['WAVEFRONT_ENDPOINT'] = nil
|
54
|
+
end
|
55
|
+
|
56
|
+
def test_default_config_no_env
|
57
|
+
opts = { config: CF }
|
58
|
+
x = WavefrontCli::OptHandler.new(opts)
|
59
|
+
o = x.opts
|
60
|
+
assert x.is_a?(WavefrontCli::OptHandler)
|
61
|
+
assert o.is_a?(Hash)
|
62
|
+
assert_equal(o[:token], '12345678-abcd-1234-abcd-123456789012')
|
63
|
+
assert_equal(o[:config], CF)
|
64
|
+
assert_equal(o[:endpoint], 'default.wavefront.com')
|
65
|
+
assert_equal(o[:proxy], 'wavefront.localnet')
|
66
|
+
assert_output("") { WavefrontCli::OptHandler.new(opts) }
|
67
|
+
end
|
68
|
+
|
69
|
+
def test_alt_config_env
|
70
|
+
ENV['WAVEFRONT_TOKEN'] = 'abdc1234'
|
71
|
+
ENV['WAVEFRONT_ENDPOINT'] = nil
|
72
|
+
opts = { config: CF, profile: 'other' }
|
73
|
+
x = WavefrontCli::OptHandler.new(opts)
|
74
|
+
o = x.opts
|
75
|
+
assert x.is_a?(WavefrontCli::OptHandler)
|
76
|
+
assert o.is_a?(Hash)
|
77
|
+
assert_equal(o[:token], 'abdc1234')
|
78
|
+
assert_equal(o[:config], CF)
|
79
|
+
assert_equal(o[:endpoint], 'other.wavefront.com')
|
80
|
+
assert_equal(o[:proxy], 'otherwf.localnet')
|
81
|
+
assert_output("") { WavefrontCli::OptHandler.new(opts) }
|
82
|
+
ENV['WAVEFRONT_TOKEN'] = nil
|
83
|
+
ENV['WAVEFRONT_ENDPOINT'] = nil
|
84
|
+
end
|
85
|
+
|
86
|
+
def test_alt_config_env
|
87
|
+
ENV['WAVEFRONT_TOKEN'] = nil
|
88
|
+
ENV['WAVEFRONT_ENDPOINT'] = 'myendpoint.wavefront.com'
|
89
|
+
opts = { config: CF, profile: 'other' }
|
90
|
+
x = WavefrontCli::OptHandler.new(opts)
|
91
|
+
o = x.opts
|
92
|
+
assert x.is_a?(WavefrontCli::OptHandler)
|
93
|
+
assert o.is_a?(Hash)
|
94
|
+
assert_equal(o[:token], 'abcdefab-0123-abcd-0123-abcdefabcdef')
|
95
|
+
assert_equal(o[:config], CF)
|
96
|
+
assert_equal(o[:endpoint], 'myendpoint.wavefront.com')
|
97
|
+
assert_equal(o[:proxy], 'otherwf.localnet')
|
98
|
+
assert_output("") { WavefrontCli::OptHandler.new(opts) }
|
99
|
+
ENV['WAVEFRONT_TOKEN'] = nil
|
100
|
+
ENV['WAVEFRONT_ENDPOINT'] = nil
|
101
|
+
end
|
102
|
+
end
|
File without changes
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: wavefront-cli
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.1.
|
4
|
+
version: 2.1.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Robert Fisher
|
@@ -217,7 +217,6 @@ files:
|
|
217
217
|
- spec/spec_helper.rb
|
218
218
|
- spec/wavefront-cli/alert_spec.rb
|
219
219
|
- spec/wavefront-cli/base_spec.rb
|
220
|
-
- spec/wavefront-cli/cli_help_spec.rb
|
221
220
|
- spec/wavefront-cli/cloudintegration_spec.rb
|
222
221
|
- spec/wavefront-cli/commands/alert_spec.rb
|
223
222
|
- spec/wavefront-cli/commands/base_spec.rb
|
@@ -233,6 +232,7 @@ files:
|
|
233
232
|
- spec/wavefront-cli/commands/webhook_spec.rb
|
234
233
|
- spec/wavefront-cli/commands/window_spec.rb
|
235
234
|
- spec/wavefront-cli/commands/write_spec.rb
|
235
|
+
- spec/wavefront-cli/controller_spec.rb
|
236
236
|
- spec/wavefront-cli/dashboard_spec.rb
|
237
237
|
- spec/wavefront-cli/display/base_spec.rb
|
238
238
|
- spec/wavefront-cli/display/printer/base_spec.rb
|
@@ -245,9 +245,10 @@ files:
|
|
245
245
|
- spec/wavefront-cli/maintanancewindow_spec.rb
|
246
246
|
- spec/wavefront-cli/message_spec.rb
|
247
247
|
- spec/wavefront-cli/metric_spec.rb
|
248
|
+
- spec/wavefront-cli/opt_handler_spec.rb
|
248
249
|
- spec/wavefront-cli/proxy_spec.rb
|
249
250
|
- spec/wavefront-cli/query_spec.rb
|
250
|
-
- spec/wavefront-cli/resources/conf
|
251
|
+
- spec/wavefront-cli/resources/wavefront.conf
|
251
252
|
- spec/wavefront-cli/savedsearch_spec.rb
|
252
253
|
- spec/wavefront-cli/source_spec.rb
|
253
254
|
- spec/wavefront-cli/string_spec.rb
|
@@ -282,7 +283,6 @@ test_files:
|
|
282
283
|
- spec/spec_helper.rb
|
283
284
|
- spec/wavefront-cli/alert_spec.rb
|
284
285
|
- spec/wavefront-cli/base_spec.rb
|
285
|
-
- spec/wavefront-cli/cli_help_spec.rb
|
286
286
|
- spec/wavefront-cli/cloudintegration_spec.rb
|
287
287
|
- spec/wavefront-cli/commands/alert_spec.rb
|
288
288
|
- spec/wavefront-cli/commands/base_spec.rb
|
@@ -298,6 +298,7 @@ test_files:
|
|
298
298
|
- spec/wavefront-cli/commands/webhook_spec.rb
|
299
299
|
- spec/wavefront-cli/commands/window_spec.rb
|
300
300
|
- spec/wavefront-cli/commands/write_spec.rb
|
301
|
+
- spec/wavefront-cli/controller_spec.rb
|
301
302
|
- spec/wavefront-cli/dashboard_spec.rb
|
302
303
|
- spec/wavefront-cli/display/base_spec.rb
|
303
304
|
- spec/wavefront-cli/display/printer/base_spec.rb
|
@@ -310,9 +311,10 @@ test_files:
|
|
310
311
|
- spec/wavefront-cli/maintanancewindow_spec.rb
|
311
312
|
- spec/wavefront-cli/message_spec.rb
|
312
313
|
- spec/wavefront-cli/metric_spec.rb
|
314
|
+
- spec/wavefront-cli/opt_handler_spec.rb
|
313
315
|
- spec/wavefront-cli/proxy_spec.rb
|
314
316
|
- spec/wavefront-cli/query_spec.rb
|
315
|
-
- spec/wavefront-cli/resources/conf
|
317
|
+
- spec/wavefront-cli/resources/wavefront.conf
|
316
318
|
- spec/wavefront-cli/savedsearch_spec.rb
|
317
319
|
- spec/wavefront-cli/source_spec.rb
|
318
320
|
- spec/wavefront-cli/string_spec.rb
|