wavefront-cli 4.2.1 → 4.3.0

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.
Files changed (190) hide show
  1. checksums.yaml +4 -4
  2. data/.codeclimate.yml +1 -0
  3. data/.rubocop.yml +1 -14
  4. data/.travis.yml +4 -4
  5. data/Gemfile +2 -0
  6. data/HISTORY.md +82 -60
  7. data/Rakefile +2 -0
  8. data/bin/wf +1 -0
  9. data/lib/wavefront-cli/alert.rb +13 -5
  10. data/lib/wavefront-cli/apitoken.rb +2 -0
  11. data/lib/wavefront-cli/base.rb +95 -47
  12. data/lib/wavefront-cli/cloudintegration.rb +6 -0
  13. data/lib/wavefront-cli/command_mixins/acl.rb +6 -1
  14. data/lib/wavefront-cli/command_mixins/tag.rb +2 -0
  15. data/lib/wavefront-cli/commands/.rubocop.yml +3 -4
  16. data/lib/wavefront-cli/commands/alert.rb +2 -1
  17. data/lib/wavefront-cli/commands/apitoken.rb +6 -0
  18. data/lib/wavefront-cli/commands/base.rb +30 -21
  19. data/lib/wavefront-cli/commands/cloudintegration.rb +2 -0
  20. data/lib/wavefront-cli/commands/config.rb +2 -0
  21. data/lib/wavefront-cli/commands/dashboard.rb +2 -0
  22. data/lib/wavefront-cli/commands/derivedmetric.rb +2 -0
  23. data/lib/wavefront-cli/commands/event.rb +3 -1
  24. data/lib/wavefront-cli/commands/integration.rb +2 -1
  25. data/lib/wavefront-cli/commands/link.rb +2 -0
  26. data/lib/wavefront-cli/commands/message.rb +2 -0
  27. data/lib/wavefront-cli/commands/metric.rb +2 -0
  28. data/lib/wavefront-cli/commands/notificant.rb +2 -0
  29. data/lib/wavefront-cli/commands/proxy.rb +2 -0
  30. data/lib/wavefront-cli/commands/query.rb +2 -0
  31. data/lib/wavefront-cli/commands/savedsearch.rb +2 -0
  32. data/lib/wavefront-cli/commands/serviceaccount.rb +58 -0
  33. data/lib/wavefront-cli/commands/settings.rb +2 -0
  34. data/lib/wavefront-cli/commands/source.rb +3 -1
  35. data/lib/wavefront-cli/commands/user.rb +4 -1
  36. data/lib/wavefront-cli/commands/usergroup.rb +3 -0
  37. data/lib/wavefront-cli/commands/webhook.rb +2 -0
  38. data/lib/wavefront-cli/commands/window.rb +2 -0
  39. data/lib/wavefront-cli/commands/write.rb +2 -0
  40. data/lib/wavefront-cli/config.rb +23 -12
  41. data/lib/wavefront-cli/constants.rb +10 -4
  42. data/lib/wavefront-cli/controller.rb +53 -22
  43. data/lib/wavefront-cli/dashboard.rb +3 -0
  44. data/lib/wavefront-cli/derivedmetric.rb +12 -11
  45. data/lib/wavefront-cli/display/alert.rb +7 -4
  46. data/lib/wavefront-cli/display/apitoken.rb +2 -0
  47. data/lib/wavefront-cli/display/base.rb +34 -8
  48. data/lib/wavefront-cli/display/cloudintegration.rb +4 -2
  49. data/lib/wavefront-cli/display/dashboard.rb +2 -0
  50. data/lib/wavefront-cli/display/derivedmetric.rb +2 -0
  51. data/lib/wavefront-cli/display/distribution.rb +2 -0
  52. data/lib/wavefront-cli/display/event.rb +2 -0
  53. data/lib/wavefront-cli/display/externallink.rb +2 -0
  54. data/lib/wavefront-cli/display/integration.rb +2 -0
  55. data/lib/wavefront-cli/display/maintenancewindow.rb +2 -0
  56. data/lib/wavefront-cli/display/message.rb +7 -3
  57. data/lib/wavefront-cli/display/metric.rb +3 -1
  58. data/lib/wavefront-cli/display/notificant.rb +3 -1
  59. data/lib/wavefront-cli/display/printer/long.rb +36 -11
  60. data/lib/wavefront-cli/display/printer/sparkline.rb +3 -0
  61. data/lib/wavefront-cli/display/printer/terse.rb +6 -1
  62. data/lib/wavefront-cli/display/proxy.rb +2 -0
  63. data/lib/wavefront-cli/display/query.rb +35 -24
  64. data/lib/wavefront-cli/display/savedsearch.rb +2 -0
  65. data/lib/wavefront-cli/display/serviceaccount.rb +60 -0
  66. data/lib/wavefront-cli/display/settings.rb +2 -0
  67. data/lib/wavefront-cli/display/source.rb +18 -4
  68. data/lib/wavefront-cli/display/user.rb +56 -10
  69. data/lib/wavefront-cli/display/usergroup.rb +25 -19
  70. data/lib/wavefront-cli/display/webhook.rb +2 -0
  71. data/lib/wavefront-cli/display/write.rb +6 -2
  72. data/lib/wavefront-cli/event.rb +83 -62
  73. data/lib/wavefront-cli/exception.rb +3 -0
  74. data/lib/wavefront-cli/externallink.rb +6 -4
  75. data/lib/wavefront-cli/integration.rb +2 -0
  76. data/lib/wavefront-cli/maintenancewindow.rb +28 -17
  77. data/lib/wavefront-cli/message.rb +4 -0
  78. data/lib/wavefront-cli/metric.rb +4 -1
  79. data/lib/wavefront-cli/notificant.rb +2 -0
  80. data/lib/wavefront-cli/opt_handler.rb +2 -0
  81. data/lib/wavefront-cli/output/base.rb +8 -3
  82. data/lib/wavefront-cli/output/csv.rb +2 -0
  83. data/lib/wavefront-cli/output/csv/base.rb +2 -0
  84. data/lib/wavefront-cli/output/csv/query.rb +14 -7
  85. data/lib/wavefront-cli/output/hcl.rb +2 -0
  86. data/lib/wavefront-cli/output/hcl/alert.rb +2 -0
  87. data/lib/wavefront-cli/output/hcl/base.rb +10 -4
  88. data/lib/wavefront-cli/output/hcl/dashboard.rb +17 -8
  89. data/lib/wavefront-cli/output/hcl/notificant.rb +2 -0
  90. data/lib/wavefront-cli/output/hcl/stdlib/array.rb +2 -0
  91. data/lib/wavefront-cli/output/hcl/stdlib/string.rb +2 -0
  92. data/lib/wavefront-cli/output/json.rb +2 -0
  93. data/lib/wavefront-cli/output/ruby.rb +2 -0
  94. data/lib/wavefront-cli/output/wavefront.rb +2 -0
  95. data/lib/wavefront-cli/output/wavefront/query.rb +7 -4
  96. data/lib/wavefront-cli/output/yaml.rb +2 -0
  97. data/lib/wavefront-cli/proxy.rb +15 -3
  98. data/lib/wavefront-cli/query.rb +14 -12
  99. data/lib/wavefront-cli/savedsearch.rb +2 -0
  100. data/lib/wavefront-cli/serviceaccount.rb +179 -0
  101. data/lib/wavefront-cli/settings.rb +2 -0
  102. data/lib/wavefront-cli/source.rb +2 -0
  103. data/lib/wavefront-cli/stdlib/array.rb +3 -0
  104. data/lib/wavefront-cli/stdlib/string.rb +17 -11
  105. data/lib/wavefront-cli/user.rb +10 -4
  106. data/lib/wavefront-cli/usergroup.rb +4 -2
  107. data/lib/wavefront-cli/version.rb +3 -1
  108. data/lib/wavefront-cli/webhook.rb +2 -0
  109. data/lib/wavefront-cli/write.rb +80 -46
  110. data/spec/.rubocop.yml +3 -16
  111. data/spec/constants.rb +21 -0
  112. data/spec/spec_helper.rb +8 -422
  113. data/spec/support/command_base.rb +82 -0
  114. data/spec/support/minitest_assertions.rb +262 -0
  115. data/spec/support/output_tester.rb +32 -0
  116. data/spec/support/supported_commands.rb +19 -0
  117. data/spec/test_mixins/acl.rb +169 -0
  118. data/spec/test_mixins/delete.rb +25 -0
  119. data/spec/test_mixins/deleteundelete.rb +106 -0
  120. data/spec/test_mixins/describe.rb +24 -0
  121. data/spec/test_mixins/dump.rb +43 -0
  122. data/spec/test_mixins/general.rb +11 -0
  123. data/spec/test_mixins/history.rb +35 -0
  124. data/spec/test_mixins/import.rb +65 -0
  125. data/spec/test_mixins/list.rb +29 -0
  126. data/spec/test_mixins/search.rb +98 -0
  127. data/spec/test_mixins/set.rb +47 -0
  128. data/spec/test_mixins/tag.rb +99 -0
  129. data/spec/wavefront-cli/alert_spec.rb +288 -111
  130. data/spec/wavefront-cli/apitoken_spec.rb +53 -24
  131. data/spec/wavefront-cli/base_spec.rb +9 -27
  132. data/spec/wavefront-cli/cloudintegration_spec.rb +65 -29
  133. data/spec/wavefront-cli/commands/alert_spec.rb +1 -0
  134. data/spec/wavefront-cli/commands/base_spec.rb +15 -13
  135. data/spec/wavefront-cli/commands/cloudintegration_spec.rb +1 -0
  136. data/spec/wavefront-cli/commands/config_spec.rb +3 -0
  137. data/spec/wavefront-cli/commands/dashboard_spec.rb +1 -0
  138. data/spec/wavefront-cli/commands/derivedmetric_spec.rb +1 -0
  139. data/spec/wavefront-cli/commands/event_spec.rb +1 -0
  140. data/spec/wavefront-cli/commands/link_spec.rb +1 -0
  141. data/spec/wavefront-cli/commands/message_spec.rb +1 -0
  142. data/spec/wavefront-cli/commands/metric_spec.rb +1 -0
  143. data/spec/wavefront-cli/commands/proxy_spec.rb +1 -0
  144. data/spec/wavefront-cli/commands/query_spec.rb +1 -0
  145. data/spec/wavefront-cli/commands/webhook_spec.rb +1 -0
  146. data/spec/wavefront-cli/commands/window_spec.rb +1 -0
  147. data/spec/wavefront-cli/commands/write_spec.rb +1 -0
  148. data/spec/wavefront-cli/config_spec.rb +25 -14
  149. data/spec/wavefront-cli/controller_spec.rb +13 -3
  150. data/spec/wavefront-cli/dashboard_spec.rb +125 -76
  151. data/spec/wavefront-cli/derivedmetric_spec.rb +83 -67
  152. data/spec/wavefront-cli/display/base_spec.rb +5 -7
  153. data/spec/wavefront-cli/display/printer/long_spec.rb +20 -16
  154. data/spec/wavefront-cli/display/printer/terse_spec.rb +5 -4
  155. data/spec/wavefront-cli/event_spec.rb +360 -18
  156. data/spec/wavefront-cli/externallink_spec.rb +92 -58
  157. data/spec/wavefront-cli/integration_spec.rb +129 -31
  158. data/spec/wavefront-cli/maintenancewindow_spec.rb +270 -32
  159. data/spec/wavefront-cli/message_spec.rb +73 -30
  160. data/spec/wavefront-cli/metric_spec.rb +60 -22
  161. data/spec/wavefront-cli/notificant_spec.rb +45 -32
  162. data/spec/wavefront-cli/opt_handler_spec.rb +4 -1
  163. data/spec/wavefront-cli/output/csv/query_spec.rb +21 -19
  164. data/spec/wavefront-cli/output/csv_spec.rb +5 -2
  165. data/spec/wavefront-cli/output/hcl_spec.rb +5 -2
  166. data/spec/wavefront-cli/output/helpers.rb +18 -0
  167. data/spec/wavefront-cli/output/json_spec.rb +3 -1
  168. data/spec/wavefront-cli/output/ruby_spec.rb +3 -1
  169. data/spec/wavefront-cli/output/wavefront/query_spec.rb +3 -1
  170. data/spec/wavefront-cli/output/wavefront_spec.rb +6 -4
  171. data/spec/wavefront-cli/output/yaml_spec.rb +3 -1
  172. data/spec/wavefront-cli/proxy_spec.rb +49 -27
  173. data/spec/wavefront-cli/query_spec.rb +174 -92
  174. data/spec/wavefront-cli/resources/responses/query.json +1 -0
  175. data/spec/wavefront-cli/resources/updates/alert.json +15 -0
  176. data/spec/wavefront-cli/resources/updates/dashboard.json +1 -0
  177. data/spec/wavefront-cli/savedsearch_spec.rb +35 -18
  178. data/spec/wavefront-cli/serviceaccount_spec.rb +399 -0
  179. data/spec/wavefront-cli/settings_spec.rb +42 -11
  180. data/spec/wavefront-cli/source_spec.rb +120 -23
  181. data/spec/wavefront-cli/stdlib/array_spec.rb +2 -1
  182. data/spec/wavefront-cli/stdlib/string_spec.rb +9 -6
  183. data/spec/wavefront-cli/user_spec.rb +278 -108
  184. data/spec/wavefront-cli/usergroup_spec.rb +152 -102
  185. data/spec/wavefront-cli/webhook_spec.rb +30 -15
  186. data/spec/wavefront-cli/write_spec.rb +25 -1
  187. data/wavefront-cli.gemspec +5 -3
  188. metadata +65 -21
  189. data/spec/wavefront-cli/commands/spec_helper.rb +0 -3
  190. 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
- id = '74a247a9-f67c-43ad-911f-fabafa9dc2f3joyent'
4
- bad_id = '(>_<)'
5
- word = 'source'
6
-
7
- require_relative '../spec_helper'
8
- require_relative "../../lib/wavefront-cli/#{word}"
9
-
10
- describe "#{word} command" do
11
- missing_creds(word, ['list', "describe #{id}", "clear #{id}"])
12
- cmd_to_call(word, 'list', path: "/api/v2/#{word}")
13
- cmd_to_call(word, 'list -L 50', path: "/api/v2/#{word}?limit=50")
14
- cmd_to_call(word, 'list -L 100 -o mysource',
15
- path: "/api/v2/#{word}?cursor=mysource&limit=100")
16
- cmd_to_call(word, "describe #{id}", path: "/api/v2/#{word}/#{id}")
17
- cmd_to_call(word, "clear #{id}",
18
- method: :delete, path: "/api/v2/#{word}/#{id}")
19
- invalid_ids(word, ["describe #{bad_id}", "clear #{bad_id}"])
20
- tag_tests(word, id, bad_id)
21
- cmd_noop(word, 'list',
22
- ['GET https://metrics.wavefront.com/api/v2/source'])
23
- cmd_noop(word, 'describe src',
24
- ['GET https://metrics.wavefront.com/api/v2/source/src'])
25
- search_tests(word, id)
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,7 @@
1
1
  #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
2
3
 
3
- require_relative '../../spec_helper'
4
+ require 'minitest/autorun'
4
5
  require_relative '../../../lib/wavefront-cli/stdlib/array'
5
6
 
6
7
  # Test extensions to stlib Array
@@ -1,6 +1,8 @@
1
1
  #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
2
3
 
3
- require_relative '../../spec_helper'
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, " short string\n")
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\n", str.opt_fold(30, 10))
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\n")
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
- " folding\n")
46
- assert_equal(str.opt_fold(100), " #{str}\n")
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
- id = 'someone@somewhere.com'
4
- bad_id = 'b' * 600
5
- word = 'user'
6
- gid1 = '2659191e-aad4-4302-a94e-9667e1517127'
7
- gid2 = 'abcdef12-1234-abcd-1234-abcdef012345'
8
- priv = 'alerts_management'
9
-
10
- require_relative '../spec_helper'
11
- require_relative "../../lib/wavefront-cli/#{word}"
12
-
13
- describe "#{word} command" do
14
- hdrs = JSON_POST_HEADERS.merge(
15
- 'Content-Type': 'application/x-www-form-urlencoded'
16
- )
17
-
18
- missing_creds(word, ['list',
19
- "describe #{id}",
20
- "delete #{id}",
21
- "create #{id}",
22
- "invite #{id}",
23
- "set key=val #{id}",
24
- 'import file',
25
- "groups #{id}",
26
- "join #{id} #{gid1}",
27
- "leave #{id} #{gid1}",
28
- "grant #{priv} to #{id}",
29
- "revoke #{priv} from #{id}"])
30
-
31
- cmd_to_call(word, 'list', path: "/api/v2/#{word}")
32
-
33
- cmd_to_call(word, "describe #{id}", path: "/api/v2/#{word}/#{id}")
34
-
35
- cmd_to_call(word, "create #{id}",
36
- method: :post,
37
- path: "/api/v2/#{word}?sendEmail=false",
38
- body: { emailAddress: id,
39
- groups: [],
40
- userGroups: [] }.to_json)
41
-
42
- cmd_to_call(word, "create -e #{id} -m #{priv}",
43
- method: :post,
44
- path: "/api/v2/#{word}?sendEmail=true",
45
- body: { emailAddress: id,
46
- groups: [priv],
47
- userGroups: [] }.to_json)
48
-
49
- cmd_to_call(word, "create #{id} -g #{gid1} -g #{gid2}",
50
- method: :post,
51
- path: "/api/v2/#{word}?sendEmail=false",
52
- body: { emailAddress: id,
53
- groups: [],
54
- userGroups: [gid1, gid2] }.to_json)
55
-
56
- cmd_to_call(word, "invite -m #{priv} -g #{gid2} #{id}",
57
- method: :post,
58
- path: "/api/v2/#{word}/invite",
59
- body: [{ emailAddress: id,
60
- groups: [priv],
61
- userGroups: [gid2] }].to_json)
62
-
63
- cmd_to_call(word, "delete #{id}",
64
- method: :post,
65
- path: "/api/v2/#{word}/deleteUsers",
66
- body: [id].to_json)
67
-
68
- cmd_to_call(word, "groups #{id}", path: "/api/v2/#{word}/#{id}")
69
-
70
- cmd_to_call(word, "join #{id} #{gid1}",
71
- method: :post,
72
- path: "/api/v2/#{word}/#{id}/addUserGroups",
73
- body: [gid1].to_json)
74
-
75
- cmd_to_call(word, "leave #{id} #{gid2} #{gid1}",
76
- method: :post,
77
- path: "/api/v2/#{word}/#{id}/removeUserGroups",
78
- body: [gid2, gid1].to_json)
79
-
80
- cmd_to_call(word, "grant agent_management to #{id}",
81
- method: :post,
82
- path: "/api/v2/#{word}/#{id}/grant",
83
- body: 'group=agent_management',
84
- headers: hdrs)
85
-
86
- cmd_to_call(word, "revoke agent_management from #{id}",
87
- method: :post,
88
- path: "/api/v2/#{word}/#{id}/revoke",
89
- body: 'group=agent_management',
90
- headers: hdrs)
91
-
92
- search_tests(word, id)
93
-
94
- invalid_ids(word, ["describe #{bad_id}",
95
- "delete #{bad_id}",
96
- "delete #{id} #{bad_id}",
97
- "delete #{bad_id}",
98
- "invite #{bad_id}",
99
- "create -e #{bad_id}",
100
- "groups #{bad_id}",
101
- "join #{bad_id} #{gid1}",
102
- "leave #{bad_id} #{gid1}",
103
- "grant #{priv} to #{bad_id}",
104
- "revoke #{priv} from #{bad_id}"])
105
-
106
- cmd_noop(word, 'list',
107
- ["GET https://metrics.wavefront.com/api/v2/#{word}"])
108
- cmd_noop(word, 'describe rob@a.com',
109
- ["GET https://metrics.wavefront.com/api/v2/#{word}/rob@a.com"])
110
- test_list_output(word)
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