warrant 3.1.0 → 5.0.0
Sign up to get free protection for your applications and to get access to all the features.
- 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
@@ -0,0 +1,230 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Warrant
|
4
|
+
class Object
|
5
|
+
attr_reader :object_type, :object_id, :meta, :created_at
|
6
|
+
|
7
|
+
# @!visibility private
|
8
|
+
def initialize(object_type, object_id, meta = {}, created_at = nil)
|
9
|
+
@object_type = object_type
|
10
|
+
@object_id = object_id
|
11
|
+
@meta = meta
|
12
|
+
@created_at = created_at
|
13
|
+
end
|
14
|
+
|
15
|
+
# Creates an object with the given parameters
|
16
|
+
#
|
17
|
+
# @option params [String] :object_type The type of the object (e.g. user, tenant, role, permission, etc).
|
18
|
+
# @option params [String] :object_id Customer defined string identifier for this object. Can only contain alphanumeric chars and/or '-', '_', '|', '@'. If not provided, Warrant will create a univerally unique identifier (UUID) for the object and return it. If allowing Warrant to generate an id, store the id in your application so you can provide it for authorization requests on that object. (optional)
|
19
|
+
# @option params [Hash] :meta A JSON object containing additional information about this object (e.g. role name/description, user email/name, etc.) to be persisted to Warrant. (optional)
|
20
|
+
#
|
21
|
+
# @return [Object] created object
|
22
|
+
#
|
23
|
+
# @example Create a new Object with the object type "user" and object id "test-customer"
|
24
|
+
# Warrant::Object.create(object_type: "user", object_id: "test-customer")
|
25
|
+
#
|
26
|
+
# @raise [Warrant::DuplicateRecordError]
|
27
|
+
# @raise [Warrant::InternalError]
|
28
|
+
# @raise [Warrant::InvalidParameterError]
|
29
|
+
# @raise [Warrant::InvalidRequestError]
|
30
|
+
# @raise [Warrant::NotFoundError]
|
31
|
+
# @raise [Warrant::UnauthorizedError]
|
32
|
+
def self.create(params = {}, options = {})
|
33
|
+
res = APIOperations.post(URI.parse("#{::Warrant.config.api_base}/v2/objects"), params: Util.normalize_params(params), options: options)
|
34
|
+
|
35
|
+
case res
|
36
|
+
when Net::HTTPSuccess
|
37
|
+
res_json = JSON.parse(res.body, symbolize_names: true)
|
38
|
+
Object.new(res_json[:objectType], res_json[:objectId], res_json[:meta], res_json[:createdAt])
|
39
|
+
else
|
40
|
+
APIOperations.raise_error(res)
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
# Batch creates multiple objects with given parameters
|
45
|
+
#
|
46
|
+
# @param [Array<Hash>] objects Array of objects to create.
|
47
|
+
# @option objects [String] :object_type The type of the object (e.g. user, tenant, role, permission, etc).
|
48
|
+
# @option objects [String] :object_id Customer defined string identifier for this object. Can only contain alphanumeric chars and/or '-', '_', '|', '@'. If not provided, Warrant will create a univerally unique identifier (UUID) for the object and return it. If allowing Warrant to generate an id, store the id in your application so you can provide it for authorization requests on that object. (optional)
|
49
|
+
# @option objects [Hash] :meta A JSON object containing additional information about this object (e.g. role name/description, user email/name, etc.) to be persisted to Warrant. (optional)
|
50
|
+
#
|
51
|
+
# @return [Array<Object>] all created objects
|
52
|
+
#
|
53
|
+
# @example Create two new objects with object type "user" and object ids "test-user-1" and "test-user-2"
|
54
|
+
# Warrant::Object.batch_create([{ object_type: "user", object_id: "test-user-1" }, { object_type: "user", object_id: "test-user-2" }])
|
55
|
+
#
|
56
|
+
# @raise [Warrant::DuplicateRecordError]
|
57
|
+
# @raise [Warrant::InternalError]
|
58
|
+
# @raise [Warrant::InvalidParameterError]
|
59
|
+
# @raise [Warrant::InvalidRequestError]
|
60
|
+
# @raise [Warrant::NotFoundError]
|
61
|
+
# @raise [Warrant::UnauthorizedError]
|
62
|
+
def self.batch_create(objects, options = {})
|
63
|
+
res = APIOperations.post(URI.parse("#{::Warrant.config.api_base}/v2/objects"), params: Util.normalize_params(objects), options: options)
|
64
|
+
|
65
|
+
case res
|
66
|
+
when Net::HTTPSuccess
|
67
|
+
objects = JSON.parse(res.body, symbolize_names: true)
|
68
|
+
objects.map{ |object| Object.new(object[:objectType], object[:objectId], object[:meta], object[:createdAt]) }
|
69
|
+
else
|
70
|
+
APIOperations.raise_error(res)
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
74
|
+
# Deletes a object with given object type and id
|
75
|
+
#
|
76
|
+
# @param object_type [String] The type of the object (e.g. user, tenant, role, permission, etc).
|
77
|
+
# @param object_id [String] User defined string identifier for this object.
|
78
|
+
#
|
79
|
+
# @return [nil] if delete was successful
|
80
|
+
#
|
81
|
+
# @example Delete a Object with the object type "user" and object id "test-customer"
|
82
|
+
# Warrant::Object.delete("user", "test-customer")
|
83
|
+
#
|
84
|
+
# @raise [Warrant::InternalError]
|
85
|
+
# @raise [Warrant::InvalidParameterError]
|
86
|
+
# @raise [Warrant::NotFoundError]
|
87
|
+
# @raise [Warrant::UnauthorizedError]
|
88
|
+
def self.delete(object_type, object_id, options = {})
|
89
|
+
res = APIOperations.delete(URI.parse("#{::Warrant.config.api_base}/v2/objects/#{object_type}/#{object_id}"), options: options)
|
90
|
+
|
91
|
+
case res
|
92
|
+
when Net::HTTPSuccess
|
93
|
+
return res['Warrant-Token']
|
94
|
+
else
|
95
|
+
APIOperations.raise_error(res)
|
96
|
+
end
|
97
|
+
end
|
98
|
+
|
99
|
+
# Batch deletes multiple objects with given parameters
|
100
|
+
#
|
101
|
+
# @param [Array<Hash>] objects Array of objects to delete.
|
102
|
+
# @option objects [String] :object_type The type of the object (e.g. user, tenant, role, permission, etc).
|
103
|
+
# @option objects [String] :object_id Customer defined string identifier for this object.
|
104
|
+
#
|
105
|
+
# @return [nil] if delete was successful
|
106
|
+
#
|
107
|
+
# @example Delete two objects with object type "user" and object ids "test-user-1" and "test-user-2"
|
108
|
+
# Warrant::Object.batch_delete([{ object_type: "user", object_id: "test-user-1" }, { object_type: "user", object_id: "test-user-2" }])
|
109
|
+
#
|
110
|
+
# @raise [Warrant::InternalError]
|
111
|
+
# @raise [Warrant::InvalidParameterError]
|
112
|
+
# @raise [Warrant::NotFoundError]
|
113
|
+
# @raise [Warrant::UnauthorizedError]
|
114
|
+
def self.batch_delete(objects, options = {})
|
115
|
+
res = APIOperations.delete(URI.parse("#{::Warrant.config.api_base}/v2/objects"), params: Util.normalize_params(objects), options: options)
|
116
|
+
|
117
|
+
case res
|
118
|
+
when Net::HTTPSuccess
|
119
|
+
return res['Warrant-Token']
|
120
|
+
else
|
121
|
+
APIOperations.raise_error(res)
|
122
|
+
end
|
123
|
+
end
|
124
|
+
|
125
|
+
# Lists all objects for your organization and environment
|
126
|
+
#
|
127
|
+
# @param [Hash] filters Filters to apply to result set
|
128
|
+
# @param [Hash] options Options to apply on a per-request basis
|
129
|
+
# @option filters [String] :object_type Only return objects with an +object_type+ matching this value
|
130
|
+
# @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)
|
131
|
+
# @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)
|
132
|
+
# @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)
|
133
|
+
# @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)
|
134
|
+
# @option filters [String] :sort_order The order in which to sort the result by. Valid values are +ASC+ and +DESC+. Defaults to +ASC+. (optional)
|
135
|
+
# @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)
|
136
|
+
#
|
137
|
+
# @return [Array<Object>] all objects for your organization and environment
|
138
|
+
#
|
139
|
+
# @example List all objects
|
140
|
+
# Warrant::Object.list()
|
141
|
+
#
|
142
|
+
# @raise [Warrant::InternalError]
|
143
|
+
# @raise [Warrant::InvalidParameterError]
|
144
|
+
# @raise [Warrant::UnauthorizedError]
|
145
|
+
def self.list(filters = {}, options = {})
|
146
|
+
res = APIOperations.get(URI.parse("#{::Warrant.config.api_base}/v2/objects"), params: Util.normalize_params(filters), options: options)
|
147
|
+
|
148
|
+
case res
|
149
|
+
when Net::HTTPSuccess
|
150
|
+
list_result = JSON.parse(res.body, symbolize_names: true)
|
151
|
+
objects = list_result[:results].map{ |object| Object.new(object[:objectType], object[:objectId], object[:meta], object[:createdAt]) }
|
152
|
+
return ListResponse.new(objects, list_result[:prevCursor], list_result[:nextCursor])
|
153
|
+
else
|
154
|
+
APIOperations.raise_error(res)
|
155
|
+
end
|
156
|
+
end
|
157
|
+
|
158
|
+
# Get a object with the given object_type and object_id
|
159
|
+
#
|
160
|
+
# @param object_id [String] Object defined string identifier for this object. If not provided, Warrant will create an id for the object and return it. In this case, you should store the id in your system as you will need to provide it for any authorization requests for that object. Note that objectIds in Warrant must be composed of alphanumeric chars and/or '-', '_', and '@'.
|
161
|
+
#
|
162
|
+
# @return [Object] retrieved object
|
163
|
+
#
|
164
|
+
# @raise [Warrant::InternalError]
|
165
|
+
# @raise [Warrant::InvalidParameterError]
|
166
|
+
# @raise [Warrant::NotFoundError]
|
167
|
+
# @raise [Warrant::UnauthorizedError]
|
168
|
+
def self.get(object_type, object_id, options = {})
|
169
|
+
res = APIOperations.get(URI.parse("#{::Warrant.config.api_base}/v2/objects/#{object_type}/#{object_id}"), options: options)
|
170
|
+
|
171
|
+
case res
|
172
|
+
when Net::HTTPSuccess
|
173
|
+
object = JSON.parse(res.body, symbolize_names: true)
|
174
|
+
Object.new(object[:objectType], object[:objectId], object[:meta], object[:createdAt])
|
175
|
+
else
|
176
|
+
APIOperations.raise_error(res)
|
177
|
+
end
|
178
|
+
end
|
179
|
+
|
180
|
+
# Updates a object with the given object_type and object_id and params
|
181
|
+
#
|
182
|
+
# @param object_type [String] The type of the object (e.g. user, tenant, role, permission, etc).
|
183
|
+
# @param object_id [String] User defined string identifier for this object.
|
184
|
+
# @param meta [Hash] A JSON object containing additional information about this object (e.g. role name/description, user email/name, etc.) to be persisted to Warrant.
|
185
|
+
#
|
186
|
+
# @return [Object] updated object
|
187
|
+
#
|
188
|
+
# @example Update user "test-user"'s email
|
189
|
+
# Warrant::Object.update("user", "test-user", { email: "my-new-email@example.com" })
|
190
|
+
#
|
191
|
+
# @raise [Warrant::InternalError]
|
192
|
+
# @raise [Warrant::InvalidParameterError]
|
193
|
+
# @raise [Warrant::InvalidRequestError]
|
194
|
+
# @raise [Warrant::NotFoundError]
|
195
|
+
# @raise [Warrant::UnauthorizedError]
|
196
|
+
def self.update(object_type, object_id, meta, options = {})
|
197
|
+
params = {
|
198
|
+
meta: meta,
|
199
|
+
}
|
200
|
+
res = APIOperations.put(URI.parse("#{::Warrant.config.api_base}/v2/objects/#{object_type}/#{object_id}"), params: Util.normalize_params(params), options: options)
|
201
|
+
|
202
|
+
case res
|
203
|
+
when Net::HTTPSuccess
|
204
|
+
res_json = JSON.parse(res.body, symbolize_names: true)
|
205
|
+
Object.new(res_json[:objectType], res_json[:objectId], res_json[:meta], res_json[:createdAt])
|
206
|
+
else
|
207
|
+
APIOperations.raise_error(res)
|
208
|
+
end
|
209
|
+
end
|
210
|
+
|
211
|
+
# Updates a object with the given object_type and object_id and params
|
212
|
+
#
|
213
|
+
# @param meta [Hash] A JSON object containing additional information about this object (e.g. role name/description, user email/name, etc.) to be persisted to Warrant.
|
214
|
+
#
|
215
|
+
# @return [Object] updated object
|
216
|
+
#
|
217
|
+
# @example Update user "test-user"'s email
|
218
|
+
# user = Warrant::Object.get("user", "test-user")
|
219
|
+
# user.update({ email: "my-new-email@example.com" })
|
220
|
+
#
|
221
|
+
# @raise [Warrant::InternalError]
|
222
|
+
# @raise [Warrant::InvalidParameterError]
|
223
|
+
# @raise [Warrant::InvalidRequestError]
|
224
|
+
# @raise [Warrant::NotFoundError]
|
225
|
+
# @raise [Warrant::UnauthorizedError]
|
226
|
+
def update(meta, options = {})
|
227
|
+
return Object.update(object_type, object_id, meta, options)
|
228
|
+
end
|
229
|
+
end
|
230
|
+
end
|
@@ -1,23 +1,22 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
3
|
module Warrant
|
4
|
-
class Permission
|
4
|
+
class Permission < Warrant::Object
|
5
5
|
OBJECT_TYPE = "permission"
|
6
6
|
|
7
7
|
include Warrant::WarrantObject
|
8
8
|
|
9
|
-
|
9
|
+
alias :permission_id :object_id
|
10
10
|
|
11
11
|
# @!visibility private
|
12
|
-
def initialize(permission_id,
|
13
|
-
|
14
|
-
@name = name
|
15
|
-
@description = description
|
12
|
+
def initialize(permission_id, meta = {}, created_at = nil)
|
13
|
+
super(OBJECT_TYPE, permission_id, meta, created_at)
|
16
14
|
end
|
17
15
|
|
18
16
|
# Creates a permission with the given parameters
|
19
17
|
#
|
20
|
-
# @option params [String] :
|
18
|
+
# @option params [String] :role_id User defined string identifier for this permission. If not provided, Warrant will create an id for the permission and return it. In this case, you should store the id in your system as you will need to provide it for any authorization requests for that permission. Note that permissionIds in Warrant must be composed of alphanumeric chars, '-', and/or '_'. (optional)
|
19
|
+
# @option params [Hash] :meta A JSON object containing additional information about this permission (e.g. name/description) to be persisted to Warrant. (optional)
|
21
20
|
#
|
22
21
|
# @return [Permission] created permission
|
23
22
|
#
|
@@ -28,16 +27,9 @@ module Warrant
|
|
28
27
|
# @raise [Warrant::InternalError]
|
29
28
|
# @raise [Warrant::InvalidRequestError]
|
30
29
|
# @raise [Warrant::UnauthorizedError]
|
31
|
-
def self.create(params = {})
|
32
|
-
|
33
|
-
|
34
|
-
case res
|
35
|
-
when Net::HTTPSuccess
|
36
|
-
res_json = JSON.parse(res.body)
|
37
|
-
Permission.new(res_json['permissionId'], res_json['name'], res_json['description'])
|
38
|
-
else
|
39
|
-
APIOperations.raise_error(res)
|
40
|
-
end
|
30
|
+
def self.create(params = {}, options = {})
|
31
|
+
object = Object.create({ object_type: OBJECT_TYPE, object_id: params[:permission_id], meta: params[:meta] }, options)
|
32
|
+
return Permission.new(object.object_id, object.meta, object.created_at)
|
41
33
|
end
|
42
34
|
|
43
35
|
# Deletes a permission with given permission id
|
@@ -53,21 +45,20 @@ module Warrant
|
|
53
45
|
# @raise [Warrant::MissingRequiredParameterError]
|
54
46
|
# @raise [Warrant::NotFoundError]
|
55
47
|
# @raise [Warrant::UnauthorizedError]
|
56
|
-
def self.delete(permission_id)
|
57
|
-
|
58
|
-
|
59
|
-
case res
|
60
|
-
when Net::HTTPSuccess
|
61
|
-
return
|
62
|
-
else
|
63
|
-
APIOperations.raise_error(res)
|
64
|
-
end
|
48
|
+
def self.delete(permission_id, options = {})
|
49
|
+
return Object.delete(OBJECT_TYPE, permission_id, options)
|
65
50
|
end
|
66
51
|
|
67
52
|
# Lists all permissions for your organization
|
68
53
|
#
|
69
|
-
# @
|
70
|
-
# @
|
54
|
+
# @param [Hash] filters Filters to apply to result set
|
55
|
+
# @param [Hash] options Options to apply on a per-request basis
|
56
|
+
# @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)
|
57
|
+
# @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)
|
58
|
+
# @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)
|
59
|
+
# @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)
|
60
|
+
# @option filters [String] :sort_order The order in which to sort the result by. Valid values are +ASC+ and +DESC+. Defaults to +ASC+. (optional)
|
61
|
+
# @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)
|
71
62
|
#
|
72
63
|
# @return [Array<Permission>] all permissions for your organization
|
73
64
|
#
|
@@ -77,16 +68,11 @@ module Warrant
|
|
77
68
|
# @raise [Warrant::InternalError]
|
78
69
|
# @raise [Warrant::InvalidParameterError]
|
79
70
|
# @raise [Warrant::UnauthorizedError]
|
80
|
-
def self.list(filters = {})
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
permissions = JSON.parse(res.body)
|
86
|
-
permissions.map{ |permission| Permission.new(permission['permissionId'], permission['name'], permission['description']) }
|
87
|
-
else
|
88
|
-
APIOperations.raise_error(res)
|
89
|
-
end
|
71
|
+
def self.list(filters = {}, options = {})
|
72
|
+
filters.merge({ object_type: "permission" })
|
73
|
+
list_response = Object.list(filters, options)
|
74
|
+
permissions = list_response.results.map{ |object| Permission.new(object.object_id, object.meta, object.created_at)}
|
75
|
+
return ListResponse.new(permissions, list_response.prev_cursor, list_response.next_cursor)
|
90
76
|
end
|
91
77
|
|
92
78
|
# Get a permission with the given permission_id
|
@@ -99,24 +85,15 @@ module Warrant
|
|
99
85
|
# @raise [Warrant::MissingRequiredParameterError]
|
100
86
|
# @raise [Warrant::NotFoundError]
|
101
87
|
# @raise [Warrant::UnauthorizedError]
|
102
|
-
def self.get(permission_id)
|
103
|
-
|
104
|
-
|
105
|
-
case res
|
106
|
-
when Net::HTTPSuccess
|
107
|
-
permission = JSON.parse(res.body)
|
108
|
-
Permission.new(permission['permissionId'], permission['name'], permission['description'])
|
109
|
-
else
|
110
|
-
APIOperations.raise_error(res)
|
111
|
-
end
|
88
|
+
def self.get(permission_id, options = {})
|
89
|
+
object = Object.get(OBJECT_TYPE, permission_id, options)
|
90
|
+
return Permission.new(object.object_id, object.meta, object.created_at)
|
112
91
|
end
|
113
92
|
|
114
93
|
# Updates a permission with the given role_id and params
|
115
94
|
#
|
116
95
|
# @param permission_id [String] The permission_id of the permission to be updated.
|
117
|
-
# @param [Hash]
|
118
|
-
# @option params [String] :name Name for the permission. Designed to be used as a UI-friendly identifier. (optional)
|
119
|
-
# @option params [String] :description Description of the permission. Designed to be used as a UI-friendly identifier. (optional)
|
96
|
+
# @param meta [Hash] A JSON object containing additional information about this permission (e.g. name/description, etc.) to be persisted to Warrant.
|
120
97
|
#
|
121
98
|
# @return [Permission] updated permission
|
122
99
|
#
|
@@ -128,23 +105,15 @@ module Warrant
|
|
128
105
|
# @raise [Warrant::InvalidRequestError]
|
129
106
|
# @raise [Warrant::NotFoundError]
|
130
107
|
# @raise [Warrant::UnauthorizedError]
|
131
|
-
def self.update(permission_id,
|
132
|
-
|
133
|
-
|
134
|
-
case res
|
135
|
-
when Net::HTTPSuccess
|
136
|
-
res_json = JSON.parse(res.body)
|
137
|
-
Permission.new(res_json['permissionId'], res_json['name'], res_json['description'])
|
138
|
-
else
|
139
|
-
APIOperations.raise_error(res)
|
140
|
-
end
|
108
|
+
def self.update(permission_id, meta, options = {})
|
109
|
+
object = Object.update(OBJECT_TYPE, permission_id, meta, options)
|
110
|
+
return Permission.new(object.object_id, object.meta, object.created_at)
|
141
111
|
end
|
142
112
|
|
143
113
|
# Updates a permission with the given params
|
144
114
|
#
|
145
115
|
# @param [Hash] params attributes to update user with
|
146
|
-
# @
|
147
|
-
# @option params [String] :description Description of the permission. Designed to be used as a UI-friendly identifier. (optional)
|
116
|
+
# @param meta [Hash] A JSON object containing additional information about this permission (e.g. name/description, etc.) to be persisted to Warrant.
|
148
117
|
#
|
149
118
|
# @return [Permission] updated permission
|
150
119
|
#
|
@@ -156,37 +125,39 @@ module Warrant
|
|
156
125
|
# @raise [Warrant::InvalidRequestError]
|
157
126
|
# @raise [Warrant::NotFoundError]
|
158
127
|
# @raise [Warrant::UnauthorizedError]
|
159
|
-
def update(
|
160
|
-
return Permission.update(permission_id,
|
128
|
+
def update(meta, options = {})
|
129
|
+
return Permission.update(permission_id, meta, options)
|
161
130
|
end
|
162
131
|
|
163
132
|
# List permissions for a role
|
164
133
|
#
|
165
134
|
# @param role_id [String] The role_id of the role to list assigned permissions for.
|
166
|
-
# @
|
167
|
-
# @
|
135
|
+
# @param [Hash] filters Filters to apply to result set
|
136
|
+
# @param [Hash] options Options to apply on a per-request basis
|
137
|
+
# @option filters [String] :object_type Only return objects with an `objectType` matching this value
|
138
|
+
# @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)
|
139
|
+
# @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)
|
140
|
+
# @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)
|
141
|
+
# @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)
|
142
|
+
# @option filters [String] :sort_order The order in which to sort the result by. Valid values are +ASC+ and +DESC+. Defaults to +ASC+. (optional)
|
143
|
+
# @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)
|
168
144
|
#
|
169
145
|
# @return [Array<Permission>] all assigned permissions for the role
|
170
146
|
#
|
171
147
|
# @raise [Warrant::InternalError]
|
172
148
|
# @raise [Warrant::MissingRequiredParameterError]
|
173
149
|
# @raise [Warrant::UnauthorizedError]
|
174
|
-
def self.list_for_role(role_id, filters = {})
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
when Net::HTTPSuccess
|
179
|
-
permissions = JSON.parse(res.body)
|
180
|
-
permissions.map{ |permission| Permission.new(permission['permissionId'], permission['name'], permission['description']) }
|
181
|
-
else
|
182
|
-
APIOperations.raise_error(res)
|
183
|
-
end
|
150
|
+
def self.list_for_role(role_id, filters = {}, options = {})
|
151
|
+
query_response = Warrant.query("select permission where role:#{role_id} is *", filters: filters, options: options)
|
152
|
+
permissions = query_response.results.map{ |result| Permission.new(result.object_id, result.meta) }
|
153
|
+
return ListResponse.new(permissions, query_response.prev_cursor, query_response.next_cursor)
|
184
154
|
end
|
185
155
|
|
186
156
|
# Assign a permission to a role
|
187
157
|
#
|
188
158
|
# @param role_id [String] The role_id of the role you want to assign a permission to.
|
189
159
|
# @param permission_id [String] The permission_id of the permission you want to assign to a role.
|
160
|
+
# @param relation [String] The relation for this permission to role association. The relation must be valid as per the +permission+ object type definition.
|
190
161
|
#
|
191
162
|
# @return [Warrant] warrant assigning permission to role
|
192
163
|
#
|
@@ -196,14 +167,15 @@ module Warrant
|
|
196
167
|
# @raise [Warrant::MissingRequiredParameterError]
|
197
168
|
# @raise [Warrant::NotFoundError]
|
198
169
|
# @raise [Warrant::UnauthorizedError]
|
199
|
-
def self.assign_to_role(role_id, permission_id)
|
200
|
-
Warrant.create({ object_type: Permission::OBJECT_TYPE, object_id: permission_id },
|
170
|
+
def self.assign_to_role(role_id, permission_id, relation: "member", options: {})
|
171
|
+
Warrant.create({ object_type: Permission::OBJECT_TYPE, object_id: permission_id }, relation, { object_type: Role::OBJECT_TYPE, object_id: role_id }, nil, options)
|
201
172
|
end
|
202
173
|
|
203
174
|
# Remove a permission from a role
|
204
175
|
#
|
205
176
|
# @param role_id [String] The role_id of the role you want to remove a permission from.
|
206
177
|
# @param permission_id [String] The permission_id of the permission you want to remove from a role.
|
178
|
+
# @param relation [String] The relation for this permission to role association. The relation must be valid as per the +permission+ object type definition.
|
207
179
|
#
|
208
180
|
# @return [nil] if remove was successful
|
209
181
|
#
|
@@ -212,37 +184,39 @@ module Warrant
|
|
212
184
|
# @raise [Warrant::NotFoundError]
|
213
185
|
# @raise [Warrant::UnauthorizedError]
|
214
186
|
# @raise [Warrant::WarrantError]
|
215
|
-
def self.remove_from_role(role_id, permission_id)
|
216
|
-
Warrant.delete({ object_type: Permission::OBJECT_TYPE, object_id: permission_id },
|
187
|
+
def self.remove_from_role(role_id, permission_id, relation: "member", options: {})
|
188
|
+
Warrant.delete({ object_type: Permission::OBJECT_TYPE, object_id: permission_id }, relation, { object_type: Role::OBJECT_TYPE, object_id: role_id }, nil, options)
|
217
189
|
end
|
218
190
|
|
219
191
|
# List permissions for a user
|
220
192
|
#
|
221
193
|
# @param user_id [String] The user_id of the user to list assigned permissions for.
|
222
|
-
# @
|
223
|
-
# @
|
194
|
+
# @param [Hash] filters Filters to apply to result set
|
195
|
+
# @param [Hash] options Options to apply on a per-request basis
|
196
|
+
# @option filters [String] :object_type Only return objects with an `objectType` matching this value
|
197
|
+
# @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)
|
198
|
+
# @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)
|
199
|
+
# @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)
|
200
|
+
# @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)
|
201
|
+
# @option filters [String] :sort_order The order in which to sort the result by. Valid values are +ASC+ and +DESC+. Defaults to +ASC+. (optional)
|
202
|
+
# @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)
|
224
203
|
#
|
225
204
|
# @return [Array<Permission>] all assigned permissions for the user
|
226
205
|
#
|
227
206
|
# @raise [Warrant::InternalError]
|
228
207
|
# @raise [Warrant::MissingRequiredParameterError]
|
229
208
|
# @raise [Warrant::UnauthorizedError]
|
230
|
-
def self.list_for_user(user_id, filters = {})
|
231
|
-
|
232
|
-
|
233
|
-
|
234
|
-
when Net::HTTPSuccess
|
235
|
-
permissions = JSON.parse(res.body)
|
236
|
-
permissions.map{ |permission| Permission.new(permission['permissionId'], permission['name'], permission['description']) }
|
237
|
-
else
|
238
|
-
APIOperations.raise_error(res)
|
239
|
-
end
|
209
|
+
def self.list_for_user(user_id, filters = {}, options = {})
|
210
|
+
query_response = Warrant.query("select permission where user:#{user_id} is *", filters: filters, options: options)
|
211
|
+
permissions = query_response.results.map{ |result| Permission.new(result.object_id, result.meta) }
|
212
|
+
return ListResponse.new(permissions, query_response.prev_cursor, query_response.next_cursor)
|
240
213
|
end
|
241
214
|
|
242
215
|
# Assign a permission to a user
|
243
216
|
#
|
244
217
|
# @param user_id [String] The user_id of the user you want to assign a permission to.
|
245
218
|
# @param permission_id [String] The permission_id of the permission you want to assign to a user.
|
219
|
+
# @param relation [String] The relation for this permission to user association. The relation must be valid as per the +permission+ object type definition.
|
246
220
|
#
|
247
221
|
# @return [Warrant] warrant assigning permission to user
|
248
222
|
#
|
@@ -252,14 +226,15 @@ module Warrant
|
|
252
226
|
# @raise [Warrant::MissingRequiredParameterError]
|
253
227
|
# @raise [Warrant::NotFoundError]
|
254
228
|
# @raise [Warrant::UnauthorizedError]
|
255
|
-
def self.assign_to_user(user_id, permission_id)
|
256
|
-
Warrant.create({ object_type: Permission::OBJECT_TYPE, object_id: permission_id },
|
229
|
+
def self.assign_to_user(user_id, permission_id, relation: "member", options: {})
|
230
|
+
Warrant.create({ object_type: Permission::OBJECT_TYPE, object_id: permission_id }, relation, { object_type: User::OBJECT_TYPE, object_id: user_id }, nil, options)
|
257
231
|
end
|
258
232
|
|
259
233
|
# Remove a permission from a user
|
260
234
|
#
|
261
235
|
# @param user_id [String] The user_id of the user you want to remove a permission from.
|
262
236
|
# @param permission_id [String] The permission_id of the permission you want to remove from a user.
|
237
|
+
# @param relation [String] The relation for this permission to user association. The relation must be valid as per the +permission+ object type definition.
|
263
238
|
#
|
264
239
|
# @return [nil] if remove was successful
|
265
240
|
#
|
@@ -268,8 +243,8 @@ module Warrant
|
|
268
243
|
# @raise [Warrant::NotFoundError]
|
269
244
|
# @raise [Warrant::UnauthorizedError]
|
270
245
|
# @raise [Warrant::WarrantError]
|
271
|
-
def self.remove_from_user(user_id, permission_id)
|
272
|
-
Warrant.delete({ object_type: Permission::OBJECT_TYPE, object_id: permission_id },
|
246
|
+
def self.remove_from_user(user_id, permission_id, relation: "member", options: {})
|
247
|
+
Warrant.delete({ object_type: Permission::OBJECT_TYPE, object_id: permission_id }, relation, { object_type: User::OBJECT_TYPE, object_id: user_id }, nil, options)
|
273
248
|
end
|
274
249
|
|
275
250
|
def warrant_object_type
|