wavefront-sdk 3.6.1 → 5.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (42) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop.yml +43 -2
  3. data/.travis.yml +0 -1
  4. data/HISTORY.md +33 -0
  5. data/README.md +4 -3
  6. data/lib/wavefront-sdk/account.rb +303 -0
  7. data/lib/wavefront-sdk/api_mixins/user.rb +20 -0
  8. data/lib/wavefront-sdk/core/api_caller.rb +50 -7
  9. data/lib/wavefront-sdk/core/exception.rb +6 -0
  10. data/lib/wavefront-sdk/core/response.rb +2 -1
  11. data/lib/wavefront-sdk/defs/version.rb +1 -3
  12. data/lib/wavefront-sdk/ingestionpolicy.rb +85 -0
  13. data/lib/wavefront-sdk/paginator/base.rb +21 -15
  14. data/lib/wavefront-sdk/query.rb +0 -1
  15. data/lib/wavefront-sdk/role.rb +128 -0
  16. data/lib/wavefront-sdk/spy.rb +126 -0
  17. data/lib/wavefront-sdk/stdlib/array.rb +1 -1
  18. data/lib/wavefront-sdk/stdlib/time.rb +13 -0
  19. data/lib/wavefront-sdk/unstable/README.md +4 -0
  20. data/lib/wavefront-sdk/unstable/chart.rb +90 -0
  21. data/lib/wavefront-sdk/unstable/unstable.rb +9 -0
  22. data/lib/wavefront-sdk/usage.rb +31 -0
  23. data/lib/wavefront-sdk/user.rb +41 -0
  24. data/lib/wavefront-sdk/usergroup.rb +17 -16
  25. data/lib/wavefront-sdk/validators.rb +65 -7
  26. data/lib/wavefront-sdk/write.rb +13 -3
  27. data/spec/.rubocop.yml +42 -1
  28. data/spec/spec_helper.rb +4 -0
  29. data/spec/support/minitest_assertions.rb +4 -4
  30. data/spec/wavefront-sdk/account_spec.rb +238 -0
  31. data/spec/wavefront-sdk/core/api_caller_spec.rb +43 -0
  32. data/spec/wavefront-sdk/ingestionpolicy_spec.rb +43 -0
  33. data/spec/wavefront-sdk/metric_helper_spec.rb +1 -1
  34. data/spec/wavefront-sdk/role_spec.rb +96 -0
  35. data/spec/wavefront-sdk/spy_spec.rb +113 -0
  36. data/spec/wavefront-sdk/unstable/chart_spec.rb +39 -0
  37. data/spec/wavefront-sdk/usage_spec.rb +33 -0
  38. data/spec/wavefront-sdk/user_spec.rb +20 -0
  39. data/spec/wavefront-sdk/usergroup_spec.rb +21 -11
  40. data/spec/wavefront-sdk/validators_spec.rb +52 -6
  41. data/wavefront-sdk.gemspec +4 -4
  42. metadata +30 -9
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: b39db1a4f6e5f1899b8ae8f5fef5c2d0364775de94860054101a352b71e6abf4
4
- data.tar.gz: a28e17f8e36429c3a954de36baa05ede7ba6a2972d0d30dede00a490fb4a05af
3
+ metadata.gz: e4f8e6e99d7124c4a1654be470312d6749c475d0cfbc23b33c72962d13fe0e1e
4
+ data.tar.gz: d2f43cb3bf00ddacce6cd24e92578d9876cfcbfa6b05cbdf6db68a5fbba732d9
5
5
  SHA512:
6
- metadata.gz: b56fad2f699a16dff96774c857a04b4aad1ad559147bbd50d79b0316c24c0b217e2aa3fdbb5d17aced23b99b1498d820f889003f60cc5287c4389e2fd75d003b
7
- data.tar.gz: 0b1bcbc888ebfe63fd96cbcd0c4d8569e22552ad416cdf4dc2bb216f76dc517300daf7954d345d24c253d57250ca5f8d9812545b2619f9199575f84a76b0525d
6
+ metadata.gz: b01743fb3be2eaa72ff58f857eac4f640354ec6264436e764b0f5852b987a54f16d5fde57235b29b3c7ed5623ebca1894d467da1624f56fb8a185c5becded20c
7
+ data.tar.gz: 81953b85f6638f802619f8481f70a0e98129f26139ed06d70c28ce100b266dfd13fa1279112698e13a7ecf74364d781608ad3e20feb9c4451ef21070e511516a
@@ -1,7 +1,48 @@
1
1
  ---
2
2
 
3
3
  AllCops:
4
- TargetRubyVersion: 2.3
4
+ TargetRubyVersion: 2.4
5
5
 
6
6
  Metrics/ClassLength:
7
- Max: 124
7
+ Max: 150
8
+
9
+ # New cops
10
+ #
11
+ Lint/RaiseException:
12
+ Enabled: true
13
+ Lint/StructNewOverride:
14
+ Enabled: true
15
+ Style/ExponentialNotation:
16
+ Enabled: true
17
+ Style/HashEachMethods:
18
+ Enabled: true
19
+ Style/HashTransformKeys:
20
+ Enabled: true
21
+ Style/HashTransformValues:
22
+ Enabled: true
23
+ Layout/EmptyLinesAroundAttributeAccessor:
24
+ Enabled: true
25
+ Layout/SpaceAroundMethodCallOperator:
26
+ Enabled: true
27
+ Style/SlicingWithRange:
28
+ Enabled: true
29
+ Lint/DeprecatedOpenSSLConstant:
30
+ Enabled: true
31
+ Lint/MixedRegexpCaptureTypes:
32
+ Enabled: true
33
+ Style/RedundantRegexpCharacterClass:
34
+ Enabled: true
35
+ Style/RedundantRegexpEscape:
36
+ Enabled: true
37
+ Style/AccessorGrouping:
38
+ Enabled: true
39
+ Style/BisectedAttrAccessor:
40
+ Enabled: true
41
+ Style/RedundantAssignment:
42
+ Enabled: true
43
+ Style/RedundantFetchBlock:
44
+ Enabled: true
45
+
46
+ # Is nothing sacred?
47
+ Layout/LineLength:
48
+ Max: 80
@@ -1,7 +1,6 @@
1
1
  language: ruby
2
2
  cache: bundler
3
3
  rvm:
4
- - 2.3.8
5
4
  - 2.4.9
6
5
  - 2.5.7
7
6
  - 2.6.5
data/HISTORY.md CHANGED
@@ -1,5 +1,38 @@
1
1
  # Changelog
2
2
 
3
+ ## 5.0.1 (2020-07-08)
4
+ * Reinstate `Wavefront::Role#grant` and `Wavefront::Role#revoke`, which were
5
+ accidentally removed prior to release of 5.0.0.
6
+
7
+ ## 5.0.0 (2020-07-08)
8
+ * Remove `Wavefront::UserGroup#grant` and `Wavefront::UserGroup#revoke` as [the
9
+ API paths they used have been
10
+ removed](https://docs.wavefront.com/2020.06.x_release_notes.html#obsolete-and-deprecated-apis).
11
+ (Breaking change.)
12
+ * Remove `Wavefront::MonitoredCluster` class, as it has been removed from the
13
+ public API.
14
+ * Deprecate `Wavefront::User` class, as [the user API is now
15
+ deprecated](https://docs.wavefront.com/2020.06.x_release_notes.html#obsolete-and-deprecated-apis)
16
+ * Add `Wavefront::Role` class, for managing roles.
17
+ * Promote `Wavefront::Spy` class from unstable. It is now an official API.
18
+
19
+ ## 4.0.0 (2020-02-17)
20
+ * Drop support for Ruby 2.3. (Breaking change.)
21
+ * Add `Wavefront::MonitoredCluster` class.
22
+ * Add `Wavefront::Unstable::Spy` class to speak to (undocumented) spy
23
+ interface.
24
+ * Add `Wavefront::Unstable::Chart` class to speak to (undocumented) chart
25
+ interface.
26
+
27
+ ## 3.7.1 (2020-02-09)
28
+ * `Response` object returned by `Wavefront::Write#write` includes a valid HTTP
29
+ code, rather than `nil`.
30
+
31
+ ## 3.7.0 (2020-01-23)
32
+ * Add `Account`, `Usage` and `IngestionPolicy` classes.
33
+ * Allow modification of `Wavefront::Response`'s `response` object.
34
+ * Add `User#validate_users` method.
35
+
3
36
  ## 3.6.1 (2020-01-15)
4
37
  * Test build against, and fix warning messages on, Ruby 2.7.0
5
38
 
data/README.md CHANGED
@@ -24,7 +24,7 @@ or to build locally,
24
24
  $ gem build wavefront-sdk.gemspec
25
25
  ```
26
26
 
27
- `wavefront-sdk` requires Ruby >= 2.3. All its dependencies are pure
27
+ `wavefront-sdk` requires Ruby >= 2.4. All its dependencies are pure
28
28
  Ruby, right the way down, so a compiler should never be required to
29
29
  install it.
30
30
 
@@ -100,10 +100,11 @@ when you ask for a list of objects.
100
100
 
101
101
  You can set an offset and a limit when you list, but setting the
102
102
  limit to the magic value `:all` will return all items, without you
103
- having to deal with pagination.
103
+ having to deal with pagination. When you do that, `offset` is repurposed as
104
+ the number of results fetched with each call to the API.
104
105
 
105
106
  Calling a method with the limit set to `:lazy` returns a lazy
106
- enumerable.
107
+ enumerable. Again, `offset` is the chunk size.
107
108
 
108
109
  ```ruby
109
110
  wf = Wavefront::Alert.new(creds.all)
@@ -0,0 +1,303 @@
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 accounts. '/account/serviceaccount' API paths
9
+ # are covered in the Wavefront::ServiceAccount class.
10
+ #
11
+ # Many of these methods are duplicated in the User class. This reflects the
12
+ # layout of the API.
13
+ #
14
+ class Account < CoreApi
15
+ include Wavefront::Mixin::User
16
+ #
17
+ # GET /api/v2/account
18
+ # Get all accounts (users and service accounts) of a customer
19
+ # @param offset [Int] account at which the list begins
20
+ # @param limit [Int] the number of accounts 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
+ # DELETE /api/v2/account/{id}
28
+ # Deletes an account (user or service account) identified by id
29
+ # @param id [String] ID of the account
30
+ # @return [Wavefront::Response]
31
+ #
32
+ def delete(id)
33
+ wf_account_id?(id)
34
+ api.delete(id)
35
+ end
36
+
37
+ # GET /api/v2/account/{id}
38
+ # Get a specific account (user or service account)
39
+ # @param id [String] ID of the proxy
40
+ # @return [Wavefront::Response]
41
+ #
42
+ def describe(id)
43
+ wf_account_id?(id)
44
+ api.get(id)
45
+ end
46
+
47
+ # POST /api/v2/account/{id}/addRoles
48
+ # Add specific roles to the account (user or service account)
49
+ # @param id [String] ID of the account
50
+ # @param role_list [Array[String]] list of roles to add
51
+ # @return [Wavefront::Response]
52
+ #
53
+ def add_roles(id, role_list)
54
+ wf_account_id?(id)
55
+ validate_role_list(role_list)
56
+ api.post([id, 'addRoles'].uri_concat, role_list, 'application/json')
57
+ end
58
+
59
+ # POST /api/v2/account/{id}/addUserGroups
60
+ # Adds specific user groups to the account (user or service account)
61
+ # @param id [String] ID of the account
62
+ # @param group_list [Array[String]] list of groups to add
63
+ # @return [Wavefront::Response]
64
+ #
65
+ def add_user_groups(id, group_list)
66
+ wf_account_id?(id)
67
+ validate_usergroup_list(group_list)
68
+ api.post([id, 'addUserGroups'].uri_concat, group_list,
69
+ 'application/json')
70
+ end
71
+
72
+ # GET /api/v2/account/{id}/businessFunctions
73
+ # Returns business functions of a specific account (user or service
74
+ # account).
75
+ # @param id [String] user ID
76
+ # @return [Wavefront::Response]
77
+ #
78
+ def business_functions(id)
79
+ wf_account_id?(id)
80
+ api.get([id, 'businessFunctions'].uri_concat)
81
+ end
82
+
83
+ # POST /api/v2/account/{id}/removeRoles
84
+ # Removes specific roles from the account (user or service account)
85
+ # @param id [String] ID of the account
86
+ # @param role_list [Array[String]] list of roles to remove
87
+ # @return [Wavefront::Response]
88
+ #
89
+ def remove_roles(id, role_list)
90
+ wf_account_id?(id)
91
+ validate_role_list(role_list)
92
+ api.post([id, 'removeRoles'].uri_concat, role_list, 'application/json')
93
+ end
94
+
95
+ # POST /api/v2/account/{id}/removeUserGroups
96
+ # Removes specific user groups from the account (user or service account)
97
+ # @param id [String] ID of the account
98
+ # @param group_list [Array[String]] list of groups to remove
99
+ # @return [Wavefront::Response]
100
+ #
101
+ def remove_user_groups(id, group_list)
102
+ wf_account_id?(id)
103
+ validate_usergroup_list(group_list)
104
+ api.post([id, 'removeUserGroups'].uri_concat, group_list,
105
+ 'application/json')
106
+ end
107
+
108
+ # POST /api/v2/account/{id}/grant/{permission}
109
+ # Grants a specific permission to account (user or service account)
110
+ # POST /api/v2/account/grant/{permission}
111
+ # Grants a specific permission to multiple accounts (users or service
112
+ # accounts)
113
+ # @param id_list [Array[String],String] single account ID or list of
114
+ # account IDs
115
+ # @param permission [String] permission group to grant to user.
116
+ # @return [Wavefront::Response]
117
+ #
118
+ def grant(id, permission)
119
+ if id.is_a?(String)
120
+ grant_to_id(id, permission)
121
+ else
122
+ grant_to_multiple(id, permission)
123
+ end
124
+ end
125
+
126
+ # POST /api/v2/account/{id}/revoke/{permission}
127
+ # Revokes a specific permission from account (user or service account)
128
+ # POST /api/v2/account/revoke/{permission}
129
+ # Revokes a specific permission from multiple accounts (users or service
130
+ # accounts
131
+ # @param id [String,Array[String]] ID of the user, or list of user IDs
132
+ # @param permission [String] permission group to revoke from user.
133
+ # @return [Wavefront::Response]
134
+ #
135
+ def revoke(id, permission)
136
+ if id.is_a?(String)
137
+ revoke_from_id(id, permission)
138
+ else
139
+ revoke_from_multiple(id, permission)
140
+ end
141
+ end
142
+
143
+ # POST /api/v2/account/addingestionpolicy
144
+ # Add a specific ingestion policy to multiple accounts
145
+ # @param policy_id [String] ID of the ingestion policy
146
+ # @param id_list [Array[String]] list of accounts to be put in policy
147
+ # @return [Wavefront::Response]
148
+ #
149
+ def add_ingestion_policy(policy_id, id_list)
150
+ wf_ingestionpolicy_id?(policy_id)
151
+ validate_account_list(id_list)
152
+ api.post('addingestionpolicy',
153
+ { ingestionPolicyId: policy_id,
154
+ accounts: id_list },
155
+ 'application/json')
156
+ end
157
+
158
+ # POST /api/v2/account/removeingestionpolicies
159
+ # Removes ingestion policies from multiple accounts. The API path says
160
+ # "policies" but I've made the method name "policy" for consistency.
161
+ # @param policy_id [String] ID of the ingestion policy
162
+ # @param id_list [Array[String]] list of accounts to be put in policy
163
+ # @return [Wavefront::Response]
164
+ #
165
+ def remove_ingestion_policy(policy_id, id_list)
166
+ wf_ingestionpolicy_id?(policy_id)
167
+ validate_account_list(id_list)
168
+ api.post('removeingestionpolicies',
169
+ { ingestionPolicyId: policy_id,
170
+ accounts: id_list },
171
+ 'application/json')
172
+ end
173
+
174
+ # POST /api/v2/account/deleteAccounts
175
+ # Deletes multiple accounts (users or service accounts)
176
+ # @param id [String] ID of the account
177
+ # @param group_list [Array[String]] list of accounts to delete
178
+ # @return [Wavefront::Response]
179
+ #
180
+ def delete_accounts(id_list)
181
+ validate_account_list(id_list)
182
+ api.post('deleteAccounts', id_list, 'application/json')
183
+ end
184
+
185
+ # GET /api/v2/account/user
186
+ # Get all user accounts
187
+ # @param offset [Int] user account at which the list begins
188
+ # @param limit [Int] the number of user accounts to return
189
+ # @return [Wavefront::Response]
190
+ #
191
+ def user_list(offset = 0, limit = 100)
192
+ api.get('user', offset: offset, limit: limit)
193
+ end
194
+
195
+ def user_create(body, send_email = false)
196
+ raise ArgumentError unless body.is_a?(Hash)
197
+
198
+ uri = send_email ? "?sendEmail=#{send_email}" : 'user'
199
+
200
+ api.post(uri, body, 'application/json')
201
+ end
202
+
203
+ # POST /api/v2/account/user
204
+ # Creates or updates a user account
205
+ # @param id [String] a Wavefront user ID
206
+ # @param body [Hash] key-value hash of the parameters you wish to change
207
+ # @param modify [true, false] if true, use {#describe()} to get a hash
208
+ # describing the existing object, and modify that with the new body. If
209
+ # false, pass the new body straight through.
210
+ # @return [Wavefront::Response]
211
+ def user_update(body, modify = true)
212
+ raise ArgumentError unless body.is_a?(Hash)
213
+
214
+ return api.post('user', body, 'application/json') unless modify
215
+
216
+ api.post('user',
217
+ hash_for_update(describe(id).response, body),
218
+ 'application/json')
219
+ end
220
+
221
+ # GET /api/v2/account/user/{id}
222
+ # Retrieves a user by identifier (email address)
223
+ # @param id [String] ID of the proxy
224
+ # @return [Wavefront::Response]
225
+ #
226
+ def user_describe(id)
227
+ wf_user_id?(id)
228
+ api.get(['user', id].uri_concat)
229
+ end
230
+
231
+ # POST /api/v2/account/user/invite
232
+ # Invite user accounts with given user groups and permissions.
233
+ # @param body [Array[Hash]] array of hashes, each hash describing a user.
234
+ # See API docs for more details. It is your responsibility to validate
235
+ # the data which describes each user.
236
+ # @return [Wavefront::Response]
237
+ #
238
+ def user_invite(body)
239
+ raise ArgumentError unless body.is_a?(Array)
240
+ raise ArgumentError unless body.first.is_a?(Hash)
241
+
242
+ api.post('user/invite', body, 'application/json')
243
+ end
244
+
245
+ # POST /api/v2/account/validateAccounts
246
+ # Returns valid accounts (users and service accounts), also invalid
247
+ # identifiers from the given list
248
+ # @param id_list [Array[String]] list of user IDs
249
+ # @return [Wavefront::Response]
250
+ #
251
+ def validate_accounts(id_list)
252
+ raise ArgumentError unless id_list.is_a?(Array)
253
+
254
+ api.post('validateAccounts', id_list, 'application/json')
255
+ end
256
+
257
+ private
258
+
259
+ # @param id [String] ID of the user
260
+ # @param permission [String] permission group to grant to user.
261
+ # @return [Wavefront::Response]
262
+ #
263
+ def grant_to_id(id, permission)
264
+ wf_account_id?(id)
265
+ wf_permission?(permission)
266
+ api.post([id, 'grant', permission].uri_concat)
267
+ end
268
+
269
+ # @param id_list [Array[String]] list of account IDs
270
+ # @param permission [String] permission group to grant to user.
271
+ # @return [Wavefront::Response]
272
+ #
273
+ def grant_to_multiple(id_list, permission)
274
+ validate_account_list(id_list)
275
+ wf_permission?(permission)
276
+ api.post(['grant', permission].uri_concat, id_list, 'application/json')
277
+ end
278
+
279
+ # @param id [String] ID of the user
280
+ # @param permission [String] permission group to revoke from user.
281
+ # @return [Wavefront::Response]
282
+ #
283
+ def revoke_from_id(id, permission)
284
+ wf_account_id?(id)
285
+ wf_permission?(permission)
286
+ api.post([id, 'revoke', permission].uri_concat)
287
+ end
288
+
289
+ # @param id_list [Array[String]] list of account IDs
290
+ # @param permission [String] permission group to revoke from user.
291
+ # @return [Wavefront::Response]
292
+ #
293
+ def revoke_from_multiple(id_list, permission)
294
+ validate_account_list(id_list)
295
+ wf_permission?(permission)
296
+ api.post(['revoke', permission].uri_concat, id_list, 'application/json')
297
+ end
298
+
299
+ def update_keys
300
+ %i[identifier groups userGroups roles ingestionPolicyId]
301
+ end
302
+ end
303
+ end
@@ -25,6 +25,26 @@ module Wavefront
25
25
 
26
26
  list.each { |id| wf_usergroup_id?(id) }
27
27
  end
28
+
29
+ # Validate a list of accounts.
30
+ # @param list [Array[String]] list of account IDs
31
+ # @raise Wavefront::Exception::InvalidAccount
32
+ #
33
+ def validate_account_list(list)
34
+ raise ArgumentError unless list.is_a?(Array)
35
+
36
+ list.each { |id| wf_account_id?(id) }
37
+ end
38
+
39
+ # Validate a list of roles
40
+ # @param list [Array[String]] list of role IDs
41
+ # @raise Wavefront::Exception::InvalidRole
42
+ #
43
+ def validate_role_list(list)
44
+ raise ArgumentError unless list.is_a?(Array)
45
+
46
+ list.each { |id| wf_role_id?(id) }
47
+ end
28
48
  end
29
49
  end
30
50
  end