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
@@ -0,0 +1,399 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
require_relative '../support/command_base'
|
5
|
+
require_relative '../../lib/wavefront-cli/serviceaccount'
|
6
|
+
|
7
|
+
# Ensure 'serviceaccount' commands produce the correct API calls.
|
8
|
+
#
|
9
|
+
# rubocop:disable Metrics/ClassLength
|
10
|
+
class ServiceAccountEndToEndTest < EndToEndTest
|
11
|
+
include WavefrontCliTest::Describe
|
12
|
+
# include WavefrontCliTest::Import
|
13
|
+
include WavefrontCliTest::Set
|
14
|
+
include WavefrontCliTest::Search
|
15
|
+
|
16
|
+
def test_list
|
17
|
+
quietly do
|
18
|
+
assert_cmd_gets('list', '/api/v2/account/serviceaccount')
|
19
|
+
end
|
20
|
+
|
21
|
+
assert_noop(
|
22
|
+
'list',
|
23
|
+
'uri: GET https://default.wavefront.com/api/v2/account/serviceaccount'
|
24
|
+
)
|
25
|
+
assert_abort_on_missing_creds('list')
|
26
|
+
end
|
27
|
+
|
28
|
+
def test_groups
|
29
|
+
quietly do
|
30
|
+
assert_cmd_gets("groups #{id}", "/api/v2/#{api_path}/#{id}")
|
31
|
+
end
|
32
|
+
|
33
|
+
assert_invalid_id("groups #{invalid_id}")
|
34
|
+
assert_usage('groups')
|
35
|
+
|
36
|
+
assert_noop(
|
37
|
+
"groups #{id}",
|
38
|
+
"uri: GET https://default.wavefront.com/api/v2/#{api_path}/#{id}"
|
39
|
+
)
|
40
|
+
|
41
|
+
assert_abort_on_missing_creds("groups #{id}")
|
42
|
+
end
|
43
|
+
|
44
|
+
def test_privileges
|
45
|
+
quietly do
|
46
|
+
assert_cmd_gets("privileges #{id}", "/api/v2/#{api_path}/#{id}")
|
47
|
+
end
|
48
|
+
|
49
|
+
assert_invalid_id("privileges #{invalid_id}")
|
50
|
+
assert_usage('privileges')
|
51
|
+
|
52
|
+
assert_noop(
|
53
|
+
"privileges #{id}",
|
54
|
+
"uri: GET https://default.wavefront.com/api/v2/#{api_path}/#{id}"
|
55
|
+
)
|
56
|
+
|
57
|
+
assert_abort_on_missing_creds("privileges #{id}")
|
58
|
+
end
|
59
|
+
|
60
|
+
def test_activate
|
61
|
+
assert_repeated_output("Activated service account 'sa::test-id'.") do
|
62
|
+
assert_cmd_posts("activate #{id}",
|
63
|
+
"/api/v2/account/serviceaccount/#{id}/activate")
|
64
|
+
end
|
65
|
+
|
66
|
+
assert_invalid_id("activate #{invalid_id}")
|
67
|
+
assert_abort_on_missing_creds("activate #{id}")
|
68
|
+
assert_usage('activate')
|
69
|
+
end
|
70
|
+
|
71
|
+
def test_deactivate
|
72
|
+
assert_repeated_output("Deactivated service account 'sa::test-id'.") do
|
73
|
+
assert_cmd_posts("deactivate #{id}",
|
74
|
+
"/api/v2/account/serviceaccount/#{id}/deactivate")
|
75
|
+
end
|
76
|
+
|
77
|
+
assert_invalid_id("deactivate #{invalid_id}")
|
78
|
+
assert_abort_on_missing_creds("deactivate #{id}")
|
79
|
+
assert_usage('deactivate')
|
80
|
+
end
|
81
|
+
|
82
|
+
def test_create_without_options
|
83
|
+
quietly do
|
84
|
+
assert_cmd_posts("create #{id}",
|
85
|
+
'/api/v2/account/serviceaccount',
|
86
|
+
identifier: id,
|
87
|
+
active: true,
|
88
|
+
groups: [],
|
89
|
+
tokens: [],
|
90
|
+
userGroups: [])
|
91
|
+
end
|
92
|
+
|
93
|
+
assert_noop(
|
94
|
+
"create #{id}",
|
95
|
+
'uri: POST https://default.wavefront.com/api/v2/account/serviceaccount',
|
96
|
+
'body: ' + { identifier: id,
|
97
|
+
active: true,
|
98
|
+
groups: [],
|
99
|
+
tokens: [],
|
100
|
+
userGroups: [] }.to_json
|
101
|
+
)
|
102
|
+
|
103
|
+
assert_abort_on_missing_creds("create #{id}")
|
104
|
+
assert_usage('create')
|
105
|
+
end
|
106
|
+
|
107
|
+
def test_create_inactive_account_with_description
|
108
|
+
quietly do
|
109
|
+
assert_cmd_posts("create -d words -I #{id}",
|
110
|
+
'/api/v2/account/serviceaccount',
|
111
|
+
identifier: id,
|
112
|
+
description: 'words',
|
113
|
+
active: false,
|
114
|
+
groups: [],
|
115
|
+
tokens: [],
|
116
|
+
userGroups: [])
|
117
|
+
end
|
118
|
+
end
|
119
|
+
|
120
|
+
def test_create_account_in_usergroups
|
121
|
+
quietly do
|
122
|
+
assert_cmd_posts("create -g #{usergroups[0]} -g #{usergroups[1]} #{id}",
|
123
|
+
'/api/v2/account/serviceaccount',
|
124
|
+
identifier: id,
|
125
|
+
active: true,
|
126
|
+
groups: [],
|
127
|
+
tokens: [],
|
128
|
+
userGroups: usergroups)
|
129
|
+
end
|
130
|
+
end
|
131
|
+
|
132
|
+
def test_create_account_with_tokens
|
133
|
+
quietly do
|
134
|
+
assert_cmd_posts("create -k #{tokens[0]} -k #{tokens[1]} #{id}",
|
135
|
+
'/api/v2/account/serviceaccount',
|
136
|
+
identifier: id,
|
137
|
+
active: true,
|
138
|
+
groups: [],
|
139
|
+
tokens: tokens,
|
140
|
+
userGroups: [])
|
141
|
+
end
|
142
|
+
end
|
143
|
+
|
144
|
+
def test_create_account_with_permissions
|
145
|
+
quietly do
|
146
|
+
assert_cmd_posts("create -m #{permissions[0]} -m #{permissions[1]} #{id}",
|
147
|
+
'/api/v2/account/serviceaccount',
|
148
|
+
identifier: id,
|
149
|
+
active: true,
|
150
|
+
groups: permissions,
|
151
|
+
tokens: [],
|
152
|
+
userGroups: [])
|
153
|
+
end
|
154
|
+
end
|
155
|
+
|
156
|
+
def test_create_invalid_usergroup
|
157
|
+
assert_exits_with('Unable to run command. Invalid usergroup ID.',
|
158
|
+
"create -g abcdefg #{id}")
|
159
|
+
end
|
160
|
+
|
161
|
+
def test_create_invalid_permission
|
162
|
+
assert_exits_with('Unable to run command. Invalid permission.',
|
163
|
+
"create -m 123456 #{id}")
|
164
|
+
end
|
165
|
+
|
166
|
+
def test_create_invalid_token
|
167
|
+
assert_exits_with('Unable to run command. Invalid API token.',
|
168
|
+
"create -k abcdefg #{id}")
|
169
|
+
end
|
170
|
+
|
171
|
+
def test_dump
|
172
|
+
_out = capture_io do
|
173
|
+
assert_raises(SystemExit) do
|
174
|
+
assert_cmd_gets('dump --format=json', '/api/v2/account/serviceaccount')
|
175
|
+
end
|
176
|
+
end
|
177
|
+
|
178
|
+
assert_cannot_noop('dump --format=json')
|
179
|
+
end
|
180
|
+
|
181
|
+
def test_join
|
182
|
+
assert_repeated_output(
|
183
|
+
'2659191e-aad4-4302-a94e-9667e1517127 (Everyone)'
|
184
|
+
) do
|
185
|
+
all_permutations do |p|
|
186
|
+
get_stub = stub_request(
|
187
|
+
:get,
|
188
|
+
"https://#{p[:endpoint]}/api/v2/account/serviceaccount/#{id}"
|
189
|
+
).to_return(body: canned_response.to_json, status: 200)
|
190
|
+
|
191
|
+
put_stub = stub_request(
|
192
|
+
:put,
|
193
|
+
"https://#{p[:endpoint]}/api/v2/account/serviceaccount/#{id}"
|
194
|
+
).with(body: { tokens: [],
|
195
|
+
userGroups: usergroups,
|
196
|
+
groups: %w[events_management dashboard_management],
|
197
|
+
description: 'some information',
|
198
|
+
active: true,
|
199
|
+
identifier: 'sa::test' })
|
200
|
+
.to_return(body: canned_response.to_json, status: 200)
|
201
|
+
|
202
|
+
wf.new("serviceaccount join #{id} #{usergroups[1]} " \
|
203
|
+
"#{p[:cmdline]}".split)
|
204
|
+
|
205
|
+
assert_requested(get_stub, times: 2)
|
206
|
+
assert_requested(put_stub)
|
207
|
+
end
|
208
|
+
end
|
209
|
+
end
|
210
|
+
|
211
|
+
# rubocop:disable Metrics/MethodLength
|
212
|
+
# rubocop:disable Metrics/BlockLength
|
213
|
+
def test_leave
|
214
|
+
assert_repeated_output(
|
215
|
+
'2659191e-aad4-4302-a94e-9667e1517127 (Everyone)'
|
216
|
+
) do
|
217
|
+
all_permutations do |p|
|
218
|
+
get_stub = stub_request(
|
219
|
+
:get,
|
220
|
+
"https://#{p[:endpoint]}/api/v2/account/serviceaccount/#{id}"
|
221
|
+
).to_return(
|
222
|
+
body: { tokens: [],
|
223
|
+
userGroups: [{ id: usergroups[0],
|
224
|
+
name: 'Everyone',
|
225
|
+
permissions: [],
|
226
|
+
customer: 'sysdef',
|
227
|
+
properties: { nameEditable: false,
|
228
|
+
permissionsEditable: true,
|
229
|
+
usersEditable: false },
|
230
|
+
description: 'System group' },
|
231
|
+
{ id: usergroups[1],
|
232
|
+
name: 'newgroup',
|
233
|
+
permissions: [],
|
234
|
+
customer: 'sysdef' }],
|
235
|
+
active: true,
|
236
|
+
groups: %w[events_management dashboard_management],
|
237
|
+
description: 'some information',
|
238
|
+
identifier: 'sa::test' }.to_json, status: 200
|
239
|
+
)
|
240
|
+
|
241
|
+
put_stub = stub_request(
|
242
|
+
:put,
|
243
|
+
"https://#{p[:endpoint]}/api/v2/account/serviceaccount/#{id}"
|
244
|
+
).with(body: { tokens: [],
|
245
|
+
userGroups: [usergroups[0]],
|
246
|
+
groups: %w[events_management dashboard_management],
|
247
|
+
description: 'some information',
|
248
|
+
active: true,
|
249
|
+
identifier: 'sa::test' })
|
250
|
+
.to_return(body: canned_response.to_json, status: 200)
|
251
|
+
|
252
|
+
wf.new("serviceaccount leave #{id} #{usergroups[1]} " \
|
253
|
+
"#{p[:cmdline]}".split)
|
254
|
+
|
255
|
+
assert_requested(get_stub, times: 2)
|
256
|
+
assert_requested(put_stub)
|
257
|
+
end
|
258
|
+
end
|
259
|
+
end
|
260
|
+
# rubocop:enable Metrics/BlockLength
|
261
|
+
# rubocop:enable Metrics/MethodLength
|
262
|
+
|
263
|
+
def test_grant_to
|
264
|
+
quietly do
|
265
|
+
all_permutations do |p|
|
266
|
+
get_stub = stub_request(
|
267
|
+
:get,
|
268
|
+
"https://#{p[:endpoint]}/api/v2/account/serviceaccount/#{id}"
|
269
|
+
).to_return(body: canned_response.to_json, status: 200)
|
270
|
+
|
271
|
+
put_stub = stub_request(
|
272
|
+
:put,
|
273
|
+
"https://#{p[:endpoint]}/api/v2/account/serviceaccount/#{id}"
|
274
|
+
).with(body: { tokens: [],
|
275
|
+
userGroups: [usergroups[0]],
|
276
|
+
groups: %w[events_management
|
277
|
+
dashboard_management
|
278
|
+
alerts_management],
|
279
|
+
description: 'some information',
|
280
|
+
active: true,
|
281
|
+
identifier: 'sa::test' })
|
282
|
+
.to_return(body: canned_response.to_json, status: 200)
|
283
|
+
|
284
|
+
wf.new("serviceaccount grant alerts_management to #{id} " \
|
285
|
+
"#{p[:cmdline]}".split)
|
286
|
+
|
287
|
+
assert_requested(get_stub, times: 2)
|
288
|
+
assert_requested(put_stub)
|
289
|
+
end
|
290
|
+
end
|
291
|
+
end
|
292
|
+
|
293
|
+
def test_revoke_from
|
294
|
+
quietly do
|
295
|
+
all_permutations do |p|
|
296
|
+
get_stub = stub_request(
|
297
|
+
:get,
|
298
|
+
"https://#{p[:endpoint]}/api/v2/account/serviceaccount/#{id}"
|
299
|
+
).to_return(body: canned_response.to_json, status: 200)
|
300
|
+
|
301
|
+
put_stub = stub_request(
|
302
|
+
:put,
|
303
|
+
"https://#{p[:endpoint]}/api/v2/account/serviceaccount/#{id}"
|
304
|
+
).with(body: { tokens: [],
|
305
|
+
userGroups: [usergroups[0]],
|
306
|
+
groups: %w[events_management],
|
307
|
+
description: 'some information',
|
308
|
+
active: true,
|
309
|
+
identifier: 'sa::test' })
|
310
|
+
.to_return(body: canned_response.to_json, status: 200)
|
311
|
+
|
312
|
+
wf.new("serviceaccount revoke dashboard_management from #{id} " \
|
313
|
+
"#{p[:cmdline]}".split)
|
314
|
+
|
315
|
+
assert_requested(get_stub, times: 2)
|
316
|
+
assert_requested(put_stub)
|
317
|
+
end
|
318
|
+
end
|
319
|
+
end
|
320
|
+
|
321
|
+
# Override this method from the set helper: we don't pass an ID with service
|
322
|
+
# accounts
|
323
|
+
|
324
|
+
def _set_put_stub(perm)
|
325
|
+
stub_request(:put, "https://#{perm[:endpoint]}/api/v2/#{api_path}/#{id}")
|
326
|
+
.with(body: { set_key => 'new_value' },
|
327
|
+
headers: mk_headers(perm[:token]))
|
328
|
+
.to_return(status: 200, body: '', headers: {})
|
329
|
+
end
|
330
|
+
|
331
|
+
private
|
332
|
+
|
333
|
+
def id
|
334
|
+
'sa::test-id'
|
335
|
+
end
|
336
|
+
|
337
|
+
def invalid_id
|
338
|
+
'__BAD__'
|
339
|
+
end
|
340
|
+
|
341
|
+
def cmd_word
|
342
|
+
'serviceaccount'
|
343
|
+
end
|
344
|
+
|
345
|
+
def api_path
|
346
|
+
'account/serviceaccount'
|
347
|
+
end
|
348
|
+
|
349
|
+
def search_api_path
|
350
|
+
'serviceaccount'
|
351
|
+
end
|
352
|
+
|
353
|
+
def sdk_class_name
|
354
|
+
'ServiceAccount'
|
355
|
+
end
|
356
|
+
|
357
|
+
def friendly_name
|
358
|
+
'service account'
|
359
|
+
end
|
360
|
+
|
361
|
+
def permissions
|
362
|
+
%w[alerts_management events_management]
|
363
|
+
end
|
364
|
+
|
365
|
+
def tokens
|
366
|
+
%w[3d986e9e-9ab7-492b-89d5-15bb38d95674
|
367
|
+
30cac18a-4ebc-4204-ae09-34270d9f50e5]
|
368
|
+
end
|
369
|
+
|
370
|
+
def usergroups
|
371
|
+
%w[2659191e-aad4-4302-a94e-9667e1517127
|
372
|
+
abcdef12-1234-abcd-1234-abcdef012345]
|
373
|
+
end
|
374
|
+
|
375
|
+
def import_fields
|
376
|
+
%i[identifier description active tokens groups userGroups]
|
377
|
+
end
|
378
|
+
|
379
|
+
def set_key
|
380
|
+
'description'
|
381
|
+
end
|
382
|
+
|
383
|
+
def canned_response
|
384
|
+
{ tokens: [],
|
385
|
+
userGroups: [{ id: usergroups[0],
|
386
|
+
name: 'Everyone',
|
387
|
+
permissions: [],
|
388
|
+
customer: 'sysdef',
|
389
|
+
properties: { nameEditable: false,
|
390
|
+
permissionsEditable: true,
|
391
|
+
usersEditable: false },
|
392
|
+
description: 'System group which contains all users' }],
|
393
|
+
active: true,
|
394
|
+
groups: %w[events_management dashboard_management],
|
395
|
+
description: 'some information',
|
396
|
+
identifier: 'sa::test' }
|
397
|
+
end
|
398
|
+
end
|
399
|
+
# rubocop:enable Metrics/ClassLength
|
@@ -1,19 +1,50 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
|
+
# frozen_string_literal: true
|
2
3
|
|
3
|
-
require_relative '../
|
4
|
+
require_relative '../support/command_base'
|
4
5
|
require_relative '../../lib/wavefront-cli/settings'
|
5
6
|
|
6
|
-
|
7
|
+
# Tests for the settings command
|
8
|
+
#
|
9
|
+
class SettingsEndToEndTest < EndToEndTest
|
10
|
+
def test_list_permissions
|
11
|
+
quietly do
|
12
|
+
assert_cmd_gets('list permissions', '/api/v2/customer/permissions')
|
13
|
+
end
|
7
14
|
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
15
|
+
assert_abort_on_missing_creds('list permissions')
|
16
|
+
assert_usage('list')
|
17
|
+
assert_noop('list permissions',
|
18
|
+
'uri: GET https://default.wavefront.com/api/v2/' \
|
19
|
+
'customer/permissions')
|
20
|
+
end
|
13
21
|
|
14
|
-
|
15
|
-
|
22
|
+
def test_show_preferences
|
23
|
+
quietly do
|
24
|
+
assert_cmd_gets('show preferences', '/api/v2/customer/preferences')
|
25
|
+
end
|
16
26
|
|
17
|
-
|
18
|
-
|
27
|
+
assert_abort_on_missing_creds('show preferences')
|
28
|
+
assert_noop('show preferences',
|
29
|
+
'uri: GET https://default.wavefront.com/api/v2/' \
|
30
|
+
'customer/preferences')
|
31
|
+
end
|
32
|
+
|
33
|
+
def test_default_usergroups
|
34
|
+
quietly do
|
35
|
+
assert_cmd_gets('default usergroups',
|
36
|
+
'/api/v2/customer/preferences/defaultUserGroups')
|
37
|
+
end
|
38
|
+
|
39
|
+
assert_abort_on_missing_creds('default usergroups')
|
40
|
+
assert_noop('default usergroups',
|
41
|
+
'uri: GET https://default.wavefront.com/api/v2/' \
|
42
|
+
'customer/preferences/defaultUserGroups')
|
43
|
+
end
|
44
|
+
|
45
|
+
private
|
46
|
+
|
47
|
+
def cmd_word
|
48
|
+
'settings'
|
49
|
+
end
|
19
50
|
end
|