warrant 3.1.0 → 5.0.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/README.md +0 -7
- data/lib/warrant/api_operations.rb +9 -7
- data/lib/warrant/models/feature.rb +122 -93
- data/lib/warrant/models/list_response.rb +14 -0
- data/lib/warrant/models/object.rb +230 -0
- data/lib/warrant/models/permission.rb +72 -97
- data/lib/warrant/models/pricing_tier.rb +128 -93
- data/lib/warrant/models/query_result.rb +16 -0
- data/lib/warrant/models/role.rb +72 -91
- data/lib/warrant/models/session.rb +4 -4
- data/lib/warrant/models/tenant.rb +131 -123
- data/lib/warrant/models/user.rb +180 -147
- data/lib/warrant/models/warrant.rb +201 -110
- data/lib/warrant/util.rb +6 -0
- data/lib/warrant/version.rb +1 -1
- data/lib/warrant.rb +3 -0
- metadata +5 -2
@@ -1,24 +1,22 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
module Warrant
|
4
|
-
class Tenant
|
4
|
+
class Tenant < Warrant::Object
|
5
5
|
OBJECT_TYPE = "tenant"
|
6
6
|
|
7
7
|
include Warrant::WarrantObject
|
8
8
|
|
9
|
-
|
9
|
+
alias :tenant_id :object_id
|
10
10
|
|
11
11
|
# @!visibility private
|
12
|
-
def initialize(tenant_id,
|
13
|
-
|
14
|
-
@name = name
|
15
|
-
@created_at = created_at
|
12
|
+
def initialize(tenant_id, meta = {}, created_at = nil)
|
13
|
+
super(OBJECT_TYPE, tenant_id, meta, created_at)
|
16
14
|
end
|
17
15
|
|
18
16
|
# Creates a tenant with the given parameters
|
19
17
|
#
|
20
18
|
# @option params [String] :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)
|
21
|
-
# @option params [
|
19
|
+
# @option params [Hash] :meta A JSON object containing additional information about this tenant (e.g. name/description, etc.) to be persisted to Warrant. (optional)
|
22
20
|
#
|
23
21
|
# @return [Tenant] created tenant
|
24
22
|
#
|
@@ -31,23 +29,16 @@ module Warrant
|
|
31
29
|
# @raise [Warrant::InvalidRequestError]
|
32
30
|
# @raise [Warrant::NotFoundError]
|
33
31
|
# @raise [Warrant::UnauthorizedError]
|
34
|
-
def self.create(params = {})
|
35
|
-
|
36
|
-
|
37
|
-
case res
|
38
|
-
when Net::HTTPSuccess
|
39
|
-
res_json = JSON.parse(res.body)
|
40
|
-
Tenant.new(res_json['tenantId'], res_json['name'], res_json['createdAt'])
|
41
|
-
else
|
42
|
-
APIOperations.raise_error(res)
|
43
|
-
end
|
32
|
+
def self.create(params = {}, options = {})
|
33
|
+
object = Object.create({ object_type: OBJECT_TYPE, object_id: params[:tenant_id], meta: params[:meta] }, options)
|
34
|
+
return Tenant.new(object.object_id, object.meta, object.created_at)
|
44
35
|
end
|
45
36
|
|
46
37
|
# Batch creates multiple tenants with given parameters
|
47
38
|
#
|
48
|
-
# @param [Array] Array of tenants to create.
|
49
|
-
#
|
50
|
-
#
|
39
|
+
# @param [Array<Hash>] tenants Array of tenants to create.
|
40
|
+
# @option tenants [String] :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)
|
41
|
+
# @option tenants [Hash] :meta A JSON object containing additional information about the tenant (e.g. name/description, etc.) to be persisted to Warrant. (optional)
|
51
42
|
#
|
52
43
|
# @return [Array<Tenant>] all created tenants
|
53
44
|
#
|
@@ -60,21 +51,14 @@ module Warrant
|
|
60
51
|
# @raise [Warrant::InvalidRequestError]
|
61
52
|
# @raise [Warrant::NotFoundError]
|
62
53
|
# @raise [Warrant::UnauthorizedError]
|
63
|
-
def self.batch_create(tenants =
|
64
|
-
res =
|
65
|
-
|
66
|
-
case res
|
67
|
-
when Net::HTTPSuccess
|
68
|
-
tenants = JSON.parse(res.body)
|
69
|
-
tenants.map{ |tenant| Tenant.new(tenant['tenantId'], tenant['name'], tenant['createdAt']) }
|
70
|
-
else
|
71
|
-
APIOperations.raise_error(res)
|
72
|
-
end
|
54
|
+
def self.batch_create(tenants, options = {})
|
55
|
+
res = Object.batch_create(tenants.map{ |tenant| { object_type: OBJECT_TYPE, object_id: tenant[:tenant_id], meta: tenant[:meta] }}, options)
|
56
|
+
return res.map{ |obj| Tenant.new(obj.object_id, obj.meta, obj.created_at)}
|
73
57
|
end
|
74
58
|
|
75
59
|
# Deletes a tenant with given tenant id
|
76
60
|
#
|
77
|
-
# @param tenant_id [String] User defined string identifier for this tenant.
|
61
|
+
# @param tenant_id [String] User defined string identifier for this tenant.
|
78
62
|
#
|
79
63
|
# @return [nil] if delete was successful
|
80
64
|
#
|
@@ -84,21 +68,44 @@ module Warrant
|
|
84
68
|
# @raise [Warrant::InternalError]
|
85
69
|
# @raise [Warrant::NotFoundError]
|
86
70
|
# @raise [Warrant::UnauthorizedError]
|
87
|
-
def self.delete(tenant_id)
|
88
|
-
|
71
|
+
def self.delete(tenant_id, options = {})
|
72
|
+
return Object.delete(OBJECT_TYPE, tenant_id, options)
|
73
|
+
end
|
89
74
|
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
75
|
+
# Batch deletes multiple tenants with given parameters
|
76
|
+
#
|
77
|
+
# @param [Array<Hash, Tenant>] tenants Array of tenants to delete.
|
78
|
+
# @option tenants [String] :tenant_id Customer defined string identifier for this tenant.
|
79
|
+
#
|
80
|
+
# @return [nil] if delete was successful
|
81
|
+
#
|
82
|
+
# @example Delete two tenants with ids "test-tenant-1" and "test-tenant-2"
|
83
|
+
# Warrant::Tenant.batch_delete([{ tenant_id: "test-tenant-1" }, { tenant_id: "test-tenant-2" }])
|
84
|
+
#
|
85
|
+
# @raise [Warrant::InternalError]
|
86
|
+
# @raise [Warrant::InvalidParameterError]
|
87
|
+
# @raise [Warrant::NotFoundError]
|
88
|
+
# @raise [Warrant::UnauthorizedError]
|
89
|
+
def self.batch_delete(tenants, options = {})
|
90
|
+
return Object.batch_delete(tenants.map{ |tenant|
|
91
|
+
if tenant.instance_of? Tenant
|
92
|
+
{ object_type: OBJECT_TYPE, object_id: tenant.object_id }
|
93
|
+
else
|
94
|
+
{ object_type: OBJECT_TYPE, object_id: tenant[:tenant_id] }
|
95
|
+
end
|
96
|
+
}, options)
|
96
97
|
end
|
97
98
|
|
98
99
|
# Lists all tenants for your organization
|
99
100
|
#
|
100
|
-
# @
|
101
|
-
# @
|
101
|
+
# @param [Hash] filters Filters to apply to result set
|
102
|
+
# @param [Hash] options Options to apply on a per-request basis
|
103
|
+
# @option filters [Integer] :limit A positive integer representing the maximum number of items to return in the response. Must be less than or equal to 1000. Defaults to 25. (optional)
|
104
|
+
# @option filters [String] :prev_cursor A cursor representing your place in a list of results. Requests containing prev_cursor will return the results immediately preceding the cursor. (optional)
|
105
|
+
# @option filters [String] :next_cursor A cursor representing your place in a list of results. Requests containing next_cursor will return the results immediately following the cursor. (optional)
|
106
|
+
# @option filters [String] :sort_by The column to sort the result by. Unless otherwise specified, all list endpoints are sorted by their unique identifier by default. Supported values for objects are +object_type+, +object_id+, and +created_at+ (optional)
|
107
|
+
# @option filters [String] :sort_order The order in which to sort the result by. Valid values are +ASC+ and +DESC+. Defaults to +ASC+. (optional)
|
108
|
+
# @option options [String] :warrant_token A valid warrant token from a previous write operation or latest. Used to specify desired consistency for this read operation. (optional)
|
102
109
|
#
|
103
110
|
# @return [Array<Tenant>] all tenants for your organization
|
104
111
|
#
|
@@ -108,16 +115,11 @@ module Warrant
|
|
108
115
|
# @raise [Warrant::InternalError]
|
109
116
|
# @raise [Warrant::InvalidParameterError]
|
110
117
|
# @raise [Warrant::UnauthorizedError]
|
111
|
-
def self.list(filters = {})
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
tenants = JSON.parse(res.body)
|
117
|
-
tenants.map{ |tenant| Tenant.new(tenant['tenantId'], tenant['name'], tenant['createdAt']) }
|
118
|
-
else
|
119
|
-
APIOperations.raise_error(res)
|
120
|
-
end
|
118
|
+
def self.list(filters = {}, options = {})
|
119
|
+
filters.merge({ object_type: "tenant" })
|
120
|
+
list_response = Object.list(filters, options)
|
121
|
+
tenants = list_response.results.map{ |object| Tenant.new(object.object_id, object.meta, object.created_at)}
|
122
|
+
return ListResponse.new(tenants, list_response.prev_cursor, list_response.next_cursor)
|
121
123
|
end
|
122
124
|
|
123
125
|
# Get a tenant with the given tenant_id
|
@@ -130,67 +132,53 @@ module Warrant
|
|
130
132
|
# @raise [Warrant::InvalidParameterError]
|
131
133
|
# @raise [Warrant::NotFoundError]
|
132
134
|
# @raise [Warrant::UnauthorizedError]
|
133
|
-
def self.get(tenant_id)
|
134
|
-
|
135
|
-
|
136
|
-
case res
|
137
|
-
when Net::HTTPSuccess
|
138
|
-
tenant = JSON.parse(res.body)
|
139
|
-
Tenant.new(tenant['tenantId'], tenant['name'], tenant['createdAt'])
|
140
|
-
else
|
141
|
-
APIOperations.raise_error(res)
|
142
|
-
end
|
135
|
+
def self.get(tenant_id, options = {})
|
136
|
+
object = Object.get(OBJECT_TYPE, tenant_id, options)
|
137
|
+
return Tenant.new(object.object_id, object.meta, object.created_at)
|
143
138
|
end
|
144
139
|
|
145
|
-
# Updates a tenant with the given tenant_id
|
140
|
+
# Updates a tenant with the given tenant_id
|
146
141
|
#
|
147
|
-
# @param tenant_id [String] User defined string identifier for this tenant.
|
148
|
-
# @param [Hash]
|
149
|
-
# @option params [String] :name A displayable name for this tenant. (optional)
|
142
|
+
# @param tenant_id [String] User defined string identifier for this tenant.
|
143
|
+
# @param meta [Hash] A JSON object containing additional information about this tenant (e.g. name/description, etc.) to be persisted to Warrant.
|
150
144
|
#
|
151
145
|
# @return [Tenant] updated tenant
|
152
146
|
#
|
153
|
-
# @example Update tenant "test-tenant"'s
|
154
|
-
# Warrant::Tenant.update("test-tenant", {
|
147
|
+
# @example Update tenant "test-tenant"'s email
|
148
|
+
# Warrant::Tenant.update("test-tenant", { email: "my-new-email@example.com" })
|
155
149
|
#
|
156
150
|
# @raise [Warrant::InternalError]
|
157
151
|
# @raise [Warrant::InvalidParameterError]
|
158
152
|
# @raise [Warrant::InvalidRequestError]
|
159
153
|
# @raise [Warrant::NotFoundError]
|
160
154
|
# @raise [Warrant::UnauthorizedError]
|
161
|
-
def self.update(tenant_id,
|
162
|
-
|
163
|
-
|
164
|
-
case res
|
165
|
-
when Net::HTTPSuccess
|
166
|
-
res_json = JSON.parse(res.body)
|
167
|
-
Tenant.new(res_json['tenantId'], res_json['name'], res_json['createdAt'])
|
168
|
-
else
|
169
|
-
APIOperations.raise_error(res)
|
170
|
-
end
|
155
|
+
def self.update(tenant_id, meta, options = {})
|
156
|
+
object = Object.update(OBJECT_TYPE, tenant_id, meta, options)
|
157
|
+
return Tenant.new(object.object_id, object.meta, object.created_at)
|
171
158
|
end
|
172
159
|
|
173
160
|
# Updates the tenant with the given params
|
174
161
|
#
|
175
|
-
# @
|
162
|
+
# @param meta [Hash] A JSON object containing additional information about this tenant (e.g. name/description, etc.) to be persisted to Warrant.
|
176
163
|
#
|
177
164
|
# @return [Tenant] updated tenant
|
178
165
|
#
|
179
166
|
# @example Update tenant "test-tenant"'s name
|
180
167
|
# tenant = Warrant::Tenant.get("test-tenant")
|
181
|
-
# tenant.update(name: "my-new-name@example.com")
|
168
|
+
# tenant.update({ name: "my-new-name@example.com" })
|
182
169
|
#
|
183
170
|
# @raise [Warrant::InternalError]
|
184
171
|
# @raise [Warrant::InvalidParameterError]
|
185
172
|
# @raise [Warrant::NotFoundError]
|
186
173
|
# @raise [Warrant::UnauthorizedError]
|
187
|
-
def update(
|
188
|
-
return Tenant.update(tenant_id,
|
174
|
+
def update(meta, options = {})
|
175
|
+
return Tenant.update(tenant_id, meta, options)
|
189
176
|
end
|
190
177
|
|
191
178
|
# Add a user to a tenant
|
192
179
|
#
|
193
180
|
# @param user_id [String] The user_id of the user you want to add to the tenant.
|
181
|
+
# @param relation [String] The relation for this tenant to user association. The relation must be valid as per the +tenant+ object type definition.
|
194
182
|
#
|
195
183
|
# @return [Warrant] warrant assigning user to the tenant
|
196
184
|
#
|
@@ -199,13 +187,14 @@ module Warrant
|
|
199
187
|
# @raise [Warrant::InvalidParameterError]
|
200
188
|
# @raise [Warrant::NotFoundError]
|
201
189
|
# @raise [Warrant::UnauthorizedError]
|
202
|
-
def assign_user(user_id)
|
203
|
-
return User.assign_to_tenant(tenant_id, user_id)
|
190
|
+
def assign_user(user_id, relation: "member", options: {})
|
191
|
+
return User.assign_to_tenant(tenant_id, user_id, relation: relation, options: options)
|
204
192
|
end
|
205
193
|
|
206
194
|
# Remove a user from a tenant
|
207
195
|
#
|
208
196
|
# @param user_id [String] The user_id of the user you want to remove from the tenant.
|
197
|
+
# @param relation [String] The relation for this tenant to user association. The relation must be valid as per the +tenant+ object type definition.
|
209
198
|
#
|
210
199
|
# @return [nil] if remove was successful
|
211
200
|
#
|
@@ -213,31 +202,32 @@ module Warrant
|
|
213
202
|
# @raise [Warrant::NotFoundError]
|
214
203
|
# @raise [Warrant::UnauthorizedError]
|
215
204
|
# @raise [Warrant::WarrantError]
|
216
|
-
def remove_user(user_id)
|
217
|
-
return User.remove_from_tenant(tenant_id, user_id)
|
205
|
+
def remove_user(user_id, relation: "member", options: {})
|
206
|
+
return User.remove_from_tenant(tenant_id, user_id, relation: relation, options: options)
|
218
207
|
end
|
219
208
|
|
220
209
|
# List all tenants for a user
|
221
210
|
#
|
222
211
|
# @param user_id [String] The user_id of the user from which to fetch tenants
|
223
|
-
# @
|
224
|
-
# @
|
212
|
+
# @param [Hash] filters Filters to apply to result set
|
213
|
+
# @param [Hash] options Options to apply on a per-request basis
|
214
|
+
# @option filters [String] :object_type Only return objects with an `objectType` matching this value
|
215
|
+
# @option filters [Integer] :limit A positive integer representing the maximum number of items to return in the response. Must be less than or equal to 1000. Defaults to 25. (optional)
|
216
|
+
# @option filters [String] :prev_cursor A cursor representing your place in a list of results. Requests containing prev_cursor will return the results immediately preceding the cursor. (optional)
|
217
|
+
# @option filters [String] :next_cursor A cursor representing your place in a list of results. Requests containing next_cursor will return the results immediately following the cursor. (optional)
|
218
|
+
# @option filters [String] :sort_by The column to sort the result by. Unless otherwise specified, all list endpoints are sorted by their unique identifier by default. Supported values for objects are +object_type+, +object_id+, and +created_at+ (optional)
|
219
|
+
# @option filters [String] :sort_order The order in which to sort the result by. Valid values are +ASC+ and +DESC+. Defaults to +ASC+. (optional)
|
220
|
+
# @option options [String] :warrant_token A valid warrant token from a previous write operation or latest. Used to specify desired consistency for this read operation. (optional)
|
225
221
|
#
|
226
222
|
# @return [Array<Tenant>] all tenants for the user
|
227
223
|
#
|
228
224
|
# @raise [Warrant::InternalError]
|
229
225
|
# @raise [Warrant::InvalidParameterError]
|
230
226
|
# @raise [Warrant::UnauthorizedError]
|
231
|
-
def self.list_for_user(user_id, filters = {})
|
232
|
-
|
233
|
-
|
234
|
-
|
235
|
-
when Net::HTTPSuccess
|
236
|
-
tenants = JSON.parse(res.body)
|
237
|
-
tenants.map{ |tenant| Tenant.new(tenant['tenantId'], tenant['name'], tenant['createdAt']) }
|
238
|
-
else
|
239
|
-
APIOperations.raise_error(res)
|
240
|
-
end
|
227
|
+
def self.list_for_user(user_id, filters = {}, options = {})
|
228
|
+
query_response = Warrant.query("select tenant where user:#{user_id} is *", filters: filters, options: options)
|
229
|
+
tenants = query_response.results.map{ |result| Tenant.new(result.object_id, result.meta) }
|
230
|
+
return ListResponse.new(tenants, query_response.prev_cursor, query_response.next_cursor)
|
241
231
|
end
|
242
232
|
|
243
233
|
# List all users for a tenant
|
@@ -248,27 +238,35 @@ module Warrant
|
|
248
238
|
# @raise [Warrant::InvalidRequestError]
|
249
239
|
# @raise [Warrant::UnauthorizedError]
|
250
240
|
# @raise [Warrant::WarrantError]
|
251
|
-
def list_users
|
252
|
-
return User.list_for_tenant(tenant_id)
|
241
|
+
def list_users(filters = {}, options = {})
|
242
|
+
return User.list_for_tenant(tenant_id, filters, options)
|
253
243
|
end
|
254
244
|
|
255
245
|
# List pricing tiers for a tenant
|
256
246
|
#
|
257
|
-
# @
|
258
|
-
# @
|
247
|
+
# @param [Hash] filters Filters to apply to result set
|
248
|
+
# @param [Hash] options Options to apply on a per-request basis
|
249
|
+
# @option filters [String] :object_type Only return objects with an `objectType` matching this value
|
250
|
+
# @option filters [Integer] :limit A positive integer representing the maximum number of items to return in the response. Must be less than or equal to 1000. Defaults to 25. (optional)
|
251
|
+
# @option filters [String] :prev_cursor A cursor representing your place in a list of results. Requests containing prev_cursor will return the results immediately preceding the cursor. (optional)
|
252
|
+
# @option filters [String] :next_cursor A cursor representing your place in a list of results. Requests containing next_cursor will return the results immediately following the cursor. (optional)
|
253
|
+
# @option filters [String] :sort_by The column to sort the result by. Unless otherwise specified, all list endpoints are sorted by their unique identifier by default. Supported values for objects are +object_type+, +object_id+, and +created_at+ (optional)
|
254
|
+
# @option filters [String] :sort_order The order in which to sort the result by. Valid values are +ASC+ and +DESC+. Defaults to +ASC+. (optional)
|
255
|
+
# @option options [String] :warrant_token A valid warrant token from a previous write operation or latest. Used to specify desired consistency for this read operation. (optional)
|
259
256
|
#
|
260
257
|
# @return [Array<Feature>] assigned pricing tiers for the tenant
|
261
258
|
#
|
262
259
|
# @raise [Warrant::InternalError]
|
263
260
|
# @raise [Warrant::InvalidParameterError]
|
264
261
|
# @raise [Warrant::UnauthorizedError]
|
265
|
-
def list_pricing_tiers(filters = {})
|
266
|
-
return PricingTier.list_for_tenant(tenant_id, filters)
|
262
|
+
def list_pricing_tiers(filters = {}, options = {})
|
263
|
+
return PricingTier.list_for_tenant(tenant_id, filters, options)
|
267
264
|
end
|
268
265
|
|
269
266
|
# Assign a pricing tier to a tenant
|
270
267
|
#
|
271
268
|
# @param pricing_tier_id [String] The pricing_tier_id of the pricing tier you want to assign to the tenant.
|
269
|
+
# @param relation [String] The relation for this pricing tier to tenant association. The relation must be valid as per the +pricing tier+ object type definition.
|
272
270
|
#
|
273
271
|
# @return [PricingTier] assigned pricing tier
|
274
272
|
#
|
@@ -277,13 +275,14 @@ module Warrant
|
|
277
275
|
# @raise [Warrant::InvalidParameterError]
|
278
276
|
# @raise [Warrant::NotFoundError]
|
279
277
|
# @raise [Warrant::UnauthorizedError]
|
280
|
-
def assign_pricing_tier(pricing_tier_id)
|
281
|
-
return PricingTier.assign_to_tenant(tenant_id, pricing_tier_id)
|
278
|
+
def assign_pricing_tier(pricing_tier_id, relation: "member", options: {})
|
279
|
+
return PricingTier.assign_to_tenant(tenant_id, pricing_tier_id, relation: relation, options: options)
|
282
280
|
end
|
283
281
|
|
284
282
|
# Remove a pricing_tier from a tenant
|
285
283
|
#
|
286
284
|
# @param pricing_tier_id [String] The pricing_tier_id of the pricing_tier you want to remove from the tenant.
|
285
|
+
# @param relation [String] The relation for this pricing tier to tenant association. The relation must be valid as per the +pricing tier+ object type definition.
|
287
286
|
#
|
288
287
|
# @return [nil] if remove was successful
|
289
288
|
#
|
@@ -292,27 +291,35 @@ module Warrant
|
|
292
291
|
# @raise [Warrant::NotFoundError]
|
293
292
|
# @raise [Warrant::UnauthorizedError]
|
294
293
|
# @raise [Warrant::WarrantError]
|
295
|
-
def remove_pricing_tier(pricing_tier_id)
|
296
|
-
return PricingTier.remove_from_tenant(tenant_id, pricing_tier_id)
|
294
|
+
def remove_pricing_tier(pricing_tier_id, relation: "member", options: {})
|
295
|
+
return PricingTier.remove_from_tenant(tenant_id, pricing_tier_id, relation: relation, options: options)
|
297
296
|
end
|
298
297
|
|
299
298
|
# List features for a tenant
|
300
299
|
#
|
301
|
-
# @
|
302
|
-
# @
|
300
|
+
# @param [Hash] filters Filters to apply to result set
|
301
|
+
# @param [Hash] options Options to apply on a per-request basis
|
302
|
+
# @option filters [String] :object_type Only return objects with an `objectType` matching this value
|
303
|
+
# @option filters [Integer] :limit A positive integer representing the maximum number of items to return in the response. Must be less than or equal to 1000. Defaults to 25. (optional)
|
304
|
+
# @option filters [String] :prev_cursor A cursor representing your place in a list of results. Requests containing prev_cursor will return the results immediately preceding the cursor. (optional)
|
305
|
+
# @option filters [String] :next_cursor A cursor representing your place in a list of results. Requests containing next_cursor will return the results immediately following the cursor. (optional)
|
306
|
+
# @option filters [String] :sort_by The column to sort the result by. Unless otherwise specified, all list endpoints are sorted by their unique identifier by default. Supported values for objects are +object_type+, +object_id+, and +created_at+ (optional)
|
307
|
+
# @option filters [String] :sort_order The order in which to sort the result by. Valid values are +ASC+ and +DESC+. Defaults to +ASC+. (optional)
|
308
|
+
# @option options [String] :warrant_token A valid warrant token from a previous write operation or latest. Used to specify desired consistency for this read operation. (optional)
|
303
309
|
#
|
304
310
|
# @return [Array<Feature>] assigned features for the tenant
|
305
311
|
#
|
306
312
|
# @raise [Warrant::InternalError]
|
307
313
|
# @raise [Warrant::InvalidParameterError]
|
308
314
|
# @raise [Warrant::UnauthorizedError]
|
309
|
-
def list_features(filters = {})
|
310
|
-
return Feature.list_for_tenant(tenant_id, filters)
|
315
|
+
def list_features(filters = {}, options = {})
|
316
|
+
return Feature.list_for_tenant(tenant_id, filters, options)
|
311
317
|
end
|
312
318
|
|
313
319
|
# Assign a feature to a tenant
|
314
320
|
#
|
315
321
|
# @param feature_id [String] The feature_id of the feature you want to assign to the tenant.
|
322
|
+
# @param relation [String] The relation for this feature to tenant association. The relation must be valid as per the +feature+ object type definition.
|
316
323
|
#
|
317
324
|
# @return [Feature] assigned feature
|
318
325
|
#
|
@@ -321,13 +328,14 @@ module Warrant
|
|
321
328
|
# @raise [Warrant::InvalidParameterError]
|
322
329
|
# @raise [Warrant::NotFoundError]
|
323
330
|
# @raise [Warrant::UnauthorizedError]
|
324
|
-
def assign_feature(feature_id)
|
325
|
-
return Feature.assign_to_tenant(tenant_id, feature_id)
|
331
|
+
def assign_feature(feature_id, relation: "member", options: {})
|
332
|
+
return Feature.assign_to_tenant(tenant_id, feature_id, relation: relation, options: options)
|
326
333
|
end
|
327
334
|
|
328
335
|
# Remove a feature from a tenant
|
329
336
|
#
|
330
337
|
# @param feature_id [String] The feature_id of the feature you want to remove from the tenant.
|
338
|
+
# @param relation [String] The relation for this feature to tenant association. The relation must be valid as per the +feature+ object type definition.
|
331
339
|
#
|
332
340
|
# @return [nil] if remove was successful
|
333
341
|
#
|
@@ -336,34 +344,34 @@ module Warrant
|
|
336
344
|
# @raise [Warrant::NotFoundError]
|
337
345
|
# @raise [Warrant::UnauthorizedError]
|
338
346
|
# @raise [Warrant::WarrantError]
|
339
|
-
def remove_feature(feature_id)
|
340
|
-
return Feature.remove_from_tenant(tenant_id, feature_id)
|
347
|
+
def remove_feature(feature_id, relation: "member", options: {})
|
348
|
+
return Feature.remove_from_tenant(tenant_id, feature_id, relation: relation, options: options)
|
341
349
|
end
|
342
350
|
|
343
351
|
# Check whether a tenant has a given feature
|
344
352
|
#
|
345
353
|
# @param feature_id [String] The feature_id of the feature to check whether the tenant has access to.
|
354
|
+
# @param relation [String] The relation for this feature to tenant association. The relation must be valid as per the +feature+ object type definition.
|
346
355
|
# @option options [Hash] :context Object containing key-value pairs that specifies the context the warrant should be checked in. (optional)
|
347
|
-
# @option options [Boolean] :consistent_read Boolean flag indicating whether or not to enforce strict consistency for this access check. Defaults to false. (optional)
|
348
356
|
# @option options [Boolean] :debug Boolean flag indicating whether or not to return debug information for this access check. Defaults to false. (optional)
|
349
357
|
#
|
350
|
-
# @
|
358
|
+
# @return [Boolean] whether or not the tenant has the given feature
|
351
359
|
#
|
352
360
|
# @raise [Warrant::InternalError]
|
353
361
|
# @raise [Warrant::InvalidParameterError]
|
354
362
|
# @raise [Warrant::NotFoundError]
|
355
363
|
# @raise [Warrant::UnauthorizedError]
|
356
|
-
def has_feature?(feature_id,
|
357
|
-
return Warrant.has_feature?(
|
364
|
+
def has_feature?(feature_id, relation: "member", options: {})
|
365
|
+
return Warrant.has_feature?({
|
358
366
|
feature_id: feature_id,
|
367
|
+
relation: relation,
|
359
368
|
subject: {
|
360
369
|
object_type: "tenant",
|
361
370
|
object_id: tenant_id
|
362
371
|
},
|
363
|
-
context:
|
364
|
-
|
365
|
-
|
366
|
-
)
|
372
|
+
context: options[:context],
|
373
|
+
debug: options[:debug]
|
374
|
+
}, options)
|
367
375
|
end
|
368
376
|
|
369
377
|
def warrant_object_type
|