wavefront-cli 6.0.0 → 8.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (69) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop.yml +12 -7
  3. data/.travis.yml +4 -5
  4. data/HISTORY.md +34 -1
  5. data/README.md +3 -4
  6. data/lib/wavefront-cli/account.rb +119 -0
  7. data/lib/wavefront-cli/alert.rb +29 -0
  8. data/lib/wavefront-cli/base.rb +10 -12
  9. data/lib/wavefront-cli/cloudintegration.rb +12 -0
  10. data/lib/wavefront-cli/commands/.rubocop.yml +12 -6
  11. data/lib/wavefront-cli/commands/account.rb +61 -0
  12. data/lib/wavefront-cli/commands/alert.rb +1 -0
  13. data/lib/wavefront-cli/commands/base.rb +1 -1
  14. data/lib/wavefront-cli/commands/cloudintegration.rb +4 -1
  15. data/lib/wavefront-cli/commands/proxy.rb +2 -1
  16. data/lib/wavefront-cli/commands/query.rb +4 -1
  17. data/lib/wavefront-cli/commands/role.rb +44 -0
  18. data/lib/wavefront-cli/commands/spy.rb +0 -5
  19. data/lib/wavefront-cli/commands/usergroup.rb +7 -11
  20. data/lib/wavefront-cli/commands/write.rb +7 -2
  21. data/lib/wavefront-cli/config.rb +3 -1
  22. data/lib/wavefront-cli/controller.rb +6 -66
  23. data/lib/wavefront-cli/display/account.rb +122 -0
  24. data/lib/wavefront-cli/display/alert.rb +8 -0
  25. data/lib/wavefront-cli/display/base.rb +1 -1
  26. data/lib/wavefront-cli/display/cloudintegration.rb +15 -2
  27. data/lib/wavefront-cli/display/printer/long.rb +6 -1
  28. data/lib/wavefront-cli/display/proxy.rb +16 -0
  29. data/lib/wavefront-cli/display/role.rb +66 -0
  30. data/lib/wavefront-cli/display/settings.rb +1 -0
  31. data/lib/wavefront-cli/display/usergroup.rb +18 -14
  32. data/lib/wavefront-cli/event.rb +2 -0
  33. data/lib/wavefront-cli/exception_handler.rb +87 -0
  34. data/lib/wavefront-cli/externallink.rb +4 -6
  35. data/lib/wavefront-cli/helpers/load_file.rb +1 -1
  36. data/lib/wavefront-cli/opt_handler.rb +5 -3
  37. data/lib/wavefront-cli/output/hcl/base.rb +1 -1
  38. data/lib/wavefront-cli/proxy.rb +5 -0
  39. data/lib/wavefront-cli/query.rb +13 -7
  40. data/lib/wavefront-cli/role.rb +54 -0
  41. data/lib/wavefront-cli/serviceaccount.rb +0 -6
  42. data/lib/wavefront-cli/spy.rb +0 -8
  43. data/lib/wavefront-cli/usergroup.rb +8 -8
  44. data/lib/wavefront-cli/version.rb +1 -1
  45. data/lib/wavefront-cli/write.rb +33 -11
  46. data/spec/.rubocop.yml +13 -6
  47. data/spec/support/minitest_assertions.rb +2 -4
  48. data/spec/test_mixins/delete.rb +1 -2
  49. data/spec/wavefront-cli/account_spec.rb +303 -0
  50. data/spec/wavefront-cli/alert_spec.rb +28 -0
  51. data/spec/wavefront-cli/cloudintegration_spec.rb +19 -6
  52. data/spec/wavefront-cli/commands/write_spec.rb +1 -1
  53. data/spec/wavefront-cli/config_spec.rb +1 -1
  54. data/spec/wavefront-cli/controller_spec.rb +2 -0
  55. data/spec/wavefront-cli/event_spec.rb +1 -1
  56. data/spec/wavefront-cli/output/csv/query_spec.rb +1 -1
  57. data/spec/wavefront-cli/output/wavefront/query_spec.rb +2 -2
  58. data/spec/wavefront-cli/query_spec.rb +20 -3
  59. data/spec/wavefront-cli/role_spec.rb +187 -0
  60. data/spec/wavefront-cli/serviceaccount_spec.rb +3 -3
  61. data/spec/wavefront-cli/usergroup_spec.rb +48 -43
  62. data/spec/wavefront-cli/write_spec.rb +44 -0
  63. data/wavefront-cli.gemspec +6 -6
  64. metadata +27 -36
  65. data/lib/wavefront-cli/commands/user.rb +0 -54
  66. data/lib/wavefront-cli/display/user.rb +0 -103
  67. data/lib/wavefront-cli/user.rb +0 -92
  68. data/spec/wavefront-cli/resources/responses/user-list.json +0 -1
  69. data/spec/wavefront-cli/user_spec.rb +0 -311
@@ -1,92 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require_relative 'base'
4
-
5
- module WavefrontCli
6
- #
7
- # CLI coverage for the v2 'user' API.
8
- #
9
- class User < WavefrontCli::Base
10
- def do_list
11
- wf.list
12
- end
13
-
14
- def do_delete
15
- wf.delete_users(options[:'<user>'])
16
- end
17
-
18
- def do_create
19
- wf_user_id?(options[:'<id>'])
20
- wf.create(user_body, options[:email])
21
- end
22
-
23
- alias do_groups do_describe
24
- alias do_privileges do_describe
25
-
26
- def do_join
27
- wf.add_groups_to_user(options[:'<id>'], options[:'<group>'])
28
- end
29
-
30
- def do_leave
31
- wf.remove_groups_from_user(options[:'<id>'], options[:'<group>'])
32
- end
33
-
34
- def do_grant
35
- wf.grant(options[:'<id>'], options[:'<privilege>'])
36
- end
37
-
38
- def do_revoke
39
- wf.revoke(options[:'<id>'], options[:'<privilege>'])
40
- end
41
-
42
- def do_invite
43
- wf_user_id?(options[:'<id>'])
44
- wf.invite([user_body])
45
- end
46
-
47
- def do_business_functions
48
- wf_user_id?(options[:'<id>'])
49
- wf.business_functions(options[:'<id>'])
50
- end
51
-
52
- def do_validate
53
- wf.validate_users(options[:'<user>'])
54
- end
55
-
56
- def import_to_create(raw)
57
- { emailAddress: raw['items']['identifier'],
58
- groups: raw['items']['groups'] }.tap do |r|
59
- if raw['items'].key?('userGroups')
60
- r['userGroups'] = raw['items']['userGroups'].map { |g| g['id'] }
61
- end
62
- end
63
- end
64
-
65
- # Object used to create and invite users.
66
- #
67
- def user_body
68
- { emailAddress: options[:'<id>'],
69
- groups: options[:permission],
70
- userGroups: options[:group] }
71
- end
72
-
73
- # Because of the way docopt works, we have to call the user ID
74
- # parameter something else on the delete command. This means the
75
- # automatic validtion doesn't work, and we have to do it
76
- # ourselves.
77
- #
78
- def extra_validation
79
- options[:'<user>']&.each { |u| validate_user(u) }
80
- end
81
-
82
- def validate_user(user)
83
- wf_user_id?(user)
84
- rescue Wavefront::Exception::InvalidUserId
85
- abort failed_validation_message(user)
86
- end
87
-
88
- def item_dump_call
89
- wf.list.response.items
90
- end
91
- end
92
- end
@@ -1 +0,0 @@
1
- {"items":[{"identifier":"dev+sysdef@wavefront.com","customer":"sysdef","lastSuccessfulLogin":1549996596333,"groups":["agent_management","alerts_management","dashboard_management","ingestion","events_management","host_tag_management","user_management","embedded_charts","metrics_management","application_management","external_links_management"]},{"identifier":"rob@somewhere.xyz","customer":"sysdef","lastSuccessfulLogin":1550676149122,"groups":["agent_management","host_tag_management","events_management","alerts_management","dashboard_management","metrics_management","embedded_charts","ingestion","user_management","application_management","external_links_management"]},{"identifier":"sam@elsewhere.net","customer":"sysdef","lastSuccessfulLogin":1541000935563,"groups":[]},{"identifier":"services@example.com","customer":"sysdef","groups":[]},{"identifier":"someone@example.com","customer":"sysdef","lastSuccessfulLogin":1535977667674,"groups":["host_tag_management","dashboard_management","embedded_charts","metrics_management","agent_management","events_management","external_links_management","alerts_management","ingestion","user_management","application_management"]}],"offset":0,"limit":5,"totalItems":5,"modeItems":false}
@@ -1,311 +0,0 @@
1
- #!/usr/bin/env ruby
2
- # frozen_string_literal: true
3
-
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
- def test_business_functions
255
- quietly do
256
- assert_cmd_gets("business functions #{id}",
257
- "/api/v2/user/#{id}/businessFunctions")
258
- end
259
-
260
- assert_noop("business functions #{id}",
261
- 'uri: GET https://default.wavefront.com/api/v2/user/' \
262
- "#{id}/businessFunctions")
263
- assert_invalid_id("business functions #{invalid_id}")
264
- assert_abort_on_missing_creds("business functions #{id}")
265
- assert_usage('business functions')
266
- end
267
-
268
- def test_validate
269
- quietly do
270
- assert_cmd_posts("validate #{user_list.join(' ')}",
271
- '/api/v2/user/validateUsers',
272
- user_list.to_json,
273
- IO.read(RES_DIR + 'responses' + 'user-validate.json'))
274
- end
275
- end
276
-
277
- private
278
-
279
- def id
280
- 'someonesomewhere.com'
281
- end
282
-
283
- def invalid_id
284
- 'bad' * 200
285
- end
286
-
287
- def cmd_word
288
- 'user'
289
- end
290
-
291
- def groups
292
- %w[2659191e-aad4-4302-a94e-9667e1517127
293
- abcdef12-1234-abcd-1234-abcdef012345]
294
- end
295
-
296
- def list_response
297
- { items: [{ identifier: 'user1@example.com' },
298
- { identifier: 'user2@example.com' }] }.to_json
299
- end
300
-
301
- def privilege
302
- 'alerts_management'
303
- end
304
-
305
- def user_list
306
- %w[rob@somewhere.xyz
307
- services@elsewhere.net
308
- rob@elsewhere.net
309
- no-such-thing]
310
- end
311
- end