warrant 1.2.0 → 2.0.0.rc3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile +4 -0
- data/lib/warrant/api_operations.rb +9 -3
- data/lib/warrant/errors.rb +2 -0
- data/lib/warrant/models/feature.rb +327 -0
- data/lib/warrant/models/permission.rb +140 -41
- data/lib/warrant/models/pricing_tier.rb +328 -0
- data/lib/warrant/models/role.rb +128 -37
- data/lib/warrant/models/session.rb +4 -5
- data/lib/warrant/models/tenant.rb +176 -35
- data/lib/warrant/models/user.rb +225 -98
- data/lib/warrant/models/warrant.rb +208 -61
- data/lib/warrant/util.rb +20 -19
- data/lib/warrant/version.rb +1 -1
- data/lib/warrant/warrant_configuration.rb +3 -3
- data/lib/warrant/warrant_object.rb +13 -0
- data/lib/warrant.rb +5 -1
- metadata +8 -5
@@ -2,8 +2,10 @@
|
|
2
2
|
|
3
3
|
module Warrant
|
4
4
|
class Tenant
|
5
|
+
include Warrant::WarrantObject
|
6
|
+
|
5
7
|
attr_reader :tenant_id, :name, :created_at
|
6
|
-
|
8
|
+
|
7
9
|
# @!visibility private
|
8
10
|
def initialize(tenant_id, name, created_at)
|
9
11
|
@tenant_id = tenant_id
|
@@ -20,15 +22,13 @@ module Warrant
|
|
20
22
|
#
|
21
23
|
# @example Create a new Tenant with the tenant id "test-customer"
|
22
24
|
# Warrant::Tenant.create(tenant_id: "test-customer")
|
23
|
-
#
|
25
|
+
#
|
24
26
|
# @raise [Warrant::DuplicateRecordError]
|
25
27
|
# @raise [Warrant::InternalError]
|
26
28
|
# @raise [Warrant::InvalidParameterError]
|
27
29
|
# @raise [Warrant::InvalidRequestError]
|
28
|
-
# @raise [Warrant::MissingRequiredParameterError]
|
29
30
|
# @raise [Warrant::NotFoundError]
|
30
31
|
# @raise [Warrant::UnauthorizedError]
|
31
|
-
# @raise [Warrant::WarrantError]
|
32
32
|
def self.create(params = {})
|
33
33
|
res = APIOperations.post(URI.parse("#{::Warrant.config.api_base}/v1/tenants"), Util.normalize_params(params))
|
34
34
|
|
@@ -41,6 +41,35 @@ module Warrant
|
|
41
41
|
end
|
42
42
|
end
|
43
43
|
|
44
|
+
# Batch creates multiple tenants with given parameters
|
45
|
+
#
|
46
|
+
# @param [Array] Array of tenants to create.
|
47
|
+
# * tenant_id User defined string identifier for this tenant. If not provided, Warrant will create an id for the tenant and return it. In this case, you should store the id in your system for future reference. Note that tenantIds in Warrant must be composed of alphanumeric chars and/or '-', '_', and '@'. (optional)
|
48
|
+
# * name A displayable name for this tenant. (optional)
|
49
|
+
#
|
50
|
+
# @return [Array<Tenant>] all created tenants
|
51
|
+
#
|
52
|
+
# @example Create two new tenants with tenant ids "test-tenant-1" and "test-tenant-2"
|
53
|
+
# Warrant::Tenant.batch_create([{ tenant_id: "test-tenant-1" }, { tenant_id: "test-tenant-2" }])
|
54
|
+
#
|
55
|
+
# @raise [Warrant::DuplicateRecordError]
|
56
|
+
# @raise [Warrant::InternalError]
|
57
|
+
# @raise [Warrant::InvalidParameterError]
|
58
|
+
# @raise [Warrant::InvalidRequestError]
|
59
|
+
# @raise [Warrant::NotFoundError]
|
60
|
+
# @raise [Warrant::UnauthorizedError]
|
61
|
+
def self.batch_create(tenants = [])
|
62
|
+
res = APIOperations.post(URI.parse("#{::Warrant.config.api_base}/v1/tenants"), Util.normalize_params(tenants))
|
63
|
+
|
64
|
+
case res
|
65
|
+
when Net::HTTPSuccess
|
66
|
+
tenants = JSON.parse(res.body)
|
67
|
+
tenants.map{ |tenant| Tenant.new(tenant['tenantId'], tenant['name'], tenant['createdAt']) }
|
68
|
+
else
|
69
|
+
APIOperations.raise_error(res)
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
44
73
|
# Deletes a tenant with given tenant id
|
45
74
|
#
|
46
75
|
# @param tenant_id [String] User defined string identifier for this tenant. If not provided, Warrant will create an id for the tenant and return it. In this case, you should store the id in your system for future reference. Note that tenantIds in Warrant must be composed of alphanumeric chars and/or '-', '_', and '@'.
|
@@ -51,10 +80,8 @@ module Warrant
|
|
51
80
|
# Warrant::Tenant.delete("test-customer")
|
52
81
|
#
|
53
82
|
# @raise [Warrant::InternalError]
|
54
|
-
# @raise [Warrant::InvalidRequestError]
|
55
83
|
# @raise [Warrant::NotFoundError]
|
56
84
|
# @raise [Warrant::UnauthorizedError]
|
57
|
-
# @raise [Warrant::WarrantError]
|
58
85
|
def self.delete(tenant_id)
|
59
86
|
res = APIOperations.delete(URI.parse("#{::Warrant.config.api_base}/v1/tenants/#{tenant_id}"))
|
60
87
|
|
@@ -68,18 +95,19 @@ module Warrant
|
|
68
95
|
|
69
96
|
# Lists all tenants for your organization
|
70
97
|
#
|
98
|
+
# @option filters [Integer] :page A positive integer (starting with 1) representing the page of items to return in response. Used in conjunction with the limit param. (optional)
|
99
|
+
# @option filters [Integer] :limit A positive integer representing the max number of items to return in response. (optional)
|
100
|
+
#
|
71
101
|
# @return [Array<Tenant>] all tenants for your organization
|
72
102
|
#
|
73
103
|
# @example List all tenants
|
74
104
|
# Warrant::Tenant.list()
|
75
105
|
#
|
76
106
|
# @raise [Warrant::InternalError]
|
77
|
-
# @raise [Warrant::
|
78
|
-
# @raise [Warrant::NotFoundError]
|
107
|
+
# @raise [Warrant::InvalidParameterError]
|
79
108
|
# @raise [Warrant::UnauthorizedError]
|
80
|
-
# @raise [Warrant::WarrantError]
|
81
109
|
def self.list(filters = {})
|
82
|
-
res = APIOperations.get(URI.parse("#{::Warrant.config.api_base}/v1/tenants"))
|
110
|
+
res = APIOperations.get(URI.parse("#{::Warrant.config.api_base}/v1/tenants"), Util.normalize_params(filters))
|
83
111
|
|
84
112
|
case res
|
85
113
|
when Net::HTTPSuccess
|
@@ -87,7 +115,7 @@ module Warrant
|
|
87
115
|
tenants.map{ |tenant| Tenant.new(tenant['tenantId'], tenant['name'], tenant['createdAt']) }
|
88
116
|
else
|
89
117
|
APIOperations.raise_error(res)
|
90
|
-
end
|
118
|
+
end
|
91
119
|
end
|
92
120
|
|
93
121
|
# Get a tenant with the given tenant_id
|
@@ -95,13 +123,11 @@ module Warrant
|
|
95
123
|
# @param tenant_id [String] User defined string identifier for this tenant. If not provided, Warrant will create an id for the tenant and return it. In this case, you should store the id in your system for future reference. Note that tenantIds in Warrant must be composed of alphanumeric chars and/or '-', '_', and '@'.
|
96
124
|
#
|
97
125
|
# @return [Tenant] retrieved tenant
|
98
|
-
#
|
126
|
+
#
|
99
127
|
# @raise [Warrant::InternalError]
|
100
128
|
# @raise [Warrant::InvalidParameterError]
|
101
|
-
# @raise [Warrant::InvalidRequestError]
|
102
129
|
# @raise [Warrant::NotFoundError]
|
103
130
|
# @raise [Warrant::UnauthorizedError]
|
104
|
-
# @raise [Warrant::WarrantError]
|
105
131
|
def self.get(tenant_id)
|
106
132
|
res = APIOperations.get(URI.parse("#{::Warrant.config.api_base}/v1/tenants/#{tenant_id}"))
|
107
133
|
|
@@ -111,7 +137,7 @@ module Warrant
|
|
111
137
|
Tenant.new(tenant['tenantId'], tenant['name'], tenant['createdAt'])
|
112
138
|
else
|
113
139
|
APIOperations.raise_error(res)
|
114
|
-
end
|
140
|
+
end
|
115
141
|
end
|
116
142
|
|
117
143
|
# Updates a tenant with the given tenant_id and params
|
@@ -124,14 +150,12 @@ module Warrant
|
|
124
150
|
#
|
125
151
|
# @example Update tenant "test-tenant"'s name
|
126
152
|
# Warrant::Tenant.update("test-tenant", { name: "my-new-name@example.com" })
|
127
|
-
#
|
128
|
-
# @raise [Warrant::DuplicateRecordError]
|
153
|
+
#
|
129
154
|
# @raise [Warrant::InternalError]
|
130
155
|
# @raise [Warrant::InvalidParameterError]
|
131
156
|
# @raise [Warrant::InvalidRequestError]
|
132
157
|
# @raise [Warrant::NotFoundError]
|
133
158
|
# @raise [Warrant::UnauthorizedError]
|
134
|
-
# @raise [Warrant::WarrantError]
|
135
159
|
def self.update(tenant_id, params = {})
|
136
160
|
res = APIOperations.put(URI.parse("#{::Warrant.config.api_base}/v1/tenants/#{tenant_id}"), Util.normalize_params(params))
|
137
161
|
|
@@ -153,14 +177,11 @@ module Warrant
|
|
153
177
|
# @example Update tenant "test-tenant"'s name
|
154
178
|
# tenant = Warrant::Tenant.get("test-tenant")
|
155
179
|
# tenant.update(name: "my-new-name@example.com")
|
156
|
-
#
|
157
|
-
# @raise [Warrant::DuplicateRecordError]
|
180
|
+
#
|
158
181
|
# @raise [Warrant::InternalError]
|
159
182
|
# @raise [Warrant::InvalidParameterError]
|
160
|
-
# @raise [Warrant::InvalidRequestError]
|
161
183
|
# @raise [Warrant::NotFoundError]
|
162
184
|
# @raise [Warrant::UnauthorizedError]
|
163
|
-
# @raise [Warrant::WarrantError]
|
164
185
|
def update(params = {})
|
165
186
|
return Tenant.update(tenant_id, params)
|
166
187
|
end
|
@@ -171,14 +192,13 @@ module Warrant
|
|
171
192
|
#
|
172
193
|
# @return [Warrant] warrant assigning user to the tenant
|
173
194
|
#
|
195
|
+
# @raise [Warrant::DuplicateRecordError]
|
174
196
|
# @raise [Warrant::InternalError]
|
175
197
|
# @raise [Warrant::InvalidParameterError]
|
176
|
-
# @raise [Warrant::InvalidRequestError]
|
177
198
|
# @raise [Warrant::NotFoundError]
|
178
199
|
# @raise [Warrant::UnauthorizedError]
|
179
|
-
|
180
|
-
|
181
|
-
return User.add_to_tenant(tenant_id, user_id)
|
200
|
+
def assign_user(user_id)
|
201
|
+
return User.assign_to_tenant(tenant_id, user_id)
|
182
202
|
end
|
183
203
|
|
184
204
|
# Remove a user from a tenant
|
@@ -188,8 +208,6 @@ module Warrant
|
|
188
208
|
# @return [nil] if remove was successful
|
189
209
|
#
|
190
210
|
# @raise [Warrant::InternalError]
|
191
|
-
# @raise [Warrant::InvalidParameterError]
|
192
|
-
# @raise [Warrant::InvalidRequestError]
|
193
211
|
# @raise [Warrant::NotFoundError]
|
194
212
|
# @raise [Warrant::UnauthorizedError]
|
195
213
|
# @raise [Warrant::WarrantError]
|
@@ -197,18 +215,19 @@ module Warrant
|
|
197
215
|
return User.remove_from_tenant(tenant_id, user_id)
|
198
216
|
end
|
199
217
|
|
200
|
-
# List all tenants for a user
|
218
|
+
# List all tenants for a user
|
201
219
|
#
|
202
220
|
# @param user_id [String] The user_id of the user from which to fetch tenants
|
221
|
+
# @option filters [Integer] :page A positive integer (starting with 1) representing the page of items to return in response. Used in conjunction with the limit param. (optional)
|
222
|
+
# @option filters [Integer] :limit A positive integer representing the max number of items to return in response. (optional)
|
203
223
|
#
|
204
224
|
# @return [Array<Tenant>] all tenants for the user
|
205
225
|
#
|
206
226
|
# @raise [Warrant::InternalError]
|
207
|
-
# @raise [Warrant::
|
227
|
+
# @raise [Warrant::InvalidParameterError]
|
208
228
|
# @raise [Warrant::UnauthorizedError]
|
209
|
-
|
210
|
-
|
211
|
-
res = APIOperations.get(URI.parse("#{::Warrant.config.api_base}/v1/users/#{user_id}/tenants"))
|
229
|
+
def self.list_for_user(user_id, filters = {})
|
230
|
+
res = APIOperations.get(URI.parse("#{::Warrant.config.api_base}/v1/users/#{user_id}/tenants"), Util.normalize_params(filters))
|
212
231
|
|
213
232
|
case res
|
214
233
|
when Net::HTTPSuccess
|
@@ -216,10 +235,10 @@ module Warrant
|
|
216
235
|
tenants.map{ |tenant| Tenant.new(tenant['tenantId'], tenant['name'], tenant['createdAt']) }
|
217
236
|
else
|
218
237
|
APIOperations.raise_error(res)
|
219
|
-
end
|
238
|
+
end
|
220
239
|
end
|
221
240
|
|
222
|
-
# List all users for a tenant
|
241
|
+
# List all users for a tenant
|
223
242
|
#
|
224
243
|
# @return [Array<User>] all users for the tenant
|
225
244
|
#
|
@@ -230,5 +249,127 @@ module Warrant
|
|
230
249
|
def list_users
|
231
250
|
return User.list_for_tenant(tenant_id)
|
232
251
|
end
|
252
|
+
|
253
|
+
# List pricing tiers for a tenant
|
254
|
+
#
|
255
|
+
# @option filters [Integer] :page A positive integer (starting with 1) representing the page of items to return in response. Used in conjunction with the limit param. (optional)
|
256
|
+
# @option filters [Integer] :limit A positive integer representing the max number of items to return in response. (optional)
|
257
|
+
#
|
258
|
+
# @return [Array<Feature>] assigned pricing tiers for the tenant
|
259
|
+
#
|
260
|
+
# @raise [Warrant::InternalError]
|
261
|
+
# @raise [Warrant::InvalidParameterError]
|
262
|
+
# @raise [Warrant::UnauthorizedError]
|
263
|
+
def list_pricing_tiers(filters = {})
|
264
|
+
return PricingTier.list_for_tenant(tenant_id, filters)
|
265
|
+
end
|
266
|
+
|
267
|
+
# Assign a pricing tier to a tenant
|
268
|
+
#
|
269
|
+
# @param pricing_tier_id [String] The pricing_tier_id of the pricing tier you want to assign to the tenant.
|
270
|
+
#
|
271
|
+
# @return [PricingTier] assigned pricing tier
|
272
|
+
#
|
273
|
+
# @raise [Warrant::DuplicateRecordError]
|
274
|
+
# @raise [Warrant::InternalError]
|
275
|
+
# @raise [Warrant::InvalidParameterError]
|
276
|
+
# @raise [Warrant::NotFoundError]
|
277
|
+
# @raise [Warrant::UnauthorizedError]
|
278
|
+
def assign_pricing_tier(pricing_tier_id)
|
279
|
+
return PricingTier.assign_to_tenant(tenant_id, pricing_tier_id)
|
280
|
+
end
|
281
|
+
|
282
|
+
# Remove a pricing_tier from a tenant
|
283
|
+
#
|
284
|
+
# @param pricing_tier_id [String] The pricing_tier_id of the pricing_tier you want to remove from the tenant.
|
285
|
+
#
|
286
|
+
# @return [nil] if remove was successful
|
287
|
+
#
|
288
|
+
# @raise [Warrant::InternalError]
|
289
|
+
# @raise [Warrant::InvalidParameterError]
|
290
|
+
# @raise [Warrant::NotFoundError]
|
291
|
+
# @raise [Warrant::UnauthorizedError]
|
292
|
+
# @raise [Warrant::WarrantError]
|
293
|
+
def remove_pricing_tier(pricing_tier_id)
|
294
|
+
return PricingTier.remove_from_tenant(tenant_id, pricing_tier_id)
|
295
|
+
end
|
296
|
+
|
297
|
+
# List features for a tenant
|
298
|
+
#
|
299
|
+
# @option filters [Integer] :page A positive integer (starting with 1) representing the page of items to return in response. Used in conjunction with the limit param. (optional)
|
300
|
+
# @option filters [Integer] :limit A positive integer representing the max number of items to return in response. (optional)
|
301
|
+
#
|
302
|
+
# @return [Array<Feature>] assigned features for the tenant
|
303
|
+
#
|
304
|
+
# @raise [Warrant::InternalError]
|
305
|
+
# @raise [Warrant::InvalidParameterError]
|
306
|
+
# @raise [Warrant::UnauthorizedError]
|
307
|
+
def list_features(filters = {})
|
308
|
+
return Feature.list_for_tenant(tenant_id, filters)
|
309
|
+
end
|
310
|
+
|
311
|
+
# Assign a feature to a tenant
|
312
|
+
#
|
313
|
+
# @param feature_id [String] The feature_id of the feature you want to assign to the tenant.
|
314
|
+
#
|
315
|
+
# @return [Feature] assigned feature
|
316
|
+
#
|
317
|
+
# @raise [Warrant::DuplicateRecordError]
|
318
|
+
# @raise [Warrant::InternalError]
|
319
|
+
# @raise [Warrant::InvalidParameterError]
|
320
|
+
# @raise [Warrant::NotFoundError]
|
321
|
+
# @raise [Warrant::UnauthorizedError]
|
322
|
+
def assign_feature(feature_id)
|
323
|
+
return Feature.assign_to_tenant(tenant_id, feature_id)
|
324
|
+
end
|
325
|
+
|
326
|
+
# Remove a feature from a tenant
|
327
|
+
#
|
328
|
+
# @param feature_id [String] The feature_id of the feature you want to remove from the tenant.
|
329
|
+
#
|
330
|
+
# @return [nil] if remove was successful
|
331
|
+
#
|
332
|
+
# @raise [Warrant::InternalError]
|
333
|
+
# @raise [Warrant::InvalidParameterError]
|
334
|
+
# @raise [Warrant::NotFoundError]
|
335
|
+
# @raise [Warrant::UnauthorizedError]
|
336
|
+
# @raise [Warrant::WarrantError]
|
337
|
+
def remove_feature(feature_id)
|
338
|
+
return Feature.remove_from_tenant(tenant_id, feature_id)
|
339
|
+
end
|
340
|
+
|
341
|
+
# Check whether a tenant has a given feature
|
342
|
+
#
|
343
|
+
# @param feature_id [String] The feature_id of the feature to check whether the tenant has access to.
|
344
|
+
# @option options [Hash] :context Object containing key-value pairs that specifies the context the warrant should be checked in. (optional)
|
345
|
+
# @option options [Boolean] :consistent_read Boolean flag indicating whether or not to enforce strict consistency for this access check. Defaults to false. (optional)
|
346
|
+
# @option options [Boolean] :debug Boolean flag indicating whether or not to return debug information for this access check. Defaults to false. (optional)
|
347
|
+
#
|
348
|
+
# @ return [Boolean] whether or not the tenant has the given feature
|
349
|
+
#
|
350
|
+
# @raise [Warrant::InternalError]
|
351
|
+
# @raise [Warrant::InvalidParameterError]
|
352
|
+
# @raise [Warrant::NotFoundError]
|
353
|
+
# @raise [Warrant::UnauthorizedError]
|
354
|
+
def has_feature?(feature_id, opts = {})
|
355
|
+
return Warrant.has_feature?(
|
356
|
+
feature_id: feature_id,
|
357
|
+
subject: {
|
358
|
+
object_type: "tenant",
|
359
|
+
object_id: tenant_id
|
360
|
+
},
|
361
|
+
context: opts[:context],
|
362
|
+
consistent_read: opts[:consistent_read],
|
363
|
+
debug: opts[:debug]
|
364
|
+
)
|
365
|
+
end
|
366
|
+
|
367
|
+
def warrant_object_type
|
368
|
+
"tenant"
|
369
|
+
end
|
370
|
+
|
371
|
+
def warrant_object_id
|
372
|
+
tenant_id
|
373
|
+
end
|
233
374
|
end
|
234
375
|
end
|