wavefront-sdk 3.6.1 → 3.7.0
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/HISTORY.md +5 -0
- data/lib/wavefront-sdk/account.rb +202 -0
- data/lib/wavefront-sdk/api_mixins/user.rb +10 -0
- data/lib/wavefront-sdk/core/exception.rb +2 -0
- data/lib/wavefront-sdk/core/response.rb +2 -1
- data/lib/wavefront-sdk/defs/version.rb +1 -1
- data/lib/wavefront-sdk/ingestionpolicy.rb +85 -0
- data/lib/wavefront-sdk/usage.rb +31 -0
- data/lib/wavefront-sdk/user.rb +10 -0
- data/lib/wavefront-sdk/validators.rb +26 -0
- data/spec/.rubocop.yml +1 -1
- data/spec/wavefront-sdk/account_spec.rb +132 -0
- data/spec/wavefront-sdk/ingestionpolicy_spec.rb +43 -0
- data/spec/wavefront-sdk/usage_spec.rb +33 -0
- data/spec/wavefront-sdk/user_spec.rb +12 -0
- data/spec/wavefront-sdk/validators_spec.rb +27 -6
- metadata +11 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e89654234db4200e7ec25767b81eeda772092642cb238d9cf908e38e851a8755
|
4
|
+
data.tar.gz: 4de9bfd19d39da4b6e2d6b529614cc1962d8c5915ba92c82bfed736737fc7d28
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 34cf2716c935b469ec385e84445b8f2dec33e29679b6bd3cbe5bd11fff459301535c2acaf06fcfc682854df418577a810b20f4a579d1208fd63542af97ea2dee
|
7
|
+
data.tar.gz: 1d5c66c6b47015f66a07cc64acdef74e8e661fbdda138746028d3885023e36cafb895950ac6d633c27012f5a13c2380f8827072dca2a59afef8a583a2b3a1453
|
data/HISTORY.md
CHANGED
@@ -1,5 +1,10 @@
|
|
1
1
|
# Changelog
|
2
2
|
|
3
|
+
## 3.7.0 (2020-01-23)
|
4
|
+
* Add `Account`, `Usage` and `IngestionPolicy` classes.
|
5
|
+
* Allow modification of `Wavefront::Response`'s `response` object.
|
6
|
+
* Add `User#validate_users` method.
|
7
|
+
|
3
8
|
## 3.6.1 (2020-01-15)
|
4
9
|
* Test build against, and fix warning messages on, Ruby 2.7.0
|
5
10
|
|
@@ -0,0 +1,202 @@
|
|
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}/addUserGroups
|
48
|
+
# Adds specific user groups to the account (user or service account)
|
49
|
+
# @param id [String] ID of the account
|
50
|
+
# @param group_list [Array[String]] list of groups to add
|
51
|
+
# @return [Wavefront::Response]
|
52
|
+
#
|
53
|
+
def add_user_groups(id, group_list)
|
54
|
+
wf_account_id?(id)
|
55
|
+
validate_usergroup_list(group_list)
|
56
|
+
api.post([id, 'addUserGroups'].uri_concat, group_list,
|
57
|
+
'application/json')
|
58
|
+
end
|
59
|
+
|
60
|
+
# GET /api/v2/account/{id}/businessFunctions
|
61
|
+
# Returns business functions of a specific account (user or service
|
62
|
+
# account).
|
63
|
+
# @param id [String] user ID
|
64
|
+
# @return [Wavefront::Response]
|
65
|
+
#
|
66
|
+
def business_functions(id)
|
67
|
+
wf_account_id?(id)
|
68
|
+
api.get([id, 'businessFunctions'].uri_concat)
|
69
|
+
end
|
70
|
+
|
71
|
+
# POST /api/v2/account/{id}/removeUserGroups
|
72
|
+
# Removes specific user groups from the account (user or service account)
|
73
|
+
# @param id [String] ID of the account
|
74
|
+
# @param group_list [Array[String]] list of groups to add
|
75
|
+
# @return [Wavefront::Response]
|
76
|
+
#
|
77
|
+
def remove_user_groups(id, group_list)
|
78
|
+
wf_account_id?(id)
|
79
|
+
validate_usergroup_list(group_list)
|
80
|
+
api.post([id, 'removeUserGroups'].uri_concat, group_list,
|
81
|
+
'application/json')
|
82
|
+
end
|
83
|
+
|
84
|
+
# POST /api/v2/account/{id}/grant/{permission}
|
85
|
+
# Grants a specific permission to account (user or service account)
|
86
|
+
# POST /api/v2/account/grant/{permission}
|
87
|
+
# Grants a specific permission to multiple accounts (users or service
|
88
|
+
# accounts)
|
89
|
+
# @param id_list [Array[String],String] single account ID or list of
|
90
|
+
# account IDs
|
91
|
+
# @param permission [String] permission group to grant to user.
|
92
|
+
# @return [Wavefront::Response]
|
93
|
+
#
|
94
|
+
def grant(id, permission)
|
95
|
+
if id.is_a?(String)
|
96
|
+
grant_to_id(id, permission)
|
97
|
+
else
|
98
|
+
grant_to_multiple(id, permission)
|
99
|
+
end
|
100
|
+
end
|
101
|
+
|
102
|
+
# POST /api/v2/account/{id}/revoke/{permission}
|
103
|
+
# Revokes a specific permission from account (user or service account)
|
104
|
+
# POST /api/v2/account/revoke/{permission}
|
105
|
+
# Revokes a specific permission from multiple accounts (users or service
|
106
|
+
# accounts
|
107
|
+
# @param id [String,Array[String]] ID of the user, or list of user IDs
|
108
|
+
# @param permission [String] permission group to revoke from user.
|
109
|
+
# @return [Wavefront::Response]
|
110
|
+
#
|
111
|
+
def revoke(id, permission)
|
112
|
+
if id.is_a?(String)
|
113
|
+
revoke_from_id(id, permission)
|
114
|
+
else
|
115
|
+
revoke_from_multiple(id, permission)
|
116
|
+
end
|
117
|
+
end
|
118
|
+
|
119
|
+
# POST /api/v2/account/addingestionpolicy
|
120
|
+
# Add a specific ingestion policy to multiple accounts
|
121
|
+
# @param policy_id [String] ID of the ingestion policy
|
122
|
+
# @param id_list [Array[String]] list of accounts to be put in policy
|
123
|
+
# @return [Wavefront::Response]
|
124
|
+
#
|
125
|
+
def add_ingestion_policy(policy_id, id_list)
|
126
|
+
wf_ingestionpolicy_id?(policy_id)
|
127
|
+
validate_account_list(id_list)
|
128
|
+
api.post('addingestionpolicy',
|
129
|
+
{ ingestionPolicyId: policy_id,
|
130
|
+
accounts: id_list },
|
131
|
+
'application/json')
|
132
|
+
end
|
133
|
+
|
134
|
+
# POST /api/v2/account/removeingestionpolicies
|
135
|
+
# Removes ingestion policies from multiple accounts
|
136
|
+
# @param policy_id [String] ID of the ingestion policy
|
137
|
+
# @param id_list [Array[String]] list of accounts to be put in policy
|
138
|
+
# @return [Wavefront::Response]
|
139
|
+
#
|
140
|
+
def remove_ingestion_policy(policy_id, id_list)
|
141
|
+
wf_ingestionpolicy_id?(policy_id)
|
142
|
+
validate_account_list(id_list)
|
143
|
+
api.post('removeingestionpolicy',
|
144
|
+
{ ingestionPolicyId: policy_id,
|
145
|
+
accounts: id_list },
|
146
|
+
'application/json')
|
147
|
+
end
|
148
|
+
|
149
|
+
# POST /api/v2/account/deleteAccounts
|
150
|
+
# Deletes multiple accounts (users or service accounts)
|
151
|
+
# @param id [String] ID of the account
|
152
|
+
# @param group_list [Array[String]] list of accounts to delete
|
153
|
+
# @return [Wavefront::Response]
|
154
|
+
#
|
155
|
+
def delete_accounts(id_list)
|
156
|
+
validate_account_list(id_list)
|
157
|
+
api.post('deleteAccounts', id_list, 'application/json')
|
158
|
+
end
|
159
|
+
|
160
|
+
private
|
161
|
+
|
162
|
+
# @param id [String] ID of the user
|
163
|
+
# @param permission [String] permission group to grant to user.
|
164
|
+
# @return [Wavefront::Response]
|
165
|
+
#
|
166
|
+
def grant_to_id(id, permission)
|
167
|
+
wf_account_id?(id)
|
168
|
+
wf_permission?(permission)
|
169
|
+
api.post([id, 'grant', permission].uri_concat)
|
170
|
+
end
|
171
|
+
|
172
|
+
# @param id_list [Array[String]] list of account IDs
|
173
|
+
# @param permission [String] permission group to grant to user.
|
174
|
+
# @return [Wavefront::Response]
|
175
|
+
#
|
176
|
+
def grant_to_multiple(id_list, permission)
|
177
|
+
validate_account_list(id_list)
|
178
|
+
wf_permission?(permission)
|
179
|
+
api.post(['grant', permission].uri_concat, id_list, 'application/json')
|
180
|
+
end
|
181
|
+
|
182
|
+
# @param id [String] ID of the user
|
183
|
+
# @param permission [String] permission group to revoke from user.
|
184
|
+
# @return [Wavefront::Response]
|
185
|
+
#
|
186
|
+
def revoke_from_id(id, permission)
|
187
|
+
wf_account_id?(id)
|
188
|
+
wf_permission?(permission)
|
189
|
+
api.post([id, 'revoke', permission].uri_concat)
|
190
|
+
end
|
191
|
+
|
192
|
+
# @param id_list [Array[String]] list of account IDs
|
193
|
+
# @param permission [String] permission group to revoke from user.
|
194
|
+
# @return [Wavefront::Response]
|
195
|
+
#
|
196
|
+
def revoke_from_multiple(id_list, permission)
|
197
|
+
validate_account_list(id_list)
|
198
|
+
wf_permission?(permission)
|
199
|
+
api.post(['revoke', permission].uri_concat, id_list, 'application/json')
|
200
|
+
end
|
201
|
+
end
|
202
|
+
end
|
@@ -25,6 +25,16 @@ 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
|
28
38
|
end
|
29
39
|
end
|
30
40
|
end
|
@@ -8,6 +8,7 @@ module Wavefront
|
|
8
8
|
class CredentialError < RuntimeError; end
|
9
9
|
class EmptyMetricName < RuntimeError; end
|
10
10
|
class EnumerableError < RuntimeError; end
|
11
|
+
class InvalidAccountId < RuntimeError; end
|
11
12
|
class InvalidAlertId < RuntimeError; end
|
12
13
|
class InvalidAlertSeverity < RuntimeError; end
|
13
14
|
class InvalidApiTokenId < RuntimeError; end
|
@@ -23,6 +24,7 @@ module Wavefront
|
|
23
24
|
class InvalidExternalLinkId < RuntimeError; end
|
24
25
|
class InvalidGranularity < RuntimeError; end
|
25
26
|
class InvalidHostname < RuntimeError; end
|
27
|
+
class InvalidIngestionPolicyId < RuntimeError; end
|
26
28
|
class InvalidIntegrationId < RuntimeError; end
|
27
29
|
class InvalidLinkTemplate < RuntimeError; end
|
28
30
|
class InvalidMaintenanceWindowId < RuntimeError; end
|
@@ -25,7 +25,8 @@ module Wavefront
|
|
25
25
|
#
|
26
26
|
class Response
|
27
27
|
include Wavefront::Mixins
|
28
|
-
attr_reader :status, :
|
28
|
+
attr_reader :status, :opts, :logger
|
29
|
+
attr_accessor :response
|
29
30
|
|
30
31
|
# Create and return a Wavefront::Response object
|
31
32
|
# @param json [String] a raw response body from the Wavefront API
|
@@ -0,0 +1,85 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative 'core/api'
|
4
|
+
|
5
|
+
module Wavefront
|
6
|
+
#
|
7
|
+
# View and manage Wavefront ingestion policies.
|
8
|
+
#
|
9
|
+
# These use the Usage API path.
|
10
|
+
#
|
11
|
+
class IngestionPolicy < CoreApi
|
12
|
+
def api_base
|
13
|
+
'/usage/ingestionpolicy'
|
14
|
+
end
|
15
|
+
|
16
|
+
# GET /api/v2/usage/ingestionpolicy
|
17
|
+
# Get all ingestion policies for a customer
|
18
|
+
#
|
19
|
+
# @return [Wavefront::Response]
|
20
|
+
#
|
21
|
+
# @param offset [Int] ingestion policy at which the list begins
|
22
|
+
# @param limit [Int] the number of ingestion policies to return
|
23
|
+
# @return [Wavefront::Response]
|
24
|
+
#
|
25
|
+
def list(offset = 0, limit = 100)
|
26
|
+
api.get('', offset: offset, limit: limit)
|
27
|
+
end
|
28
|
+
|
29
|
+
# POST /api/v2/usage/ingestionpolicy
|
30
|
+
# Create a specific ingestion policy
|
31
|
+
#
|
32
|
+
# @param body [Hash] description of ingestion policy
|
33
|
+
# @return [Wavefront::Response]
|
34
|
+
#
|
35
|
+
def create(body)
|
36
|
+
raise ArgumentError unless body.is_a?(Hash)
|
37
|
+
|
38
|
+
api.post('', body, 'application/json')
|
39
|
+
end
|
40
|
+
|
41
|
+
# DELETE /api/v2/usage/ingestionpolicy/{id}
|
42
|
+
# Delete a specific ingestion policy
|
43
|
+
#
|
44
|
+
# @param id [String] ID of the alert
|
45
|
+
# @return [Wavefront::Response]
|
46
|
+
#
|
47
|
+
def delete(id)
|
48
|
+
wf_ingestionpolicy_id?(id)
|
49
|
+
api.delete(id)
|
50
|
+
end
|
51
|
+
|
52
|
+
# GET /api/v2/usage/ingestionpolicy/{id}
|
53
|
+
# Get a specific ingestion policy
|
54
|
+
#
|
55
|
+
# @return [Wavefront::Response]
|
56
|
+
# @param id [String] ID of the proxy
|
57
|
+
# @return [Wavefront::Response]
|
58
|
+
#
|
59
|
+
def describe(id)
|
60
|
+
wf_ingestionpolicy_id?(id)
|
61
|
+
api.get(id)
|
62
|
+
end
|
63
|
+
|
64
|
+
# PUT /api/v2/usage/ingestionpolicy/{id}
|
65
|
+
# Update a specific ingestion policy
|
66
|
+
#
|
67
|
+
# @param id [String] a Wavefront alert ID
|
68
|
+
# @param body [Hash] key-value hash of the parameters you wish
|
69
|
+
# to change
|
70
|
+
# @param modify [true, false] if true, use {#describe()} to get
|
71
|
+
# a hash describing the existing object, and modify that with
|
72
|
+
# the new body. If false, pass the new body straight through.
|
73
|
+
# @return [Wavefront::Response]
|
74
|
+
#
|
75
|
+
def update(id, body, modify = true)
|
76
|
+
wf_ingestionpolicy_id?(id)
|
77
|
+
raise ArgumentError unless body.is_a?(Hash)
|
78
|
+
|
79
|
+
return api.put(id, body, 'application/json') unless modify
|
80
|
+
|
81
|
+
api.put(id, hash_for_update(describe(id).response, body),
|
82
|
+
'application/json')
|
83
|
+
end
|
84
|
+
end
|
85
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require_relative 'core/api'
|
4
|
+
|
5
|
+
module Wavefront
|
6
|
+
#
|
7
|
+
# View and manage Wavefront usage.
|
8
|
+
#
|
9
|
+
# Ingestion policy shares this API path, but has its own SDK class.
|
10
|
+
#
|
11
|
+
class Usage < CoreApi
|
12
|
+
# GET /api/v2/usage/exportcsv
|
13
|
+
# Export a CSV report
|
14
|
+
#
|
15
|
+
# @param t_start [Integer] start time in epoch seconds
|
16
|
+
# @param t_end [Integer] end time in epoch seconds, nil being "now".
|
17
|
+
# @return [Wavefront::Response]
|
18
|
+
#
|
19
|
+
def export_csv(t_start, t_end = nil)
|
20
|
+
wf_epoch?(t_start)
|
21
|
+
args = { startTime: t_start }
|
22
|
+
|
23
|
+
if t_end
|
24
|
+
wf_epoch?(t_end)
|
25
|
+
args[:endTime] = t_end
|
26
|
+
end
|
27
|
+
|
28
|
+
api.get('exportcsv', args)
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
data/lib/wavefront-sdk/user.rb
CHANGED
@@ -212,6 +212,16 @@ module Wavefront
|
|
212
212
|
api.get([id, 'businessFunctions'].uri_concat)
|
213
213
|
end
|
214
214
|
|
215
|
+
# POST /api/v2/user/validateUsers
|
216
|
+
# Returns valid users and service accounts, also invalid identifiers from
|
217
|
+
# the given list
|
218
|
+
# @param id_list [Array[String]] list of user IDs
|
219
|
+
# @return [Wavefront::Response]
|
220
|
+
#
|
221
|
+
def validate_users(id_list)
|
222
|
+
api.post('validateUsers', id_list, 'application/json')
|
223
|
+
end
|
224
|
+
|
215
225
|
# Fake a response which looks like we get from all the other
|
216
226
|
# paths. I'm expecting the user response model to be made
|
217
227
|
# consistent with others in the future.
|
@@ -568,6 +568,32 @@ module Wavefront
|
|
568
568
|
|
569
569
|
raise Wavefront::Exception::InvalidPermission, id, id
|
570
570
|
end
|
571
|
+
|
572
|
+
# Ensure the given argument is a valid ingestion policy ID
|
573
|
+
# @param id [String]
|
574
|
+
# @raise Wavefront::Exception::InvalidIngestionPolicyId if the
|
575
|
+
# ID is not valid
|
576
|
+
#
|
577
|
+
def wf_ingestionpolicy_id?(id)
|
578
|
+
return true if id.is_a?(String) && id =~ /^[a-z0-9\-_]+-\d{13}$/
|
579
|
+
|
580
|
+
raise Wavefront::Exception::InvalidIngestionPolicyId, id
|
581
|
+
end
|
582
|
+
|
583
|
+
# Ensure the given argument is a valid User or SystemAccount ID.
|
584
|
+
# @param id [String]
|
585
|
+
# @raise Wavefront::Exception::InvalidAccountId if the
|
586
|
+
# ID is not valid
|
587
|
+
#
|
588
|
+
def wf_account_id?(id)
|
589
|
+
return true if wf_user_id?(id)
|
590
|
+
rescue Wavefront::Exception::InvalidUserId
|
591
|
+
begin
|
592
|
+
return true if wf_serviceaccount_id?(id)
|
593
|
+
rescue Wavefront::Exception::InvalidServiceAccountId
|
594
|
+
raise Wavefront::Exception::InvalidAccountId, id
|
595
|
+
end
|
596
|
+
end
|
571
597
|
end
|
572
598
|
# rubocop:enable Metrics/ModuleLength
|
573
599
|
end
|
data/spec/.rubocop.yml
CHANGED
@@ -0,0 +1,132 @@
|
|
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 Account class
|
8
|
+
#
|
9
|
+
class WavefrontAccountTest < WavefrontTestBase
|
10
|
+
include WavefrontTest::List
|
11
|
+
include WavefrontTest::Delete
|
12
|
+
include WavefrontTest::Describe
|
13
|
+
|
14
|
+
def test_add_user_groups
|
15
|
+
assert_posts("/api/v2/account/#{id}/addUserGroups", groups.to_json) do
|
16
|
+
wf.add_user_groups(id, groups)
|
17
|
+
end
|
18
|
+
|
19
|
+
assert_invalid_id { wf.add_user_groups(invalid_id, groups) }
|
20
|
+
end
|
21
|
+
|
22
|
+
def test_business_functions
|
23
|
+
assert_gets("/api/v2/account/#{id}/businessFunctions") do
|
24
|
+
wf.business_functions(id)
|
25
|
+
end
|
26
|
+
|
27
|
+
assert_raises(ArgumentError) { wf.business_functions }
|
28
|
+
end
|
29
|
+
|
30
|
+
def test_grant_to_single_user
|
31
|
+
assert_posts("/api/v2/account/#{id}/grant/#{permission}") do
|
32
|
+
wf.grant(id, permission)
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
def test_grant_to_multiple_users
|
37
|
+
assert_posts("/api/v2/account/grant/#{permission}", id_list.to_json) do
|
38
|
+
wf.grant(id_list, permission)
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
def test_remove_user_groups
|
43
|
+
assert_posts("/api/v2/account/#{id}/removeUserGroups", groups.to_json) do
|
44
|
+
wf.remove_user_groups(id, groups)
|
45
|
+
end
|
46
|
+
|
47
|
+
assert_invalid_id { wf.remove_user_groups(invalid_id, groups) }
|
48
|
+
end
|
49
|
+
|
50
|
+
def test_revoke_from_single_user
|
51
|
+
assert_posts("/api/v2/account/#{id}/revoke/#{permission}") do
|
52
|
+
wf.revoke(id, permission)
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
def test_revoke_from_multiple_users
|
57
|
+
assert_posts("/api/v2/account/revoke/#{permission}", id_list.to_json) do
|
58
|
+
wf.revoke(id_list, permission)
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
def test_delete_accounts
|
63
|
+
assert_posts('/api/v2/account/deleteAccounts', id_list.to_json) do
|
64
|
+
wf.delete_accounts(id_list)
|
65
|
+
end
|
66
|
+
|
67
|
+
assert_invalid_id { wf.delete_accounts([invalid_id]) }
|
68
|
+
end
|
69
|
+
|
70
|
+
def test_add_ingestion_policy
|
71
|
+
assert_posts('/api/v2/account/addingestionpolicy',
|
72
|
+
{ ingestionPolicyId: policy_id,
|
73
|
+
accounts: id_list }.to_json) do
|
74
|
+
wf.add_ingestion_policy(policy_id, id_list)
|
75
|
+
end
|
76
|
+
|
77
|
+
assert_raises Wavefront::Exception::InvalidIngestionPolicyId do
|
78
|
+
wf.add_ingestion_policy(invalid_policy_id, id_list)
|
79
|
+
end
|
80
|
+
|
81
|
+
assert_invalid_id { wf.add_ingestion_policy(policy_id, [invalid_id]) }
|
82
|
+
end
|
83
|
+
|
84
|
+
def test_remove_ingestion_policy
|
85
|
+
assert_posts('/api/v2/account/removeingestionpolicy',
|
86
|
+
{ ingestionPolicyId: policy_id,
|
87
|
+
accounts: id_list }.to_json) do
|
88
|
+
wf.remove_ingestion_policy(policy_id, id_list)
|
89
|
+
end
|
90
|
+
|
91
|
+
assert_raises Wavefront::Exception::InvalidIngestionPolicyId do
|
92
|
+
wf.add_ingestion_policy(invalid_policy_id, id_list)
|
93
|
+
end
|
94
|
+
|
95
|
+
assert_invalid_id { wf.add_ingestion_policy(policy_id, [invalid_id]) }
|
96
|
+
end
|
97
|
+
|
98
|
+
private
|
99
|
+
|
100
|
+
def api_class
|
101
|
+
'account'
|
102
|
+
end
|
103
|
+
|
104
|
+
def id
|
105
|
+
'sa::tester'
|
106
|
+
end
|
107
|
+
|
108
|
+
def invalid_id
|
109
|
+
'bad_id' * 1000
|
110
|
+
end
|
111
|
+
|
112
|
+
def groups
|
113
|
+
%w[f8dc0c14-91a0-4ca9-8a2a-7d47f4db4672
|
114
|
+
2659191e-aad4-4302-a94e-9667e1517127]
|
115
|
+
end
|
116
|
+
|
117
|
+
def id_list
|
118
|
+
%w[sa:test user@example.com]
|
119
|
+
end
|
120
|
+
|
121
|
+
def permission
|
122
|
+
'agent_management'
|
123
|
+
end
|
124
|
+
|
125
|
+
def policy_id
|
126
|
+
'testpolicy-1579537565010'
|
127
|
+
end
|
128
|
+
|
129
|
+
def invalid_policy_id
|
130
|
+
'badpolicy'
|
131
|
+
end
|
132
|
+
end
|
@@ -0,0 +1,43 @@
|
|
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 IngestionPolicy class
|
8
|
+
#
|
9
|
+
class WavefrontIngestionPolicyTest < WavefrontTestBase
|
10
|
+
include WavefrontTest::List
|
11
|
+
include WavefrontTest::Describe
|
12
|
+
include WavefrontTest::Update
|
13
|
+
include WavefrontTest::Delete
|
14
|
+
|
15
|
+
private
|
16
|
+
|
17
|
+
def payload
|
18
|
+
{ sampledUserAccounts: ['string'],
|
19
|
+
userAccountCount: 0,
|
20
|
+
sampledServiceAccounts: [
|
21
|
+
'string'
|
22
|
+
],
|
23
|
+
serviceAccountCount: 0,
|
24
|
+
name: 'string',
|
25
|
+
id: 'string',
|
26
|
+
description: 'string',
|
27
|
+
customer: 'string',
|
28
|
+
lastUpdatedMs: 0,
|
29
|
+
lastUpdatedAccountId: 'string' }
|
30
|
+
end
|
31
|
+
|
32
|
+
def api_class
|
33
|
+
'usage/ingestionpolicy'
|
34
|
+
end
|
35
|
+
|
36
|
+
def id
|
37
|
+
'test-ingestion-policy-1579538401492'
|
38
|
+
end
|
39
|
+
|
40
|
+
def invalid_id
|
41
|
+
'bad_id'
|
42
|
+
end
|
43
|
+
end
|
@@ -0,0 +1,33 @@
|
|
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 Usage class
|
8
|
+
#
|
9
|
+
class WavefrontUsageTest < WavefrontTestBase
|
10
|
+
def test_export_csv
|
11
|
+
assert_raises(ArgumentError) { wf.export_csv }
|
12
|
+
|
13
|
+
assert_gets("/api/v2/usage/exportcsv?startTime=#{t_start}") do
|
14
|
+
wf.export_csv(t_start)
|
15
|
+
end
|
16
|
+
|
17
|
+
assert_gets(
|
18
|
+
"/api/v2/usage/exportcsv?startTime=#{t_start}&endTime=#{t_end}"
|
19
|
+
) do
|
20
|
+
wf.export_csv(t_start, t_end)
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
private
|
25
|
+
|
26
|
+
def t_start
|
27
|
+
1_577_890_000
|
28
|
+
end
|
29
|
+
|
30
|
+
def t_end
|
31
|
+
1_577_899_999
|
32
|
+
end
|
33
|
+
end
|
@@ -110,6 +110,14 @@ class WavefrontUserTest < WavefrontTestBase
|
|
110
110
|
assert_raises(ArgumentError) { wf.business_functions }
|
111
111
|
end
|
112
112
|
|
113
|
+
def test_validate_users
|
114
|
+
assert_posts('/api/v2/user/validateUsers', id_list.to_json) do
|
115
|
+
wf.validate_users(id_list)
|
116
|
+
end
|
117
|
+
|
118
|
+
assert_raises(ArgumentError) { wf.validate_users }
|
119
|
+
end
|
120
|
+
|
113
121
|
def test_response_shim
|
114
122
|
(RESOURCE_DIR + 'user_responses').each_child do |input|
|
115
123
|
# Ugly hack for the 202 in the 'create' file
|
@@ -156,4 +164,8 @@ class WavefrontUserTest < WavefrontTestBase
|
|
156
164
|
def payload
|
157
165
|
{ emailAddress: id, groups: %w[browse] }
|
158
166
|
end
|
167
|
+
|
168
|
+
def id_list
|
169
|
+
%w[id1 id2 id3]
|
170
|
+
end
|
159
171
|
end
|
@@ -323,19 +323,19 @@ class WavefrontValidatorsTest < MiniTest::Test
|
|
323
323
|
end
|
324
324
|
end
|
325
325
|
|
326
|
-
def
|
326
|
+
def test_wf_notificant_id
|
327
327
|
good = %w[CHTo47HvsPzSaGhh]
|
328
328
|
bad = ['CTo47HvsPzSaGhh', [], {}, nil, 'bad id']
|
329
329
|
good_and_bad('wf_notificant_id?', 'InvalidNotificantId', good, bad)
|
330
330
|
end
|
331
331
|
|
332
|
-
def
|
332
|
+
def test_wf_integration_id
|
333
333
|
good = %w[aws tutorial elasticsearch cassandra go]
|
334
334
|
bad = ['CTo47HvsPzSaGhh', [], {}, nil, 'bad id']
|
335
335
|
good_and_bad('wf_integration_id?', 'InvalidIntegrationId', good, bad)
|
336
336
|
end
|
337
337
|
|
338
|
-
def
|
338
|
+
def test_wf_apitoken_id
|
339
339
|
good = %w[2bfdcac7-1c9c-4c4b-9b56-c41c22c586dc
|
340
340
|
17db4cc1-65f6-40a8-a1fa-6fcae460c4bd
|
341
341
|
fca312fb-5ff4-420d-862d-5d6d99ed6bcf
|
@@ -345,24 +345,45 @@ class WavefrontValidatorsTest < MiniTest::Test
|
|
345
345
|
good_and_bad('wf_apitoken_id?', 'InvalidApiTokenId', good, bad)
|
346
346
|
end
|
347
347
|
|
348
|
-
def
|
348
|
+
def test_wf_distribution_interval
|
349
349
|
good = %i[m h d]
|
350
350
|
bad = ['m', [], {}, nil, 'bad id', :x, 'p']
|
351
351
|
good_and_bad('wf_distribution_interval?',
|
352
352
|
'InvalidDistributionInterval', good, bad)
|
353
353
|
end
|
354
354
|
|
355
|
-
def
|
355
|
+
def test_wf_serviceaccount_id
|
356
356
|
good = %w[sa::my-id sa::ID]
|
357
357
|
bad = %w[sc:id fca312fb-5ff4-420d-862d-5d6d99ed6bcf]
|
358
358
|
good_and_bad('wf_serviceaccount_id?',
|
359
359
|
'InvalidServiceAccountId', good, bad)
|
360
360
|
end
|
361
361
|
|
362
|
-
def
|
362
|
+
def test_wf_permission
|
363
363
|
good = %w[events_management external_links_management]
|
364
364
|
bad = ['events management', 'event_management', 'EVENT_MANAGEMENT']
|
365
365
|
good_and_bad('wf_permission?',
|
366
366
|
'InvalidPermission', good, bad)
|
367
367
|
end
|
368
|
+
|
369
|
+
def test_wf_ingestionpolicy_id
|
370
|
+
good = %w[another-ingestion-policy-1579538401492
|
371
|
+
testpolicy-1579537565010
|
372
|
+
213452-34-_-0-4-ingestion-policy-1579538556267
|
373
|
+
yet_another-ingestion-policy-1579538414190]
|
374
|
+
|
375
|
+
bad = %w[fa312fb-5ff4-420d-862d-5d6d99ed6bcf thing 123]
|
376
|
+
good_and_bad('wf_ingestionpolicy_id?',
|
377
|
+
'InvalidIngestionPolicyId',
|
378
|
+
good,
|
379
|
+
bad)
|
380
|
+
end
|
381
|
+
|
382
|
+
def test_wf_account_id
|
383
|
+
good = %w[sa::my-id sa::ID Some.User@example.com
|
384
|
+
general99+specific@somewhere.net someone@somewhere.com a user
|
385
|
+
user-name]
|
386
|
+
bad = ['', [], {}, 'a' * 1000]
|
387
|
+
good_and_bad('wf_account_id?', 'InvalidAccountId', good, bad)
|
388
|
+
end
|
368
389
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: wavefront-sdk
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 3.
|
4
|
+
version: 3.7.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Robert Fisher
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-01-
|
11
|
+
date: 2020-01-23 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: addressable
|
@@ -179,6 +179,7 @@ files:
|
|
179
179
|
- LICENSE.txt
|
180
180
|
- README.md
|
181
181
|
- Rakefile
|
182
|
+
- lib/wavefront-sdk/account.rb
|
182
183
|
- lib/wavefront-sdk/alert.rb
|
183
184
|
- lib/wavefront-sdk/api_mixins/acl.rb
|
184
185
|
- lib/wavefront-sdk/api_mixins/tag.rb
|
@@ -198,6 +199,7 @@ files:
|
|
198
199
|
- lib/wavefront-sdk/distribution.rb
|
199
200
|
- lib/wavefront-sdk/event.rb
|
200
201
|
- lib/wavefront-sdk/externallink.rb
|
202
|
+
- lib/wavefront-sdk/ingestionpolicy.rb
|
201
203
|
- lib/wavefront-sdk/integration.rb
|
202
204
|
- lib/wavefront-sdk/maintenancewindow.rb
|
203
205
|
- lib/wavefront-sdk/message.rb
|
@@ -223,6 +225,7 @@ files:
|
|
223
225
|
- lib/wavefront-sdk/support/mixins.rb
|
224
226
|
- lib/wavefront-sdk/support/parse_time.rb
|
225
227
|
- lib/wavefront-sdk/types/status.rb
|
228
|
+
- lib/wavefront-sdk/usage.rb
|
226
229
|
- lib/wavefront-sdk/user.rb
|
227
230
|
- lib/wavefront-sdk/usergroup.rb
|
228
231
|
- lib/wavefront-sdk/validators.rb
|
@@ -246,6 +249,7 @@ files:
|
|
246
249
|
- spec/test_mixins/general.rb
|
247
250
|
- spec/test_mixins/tag.rb
|
248
251
|
- spec/test_mixins/update_keys.rb
|
252
|
+
- spec/wavefront-sdk/account_spec.rb
|
249
253
|
- spec/wavefront-sdk/alert_spec.rb
|
250
254
|
- spec/wavefront-sdk/api_mixins/user_mixins_spec.rb
|
251
255
|
- spec/wavefront-sdk/apitoken_spec.rb
|
@@ -260,6 +264,7 @@ files:
|
|
260
264
|
- spec/wavefront-sdk/distribution_spec.rb
|
261
265
|
- spec/wavefront-sdk/event_spec.rb
|
262
266
|
- spec/wavefront-sdk/externallink_spec.rb
|
267
|
+
- spec/wavefront-sdk/ingestionpolicy_spec.rb
|
263
268
|
- spec/wavefront-sdk/integration_spec.rb
|
264
269
|
- spec/wavefront-sdk/maintenancewindow_spec.rb
|
265
270
|
- spec/wavefront-sdk/message_spec.rb
|
@@ -291,6 +296,7 @@ files:
|
|
291
296
|
- spec/wavefront-sdk/stdlib/string_spec.rb
|
292
297
|
- spec/wavefront-sdk/support/mixins_spec.rb
|
293
298
|
- spec/wavefront-sdk/support/parse_time_spec.rb
|
299
|
+
- spec/wavefront-sdk/usage_spec.rb
|
294
300
|
- spec/wavefront-sdk/user_spec.rb
|
295
301
|
- spec/wavefront-sdk/usergroup_spec.rb
|
296
302
|
- spec/wavefront-sdk/validators_spec.rb
|
@@ -338,6 +344,7 @@ test_files:
|
|
338
344
|
- spec/test_mixins/general.rb
|
339
345
|
- spec/test_mixins/tag.rb
|
340
346
|
- spec/test_mixins/update_keys.rb
|
347
|
+
- spec/wavefront-sdk/account_spec.rb
|
341
348
|
- spec/wavefront-sdk/alert_spec.rb
|
342
349
|
- spec/wavefront-sdk/api_mixins/user_mixins_spec.rb
|
343
350
|
- spec/wavefront-sdk/apitoken_spec.rb
|
@@ -352,6 +359,7 @@ test_files:
|
|
352
359
|
- spec/wavefront-sdk/distribution_spec.rb
|
353
360
|
- spec/wavefront-sdk/event_spec.rb
|
354
361
|
- spec/wavefront-sdk/externallink_spec.rb
|
362
|
+
- spec/wavefront-sdk/ingestionpolicy_spec.rb
|
355
363
|
- spec/wavefront-sdk/integration_spec.rb
|
356
364
|
- spec/wavefront-sdk/maintenancewindow_spec.rb
|
357
365
|
- spec/wavefront-sdk/message_spec.rb
|
@@ -383,6 +391,7 @@ test_files:
|
|
383
391
|
- spec/wavefront-sdk/stdlib/string_spec.rb
|
384
392
|
- spec/wavefront-sdk/support/mixins_spec.rb
|
385
393
|
- spec/wavefront-sdk/support/parse_time_spec.rb
|
394
|
+
- spec/wavefront-sdk/usage_spec.rb
|
386
395
|
- spec/wavefront-sdk/user_spec.rb
|
387
396
|
- spec/wavefront-sdk/usergroup_spec.rb
|
388
397
|
- spec/wavefront-sdk/validators_spec.rb
|