wavefront-sdk 4.0.0 → 5.2.1
Sign up to get free protection for your applications and to get access to all the features.
- 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
data/lib/wavefront-sdk/query.rb
CHANGED
@@ -0,0 +1,128 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative 'core/api'
|
4
|
+
require_relative 'api_mixins/user'
|
5
|
+
|
6
|
+
module Wavefront
|
7
|
+
#
|
8
|
+
# Manage and query Wavefront roles
|
9
|
+
#
|
10
|
+
class Role < CoreApi
|
11
|
+
include Wavefront::Mixin::User
|
12
|
+
|
13
|
+
def update_keys
|
14
|
+
%i[id name description]
|
15
|
+
end
|
16
|
+
|
17
|
+
# GET /api/v2/role
|
18
|
+
# Get all roles for a customer
|
19
|
+
# @param offset [Int] alert at which the list begins
|
20
|
+
# @param limit [Int] the number of alerts to return
|
21
|
+
# @return [Wavefront::Response]
|
22
|
+
#
|
23
|
+
def list(offset = 0, limit = 100)
|
24
|
+
api.get('', offset: offset, limit: limit)
|
25
|
+
end
|
26
|
+
|
27
|
+
# POST /api/v2/role
|
28
|
+
# Create a specific role
|
29
|
+
# @param body [Hash] a hash of parameters describing the role. Please
|
30
|
+
# refer to the Wavefront Swagger docs for key:value information
|
31
|
+
# @return [Wavefront::Response]
|
32
|
+
#
|
33
|
+
def create(body)
|
34
|
+
raise ArgumentError unless body.is_a?(Hash)
|
35
|
+
|
36
|
+
api.post('', body, 'application/json')
|
37
|
+
end
|
38
|
+
|
39
|
+
# DELETE /api/v2/role/{id}
|
40
|
+
# Delete a specific role
|
41
|
+
# @param id [String] ID of the role
|
42
|
+
# @return [Wavefront::Response]
|
43
|
+
#
|
44
|
+
def delete(id)
|
45
|
+
wf_role_id?(id)
|
46
|
+
api.delete(id)
|
47
|
+
end
|
48
|
+
|
49
|
+
# GET /api/v2/role/{id}
|
50
|
+
# Get a specific role
|
51
|
+
# @param id [String] ID of the role
|
52
|
+
# @return [Wavefront::Response]
|
53
|
+
#
|
54
|
+
def describe(id)
|
55
|
+
wf_role_id?(id)
|
56
|
+
api.get(id)
|
57
|
+
end
|
58
|
+
|
59
|
+
# PUT /api/v2/role/{id}
|
60
|
+
# Update a specific role
|
61
|
+
# @param id [String] role ID
|
62
|
+
# @param body [Hash] key-value hash of the parameters you wish to change
|
63
|
+
# @param modify [true, false] if true, use {#describe()} to get a hash
|
64
|
+
# describing the existing object, and modify that with the new body. If
|
65
|
+
# false, pass the new body straight through.
|
66
|
+
# @return [Wavefront::Response]
|
67
|
+
#
|
68
|
+
def update(id, body, modify = true)
|
69
|
+
wf_role_id?(id)
|
70
|
+
raise ArgumentError unless body.is_a?(Hash)
|
71
|
+
|
72
|
+
return api.put(id, body, 'application/json') unless modify
|
73
|
+
|
74
|
+
api.put(id, hash_for_update(describe(id).response, body),
|
75
|
+
'application/json')
|
76
|
+
end
|
77
|
+
|
78
|
+
# POST /api/v2/role/{id}/addAssignees
|
79
|
+
# Add multiple users and user groups to a specific role
|
80
|
+
# @param id [String] role ID
|
81
|
+
# @param assignees [Array[String]] list of roles or accounts to be added
|
82
|
+
# @return [Wavefront::Response]
|
83
|
+
#
|
84
|
+
def add_assignees(id, assignees)
|
85
|
+
wf_role_id?(id)
|
86
|
+
validate_user_list(assignees)
|
87
|
+
api.post([id, 'addAssignees'].uri_concat, assignees, 'application/json')
|
88
|
+
end
|
89
|
+
|
90
|
+
# POST /api/v2/role/{id}/removeAssignees
|
91
|
+
# Remove multiple users and user groups from a specific role
|
92
|
+
# @param id [String] role ID
|
93
|
+
# @param assignees [Array[String]] list of roles or accounts to be removed
|
94
|
+
# @return [Wavefront::Response]
|
95
|
+
#
|
96
|
+
def remove_assignees(id, assignees)
|
97
|
+
wf_role_id?(id)
|
98
|
+
validate_user_list(assignees)
|
99
|
+
api.post([id, 'removeAssignees'].uri_concat,
|
100
|
+
assignees,
|
101
|
+
'application/json')
|
102
|
+
end
|
103
|
+
|
104
|
+
# POST /api/v2/role/grant/{permission}
|
105
|
+
# Grants a single permission to role(s)
|
106
|
+
# @param permission [String] permission to grant
|
107
|
+
# @param roles [Array[String]] list of roles to receive permission
|
108
|
+
# @return [Wavefront::Response]
|
109
|
+
#
|
110
|
+
def grant(permission, roles)
|
111
|
+
wf_permission?(permission)
|
112
|
+
validate_role_list(roles)
|
113
|
+
api.post(['grant', permission].uri_concat, roles, 'application/json')
|
114
|
+
end
|
115
|
+
|
116
|
+
# POST /api/v2/role/revoke/{permission}
|
117
|
+
# Revokes a single permission from role(s)
|
118
|
+
# @param permission [String] permission to revoke
|
119
|
+
# @param roles [Array[String]] list of roles to lose permission
|
120
|
+
# @return [Wavefront::Response]
|
121
|
+
#
|
122
|
+
def revoke(permission, roles)
|
123
|
+
wf_permission?(permission)
|
124
|
+
validate_role_list(roles)
|
125
|
+
api.post(['revoke', permission].uri_concat, roles, 'application/json')
|
126
|
+
end
|
127
|
+
end
|
128
|
+
end
|
@@ -0,0 +1,126 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative 'defs/constants'
|
4
|
+
require_relative 'core/api'
|
5
|
+
|
6
|
+
module Wavefront
|
7
|
+
#
|
8
|
+
# Spy on data going into Wavefront
|
9
|
+
#
|
10
|
+
class Spy < CoreApi
|
11
|
+
# GET /api/spy/points
|
12
|
+
# Gets new metric data points that are added to existing time series.
|
13
|
+
# @param sampling [Float] the amount of points to sample, from 0
|
14
|
+
# (none) to 1 (all)
|
15
|
+
# @param filter [Hash] with the following keys:
|
16
|
+
# :prefix [String] only list points whose metric name begins with this
|
17
|
+
# case-sensitive string
|
18
|
+
# :host [Array] only list points if source name begins with this
|
19
|
+
# case-sensitive string
|
20
|
+
# :tag_key [String,Array[String]] only list points with one or more of
|
21
|
+
# the given points tags
|
22
|
+
# @param options [Hash] with the following keys
|
23
|
+
# :timestamp [Boolean] prefix each block of streamed data with a
|
24
|
+
# timestamp
|
25
|
+
# :timeout [Integer] how many seconds to run the spy. After this time
|
26
|
+
# the method returns
|
27
|
+
# @raise Wavefront::Exception::InvalidSamplingValue
|
28
|
+
# @return [Nil]
|
29
|
+
#
|
30
|
+
def points(sampling = 0.01, filters = {}, options = {})
|
31
|
+
wf_sampling_value?(sampling)
|
32
|
+
api.get_stream('points', points_filter(sampling, filters), options)
|
33
|
+
end
|
34
|
+
|
35
|
+
# GET /api/spy/histograms
|
36
|
+
# Gets new histograms that are added to existing time series.
|
37
|
+
# @param sampling [Float] see #points
|
38
|
+
# @param filter [Hash] see #points
|
39
|
+
# @param options [Hash] see #points
|
40
|
+
# @raise Wavefront::Exception::InvalidSamplingValue
|
41
|
+
# @return [Nil]
|
42
|
+
#
|
43
|
+
def histograms(sampling = 0.01, filters = {}, options = {})
|
44
|
+
wf_sampling_value?(sampling)
|
45
|
+
api.get_stream('histograms',
|
46
|
+
histograms_filter(sampling, filters),
|
47
|
+
options)
|
48
|
+
end
|
49
|
+
|
50
|
+
# GET /api/spy/spans
|
51
|
+
# Gets new spans with existing source names and span tags.
|
52
|
+
# @param sampling [Float] see #points
|
53
|
+
# @param filter [Hash] see #points
|
54
|
+
# @param options [Hash] see #points
|
55
|
+
# @raise Wavefront::Exception::InvalidSamplingValue
|
56
|
+
# @return [Nil]
|
57
|
+
#
|
58
|
+
def spans(sampling = 0.01, filters = {}, options = {})
|
59
|
+
wf_sampling_value?(sampling)
|
60
|
+
api.get_stream('spans', spans_filter(sampling, filters), options)
|
61
|
+
end
|
62
|
+
|
63
|
+
# GET /api/spy/ids
|
64
|
+
# Gets newly allocated IDs that correspond to new metric names, source
|
65
|
+
# names, point tags, or span tags. A new ID generally indicates that a
|
66
|
+
# new time series has been introduced.
|
67
|
+
# @param sampling [Float] see #points
|
68
|
+
# @param filter [Hash] with keys:
|
69
|
+
# :prefix [String] only list assignments whose metric name begins with
|
70
|
+
# this case-sensitive string
|
71
|
+
# :type [String] one of METRIC, SPAN, HOST or STRING
|
72
|
+
# @param options [Hash] see #points
|
73
|
+
#
|
74
|
+
def ids(sampling = 0.01, filters = {}, options = {})
|
75
|
+
wf_sampling_value?(sampling)
|
76
|
+
api.get_stream('ids', ids_filter(sampling, filters), options)
|
77
|
+
end
|
78
|
+
|
79
|
+
def api_path
|
80
|
+
'/api/spy'
|
81
|
+
end
|
82
|
+
|
83
|
+
# We have to try to make the response we get from the API look
|
84
|
+
# like the one we get from the public API. To begin with, it's
|
85
|
+
# nothing like it.
|
86
|
+
#
|
87
|
+
# This method must be public because a #respond_to? looks for
|
88
|
+
# it.
|
89
|
+
#
|
90
|
+
def _response_shim(resp, status)
|
91
|
+
{ response: parse_response(resp),
|
92
|
+
status: { result: status == 200 ? 'OK' : 'ERROR',
|
93
|
+
message: extract_api_message(status, resp),
|
94
|
+
code: status } }.to_json
|
95
|
+
end
|
96
|
+
|
97
|
+
private
|
98
|
+
|
99
|
+
def points_filter(sampling, filters)
|
100
|
+
{ metric: filters.fetch(:prefix, nil),
|
101
|
+
host: filters.fetch(:host, nil),
|
102
|
+
sampling: sampling,
|
103
|
+
pointTagKey: filters.fetch(:tag_key, nil) }.compact
|
104
|
+
end
|
105
|
+
|
106
|
+
def histograms_filter(sampling, filters)
|
107
|
+
{ histogram: filters.fetch(:prefix, nil),
|
108
|
+
host: filters.fetch(:host, nil),
|
109
|
+
sampling: sampling,
|
110
|
+
histogramTagKey: filters.fetch(:tag_key, nil) }.compact
|
111
|
+
end
|
112
|
+
|
113
|
+
def spans_filter(sampling, filters)
|
114
|
+
{ name: filters.fetch(:prefix, nil),
|
115
|
+
host: filters.fetch(:host, nil),
|
116
|
+
sampling: sampling,
|
117
|
+
spanTagKey: filters.fetch(:tag_key, nil) }.compact
|
118
|
+
end
|
119
|
+
|
120
|
+
def ids_filter(sampling, filters)
|
121
|
+
{ name: filters.fetch(:prefix, nil),
|
122
|
+
type: filters.fetch(:type, nil),
|
123
|
+
sampling: sampling }.compact
|
124
|
+
end
|
125
|
+
end
|
126
|
+
end
|
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
|