wavefront-sdk 4.0.0 → 5.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rubocop.yml +42 -1
- data/HISTORY.md +12 -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/core/exception.rb +1 -0
- data/lib/wavefront-sdk/defs/version.rb +1 -1
- data/lib/wavefront-sdk/paginator/base.rb +21 -15
- data/lib/wavefront-sdk/query.rb +0 -1
- data/lib/wavefront-sdk/role.rb +104 -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 +18 -7
- data/spec/.rubocop.yml +41 -0
- data/spec/wavefront-sdk/account_spec.rb +107 -1
- data/spec/wavefront-sdk/metric_helper_spec.rb +1 -1
- data/spec/wavefront-sdk/role_spec.rb +68 -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 +10 -0
- data/wavefront-sdk.gemspec +2 -2
- metadata +12 -12
- 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
data/lib/wavefront-sdk/user.rb
CHANGED
@@ -4,16 +4,33 @@ require_relative 'core/api'
|
|
4
4
|
require_relative 'api_mixins/user'
|
5
5
|
|
6
6
|
module Wavefront
|
7
|
+
#
|
8
|
+
# In line with the API changes in the 2020-06 release of Wavefront, this
|
9
|
+
# class has been deprecated.
|
10
|
+
#
|
11
|
+
# Please use Wavefront::Account to manage users.
|
12
|
+
#
|
13
|
+
# https://docs.wavefront.com/2020.06.x_release_notes.html
|
7
14
|
#
|
8
15
|
# Manage and query Wavefront users
|
9
16
|
#
|
10
17
|
class User < CoreApi
|
11
18
|
include Wavefront::Mixin::User
|
12
19
|
|
20
|
+
def deprecation_warning
|
21
|
+
logger.log('Wavefront::User is deprecated and will be removed from the ' \
|
22
|
+
'next major release. Please use Wavefront::Account.', :warn)
|
23
|
+
end
|
24
|
+
|
25
|
+
def post_initialize(_creds, _opts)
|
26
|
+
deprecation_warning
|
27
|
+
end
|
28
|
+
|
13
29
|
# GET /api/v2/user
|
14
30
|
# Get all users.
|
15
31
|
#
|
16
32
|
def list
|
33
|
+
deprecation_warning
|
17
34
|
api.get('')
|
18
35
|
end
|
19
36
|
|
@@ -26,6 +43,7 @@ module Wavefront
|
|
26
43
|
# @return [Wavefront::Response]
|
27
44
|
#
|
28
45
|
def create(body, send_email = false)
|
46
|
+
deprecation_warning
|
29
47
|
raise ArgumentError unless body.is_a?(Hash)
|
30
48
|
|
31
49
|
api.post("?sendEmail=#{send_email}", body, 'application/json')
|
@@ -38,6 +56,7 @@ module Wavefront
|
|
38
56
|
# @return [Wavefront::Response]
|
39
57
|
#
|
40
58
|
def delete(id)
|
59
|
+
deprecation_warning
|
41
60
|
wf_user_id?(id)
|
42
61
|
api.delete(id)
|
43
62
|
end
|
@@ -49,6 +68,7 @@ module Wavefront
|
|
49
68
|
# @return [Wavefront::Response]
|
50
69
|
#
|
51
70
|
def describe(id)
|
71
|
+
deprecation_warning
|
52
72
|
wf_user_id?(id)
|
53
73
|
api.get(id)
|
54
74
|
end
|
@@ -65,6 +85,7 @@ module Wavefront
|
|
65
85
|
# @return [Wavefront::Response]
|
66
86
|
|
67
87
|
def update(id, body, modify = true)
|
88
|
+
deprecation_warning
|
68
89
|
wf_user_id?(id)
|
69
90
|
raise ArgumentError unless body.is_a?(Hash)
|
70
91
|
|
@@ -82,6 +103,7 @@ module Wavefront
|
|
82
103
|
# @return [Wavefront::Response]
|
83
104
|
#
|
84
105
|
def add_groups_to_user(id, group_list = [])
|
106
|
+
deprecation_warning
|
85
107
|
wf_user_id?(id)
|
86
108
|
validate_usergroup_list(group_list)
|
87
109
|
api.post([id, 'addUserGroups'].uri_concat, group_list,
|
@@ -95,6 +117,7 @@ module Wavefront
|
|
95
117
|
# @return [Wavefront::Response]
|
96
118
|
#
|
97
119
|
def remove_groups_from_user(id, group_list = [])
|
120
|
+
deprecation_warning
|
98
121
|
wf_user_id?(id)
|
99
122
|
validate_usergroup_list(group_list)
|
100
123
|
api.post([id, 'removeUserGroups'].uri_concat, group_list,
|
@@ -116,6 +139,7 @@ module Wavefront
|
|
116
139
|
# @return [Wavefront::Response]
|
117
140
|
#
|
118
141
|
def grant(id, pgroup)
|
142
|
+
deprecation_warning
|
119
143
|
wf_user_id?(id)
|
120
144
|
raise ArgumentError unless pgroup.is_a?(String)
|
121
145
|
|
@@ -133,6 +157,7 @@ module Wavefront
|
|
133
157
|
# @return [Wavefront::Response]
|
134
158
|
#
|
135
159
|
def revoke(id, pgroup)
|
160
|
+
deprecation_warning
|
136
161
|
wf_user_id?(id)
|
137
162
|
raise ArgumentError unless pgroup.is_a?(String)
|
138
163
|
|
@@ -149,6 +174,7 @@ module Wavefront
|
|
149
174
|
# @return [Wavefront::Response]
|
150
175
|
#
|
151
176
|
def delete_users(user_list)
|
177
|
+
deprecation_warning
|
152
178
|
raise ArgumentError unless user_list.is_a?(Array)
|
153
179
|
|
154
180
|
validate_user_list(user_list)
|
@@ -165,6 +191,7 @@ module Wavefront
|
|
165
191
|
# @return [Wavefront::Response]
|
166
192
|
#
|
167
193
|
def grant_permission(permission, user_list)
|
194
|
+
deprecation_warning
|
168
195
|
raise ArgumentError unless user_list.is_a?(Array)
|
169
196
|
|
170
197
|
validate_user_list(user_list)
|
@@ -182,6 +209,7 @@ module Wavefront
|
|
182
209
|
# @return [Wavefront::Response]
|
183
210
|
#
|
184
211
|
def revoke_permission(permission, user_list)
|
212
|
+
deprecation_warning
|
185
213
|
raise ArgumentError unless user_list.is_a?(Array)
|
186
214
|
|
187
215
|
validate_user_list(user_list)
|
@@ -196,6 +224,7 @@ module Wavefront
|
|
196
224
|
# @return [Wavefront::Response]
|
197
225
|
#
|
198
226
|
def invite(body)
|
227
|
+
deprecation_warning
|
199
228
|
raise ArgumentError unless body.is_a?(Array)
|
200
229
|
raise ArgumentError unless body.first.is_a?(Hash)
|
201
230
|
|
@@ -208,6 +237,7 @@ module Wavefront
|
|
208
237
|
# @return [Wavefront::Response]
|
209
238
|
#
|
210
239
|
def business_functions(id)
|
240
|
+
deprecation_warning
|
211
241
|
wf_user_id?(id)
|
212
242
|
api.get([id, 'businessFunctions'].uri_concat)
|
213
243
|
end
|
@@ -219,6 +249,7 @@ module Wavefront
|
|
219
249
|
# @return [Wavefront::Response]
|
220
250
|
#
|
221
251
|
def validate_users(id_list)
|
252
|
+
deprecation_warning
|
222
253
|
api.post('validateUsers', id_list, 'application/json')
|
223
254
|
end
|
224
255
|
|
@@ -108,30 +108,31 @@ module Wavefront
|
|
108
108
|
'application/json')
|
109
109
|
end
|
110
110
|
|
111
|
-
# POST /api/v2/usergroup/
|
112
|
-
#
|
111
|
+
# POST /api/v2/usergroup/{id}/addRoles
|
112
|
+
# Add multiple roles to a specific user group
|
113
113
|
#
|
114
|
-
# @param
|
115
|
-
# @param
|
116
|
-
# receive permission
|
114
|
+
# @param id [String] ID of the user group
|
115
|
+
# @param role_list [Array[String]] list of roles to add
|
117
116
|
# @return [Wavefront::Response]
|
118
117
|
#
|
119
|
-
def
|
120
|
-
|
121
|
-
|
118
|
+
def add_roles_to_group(id, role_list = [])
|
119
|
+
wf_usergroup_id?(id)
|
120
|
+
validate_role_list(role_list)
|
121
|
+
api.post([id, 'addRoles'].uri_concat, role_list, 'application/json')
|
122
122
|
end
|
123
123
|
|
124
|
-
# POST /api/v2/usergroup/
|
125
|
-
#
|
124
|
+
# POST /api/v2/usergroup/{id}/removeRoles
|
125
|
+
# Remove multiple roles from a specific user group
|
126
126
|
#
|
127
|
-
# @param
|
128
|
-
# @param
|
129
|
-
# lose permission
|
127
|
+
# @param id [String] ID of the user group
|
128
|
+
# @param user_list [Array[String]] list of roles to remove
|
130
129
|
# @return [Wavefront::Response]
|
131
130
|
#
|
132
|
-
def
|
133
|
-
|
134
|
-
|
131
|
+
def remove_roles_from_group(id, role_list = [])
|
132
|
+
wf_usergroup_id?(id)
|
133
|
+
validate_role_list(role_list)
|
134
|
+
api.post([id, 'removeRoles'].uri_concat, role_list,
|
135
|
+
'application/json')
|
135
136
|
end
|
136
137
|
end
|
137
138
|
end
|
@@ -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,17 @@ 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
|
618
629
|
end
|
619
630
|
# rubocop:enable Metrics/ModuleLength
|
620
631
|
end
|
data/spec/.rubocop.yml
CHANGED
@@ -11,3 +11,44 @@ Metrics/ClassLength:
|
|
11
11
|
# Configuration parameters: CountComments, ExcludedMethods.
|
12
12
|
Metrics/MethodLength:
|
13
13
|
Max: 39
|
14
|
+
|
15
|
+
# New cops
|
16
|
+
#
|
17
|
+
Lint/RaiseException:
|
18
|
+
Enabled: true
|
19
|
+
Lint/StructNewOverride:
|
20
|
+
Enabled: true
|
21
|
+
Style/ExponentialNotation:
|
22
|
+
Enabled: true
|
23
|
+
Style/HashEachMethods:
|
24
|
+
Enabled: true
|
25
|
+
Style/HashTransformKeys:
|
26
|
+
Enabled: true
|
27
|
+
Style/HashTransformValues:
|
28
|
+
Enabled: true
|
29
|
+
Layout/EmptyLinesAroundAttributeAccessor:
|
30
|
+
Enabled: true
|
31
|
+
Layout/SpaceAroundMethodCallOperator:
|
32
|
+
Enabled: true
|
33
|
+
Style/SlicingWithRange:
|
34
|
+
Enabled: true
|
35
|
+
Lint/DeprecatedOpenSSLConstant:
|
36
|
+
Enabled: true
|
37
|
+
Lint/MixedRegexpCaptureTypes:
|
38
|
+
Enabled: true
|
39
|
+
Style/RedundantRegexpCharacterClass:
|
40
|
+
Enabled: true
|
41
|
+
Style/RedundantRegexpEscape:
|
42
|
+
Enabled: true
|
43
|
+
Style/AccessorGrouping:
|
44
|
+
Enabled: true
|
45
|
+
Style/BisectedAttrAccessor:
|
46
|
+
Enabled: true
|
47
|
+
Style/RedundantAssignment:
|
48
|
+
Enabled: true
|
49
|
+
Style/RedundantFetchBlock:
|
50
|
+
Enabled: true
|
51
|
+
|
52
|
+
# Is nothing sacred?
|
53
|
+
Layout/LineLength:
|
54
|
+
Max: 80
|
@@ -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
|