wavefront-cli 4.2.1 → 4.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.codeclimate.yml +1 -0
- data/.rubocop.yml +1 -14
- data/.travis.yml +4 -4
- data/Gemfile +2 -0
- data/HISTORY.md +82 -60
- data/Rakefile +2 -0
- data/bin/wf +1 -0
- data/lib/wavefront-cli/alert.rb +13 -5
- data/lib/wavefront-cli/apitoken.rb +2 -0
- data/lib/wavefront-cli/base.rb +95 -47
- data/lib/wavefront-cli/cloudintegration.rb +6 -0
- data/lib/wavefront-cli/command_mixins/acl.rb +6 -1
- data/lib/wavefront-cli/command_mixins/tag.rb +2 -0
- data/lib/wavefront-cli/commands/.rubocop.yml +3 -4
- data/lib/wavefront-cli/commands/alert.rb +2 -1
- data/lib/wavefront-cli/commands/apitoken.rb +6 -0
- data/lib/wavefront-cli/commands/base.rb +30 -21
- data/lib/wavefront-cli/commands/cloudintegration.rb +2 -0
- data/lib/wavefront-cli/commands/config.rb +2 -0
- data/lib/wavefront-cli/commands/dashboard.rb +2 -0
- data/lib/wavefront-cli/commands/derivedmetric.rb +2 -0
- data/lib/wavefront-cli/commands/event.rb +3 -1
- data/lib/wavefront-cli/commands/integration.rb +2 -1
- data/lib/wavefront-cli/commands/link.rb +2 -0
- data/lib/wavefront-cli/commands/message.rb +2 -0
- data/lib/wavefront-cli/commands/metric.rb +2 -0
- data/lib/wavefront-cli/commands/notificant.rb +2 -0
- data/lib/wavefront-cli/commands/proxy.rb +2 -0
- data/lib/wavefront-cli/commands/query.rb +2 -0
- data/lib/wavefront-cli/commands/savedsearch.rb +2 -0
- data/lib/wavefront-cli/commands/serviceaccount.rb +58 -0
- data/lib/wavefront-cli/commands/settings.rb +2 -0
- data/lib/wavefront-cli/commands/source.rb +3 -1
- data/lib/wavefront-cli/commands/user.rb +4 -1
- data/lib/wavefront-cli/commands/usergroup.rb +3 -0
- data/lib/wavefront-cli/commands/webhook.rb +2 -0
- data/lib/wavefront-cli/commands/window.rb +2 -0
- data/lib/wavefront-cli/commands/write.rb +2 -0
- data/lib/wavefront-cli/config.rb +23 -12
- data/lib/wavefront-cli/constants.rb +10 -4
- data/lib/wavefront-cli/controller.rb +53 -22
- data/lib/wavefront-cli/dashboard.rb +3 -0
- data/lib/wavefront-cli/derivedmetric.rb +12 -11
- data/lib/wavefront-cli/display/alert.rb +7 -4
- data/lib/wavefront-cli/display/apitoken.rb +2 -0
- data/lib/wavefront-cli/display/base.rb +34 -8
- data/lib/wavefront-cli/display/cloudintegration.rb +4 -2
- data/lib/wavefront-cli/display/dashboard.rb +2 -0
- data/lib/wavefront-cli/display/derivedmetric.rb +2 -0
- data/lib/wavefront-cli/display/distribution.rb +2 -0
- data/lib/wavefront-cli/display/event.rb +2 -0
- data/lib/wavefront-cli/display/externallink.rb +2 -0
- data/lib/wavefront-cli/display/integration.rb +2 -0
- data/lib/wavefront-cli/display/maintenancewindow.rb +2 -0
- data/lib/wavefront-cli/display/message.rb +7 -3
- data/lib/wavefront-cli/display/metric.rb +3 -1
- data/lib/wavefront-cli/display/notificant.rb +3 -1
- data/lib/wavefront-cli/display/printer/long.rb +36 -11
- data/lib/wavefront-cli/display/printer/sparkline.rb +3 -0
- data/lib/wavefront-cli/display/printer/terse.rb +6 -1
- data/lib/wavefront-cli/display/proxy.rb +2 -0
- data/lib/wavefront-cli/display/query.rb +35 -24
- data/lib/wavefront-cli/display/savedsearch.rb +2 -0
- data/lib/wavefront-cli/display/serviceaccount.rb +60 -0
- data/lib/wavefront-cli/display/settings.rb +2 -0
- data/lib/wavefront-cli/display/source.rb +18 -4
- data/lib/wavefront-cli/display/user.rb +56 -10
- data/lib/wavefront-cli/display/usergroup.rb +25 -19
- data/lib/wavefront-cli/display/webhook.rb +2 -0
- data/lib/wavefront-cli/display/write.rb +6 -2
- data/lib/wavefront-cli/event.rb +83 -62
- data/lib/wavefront-cli/exception.rb +3 -0
- data/lib/wavefront-cli/externallink.rb +6 -4
- data/lib/wavefront-cli/integration.rb +2 -0
- data/lib/wavefront-cli/maintenancewindow.rb +28 -17
- data/lib/wavefront-cli/message.rb +4 -0
- data/lib/wavefront-cli/metric.rb +4 -1
- data/lib/wavefront-cli/notificant.rb +2 -0
- data/lib/wavefront-cli/opt_handler.rb +2 -0
- data/lib/wavefront-cli/output/base.rb +8 -3
- data/lib/wavefront-cli/output/csv.rb +2 -0
- data/lib/wavefront-cli/output/csv/base.rb +2 -0
- data/lib/wavefront-cli/output/csv/query.rb +14 -7
- data/lib/wavefront-cli/output/hcl.rb +2 -0
- data/lib/wavefront-cli/output/hcl/alert.rb +2 -0
- data/lib/wavefront-cli/output/hcl/base.rb +10 -4
- data/lib/wavefront-cli/output/hcl/dashboard.rb +17 -8
- data/lib/wavefront-cli/output/hcl/notificant.rb +2 -0
- data/lib/wavefront-cli/output/hcl/stdlib/array.rb +2 -0
- data/lib/wavefront-cli/output/hcl/stdlib/string.rb +2 -0
- data/lib/wavefront-cli/output/json.rb +2 -0
- data/lib/wavefront-cli/output/ruby.rb +2 -0
- data/lib/wavefront-cli/output/wavefront.rb +2 -0
- data/lib/wavefront-cli/output/wavefront/query.rb +7 -4
- data/lib/wavefront-cli/output/yaml.rb +2 -0
- data/lib/wavefront-cli/proxy.rb +15 -3
- data/lib/wavefront-cli/query.rb +14 -12
- data/lib/wavefront-cli/savedsearch.rb +2 -0
- data/lib/wavefront-cli/serviceaccount.rb +179 -0
- data/lib/wavefront-cli/settings.rb +2 -0
- data/lib/wavefront-cli/source.rb +2 -0
- data/lib/wavefront-cli/stdlib/array.rb +3 -0
- data/lib/wavefront-cli/stdlib/string.rb +17 -11
- data/lib/wavefront-cli/user.rb +10 -4
- data/lib/wavefront-cli/usergroup.rb +4 -2
- data/lib/wavefront-cli/version.rb +3 -1
- data/lib/wavefront-cli/webhook.rb +2 -0
- data/lib/wavefront-cli/write.rb +80 -46
- data/spec/.rubocop.yml +3 -16
- data/spec/constants.rb +21 -0
- data/spec/spec_helper.rb +8 -422
- data/spec/support/command_base.rb +82 -0
- data/spec/support/minitest_assertions.rb +262 -0
- data/spec/support/output_tester.rb +32 -0
- data/spec/support/supported_commands.rb +19 -0
- data/spec/test_mixins/acl.rb +169 -0
- data/spec/test_mixins/delete.rb +25 -0
- data/spec/test_mixins/deleteundelete.rb +106 -0
- data/spec/test_mixins/describe.rb +24 -0
- data/spec/test_mixins/dump.rb +43 -0
- data/spec/test_mixins/general.rb +11 -0
- data/spec/test_mixins/history.rb +35 -0
- data/spec/test_mixins/import.rb +65 -0
- data/spec/test_mixins/list.rb +29 -0
- data/spec/test_mixins/search.rb +98 -0
- data/spec/test_mixins/set.rb +47 -0
- data/spec/test_mixins/tag.rb +99 -0
- data/spec/wavefront-cli/alert_spec.rb +288 -111
- data/spec/wavefront-cli/apitoken_spec.rb +53 -24
- data/spec/wavefront-cli/base_spec.rb +9 -27
- data/spec/wavefront-cli/cloudintegration_spec.rb +65 -29
- data/spec/wavefront-cli/commands/alert_spec.rb +1 -0
- data/spec/wavefront-cli/commands/base_spec.rb +15 -13
- data/spec/wavefront-cli/commands/cloudintegration_spec.rb +1 -0
- data/spec/wavefront-cli/commands/config_spec.rb +3 -0
- data/spec/wavefront-cli/commands/dashboard_spec.rb +1 -0
- data/spec/wavefront-cli/commands/derivedmetric_spec.rb +1 -0
- data/spec/wavefront-cli/commands/event_spec.rb +1 -0
- data/spec/wavefront-cli/commands/link_spec.rb +1 -0
- data/spec/wavefront-cli/commands/message_spec.rb +1 -0
- data/spec/wavefront-cli/commands/metric_spec.rb +1 -0
- data/spec/wavefront-cli/commands/proxy_spec.rb +1 -0
- data/spec/wavefront-cli/commands/query_spec.rb +1 -0
- data/spec/wavefront-cli/commands/webhook_spec.rb +1 -0
- data/spec/wavefront-cli/commands/window_spec.rb +1 -0
- data/spec/wavefront-cli/commands/write_spec.rb +1 -0
- data/spec/wavefront-cli/config_spec.rb +25 -14
- data/spec/wavefront-cli/controller_spec.rb +13 -3
- data/spec/wavefront-cli/dashboard_spec.rb +125 -76
- data/spec/wavefront-cli/derivedmetric_spec.rb +83 -67
- data/spec/wavefront-cli/display/base_spec.rb +5 -7
- data/spec/wavefront-cli/display/printer/long_spec.rb +20 -16
- data/spec/wavefront-cli/display/printer/terse_spec.rb +5 -4
- data/spec/wavefront-cli/event_spec.rb +360 -18
- data/spec/wavefront-cli/externallink_spec.rb +92 -58
- data/spec/wavefront-cli/integration_spec.rb +129 -31
- data/spec/wavefront-cli/maintenancewindow_spec.rb +270 -32
- data/spec/wavefront-cli/message_spec.rb +73 -30
- data/spec/wavefront-cli/metric_spec.rb +60 -22
- data/spec/wavefront-cli/notificant_spec.rb +45 -32
- data/spec/wavefront-cli/opt_handler_spec.rb +4 -1
- data/spec/wavefront-cli/output/csv/query_spec.rb +21 -19
- data/spec/wavefront-cli/output/csv_spec.rb +5 -2
- data/spec/wavefront-cli/output/hcl_spec.rb +5 -2
- data/spec/wavefront-cli/output/helpers.rb +18 -0
- data/spec/wavefront-cli/output/json_spec.rb +3 -1
- data/spec/wavefront-cli/output/ruby_spec.rb +3 -1
- data/spec/wavefront-cli/output/wavefront/query_spec.rb +3 -1
- data/spec/wavefront-cli/output/wavefront_spec.rb +6 -4
- data/spec/wavefront-cli/output/yaml_spec.rb +3 -1
- data/spec/wavefront-cli/proxy_spec.rb +49 -27
- data/spec/wavefront-cli/query_spec.rb +174 -92
- data/spec/wavefront-cli/resources/responses/query.json +1 -0
- data/spec/wavefront-cli/resources/updates/alert.json +15 -0
- data/spec/wavefront-cli/resources/updates/dashboard.json +1 -0
- data/spec/wavefront-cli/savedsearch_spec.rb +35 -18
- data/spec/wavefront-cli/serviceaccount_spec.rb +399 -0
- data/spec/wavefront-cli/settings_spec.rb +42 -11
- data/spec/wavefront-cli/source_spec.rb +120 -23
- data/spec/wavefront-cli/stdlib/array_spec.rb +2 -1
- data/spec/wavefront-cli/stdlib/string_spec.rb +9 -6
- data/spec/wavefront-cli/user_spec.rb +278 -108
- data/spec/wavefront-cli/usergroup_spec.rb +152 -102
- data/spec/wavefront-cli/webhook_spec.rb +30 -15
- data/spec/wavefront-cli/write_spec.rb +25 -1
- data/wavefront-cli.gemspec +5 -3
- metadata +65 -21
- data/spec/wavefront-cli/commands/spec_helper.rb +0 -3
- data/spec/wavefront-cli/display/spec_helper.rb +0 -3
@@ -1,26 +1,123 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
|
+
# frozen_string_literal: true
|
2
3
|
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
4
|
+
require_relative '../support/command_base'
|
5
|
+
require_relative '../test_mixins/tag'
|
6
|
+
require_relative '../../lib/wavefront-cli/source'
|
7
|
+
|
8
|
+
# Ensure 'source' commands produce the correct API calls.
|
9
|
+
#
|
10
|
+
class SourceEndToEndTest < EndToEndTest
|
11
|
+
include WavefrontCliTest::Describe
|
12
|
+
include WavefrontCliTest::Search
|
13
|
+
include WavefrontCliTest::Tag
|
14
|
+
|
15
|
+
def test_list
|
16
|
+
quietly { assert_cmd_gets('list', '/api/v2/source') }
|
17
|
+
assert_noop('list',
|
18
|
+
'uri: GET https://default.wavefront.com/api/v2/source')
|
19
|
+
assert_abort_on_missing_creds('list')
|
20
|
+
end
|
21
|
+
|
22
|
+
def test_list_with_limit
|
23
|
+
quietly { assert_cmd_gets('list -L 10', '/api/v2/source?limit=10') }
|
24
|
+
|
25
|
+
assert_noop('list -L 10',
|
26
|
+
'uri: GET https://default.wavefront.com/api/v2/source',
|
27
|
+
'params: {:limit=>"10"}')
|
28
|
+
end
|
29
|
+
|
30
|
+
def test_list_with_cursor
|
31
|
+
quietly do
|
32
|
+
assert_cmd_gets('list --cursor box', '/api/v2/source?cursor=box')
|
33
|
+
end
|
34
|
+
|
35
|
+
assert_usage('list --offset 3')
|
36
|
+
end
|
37
|
+
|
38
|
+
def test_description_set
|
39
|
+
quietly do
|
40
|
+
assert_cmd_posts("description set #{id} tester",
|
41
|
+
"/api/v2/source/#{id}/description",
|
42
|
+
'tester')
|
43
|
+
end
|
44
|
+
|
45
|
+
assert_noop("description set #{id} tester",
|
46
|
+
'uri: POST https://default.wavefront.com/api/v2/source' \
|
47
|
+
"/#{id}/description",
|
48
|
+
'body: tester')
|
49
|
+
|
50
|
+
assert_invalid_id("description set #{invalid_id} tester")
|
51
|
+
assert_usage('description')
|
52
|
+
assert_usage('description set')
|
53
|
+
assert_usage("description set #{id}")
|
54
|
+
assert_abort_on_missing_creds("description set #{id} tester")
|
55
|
+
end
|
56
|
+
|
57
|
+
def test_description_clear
|
58
|
+
quietly do
|
59
|
+
assert_cmd_deletes("description clear #{id}",
|
60
|
+
"/api/v2/source/#{id}/description")
|
61
|
+
end
|
62
|
+
|
63
|
+
assert_noop("description clear #{id}",
|
64
|
+
'uri: DELETE https://default.wavefront.com/api/v2/source' \
|
65
|
+
"/#{id}/description")
|
66
|
+
|
67
|
+
assert_invalid_id("description clear #{invalid_id}")
|
68
|
+
assert_usage('description')
|
69
|
+
assert_usage('description clear')
|
70
|
+
assert_abort_on_missing_creds("description clear #{id}")
|
71
|
+
end
|
72
|
+
|
73
|
+
def test_clear
|
74
|
+
quietly do
|
75
|
+
assert_cmd_deletes("clear #{id}", "/api/v2/source/#{id}")
|
76
|
+
end
|
77
|
+
|
78
|
+
assert_noop("clear #{id}",
|
79
|
+
'uri: DELETE https://default.wavefront.com/api/v2/source' \
|
80
|
+
"/#{id}")
|
81
|
+
|
82
|
+
assert_invalid_id("clear #{invalid_id}")
|
83
|
+
assert_abort_on_missing_creds("clear #{id}")
|
84
|
+
assert_usage('clear')
|
85
|
+
end
|
86
|
+
|
87
|
+
# We tell the search mixin not to test with limits, so we'll have
|
88
|
+
# to test a cursor ourselves.
|
89
|
+
#
|
90
|
+
def test_search_equals_with_cursor
|
91
|
+
assert_repeated_output('No matches.') do
|
92
|
+
assert_cmd_posts("search id=#{id} -L 5 --cursor box",
|
93
|
+
"/api/v2/search/#{api_path}",
|
94
|
+
limit: '5',
|
95
|
+
cursor: 'box',
|
96
|
+
query: [{ key: 'id',
|
97
|
+
value: id,
|
98
|
+
matchingMethod: 'EXACT',
|
99
|
+
negated: false }],
|
100
|
+
sort: { field: 'id', ascending: true })
|
101
|
+
end
|
102
|
+
|
103
|
+
assert_abort_on_missing_creds("search id=#{id} -L 5 --cursor box")
|
104
|
+
end
|
105
|
+
|
106
|
+
private
|
107
|
+
|
108
|
+
def id
|
109
|
+
'74a247a9-f67c-43ad-911f-fabafa9dc2f3joyent'
|
110
|
+
end
|
111
|
+
|
112
|
+
def invalid_id
|
113
|
+
'(>_<)'
|
114
|
+
end
|
115
|
+
|
116
|
+
def cmd_word
|
117
|
+
'source'
|
118
|
+
end
|
119
|
+
|
120
|
+
def cannot_handle_offsets
|
121
|
+
true
|
122
|
+
end
|
26
123
|
end
|
@@ -1,6 +1,8 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
|
+
# frozen_string_literal: true
|
2
3
|
|
3
|
-
|
4
|
+
require 'minitest/autorun'
|
5
|
+
require_relative '../../constants'
|
4
6
|
require_relative '../../../lib/wavefront-cli/stdlib/string'
|
5
7
|
require_relative '../../../lib/wavefront-cli/commands/base'
|
6
8
|
|
@@ -22,14 +24,15 @@ class StringTest < MiniTest::Test
|
|
22
24
|
end
|
23
25
|
|
24
26
|
def test_opt_fold
|
25
|
-
assert_equal('short string'.opt_fold,
|
27
|
+
assert_equal('short string'.opt_fold, ' short string')
|
26
28
|
|
27
29
|
str = '-o, --option PARAMETER a rather pointless option with a ' \
|
28
30
|
'needlessly wordy description string'
|
29
31
|
pad = "\n" + ' ' * 12
|
30
32
|
assert_equal(" -o, --option PARAMETER a#{pad}rather pointless" \
|
31
33
|
"#{pad}option with a#{pad}needlessly wordy#{pad}" \
|
32
|
-
"description#{pad}string
|
34
|
+
"description#{pad}string",
|
35
|
+
str.opt_fold(30, 10))
|
33
36
|
end
|
34
37
|
|
35
38
|
def test_fold_options
|
@@ -38,12 +41,12 @@ class StringTest < MiniTest::Test
|
|
38
41
|
|
39
42
|
assert_equal(str.opt_fold,
|
40
43
|
' -l, --longoption a long option with a quite ' \
|
41
|
-
"long description which\n needs folding
|
44
|
+
"long description which\n needs folding")
|
42
45
|
assert_equal(str.opt_fold(50),
|
43
46
|
" -l, --longoption a long option with a\n " \
|
44
47
|
" quite long description which needs\n " \
|
45
|
-
|
46
|
-
assert_equal(str.opt_fold(100), " #{str}
|
48
|
+
' folding')
|
49
|
+
assert_equal(str.opt_fold(100), " #{str}")
|
47
50
|
end
|
48
51
|
|
49
52
|
def test_to_seconds
|
@@ -1,111 +1,281 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
|
+
# frozen_string_literal: true
|
2
3
|
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
4
|
+
require_relative '../support/command_base'
|
5
|
+
require_relative '../../lib/wavefront-cli/user'
|
6
|
+
|
7
|
+
# Ensure 'user' commands produce the correct API calls.
|
8
|
+
#
|
9
|
+
class UserEndToEndTest < EndToEndTest
|
10
|
+
include WavefrontCliTest::Search
|
11
|
+
include WavefrontCliTest::Describe
|
12
|
+
|
13
|
+
def test_list
|
14
|
+
quietly do
|
15
|
+
assert_cmd_gets('list', '/api/v2/user')
|
16
|
+
end
|
17
|
+
assert_noop('list',
|
18
|
+
'uri: GET https://default.wavefront.com/api/v2/user')
|
19
|
+
assert_abort_on_missing_creds('list')
|
20
|
+
end
|
21
|
+
|
22
|
+
def test_create
|
23
|
+
out, err = capture_io do
|
24
|
+
assert_cmd_posts(
|
25
|
+
"create #{id}", '/api/v2/user?sendEmail=false',
|
26
|
+
{ emailAddress: id,
|
27
|
+
groups: [],
|
28
|
+
userGroups: [] },
|
29
|
+
{ status: { result: 'OK', message: '', code: 200 },
|
30
|
+
response: { identifier: 'test1@sysdef.xyz',
|
31
|
+
customer: 'sysdef',
|
32
|
+
groups: [],
|
33
|
+
userGroups:
|
34
|
+
[{ id: '2659191e-aad4-4302-a94e-9667e1517127',
|
35
|
+
name: 'Everyone',
|
36
|
+
permissions: [],
|
37
|
+
customer: 'sysdef',
|
38
|
+
properties:
|
39
|
+
{ nameEditable: false,
|
40
|
+
permissionsEditable: true,
|
41
|
+
usersEditable: false },
|
42
|
+
description: 'System group which contains all users' }] } }.to_json
|
43
|
+
)
|
44
|
+
end
|
45
|
+
|
46
|
+
assert_empty err
|
47
|
+
out = out.split("\n")
|
48
|
+
assert_equal("Created user 'test1@sysdef.xyz'.", out[0])
|
49
|
+
assert_equal('Permission groups', out[1])
|
50
|
+
assert_equal(' <none>', out[2])
|
51
|
+
assert_equal('User groups', out[3])
|
52
|
+
assert_match(/^ Everyone \([0-9a-f\-]{36}\)$/, out.last)
|
53
|
+
end
|
54
|
+
|
55
|
+
def test_create_with_email_invite
|
56
|
+
out, err = capture_io do
|
57
|
+
assert_cmd_posts(
|
58
|
+
"create -e #{id}", '/api/v2/user?sendEmail=true',
|
59
|
+
{ emailAddress: id,
|
60
|
+
groups: [],
|
61
|
+
userGroups: [] },
|
62
|
+
{ status: { result: 'OK', message: '', code: 200 },
|
63
|
+
response: { identifier: 'test1@sysdef.xyz',
|
64
|
+
customer: 'sysdef',
|
65
|
+
groups: [],
|
66
|
+
userGroups:
|
67
|
+
[{ id: '2659191e-aad4-4302-a94e-9667e1517127',
|
68
|
+
name: 'Everyone',
|
69
|
+
permissions: [],
|
70
|
+
customer: 'sysdef',
|
71
|
+
properties:
|
72
|
+
{ nameEditable: false,
|
73
|
+
permissionsEditable: true,
|
74
|
+
usersEditable: false },
|
75
|
+
description: 'System group which contains all users' }] } }.to_json
|
76
|
+
)
|
77
|
+
end
|
78
|
+
|
79
|
+
assert_empty err
|
80
|
+
out = out.split("\n")
|
81
|
+
assert_equal("Created user 'test1@sysdef.xyz'.", out[0])
|
82
|
+
assert_equal('Permission groups', out[1])
|
83
|
+
assert_equal(' <none>', out[2])
|
84
|
+
assert_equal('User groups', out[3])
|
85
|
+
assert_match(/^ Everyone \([0-9a-f\-]{36}\)$/, out.last)
|
86
|
+
end
|
87
|
+
|
88
|
+
def test_create_with_groups
|
89
|
+
out, err = capture_io do
|
90
|
+
assert_cmd_posts(
|
91
|
+
"create -g #{groups[0]} -g #{groups[1]} #{id}",
|
92
|
+
'/api/v2/user?sendEmail=false',
|
93
|
+
{ emailAddress: id,
|
94
|
+
groups: [],
|
95
|
+
userGroups: groups },
|
96
|
+
{ status: { result: 'OK', message: '', code: 200 },
|
97
|
+
response: { identifier: 'test1@sysdef.xyz',
|
98
|
+
customer: 'sysdef',
|
99
|
+
groups: [],
|
100
|
+
userGroups:
|
101
|
+
[{ id: '2659191e-aad4-4302-a94e-9667e1517127',
|
102
|
+
name: 'Everyone',
|
103
|
+
permissions: [],
|
104
|
+
customer: 'sysdef',
|
105
|
+
properties:
|
106
|
+
{ nameEditable: false,
|
107
|
+
permissionsEditable: true,
|
108
|
+
usersEditable: false },
|
109
|
+
description: 'System group which contains all users' }] } }.to_json
|
110
|
+
)
|
111
|
+
end
|
112
|
+
|
113
|
+
assert_empty err
|
114
|
+
out = out.split("\n")
|
115
|
+
assert_equal("Created user 'test1@sysdef.xyz'.", out[0])
|
116
|
+
assert_equal('Permission groups', out[1])
|
117
|
+
assert_equal(' <none>', out[2])
|
118
|
+
assert_equal('User groups', out[3])
|
119
|
+
assert_match(/^ Everyone \([0-9a-f\-]{36}\)$/, out.last)
|
120
|
+
end
|
121
|
+
|
122
|
+
def test_invite
|
123
|
+
assert_repeated_output("Sent invitation to '#{id}'.") do
|
124
|
+
assert_cmd_posts("invite -m #{privilege} -g #{groups[1]} #{id}",
|
125
|
+
'/api/v2/user/invite',
|
126
|
+
[{ emailAddress: id,
|
127
|
+
groups: [privilege],
|
128
|
+
userGroups: [groups[1]] }].to_json)
|
129
|
+
end
|
130
|
+
|
131
|
+
assert_invalid_id("invite -m #{privilege} #{invalid_id}")
|
132
|
+
assert_abort_on_missing_creds("invite -m #{privilege} #{id}")
|
133
|
+
assert_usage('invite')
|
134
|
+
end
|
135
|
+
|
136
|
+
def test_delete
|
137
|
+
assert_repeated_output("Deleted '#{id}'.") do
|
138
|
+
assert_cmd_posts("delete #{id}",
|
139
|
+
'/api/v2/user/deleteUsers',
|
140
|
+
[id].to_json)
|
141
|
+
end
|
142
|
+
|
143
|
+
assert_invalid_id("delete #{invalid_id}")
|
144
|
+
assert_abort_on_missing_creds("delete #{id}")
|
145
|
+
assert_usage('delete')
|
146
|
+
end
|
147
|
+
|
148
|
+
def test_groups
|
149
|
+
assert_repeated_output('a7d26e51-cce1-4515-5ae8-1946f57ef5b3 (Everyone)') do
|
150
|
+
assert_cmd_gets("groups #{id}", "/api/v2/user/#{id}",
|
151
|
+
[{ identifier: 'someone@example.com',
|
152
|
+
userGroups:
|
153
|
+
[{ id: 'a7d26e51-cce1-4515-5ae8-1946f57ef5b3',
|
154
|
+
name: 'Everyone',
|
155
|
+
description: 'System group which contains all users' }] }].to_json)
|
156
|
+
end
|
157
|
+
|
158
|
+
assert_invalid_id("groups #{invalid_id}")
|
159
|
+
assert_abort_on_missing_creds("groups #{id}")
|
160
|
+
assert_usage('groups')
|
161
|
+
end
|
162
|
+
|
163
|
+
def test_privileges
|
164
|
+
quietly do
|
165
|
+
assert_cmd_gets("privileges #{id}", "/api/v2/user/#{id}")
|
166
|
+
end
|
167
|
+
|
168
|
+
assert_invalid_id("privileges #{invalid_id}")
|
169
|
+
assert_usage('privileges')
|
170
|
+
|
171
|
+
assert_noop(
|
172
|
+
"privileges #{id}",
|
173
|
+
"uri: GET https://default.wavefront.com/api/v2/user/#{id}"
|
174
|
+
)
|
175
|
+
|
176
|
+
assert_abort_on_missing_creds("privileges #{id}")
|
177
|
+
end
|
178
|
+
|
179
|
+
def test_join
|
180
|
+
assert_repeated_output("Added '#{id}' to '#{groups[0]}'.") do
|
181
|
+
assert_cmd_posts("join #{id} #{groups[0]}",
|
182
|
+
"/api/v2/user/#{id}/addUserGroups",
|
183
|
+
[groups[0]].to_json)
|
184
|
+
end
|
185
|
+
end
|
186
|
+
|
187
|
+
def test_leave
|
188
|
+
assert_repeated_output(
|
189
|
+
"Removed '#{id}' from '#{groups[0]}', '#{groups[1]}'."
|
190
|
+
) do
|
191
|
+
assert_cmd_posts("leave #{id} #{groups[0]} #{groups[1]}",
|
192
|
+
"/api/v2/user/#{id}/removeUserGroups",
|
193
|
+
groups.to_json)
|
194
|
+
end
|
195
|
+
|
196
|
+
assert_invalid_id("leave #{invalid_id} #{groups[0]} #{groups[1]}")
|
197
|
+
assert_abort_on_missing_creds("leave #{id} #{groups[0]} #{groups[1]}")
|
198
|
+
assert_usage('leave')
|
199
|
+
end
|
200
|
+
|
201
|
+
def test_grant
|
202
|
+
assert_repeated_output("Granted '#{privilege}' to '#{id}'.") do
|
203
|
+
assert_cmd_posts("grant #{privilege} to #{id}",
|
204
|
+
"/api/v2/user/#{id}/grant",
|
205
|
+
group: privilege)
|
206
|
+
end
|
207
|
+
|
208
|
+
assert_invalid_id("grant #{privilege} to #{invalid_id}")
|
209
|
+
assert_abort_on_missing_creds("grant #{privilege} to #{id}")
|
210
|
+
assert_usage("grant #{privilege}")
|
211
|
+
end
|
212
|
+
|
213
|
+
def test_revoke
|
214
|
+
assert_repeated_output("Revoked '#{privilege}' from '#{id}'.") do
|
215
|
+
assert_cmd_posts("revoke #{privilege} from #{id}",
|
216
|
+
"/api/v2/user/#{id}/revoke",
|
217
|
+
group: privilege)
|
218
|
+
end
|
219
|
+
|
220
|
+
assert_invalid_id("revoke #{privilege} from #{invalid_id}")
|
221
|
+
assert_abort_on_missing_creds("revoke #{privilege} from #{id}")
|
222
|
+
assert_usage("revoke #{privilege} #{id}")
|
223
|
+
end
|
224
|
+
|
225
|
+
# We have to override most of the dump tests because of the
|
226
|
+
# fudgery that goes on in the user API class.
|
227
|
+
#
|
228
|
+
def test_dump_json
|
229
|
+
out, err = capture_io do
|
230
|
+
assert_raises(SystemExit) do
|
231
|
+
assert_cmd_gets('dump --format=json', '/api/v2/user', list_response)
|
232
|
+
end
|
233
|
+
Spy.teardown
|
234
|
+
end
|
235
|
+
|
236
|
+
assert_empty(err)
|
237
|
+
assert_equal('[{"items":[{"identifier":"user1@example.com"},' \
|
238
|
+
'{"identifier":"user2@example.com"}]}]', out.strip)
|
239
|
+
end
|
240
|
+
|
241
|
+
def test_dump_yaml
|
242
|
+
out, err = capture_io do
|
243
|
+
assert_raises(SystemExit) do
|
244
|
+
assert_cmd_gets('dump --format=yaml', '/api/v2/user', list_response)
|
245
|
+
end
|
246
|
+
Spy.teardown
|
247
|
+
end
|
248
|
+
|
249
|
+
assert_empty(err)
|
250
|
+
assert_equal("---\n- items:\n - identifier: user1@example.com\n " \
|
251
|
+
'- identifier: user2@example.com', out.strip)
|
252
|
+
end
|
253
|
+
|
254
|
+
private
|
255
|
+
|
256
|
+
def id
|
257
|
+
'someonesomewhere.com'
|
258
|
+
end
|
259
|
+
|
260
|
+
def invalid_id
|
261
|
+
'bad' * 200
|
262
|
+
end
|
263
|
+
|
264
|
+
def cmd_word
|
265
|
+
'user'
|
266
|
+
end
|
267
|
+
|
268
|
+
def groups
|
269
|
+
%w[2659191e-aad4-4302-a94e-9667e1517127
|
270
|
+
abcdef12-1234-abcd-1234-abcdef012345]
|
271
|
+
end
|
272
|
+
|
273
|
+
def list_response
|
274
|
+
{ items: [{ identifier: 'user1@example.com' },
|
275
|
+
{ identifier: 'user2@example.com' }] }.to_json
|
276
|
+
end
|
277
|
+
|
278
|
+
def privilege
|
279
|
+
'alerts_management'
|
280
|
+
end
|
111
281
|
end
|