wavefront-cli 5.1.0 → 7.1.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.
- checksums.yaml +4 -4
- data/.rubocop.yml +37 -1
- data/HISTORY.md +29 -0
- data/README.md +2 -4
- data/lib/wavefront-cli/account.rb +119 -0
- data/lib/wavefront-cli/alert.rb +29 -0
- data/lib/wavefront-cli/base.rb +13 -121
- data/lib/wavefront-cli/commands/.rubocop.yml +34 -0
- data/lib/wavefront-cli/commands/account.rb +61 -0
- data/lib/wavefront-cli/commands/alert.rb +1 -0
- data/lib/wavefront-cli/commands/base.rb +1 -1
- data/lib/wavefront-cli/commands/proxy.rb +2 -1
- data/lib/wavefront-cli/commands/query.rb +4 -1
- data/lib/wavefront-cli/commands/role.rb +44 -0
- data/lib/wavefront-cli/commands/spy.rb +0 -5
- data/lib/wavefront-cli/commands/usergroup.rb +7 -11
- data/lib/wavefront-cli/commands/write.rb +7 -2
- data/lib/wavefront-cli/controller.rb +5 -63
- data/lib/wavefront-cli/display/account.rb +122 -0
- data/lib/wavefront-cli/display/alert.rb +8 -0
- data/lib/wavefront-cli/display/base.rb +1 -1
- data/lib/wavefront-cli/display/cloudintegration.rb +3 -2
- data/lib/wavefront-cli/display/printer/long.rb +2 -1
- data/lib/wavefront-cli/display/proxy.rb +16 -0
- data/lib/wavefront-cli/display/role.rb +66 -0
- data/lib/wavefront-cli/display/settings.rb +1 -0
- data/lib/wavefront-cli/display/usergroup.rb +18 -14
- data/lib/wavefront-cli/exception_handler.rb +87 -0
- data/lib/wavefront-cli/helpers/load_file.rb +80 -0
- data/lib/wavefront-cli/output/hcl/base.rb +1 -1
- data/lib/wavefront-cli/output/hcl/dashboard.rb +1 -1
- data/lib/wavefront-cli/proxy.rb +5 -0
- data/lib/wavefront-cli/query.rb +13 -7
- data/lib/wavefront-cli/role.rb +54 -0
- data/lib/wavefront-cli/serviceaccount.rb +0 -6
- data/lib/wavefront-cli/spy.rb +0 -8
- data/lib/wavefront-cli/subcommands/import.rb +78 -0
- data/lib/wavefront-cli/usergroup.rb +8 -8
- data/lib/wavefront-cli/version.rb +1 -1
- data/lib/wavefront-cli/write.rb +29 -5
- data/spec/.rubocop.yml +34 -0
- data/spec/test_mixins/delete.rb +1 -2
- data/spec/test_mixins/import.rb +9 -3
- data/spec/wavefront-cli/account_spec.rb +303 -0
- data/spec/wavefront-cli/alert_spec.rb +28 -0
- data/spec/wavefront-cli/commands/write_spec.rb +1 -1
- data/spec/wavefront-cli/event_spec.rb +1 -1
- data/spec/wavefront-cli/output/csv/query_spec.rb +1 -1
- data/spec/wavefront-cli/output/wavefront/query_spec.rb +2 -2
- data/spec/wavefront-cli/query_spec.rb +20 -3
- data/spec/wavefront-cli/role_spec.rb +187 -0
- data/spec/wavefront-cli/serviceaccount_spec.rb +3 -3
- data/spec/wavefront-cli/usergroup_spec.rb +48 -43
- data/spec/wavefront-cli/write_spec.rb +44 -0
- data/wavefront-cli.gemspec +3 -3
- metadata +32 -32
- data/lib/wavefront-cli/commands/cluster.rb +0 -44
- data/lib/wavefront-cli/commands/user.rb +0 -54
- data/lib/wavefront-cli/display/monitoredcluster.rb +0 -14
- data/lib/wavefront-cli/display/user.rb +0 -103
- data/lib/wavefront-cli/monitoredcluster.rb +0 -50
- data/lib/wavefront-cli/user.rb +0 -92
- data/spec/wavefront-cli/monitoredcluster_spec.rb +0 -85
- data/spec/wavefront-cli/resources/responses/user-list.json +0 -1
- data/spec/wavefront-cli/user_spec.rb +0 -311
@@ -1,103 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require_relative 'base'
|
4
|
-
|
5
|
-
module WavefrontDisplay
|
6
|
-
#
|
7
|
-
# Format human-readable output for user management.
|
8
|
-
#
|
9
|
-
class User < Base
|
10
|
-
def do_list_brief
|
11
|
-
data.each { |user| puts user[:identifier] }
|
12
|
-
end
|
13
|
-
|
14
|
-
def do_groups
|
15
|
-
groups = data.first.userGroups
|
16
|
-
|
17
|
-
if groups.empty?
|
18
|
-
puts 'User does not belong to any groups.'
|
19
|
-
else
|
20
|
-
groups.each { |u| puts format('%<id>s (%<name>s)', u) }
|
21
|
-
end
|
22
|
-
end
|
23
|
-
|
24
|
-
def do_privileges
|
25
|
-
puts(if data.first[:groups].empty?
|
26
|
-
'User does not have any Wavefront privileges.'
|
27
|
-
else
|
28
|
-
data.first[:groups]
|
29
|
-
end)
|
30
|
-
end
|
31
|
-
|
32
|
-
def do_create
|
33
|
-
info = data[0]
|
34
|
-
puts format("Created user '%<user>s'.\nPermission groups\n" \
|
35
|
-
"%<perm_groups>s\nUser groups\n%<user_groups>s",
|
36
|
-
user: info[:identifier],
|
37
|
-
perm_groups: groups_as_string(info[:groups]),
|
38
|
-
user_groups: user_groups_as_string(info[:userGroups]))
|
39
|
-
end
|
40
|
-
|
41
|
-
def groups_as_string(groups)
|
42
|
-
return ' <none>' if groups.empty?
|
43
|
-
|
44
|
-
data.response.groups.map do |g|
|
45
|
-
format(' %<group>s', group: g)
|
46
|
-
end.join("\n ")
|
47
|
-
end
|
48
|
-
|
49
|
-
def user_groups_as_string(groups)
|
50
|
-
return ' <none>' if groups.empty?
|
51
|
-
|
52
|
-
groups.map { |g| format(' %<name>s (%<id>s)', g) }.join("\n")
|
53
|
-
end
|
54
|
-
|
55
|
-
def do_delete
|
56
|
-
puts format('Deleted %<quoted_user>s.',
|
57
|
-
quoted_user: quoted(options[:'<user>']))
|
58
|
-
end
|
59
|
-
|
60
|
-
def do_invite
|
61
|
-
puts format("Sent invitation to '%<id>s'.", id: options[:'<id>'])
|
62
|
-
end
|
63
|
-
|
64
|
-
def do_grant
|
65
|
-
puts format("Granted '%<priv>s' to '%<id>s'.",
|
66
|
-
priv: options[:'<privilege>'],
|
67
|
-
id: options[:'<id>'])
|
68
|
-
end
|
69
|
-
|
70
|
-
def do_revoke
|
71
|
-
puts format("Revoked '%<priv>s' from '%<id>s'.",
|
72
|
-
priv: options[:'<privilege>'],
|
73
|
-
id: options[:'<id>'])
|
74
|
-
end
|
75
|
-
|
76
|
-
def do_join
|
77
|
-
puts format("Added '%<id>s' to %<quoted_group>s.",
|
78
|
-
id: options[:'<id>'],
|
79
|
-
quoted_group: quoted(options[:'<group>']))
|
80
|
-
end
|
81
|
-
|
82
|
-
def do_leave
|
83
|
-
puts format("Removed '%<id>s' from %<quoted_group>s.",
|
84
|
-
id: options[:'<id>'],
|
85
|
-
quoted_group: quoted(options[:'<group>']))
|
86
|
-
end
|
87
|
-
|
88
|
-
def do_business_functions
|
89
|
-
puts data.sort
|
90
|
-
end
|
91
|
-
|
92
|
-
def do_validate_brief
|
93
|
-
valid = data[0][:validUsers]
|
94
|
-
invalid = data[0][:invalidIdentifiers]
|
95
|
-
|
96
|
-
puts 'valid ',
|
97
|
-
valid.empty? ? ' <none>' : valid.map { |u| " #{u[:identifier]}" }
|
98
|
-
|
99
|
-
puts 'invalid',
|
100
|
-
invalid.empty? ? ' <none>' : invalid.map { |u| " #{u}" }
|
101
|
-
end
|
102
|
-
end
|
103
|
-
end
|
@@ -1,50 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
require_relative 'base'
|
4
|
-
require_relative 'command_mixins/tag'
|
5
|
-
|
6
|
-
module WavefrontCli
|
7
|
-
#
|
8
|
-
# CLI coverage for the v2 'maintenancewindow' API.
|
9
|
-
#
|
10
|
-
class MonitoredCluster < WavefrontCli::Base
|
11
|
-
include WavefrontCli::Mixin::Tag
|
12
|
-
|
13
|
-
def do_create
|
14
|
-
body = { version: options[:version],
|
15
|
-
name: options[:'<name>'],
|
16
|
-
platform: options[:'<platform>'],
|
17
|
-
id: options[:'<id>'],
|
18
|
-
additionalTags: {},
|
19
|
-
tags: [] }
|
20
|
-
wf.create(body)
|
21
|
-
end
|
22
|
-
|
23
|
-
def do_merge
|
24
|
-
wf.merge(options[:'<id_to>'], options[:'<id_from>'])
|
25
|
-
end
|
26
|
-
|
27
|
-
def validator_exception
|
28
|
-
Wavefront::Exception::InvalidMonitoredClusterId
|
29
|
-
end
|
30
|
-
|
31
|
-
def descriptive_name
|
32
|
-
'monitored cluster'
|
33
|
-
end
|
34
|
-
|
35
|
-
def extra_validation
|
36
|
-
return unless options[:merge]
|
37
|
-
|
38
|
-
validate_merge_id(options[:'<id_to>'])
|
39
|
-
validate_merge_id(options[:'<id_from>'])
|
40
|
-
end
|
41
|
-
|
42
|
-
private
|
43
|
-
|
44
|
-
def validate_merge_id(id)
|
45
|
-
wf_monitoredcluster_id?(id)
|
46
|
-
rescue Wavefront::Exception::InvalidMonitoredClusterId
|
47
|
-
abort "'#{id}' is not a valid cluster ID."
|
48
|
-
end
|
49
|
-
end
|
50
|
-
end
|
data/lib/wavefront-cli/user.rb
DELETED
@@ -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,85 +0,0 @@
|
|
1
|
-
#!/usr/bin/env ruby
|
2
|
-
# frozen_string_literal: true
|
3
|
-
|
4
|
-
require_relative '../support/command_base'
|
5
|
-
require_relative '../test_mixins/tag'
|
6
|
-
require_relative '../../lib/wavefront-cli/monitoredcluster'
|
7
|
-
|
8
|
-
# Ensure 'cluster' commands produce the correct API calls.
|
9
|
-
#
|
10
|
-
class MonitoredClusterEndToEndTest < EndToEndTest
|
11
|
-
include WavefrontCliTest::Delete
|
12
|
-
include WavefrontCliTest::Describe
|
13
|
-
include WavefrontCliTest::List
|
14
|
-
include WavefrontCliTest::Search
|
15
|
-
include WavefrontCliTest::Tag
|
16
|
-
|
17
|
-
def test_create
|
18
|
-
quietly do
|
19
|
-
assert_cmd_posts("create EKS cluster #{id}",
|
20
|
-
'/api/v2/monitoredcluster',
|
21
|
-
version: nil,
|
22
|
-
name: 'cluster',
|
23
|
-
platform: 'EKS',
|
24
|
-
id: 'test-cluster',
|
25
|
-
additionalTags: {},
|
26
|
-
tags: [])
|
27
|
-
end
|
28
|
-
|
29
|
-
assert_abort_on_missing_creds("create EKS cluster #{id}")
|
30
|
-
assert_noop("create EKS -v 1.2 cluster #{id}",
|
31
|
-
'uri: POST https://default.wavefront.com/api/v2/monitoredcluster',
|
32
|
-
"body: #{ { version: '1.2',
|
33
|
-
name: 'cluster',
|
34
|
-
platform: 'EKS',
|
35
|
-
id: 'test-cluster',
|
36
|
-
additionalTags: {},
|
37
|
-
tags: [] }.to_json}")
|
38
|
-
end
|
39
|
-
|
40
|
-
def test_merge
|
41
|
-
quietly do
|
42
|
-
assert_cmd_puts(
|
43
|
-
"merge #{id} #{id2}", "/api/v2/monitoredcluster/merge/#{id}/#{id2}",
|
44
|
-
{}
|
45
|
-
)
|
46
|
-
end
|
47
|
-
|
48
|
-
assert_noop("merge #{id} #{id2}",
|
49
|
-
'uri: PUT https://default.wavefront.com/api/v2/' \
|
50
|
-
"monitoredcluster/merge/#{id}/#{id2}",
|
51
|
-
'body: null')
|
52
|
-
assert_invalid_id("merge #{invalid_id} #{id2} -D")
|
53
|
-
assert_abort_on_missing_creds("merge #{id} #{id2}")
|
54
|
-
end
|
55
|
-
|
56
|
-
private
|
57
|
-
|
58
|
-
def id
|
59
|
-
'test-cluster'
|
60
|
-
end
|
61
|
-
|
62
|
-
def id2
|
63
|
-
'other-cluster'
|
64
|
-
end
|
65
|
-
|
66
|
-
def invalid_id
|
67
|
-
'!__BAD__!'
|
68
|
-
end
|
69
|
-
|
70
|
-
def cmd_word
|
71
|
-
'cluster'
|
72
|
-
end
|
73
|
-
|
74
|
-
def api_path
|
75
|
-
'monitoredcluster'
|
76
|
-
end
|
77
|
-
|
78
|
-
def sdk_class_name
|
79
|
-
'MonitoredCluster'
|
80
|
-
end
|
81
|
-
|
82
|
-
def friendly_name
|
83
|
-
'monitored cluster'
|
84
|
-
end
|
85
|
-
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
|