wavefront-sdk 3.6.0 → 5.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (43) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop.yml +43 -2
  3. data/.travis.yml +5 -5
  4. data/HISTORY.md +32 -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 +104 -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/support/mixins.rb +1 -1
  20. data/lib/wavefront-sdk/unstable/README.md +4 -0
  21. data/lib/wavefront-sdk/unstable/chart.rb +90 -0
  22. data/lib/wavefront-sdk/unstable/unstable.rb +9 -0
  23. data/lib/wavefront-sdk/usage.rb +31 -0
  24. data/lib/wavefront-sdk/user.rb +41 -0
  25. data/lib/wavefront-sdk/usergroup.rb +17 -16
  26. data/lib/wavefront-sdk/validators.rb +65 -7
  27. data/lib/wavefront-sdk/write.rb +13 -3
  28. data/spec/.rubocop.yml +42 -1
  29. data/spec/spec_helper.rb +4 -0
  30. data/spec/support/minitest_assertions.rb +4 -4
  31. data/spec/wavefront-sdk/account_spec.rb +238 -0
  32. data/spec/wavefront-sdk/core/api_caller_spec.rb +43 -0
  33. data/spec/wavefront-sdk/ingestionpolicy_spec.rb +43 -0
  34. data/spec/wavefront-sdk/metric_helper_spec.rb +1 -1
  35. data/spec/wavefront-sdk/role_spec.rb +68 -0
  36. data/spec/wavefront-sdk/spy_spec.rb +113 -0
  37. data/spec/wavefront-sdk/unstable/chart_spec.rb +39 -0
  38. data/spec/wavefront-sdk/usage_spec.rb +33 -0
  39. data/spec/wavefront-sdk/user_spec.rb +20 -0
  40. data/spec/wavefront-sdk/usergroup_spec.rb +21 -11
  41. data/spec/wavefront-sdk/validators_spec.rb +52 -6
  42. data/wavefront-sdk.gemspec +4 -4
  43. metadata +30 -9
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: cebe33cf2ebe1428fe26352575f9271d951d42d1e8ba171ae20636da3295b342
4
- data.tar.gz: 566fc5988025e8bc3db50c7df0d4dd4cf3578b2a9156ef6cb605e4882553e6b7
3
+ metadata.gz: 97f7ce778de07ac5c70631f69d24c84bf9aad453dcf68ee28518f85b6bca7e03
4
+ data.tar.gz: d8b9d202a25cb88c501ac0e4101245c9c582990401b400ef759e057986b67864
5
5
  SHA512:
6
- metadata.gz: 6cdc071dc6f152192e565dec067ddd756a055b5b976dc4a1a76ef254e4eae08577419662ba8411926fc2639b6280210223ba3674e0ea4097063e8ced46af1245
7
- data.tar.gz: 85b7b0a209643379af464c8a9c1b5bf465374712ed23b148ae7a4a7c7a23ffc7535e1cef32e83e7a33dae47100ab00eaaa5aced4f5781dd14a224f97d43cbb0b
6
+ metadata.gz: 182e6262ddc79f9f88d94505c9b1488dd5f69e19d7e3edfb854ab74378519c83bf60056b709572c21a994c3420802a022eb4a9679395cc7f195e592ca9725c9e
7
+ data.tar.gz: 8a0fb76bc633bff58dbb8957fef6bf18a41f2bcc11baf27465a2a8b267625511bb0817207975f58c32daf9c51d78b4016fd1f155f121e509dc3b30ef016f87f0
@@ -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,10 +1,10 @@
1
1
  language: ruby
2
2
  cache: bundler
3
3
  rvm:
4
- - 2.3.8
5
- - 2.4.7
6
- - 2.5.6
7
- - 2.6.4
4
+ - 2.4.9
5
+ - 2.5.7
6
+ - 2.6.5
7
+ - 2.7.0
8
8
  before_install: gem install bundler --no-document
9
9
  deploy:
10
10
  provider: rubygems
@@ -14,7 +14,7 @@ deploy:
14
14
  on:
15
15
  tags: true
16
16
  repo: snltd/wavefront-sdk
17
- ruby: 2.6.4
17
+ ruby: 2.6.5
18
18
  notifications:
19
19
  email: false
20
20
  slack:
data/HISTORY.md CHANGED
@@ -1,5 +1,37 @@
1
1
  # Changelog
2
2
 
3
+ ## 5.0.0 (2020-07-08)
4
+ * Remove `Wavefront::UserGroup#grant` and `Wavefront::UserGroup#revoke` as [the
5
+ API paths they used have been
6
+ removed](https://docs.wavefront.com/2020.06.x_release_notes.html#obsolete-and-deprecated-apis).
7
+ (Breaking change.)
8
+ * Remove `Wavefront::MonitoredCluster` class, as it has been removed from the
9
+ public API.
10
+ * Deprecate `Wavefront::User` class, as [the user API is now
11
+ deprecated](https://docs.wavefront.com/2020.06.x_release_notes.html#obsolete-and-deprecated-apis)
12
+ * Add `Wavefront::Role` class, for managing roles.
13
+ * Promote `Wavefront::Spy` class from unstable. It is now an official API.
14
+
15
+ ## 4.0.0 (2020-02-17)
16
+ * Drop support for Ruby 2.3. (Breaking change.)
17
+ * Add `Wavefront::MonitoredCluster` class.
18
+ * Add `Wavefront::Unstable::Spy` class to speak to (undocumented) spy
19
+ interface.
20
+ * Add `Wavefront::Unstable::Chart` class to speak to (undocumented) chart
21
+ interface.
22
+
23
+ ## 3.7.1 (2020-02-09)
24
+ * `Response` object returned by `Wavefront::Write#write` includes a valid HTTP
25
+ code, rather than `nil`.
26
+
27
+ ## 3.7.0 (2020-01-23)
28
+ * Add `Account`, `Usage` and `IngestionPolicy` classes.
29
+ * Allow modification of `Wavefront::Response`'s `response` object.
30
+ * Add `User#validate_users` method.
31
+
32
+ ## 3.6.1 (2020-01-15)
33
+ * Test build against, and fix warning messages on, Ruby 2.7.0
34
+
3
35
  ## 3.6.0 (2019-11-12)
4
36
  * Add `User#business_functions` method.
5
37
  * Update Faraday and Rubocop dependencies
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