wavefront-sdk 4.0.0 → 5.2.1
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 +12 -1
- data/HISTORY.md +28 -0
- data/README.md +3 -2
- data/lib/wavefront-sdk/account.rb +104 -3
- data/lib/wavefront-sdk/api_mixins/user.rb +10 -0
- data/lib/wavefront-sdk/cloudintegration.rb +27 -0
- data/lib/wavefront-sdk/core/exception.rb +3 -0
- data/lib/wavefront-sdk/credentials.rb +28 -9
- data/lib/wavefront-sdk/defs/version.rb +3 -1
- data/lib/wavefront-sdk/distribution.rb +2 -0
- data/lib/wavefront-sdk/paginator/base.rb +21 -15
- data/lib/wavefront-sdk/query.rb +0 -1
- data/lib/wavefront-sdk/role.rb +128 -0
- data/lib/wavefront-sdk/spy.rb +126 -0
- data/lib/wavefront-sdk/stdlib/array.rb +1 -1
- data/lib/wavefront-sdk/user.rb +31 -0
- data/lib/wavefront-sdk/usergroup.rb +17 -16
- data/lib/wavefront-sdk/validators.rb +31 -7
- data/lib/wavefront-sdk/writers/core.rb +2 -2
- data/spec/.rubocop.yml +13 -3
- data/spec/support/minitest_assertions.rb +5 -11
- data/spec/wavefront-sdk/account_spec.rb +107 -1
- data/spec/wavefront-sdk/cloudintegration_spec.rb +38 -0
- data/spec/wavefront-sdk/core/logger_spec.rb +3 -3
- data/spec/wavefront-sdk/credentials_spec.rb +5 -4
- data/spec/wavefront-sdk/metric_helper_spec.rb +1 -1
- data/spec/wavefront-sdk/role_spec.rb +96 -0
- data/spec/wavefront-sdk/{unstable/spy_spec.rb → spy_spec.rb} +3 -3
- data/spec/wavefront-sdk/user_spec.rb +8 -0
- data/spec/wavefront-sdk/usergroup_spec.rb +21 -11
- data/spec/wavefront-sdk/validators_spec.rb +16 -0
- data/spec/wavefront-sdk/writers/core_spec.rb +1 -1
- data/wavefront-sdk.gemspec +6 -6
- metadata +23 -24
- data/lib/wavefront-sdk/monitoredcluster.rb +0 -93
- data/lib/wavefront-sdk/unstable/spy.rb +0 -134
- data/spec/wavefront-sdk/monitoredcluster_spec.rb +0 -55
@@ -48,8 +48,8 @@ module Wavefront
|
|
48
48
|
#
|
49
49
|
def wf_metric_name?(metric)
|
50
50
|
if metric.is_a?(String) && metric.size < 1024 &&
|
51
|
-
(metric.match(/^#{DELTA}?[\w
|
52
|
-
metric.match(%r{
|
51
|
+
(metric.match(/^#{DELTA}?[\w\-.]+$/) ||
|
52
|
+
metric.match(%r{^"#{DELTA}?[\w\-./,]+"$}))
|
53
53
|
return true
|
54
54
|
end
|
55
55
|
|
@@ -81,7 +81,7 @@ module Wavefront
|
|
81
81
|
# commas in tags and descriptions. This might be too restrictive,
|
82
82
|
# but if it is, this is the only place we need to change it.
|
83
83
|
#
|
84
|
-
if str.is_a?(String) && str.size < 1024 && str =~ /^[\-\w
|
84
|
+
if str.is_a?(String) && str.size < 1024 && str =~ /^[\-\w .,]*$/
|
85
85
|
return true
|
86
86
|
end
|
87
87
|
|
@@ -139,7 +139,7 @@ module Wavefront
|
|
139
139
|
#
|
140
140
|
def wf_tag?(*tags)
|
141
141
|
Array(*tags).each do |tag|
|
142
|
-
unless tag.is_a?(String) && tag.size < 255 && tag =~ /^[\w
|
142
|
+
unless tag.is_a?(String) && tag.size < 255 && tag =~ /^[\w:\-.]+$/
|
143
143
|
raise Wavefront::Exception::InvalidTag, tag
|
144
144
|
end
|
145
145
|
end
|
@@ -196,7 +196,7 @@ module Wavefront
|
|
196
196
|
#
|
197
197
|
def wf_point_tag?(key, val)
|
198
198
|
if key && val && (key.size + val.size < 254) &&
|
199
|
-
key =~ /^[\w
|
199
|
+
key =~ /^[\w\-.:]+$/ && val !~ /\\$/
|
200
200
|
return
|
201
201
|
end
|
202
202
|
|
@@ -391,7 +391,7 @@ module Wavefront
|
|
391
391
|
# is not valid
|
392
392
|
#
|
393
393
|
def wf_source_id?(source)
|
394
|
-
if source.is_a?(String) && source.match(/^[\w
|
394
|
+
if source.is_a?(String) && source.match(/^[\w.\-]+$/) &&
|
395
395
|
source.size < 1024
|
396
396
|
return true
|
397
397
|
end
|
@@ -566,7 +566,7 @@ module Wavefront
|
|
566
566
|
return true
|
567
567
|
end
|
568
568
|
|
569
|
-
raise Wavefront::Exception::InvalidPermission, id
|
569
|
+
raise Wavefront::Exception::InvalidPermission, id
|
570
570
|
end
|
571
571
|
|
572
572
|
# Ensure the given argument is a valid ingestion policy ID
|
@@ -615,6 +615,30 @@ module Wavefront
|
|
615
615
|
|
616
616
|
raise Wavefront::Exception::InvalidSamplingValue, value
|
617
617
|
end
|
618
|
+
|
619
|
+
# Ensure the given argument is a valid Wavefront role ID
|
620
|
+
# @param id [String] the role ID to validate
|
621
|
+
# @return true if the role ID is valid
|
622
|
+
# @raise Wavefront::Exception::InvalidRoleId if the role ID is not valid
|
623
|
+
#
|
624
|
+
def wf_role_id?(id)
|
625
|
+
return true if uuid?(id)
|
626
|
+
|
627
|
+
raise Wavefront::Exception::InvalidRoleId, id
|
628
|
+
end
|
629
|
+
|
630
|
+
# Ensure the given argument is a valid AWS external ID, used in the AWS
|
631
|
+
# cloud integration.
|
632
|
+
# @param id [String] the external ID to validate
|
633
|
+
# @return true if the external ID is valid
|
634
|
+
# @raise Wavefront::Exception::InvalidAwsExternalId if the external ID is
|
635
|
+
# not valid
|
636
|
+
#
|
637
|
+
def wf_aws_external_id?(id)
|
638
|
+
return true if id.is_a?(String) && id =~ /^[a-z0-9A-Z]{16}$/
|
639
|
+
|
640
|
+
raise Wavefront::Exception::InvalidAwsExternalId, id
|
641
|
+
end
|
618
642
|
end
|
619
643
|
# rubocop:enable Metrics/ModuleLength
|
620
644
|
end
|
@@ -138,8 +138,8 @@ module Wavefront
|
|
138
138
|
end
|
139
139
|
|
140
140
|
def log_invalid_point(rawpoint, exception)
|
141
|
-
logger.log('Invalid point, skipping.', :
|
142
|
-
logger.log(exception.class, :
|
141
|
+
logger.log('Invalid point, skipping.', :warn)
|
142
|
+
logger.log(exception.class, :warn)
|
143
143
|
logger.log(format('Invalid point: %<rawpoint>s (%<message>s)',
|
144
144
|
rawpoint: rawpoint,
|
145
145
|
message: exception.to_s), :debug)
|
data/spec/.rubocop.yml
CHANGED
@@ -1,13 +1,23 @@
|
|
1
|
-
|
1
|
+
AllCops:
|
2
|
+
NewCops: enable
|
3
|
+
|
2
4
|
Metrics/AbcSize:
|
3
5
|
Max: 64
|
4
6
|
|
5
|
-
# Offense count: 5
|
6
7
|
# Configuration parameters: CountComments.
|
7
8
|
Metrics/ClassLength:
|
8
9
|
Max: 400
|
9
10
|
|
10
|
-
# Offense count: 46
|
11
11
|
# Configuration parameters: CountComments, ExcludedMethods.
|
12
12
|
Metrics/MethodLength:
|
13
13
|
Max: 39
|
14
|
+
|
15
|
+
# Is nothing sacred?
|
16
|
+
Layout/LineLength:
|
17
|
+
Max: 80
|
18
|
+
|
19
|
+
Style/StringConcatenation:
|
20
|
+
Enabled: false
|
21
|
+
|
22
|
+
Style/OptionalBooleanParameter:
|
23
|
+
Enabled: false
|
@@ -95,18 +95,12 @@ module Minitest
|
|
95
95
|
end
|
96
96
|
|
97
97
|
def header_lookup(type)
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
'application/json'
|
103
|
-
when :octet
|
104
|
-
'application/octet-stream'
|
105
|
-
when :form
|
106
|
-
'application/x-www-form-urlencoded'
|
107
|
-
end
|
98
|
+
ctypes = { plain: 'text/plain',
|
99
|
+
json: 'application/json',
|
100
|
+
octet: 'application/octet-stream',
|
101
|
+
form: 'application/x-www-form-urlencoded' }
|
108
102
|
|
109
|
-
{ 'Content-Type':
|
103
|
+
{ 'Content-Type': ctypes[type], Accept: 'application/json' }
|
110
104
|
end
|
111
105
|
end
|
112
106
|
end
|
@@ -11,6 +11,18 @@ class WavefrontAccountTest < WavefrontTestBase
|
|
11
11
|
include WavefrontTest::Delete
|
12
12
|
include WavefrontTest::Describe
|
13
13
|
|
14
|
+
def test_add_roles
|
15
|
+
assert_posts("/api/v2/account/#{id}/addRoles", roles.to_json) do
|
16
|
+
wf.add_roles(id, roles)
|
17
|
+
end
|
18
|
+
|
19
|
+
assert_invalid_id { wf.add_roles(invalid_id, roles) }
|
20
|
+
|
21
|
+
assert_raises(Wavefront::Exception::InvalidRoleId) do
|
22
|
+
wf.add_roles(id, invalid_role)
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
14
26
|
def test_add_user_groups
|
15
27
|
assert_posts("/api/v2/account/#{id}/addUserGroups", groups.to_json) do
|
16
28
|
wf.add_user_groups(id, groups)
|
@@ -37,6 +49,22 @@ class WavefrontAccountTest < WavefrontTestBase
|
|
37
49
|
assert_posts("/api/v2/account/grant/#{permission}", id_list.to_json) do
|
38
50
|
wf.grant(id_list, permission)
|
39
51
|
end
|
52
|
+
|
53
|
+
assert_raises(Wavefront::Exception::InvalidRoleId) do
|
54
|
+
wf.remove_roles(id, invalid_role)
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
def test_remove_roles
|
59
|
+
assert_posts("/api/v2/account/#{id}/removeRoles", roles.to_json) do
|
60
|
+
wf.remove_roles(id, roles)
|
61
|
+
end
|
62
|
+
|
63
|
+
assert_invalid_id { wf.remove_roles(invalid_id, roles) }
|
64
|
+
|
65
|
+
assert_raises(Wavefront::Exception::InvalidRoleId) do
|
66
|
+
wf.remove_roles(id, invalid_role)
|
67
|
+
end
|
40
68
|
end
|
41
69
|
|
42
70
|
def test_remove_user_groups
|
@@ -45,12 +73,22 @@ class WavefrontAccountTest < WavefrontTestBase
|
|
45
73
|
end
|
46
74
|
|
47
75
|
assert_invalid_id { wf.remove_user_groups(invalid_id, groups) }
|
76
|
+
|
77
|
+
assert_raises(Wavefront::Exception::InvalidUserGroupId) do
|
78
|
+
wf.remove_user_groups(id, invalid_group)
|
79
|
+
end
|
48
80
|
end
|
49
81
|
|
50
82
|
def test_revoke_from_single_user
|
51
83
|
assert_posts("/api/v2/account/#{id}/revoke/#{permission}") do
|
52
84
|
wf.revoke(id, permission)
|
53
85
|
end
|
86
|
+
|
87
|
+
assert_invalid_id { wf.revoke(invalid_id, permission) }
|
88
|
+
|
89
|
+
assert_raises(Wavefront::Exception::InvalidPermission) do
|
90
|
+
wf.revoke(id, invalid_permission)
|
91
|
+
end
|
54
92
|
end
|
55
93
|
|
56
94
|
def test_revoke_from_multiple_users
|
@@ -82,7 +120,7 @@ class WavefrontAccountTest < WavefrontTestBase
|
|
82
120
|
end
|
83
121
|
|
84
122
|
def test_remove_ingestion_policy
|
85
|
-
assert_posts('/api/v2/account/
|
123
|
+
assert_posts('/api/v2/account/removeingestionpolicies',
|
86
124
|
{ ingestionPolicyId: policy_id,
|
87
125
|
accounts: id_list }.to_json) do
|
88
126
|
wf.remove_ingestion_policy(policy_id, id_list)
|
@@ -95,6 +133,52 @@ class WavefrontAccountTest < WavefrontTestBase
|
|
95
133
|
assert_invalid_id { wf.add_ingestion_policy(policy_id, [invalid_id]) }
|
96
134
|
end
|
97
135
|
|
136
|
+
def test_user_list
|
137
|
+
assert_gets('/api/v2/account/user?offset=0&limit=100') do
|
138
|
+
wf.user_list
|
139
|
+
end
|
140
|
+
|
141
|
+
assert_gets('/api/v2/account/user?offset=10&limit=50') do
|
142
|
+
wf.user_list(10, 50)
|
143
|
+
end
|
144
|
+
end
|
145
|
+
|
146
|
+
def test_user_describe
|
147
|
+
assert_gets("/api/v2/account/user/#{id}") { wf.user_describe(id) }
|
148
|
+
|
149
|
+
assert_raises(Wavefront::Exception::InvalidUserId) do
|
150
|
+
wf.user_describe(invalid_id)
|
151
|
+
end
|
152
|
+
|
153
|
+
assert_raises(ArgumentError) { wf.user_describe }
|
154
|
+
end
|
155
|
+
|
156
|
+
def test_user_create
|
157
|
+
assert_posts('/api/v2/account/user', payload.to_json) do
|
158
|
+
wf.user_create(payload)
|
159
|
+
end
|
160
|
+
|
161
|
+
assert_raises(ArgumentError) { wf.user_create }
|
162
|
+
assert_raises(ArgumentError) { wf.user_create('test') }
|
163
|
+
end
|
164
|
+
|
165
|
+
def test_user_invite
|
166
|
+
assert_posts('/api/v2/account/user/invite', [payload].to_json) do
|
167
|
+
wf.user_invite([payload])
|
168
|
+
end
|
169
|
+
|
170
|
+
assert_raises(ArgumentError) { wf.user_invite }
|
171
|
+
assert_raises(ArgumentError) { wf.user_invite('test') }
|
172
|
+
end
|
173
|
+
|
174
|
+
def test_validate_accounts
|
175
|
+
assert_posts('/api/v2/account/validateAccounts', id_list.to_json) do
|
176
|
+
wf.validate_accounts(id_list)
|
177
|
+
end
|
178
|
+
|
179
|
+
assert_raises(ArgumentError) { wf.validate_accounts }
|
180
|
+
end
|
181
|
+
|
98
182
|
private
|
99
183
|
|
100
184
|
def api_class
|
@@ -114,10 +198,27 @@ class WavefrontAccountTest < WavefrontTestBase
|
|
114
198
|
2659191e-aad4-4302-a94e-9667e1517127]
|
115
199
|
end
|
116
200
|
|
201
|
+
def roles
|
202
|
+
%w[f8dc0c14-91a0-4ca9-8a2a-7d47f4db1234
|
203
|
+
2659191e-aad4-4302-a94e-9667e1515678]
|
204
|
+
end
|
205
|
+
|
206
|
+
def invalid_role
|
207
|
+
%w[bad_role]
|
208
|
+
end
|
209
|
+
|
210
|
+
def invalid_group
|
211
|
+
%w[bad_group]
|
212
|
+
end
|
213
|
+
|
117
214
|
def id_list
|
118
215
|
%w[sa:test user@example.com]
|
119
216
|
end
|
120
217
|
|
218
|
+
def invalid_permission
|
219
|
+
'some_nonsense_permission_i_made_up'
|
220
|
+
end
|
221
|
+
|
121
222
|
def permission
|
122
223
|
'agent_management'
|
123
224
|
end
|
@@ -129,4 +230,9 @@ class WavefrontAccountTest < WavefrontTestBase
|
|
129
230
|
def invalid_policy_id
|
130
231
|
'badpolicy'
|
131
232
|
end
|
233
|
+
|
234
|
+
def payload
|
235
|
+
{ emailAddress: id,
|
236
|
+
groups: %w[browse] }
|
237
|
+
end
|
132
238
|
end
|
@@ -37,6 +37,36 @@ class WavefrontCloudIntegrationTest < WavefrontTestBase
|
|
37
37
|
assert_raises(ArgumentError) { wf.disable }
|
38
38
|
end
|
39
39
|
|
40
|
+
def test_create_aws_external_id
|
41
|
+
assert_posts('/api/v2/cloudintegration/awsExternalId', nil, :json) do
|
42
|
+
wf.create_aws_external_id
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
def test_delete_aws_external_id
|
47
|
+
assert_deletes("/api/v2/cloudintegration/awsExternalId/#{external_id}") do
|
48
|
+
wf.delete_aws_external_id(external_id)
|
49
|
+
end
|
50
|
+
|
51
|
+
assert_raises(Wavefront::Exception::InvalidAwsExternalId) do
|
52
|
+
wf.delete_aws_external_id(invalid_external_id)
|
53
|
+
end
|
54
|
+
|
55
|
+
assert_raises(ArgumentError) { wf.delete_aws_external_id }
|
56
|
+
end
|
57
|
+
|
58
|
+
def test_confirm_aws_external_id
|
59
|
+
assert_gets("/api/v2/cloudintegration/awsExternalId/#{external_id}") do
|
60
|
+
wf.confirm_aws_external_id(external_id)
|
61
|
+
end
|
62
|
+
|
63
|
+
assert_raises(Wavefront::Exception::InvalidAwsExternalId) do
|
64
|
+
wf.confirm_aws_external_id(invalid_external_id)
|
65
|
+
end
|
66
|
+
|
67
|
+
assert_raises(ArgumentError) { wf.confirm_aws_external_id }
|
68
|
+
end
|
69
|
+
|
40
70
|
private
|
41
71
|
|
42
72
|
def id
|
@@ -62,4 +92,12 @@ class WavefrontCloudIntegrationTest < WavefrontTestBase
|
|
62
92
|
def api_class
|
63
93
|
'cloudintegration'
|
64
94
|
end
|
95
|
+
|
96
|
+
def external_id
|
97
|
+
'HqOM4mru5svd3uFp'
|
98
|
+
end
|
99
|
+
|
100
|
+
def invalid_external_id
|
101
|
+
'__nonsense__'
|
102
|
+
end
|
65
103
|
end
|
@@ -41,21 +41,21 @@ class WavefrontLoggerTest < MiniTest::Test
|
|
41
41
|
end
|
42
42
|
|
43
43
|
def test_log_logger_debug
|
44
|
-
l = Wavefront::Logger.new(logger: Logger.new(
|
44
|
+
l = Wavefront::Logger.new(logger: Logger.new($stdout))
|
45
45
|
out, err = capture_subprocess_io { l.log('my message', :debug) }
|
46
46
|
assert_match(/DEBUG -- : my message$/, out)
|
47
47
|
assert_empty(err)
|
48
48
|
end
|
49
49
|
|
50
50
|
def test_log_logger_info
|
51
|
-
l = Wavefront::Logger.new(logger: Logger.new(
|
51
|
+
l = Wavefront::Logger.new(logger: Logger.new($stdout))
|
52
52
|
out, err = capture_subprocess_io { l.log('my message', :info) }
|
53
53
|
assert_match(/INFO -- : my message$/, out)
|
54
54
|
assert_empty(err)
|
55
55
|
end
|
56
56
|
|
57
57
|
def test_log_logger_error
|
58
|
-
l = Wavefront::Logger.new(logger: Logger.new(
|
58
|
+
l = Wavefront::Logger.new(logger: Logger.new($stdout))
|
59
59
|
out, err = capture_subprocess_io { l.log('my message', :error) }
|
60
60
|
assert_match(/ERROR -- : my message$/, out)
|
61
61
|
assert_empty(err)
|
@@ -60,9 +60,11 @@ end
|
|
60
60
|
# Test individual methods. We must override the constructor to do
|
61
61
|
# this.
|
62
62
|
#
|
63
|
+
# rubocop:disable Lint/MissingSuper
|
63
64
|
class Giblets < Wavefront::Credentials
|
64
65
|
def initialize; end
|
65
66
|
end
|
67
|
+
# rubocop:enable Lint/MissingSuper
|
66
68
|
|
67
69
|
# And here are the tests
|
68
70
|
#
|
@@ -153,10 +155,9 @@ class GibletsTest < MiniTest::Test
|
|
153
155
|
end
|
154
156
|
|
155
157
|
def test_load_from_file
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
))
|
158
|
+
assert_raises(Wavefront::Exception::InvalidConfigFile) do
|
159
|
+
wf.load_from_file([Pathname.new('/nofile/1'), Pathname.new('/nofile/2')])
|
160
|
+
end
|
160
161
|
|
161
162
|
assert_equal({ file: CONF1 }, wf.load_from_file([CONF1], 'noprofile'))
|
162
163
|
|
@@ -118,7 +118,7 @@ class WavefrontMetricHelperTest < MiniTest::Test
|
|
118
118
|
assert_equal(1, out.select do |o|
|
119
119
|
o[:value] == [[2, 10.0], [1, 11.0],
|
120
120
|
[1, 12.0]]
|
121
|
-
end
|
121
|
+
end.size)
|
122
122
|
assert_equal(1, out.select { |o| o[:tags] == WH_TAGS }.size)
|
123
123
|
assert_equal(3, out.select { |o| o[:path] == 'test.dist1' }.size)
|
124
124
|
end
|
@@ -0,0 +1,96 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
require_relative '../spec_helper'
|
5
|
+
require_relative '../test_mixins/general'
|
6
|
+
|
7
|
+
# Unit tests for Wavefront::Role
|
8
|
+
#
|
9
|
+
class WavefrontRoleTest < WavefrontTestBase
|
10
|
+
include WavefrontTest::Create
|
11
|
+
include WavefrontTest::Delete
|
12
|
+
include WavefrontTest::Describe
|
13
|
+
include WavefrontTest::List
|
14
|
+
include WavefrontTest::Update
|
15
|
+
|
16
|
+
def test_add_assignees
|
17
|
+
assert_posts("/api/v2/role/#{id}/addAssignees", assignees.to_json) do
|
18
|
+
wf.add_assignees(id, assignees)
|
19
|
+
end
|
20
|
+
|
21
|
+
assert_raises(Wavefront::Exception::InvalidRoleId) do
|
22
|
+
wf.add_assignees(invalid_id, assignees)
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
def test_remove_assignees
|
27
|
+
assert_posts("/api/v2/role/#{id}/removeAssignees", assignees.to_json) do
|
28
|
+
wf.remove_assignees(id, assignees)
|
29
|
+
end
|
30
|
+
|
31
|
+
assert_raises(Wavefront::Exception::InvalidRoleId) do
|
32
|
+
wf.remove_assignees(invalid_id, assignees)
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
def test_grant
|
37
|
+
assert_posts("/api/v2/role/grant/#{permission}", roles.to_json) do
|
38
|
+
wf.grant(permission, roles)
|
39
|
+
end
|
40
|
+
|
41
|
+
assert_raises(Wavefront::Exception::InvalidRoleId) do
|
42
|
+
wf.grant(permission, [invalid_id])
|
43
|
+
end
|
44
|
+
|
45
|
+
assert_raises(Wavefront::Exception::InvalidPermission) do
|
46
|
+
wf.grant('made_up_permission', roles)
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
def test_revoke
|
51
|
+
assert_posts("/api/v2/role/revoke/#{permission}", roles.to_json) do
|
52
|
+
wf.revoke(permission, roles)
|
53
|
+
end
|
54
|
+
|
55
|
+
assert_raises(Wavefront::Exception::InvalidRoleId) do
|
56
|
+
wf.revoke(permission, [invalid_id])
|
57
|
+
end
|
58
|
+
|
59
|
+
assert_raises(Wavefront::Exception::InvalidPermission) do
|
60
|
+
wf.revoke('made_up_permission', roles)
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
private
|
65
|
+
|
66
|
+
def api_class
|
67
|
+
:role
|
68
|
+
end
|
69
|
+
|
70
|
+
def id
|
71
|
+
'f8dc0c14-91a0-4ca9-8a2a-7d47f4db4672'
|
72
|
+
end
|
73
|
+
|
74
|
+
def roles
|
75
|
+
%w[f8dc0c14-91a0-4ca9-8a2a-7d47f4db4672
|
76
|
+
2659191e-aad4-4302-a94e-9667e1517127]
|
77
|
+
end
|
78
|
+
|
79
|
+
def assignees
|
80
|
+
roles.push('sa::test')
|
81
|
+
end
|
82
|
+
|
83
|
+
def invalid_id
|
84
|
+
'__BAD_ID__'
|
85
|
+
end
|
86
|
+
|
87
|
+
def payload
|
88
|
+
{ name: 'test role',
|
89
|
+
permissions: %w[alerts_management events_management],
|
90
|
+
description: 'dummy role for unit tests' }
|
91
|
+
end
|
92
|
+
|
93
|
+
def permission
|
94
|
+
'alerts_management'
|
95
|
+
end
|
96
|
+
end
|