warrant 1.2.0 → 2.0.0.rc1
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
data/lib/warrant/models/role.rb
CHANGED
@@ -2,16 +2,20 @@
|
|
2
2
|
|
3
3
|
module Warrant
|
4
4
|
class Role
|
5
|
-
|
5
|
+
include Warrant::WarrantObject
|
6
|
+
|
7
|
+
attr_reader :role_id, :name, :description
|
6
8
|
|
7
9
|
# @!visibility private
|
8
|
-
def initialize(role_id)
|
10
|
+
def initialize(role_id, name = nil, description = nil)
|
9
11
|
@role_id = role_id
|
12
|
+
@name = name
|
13
|
+
@description = description
|
10
14
|
end
|
11
15
|
|
12
16
|
# Creates a role with the given parameters
|
13
17
|
#
|
14
|
-
# @option params [String] :role_id A string identifier for this new role. The role_id can only be composed of lower-case alphanumeric chars and/or '-' and '_'.
|
18
|
+
# @option params [String] :role_id A string identifier for this new role. The role_id can only be composed of lower-case alphanumeric chars and/or '-' and '_'.
|
15
19
|
#
|
16
20
|
# @return [Role] created role
|
17
21
|
#
|
@@ -20,19 +24,15 @@ module Warrant
|
|
20
24
|
#
|
21
25
|
# @raise [Warrant::DuplicateRecordError]
|
22
26
|
# @raise [Warrant::InternalError]
|
23
|
-
# @raise [Warrant::InvalidParameterError]
|
24
27
|
# @raise [Warrant::InvalidRequestError]
|
25
|
-
# @raise [Warrant::MissingRequiredParameterError]
|
26
|
-
# @raise [Warrant::NotFoundError]
|
27
28
|
# @raise [Warrant::UnauthorizedError]
|
28
|
-
# @raise [Warrant::WarrantError]
|
29
29
|
def self.create(params = {})
|
30
30
|
res = APIOperations.post(URI.parse("#{::Warrant.config.api_base}/v1/roles"), Util.normalize_params(params))
|
31
31
|
|
32
32
|
case res
|
33
33
|
when Net::HTTPSuccess
|
34
34
|
res_json = JSON.parse(res.body)
|
35
|
-
Role.new(res_json['roleId'])
|
35
|
+
Role.new(res_json['roleId'], res_json['name'], res_json['description'])
|
36
36
|
else
|
37
37
|
APIOperations.raise_error(res)
|
38
38
|
end
|
@@ -40,7 +40,7 @@ module Warrant
|
|
40
40
|
|
41
41
|
# Deletes a role with given role id
|
42
42
|
#
|
43
|
-
# @param role_id [String]
|
43
|
+
# @param role_id [String] The role_id of the role to delete.
|
44
44
|
#
|
45
45
|
# @return [nil] if delete was successful
|
46
46
|
#
|
@@ -48,10 +48,9 @@ module Warrant
|
|
48
48
|
# Warrant::Role.delete("test-role")
|
49
49
|
#
|
50
50
|
# @raise [Warrant::InternalError]
|
51
|
-
# @raise [Warrant::
|
51
|
+
# @raise [Warrant::MissingRequiredParameterError]
|
52
52
|
# @raise [Warrant::NotFoundError]
|
53
53
|
# @raise [Warrant::UnauthorizedError]
|
54
|
-
# @raise [Warrant::WarrantError]
|
55
54
|
def self.delete(role_id)
|
56
55
|
res = APIOperations.delete(URI.parse("#{::Warrant.config.api_base}/v1/roles/#{role_id}"))
|
57
56
|
|
@@ -65,50 +64,121 @@ module Warrant
|
|
65
64
|
|
66
65
|
# Lists all roles for your organization
|
67
66
|
#
|
67
|
+
# @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)
|
68
|
+
# @option filters [Integer] :limit A positive integer representing the max number of items to return in response. (optional)
|
69
|
+
#
|
68
70
|
# @return [Array<Role>] all roles for your organization
|
69
71
|
#
|
70
72
|
# @example List all roles
|
71
73
|
# Warrant::Role.list()
|
72
74
|
#
|
73
75
|
# @raise [Warrant::InternalError]
|
74
|
-
# @raise [Warrant::
|
75
|
-
# @raise [Warrant::NotFoundError]
|
76
|
+
# @raise [Warrant::InvalidParameterError]
|
76
77
|
# @raise [Warrant::UnauthorizedError]
|
77
|
-
# @raise [Warrant::WarrantError]
|
78
78
|
def self.list(filters = {})
|
79
|
-
res = APIOperations.get(URI.parse("#{::Warrant.config.api_base}/v1/roles"))
|
79
|
+
res = APIOperations.get(URI.parse("#{::Warrant.config.api_base}/v1/roles"), Util.normalize_params(filters))
|
80
80
|
|
81
81
|
case res
|
82
82
|
when Net::HTTPSuccess
|
83
83
|
roles = JSON.parse(res.body)
|
84
|
-
roles.map{ |role| Role.new(role['roleId']) }
|
84
|
+
roles.map{ |role| Role.new(role['roleId'], role['name'], role['description']) }
|
85
85
|
else
|
86
86
|
APIOperations.raise_error(res)
|
87
|
-
end
|
87
|
+
end
|
88
88
|
end
|
89
89
|
|
90
90
|
# Get a role with the given role_id
|
91
91
|
#
|
92
|
-
# @param role_id [String]
|
92
|
+
# @param role_id [String] The role_id of the role to retrieve.
|
93
93
|
#
|
94
94
|
# @return [Role] retrieved role
|
95
95
|
#
|
96
96
|
# @raise [Warrant::InternalError]
|
97
|
-
# @raise [Warrant::
|
98
|
-
# @raise [Warrant::InvalidRequestError]
|
97
|
+
# @raise [Warrant::MissingRequiredParameterError]
|
99
98
|
# @raise [Warrant::NotFoundError]
|
100
99
|
# @raise [Warrant::UnauthorizedError]
|
101
|
-
# @raise [Warrant::WarrantError]
|
102
100
|
def self.get(role_id)
|
103
101
|
res = APIOperations.get(URI.parse("#{::Warrant.config.api_base}/v1/roles/#{role_id}"))
|
104
102
|
|
105
103
|
case res
|
106
104
|
when Net::HTTPSuccess
|
107
105
|
role = JSON.parse(res.body)
|
108
|
-
Role.new(role['roleId'])
|
106
|
+
Role.new(role['roleId'], role['name'], role['description'])
|
107
|
+
else
|
108
|
+
APIOperations.raise_error(res)
|
109
|
+
end
|
110
|
+
end
|
111
|
+
|
112
|
+
# Updates a role with the given role_id and params
|
113
|
+
#
|
114
|
+
# @param role_id [String] The role_id of the role to be updated.
|
115
|
+
# @param [Hash] params attributes to update user with
|
116
|
+
# @option params [String] :name Name for the role. Designed to be used as a UI-friendly identifier. (optional)
|
117
|
+
# @option params [String] :description Description of the role. Designed to be used as a UI-friendly identifier. (optional)
|
118
|
+
#
|
119
|
+
# @return [Role] updated role
|
120
|
+
#
|
121
|
+
# @example Update role "test-role"'s name
|
122
|
+
# Warrant::Role.update("test-role", { name: "Test Role" })
|
123
|
+
#
|
124
|
+
# @raise [Warrant::InternalError]
|
125
|
+
# @raise [Warrant::InvalidParameterError]
|
126
|
+
# @raise [Warrant::InvalidRequestError]
|
127
|
+
# @raise [Warrant::NotFoundError]
|
128
|
+
# @raise [Warrant::UnauthorizedError]
|
129
|
+
def self.update(role_id, params = {})
|
130
|
+
res = APIOperations.put(URI.parse("#{::Warrant.config.api_base}/v1/roles/#{role_id}"), Util.normalize_params(params))
|
131
|
+
|
132
|
+
case res
|
133
|
+
when Net::HTTPSuccess
|
134
|
+
res_json = JSON.parse(res.body)
|
135
|
+
Role.new(res_json['roleId'], res_json['name'], res_json['description'])
|
136
|
+
else
|
137
|
+
APIOperations.raise_error(res)
|
138
|
+
end
|
139
|
+
end
|
140
|
+
|
141
|
+
# Updates a role with the given params
|
142
|
+
#
|
143
|
+
# @param [Hash] params attributes to update user with
|
144
|
+
# @option params [String] :name Name for the role. Designed to be used as a UI-friendly identifier. (optional)
|
145
|
+
# @option params [String] :description Description of the role. Designed to be used as a UI-friendly identifier. (optional)
|
146
|
+
#
|
147
|
+
# @return [Role] updated role
|
148
|
+
#
|
149
|
+
# @example Update role "test-role"'s name
|
150
|
+
# Warrant::Role.update("test-role", { name: "Test Role" })
|
151
|
+
#
|
152
|
+
# @raise [Warrant::InternalError]
|
153
|
+
# @raise [Warrant::InvalidParameterError]
|
154
|
+
# @raise [Warrant::InvalidRequestError]
|
155
|
+
# @raise [Warrant::NotFoundError]
|
156
|
+
# @raise [Warrant::UnauthorizedError]
|
157
|
+
def update(params = {})
|
158
|
+
return Role.update(role_id, params)
|
159
|
+
end
|
160
|
+
|
161
|
+
# List roles for user
|
162
|
+
#
|
163
|
+
# @param user_id [String] The user_id of the user you want to retrieve roles for.
|
164
|
+
# @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)
|
165
|
+
# @option filters [Integer] :limit A positive integer representing the max number of items to return in response. (optional)
|
166
|
+
#
|
167
|
+
# @return [Array<Role>] all assigned roles for the user
|
168
|
+
#
|
169
|
+
# @raise [Warrant::InternalError]
|
170
|
+
# @raise [Warrant::MissingRequiredParameterError]
|
171
|
+
# @raise [Warrant::UnauthorizedError]
|
172
|
+
def self.list_for_user(user_id, filters = {})
|
173
|
+
res = APIOperations.get(URI.parse("#{::Warrant.config.api_base}/v1/users/#{user_id}/roles"), Util.normalize_params(filters))
|
174
|
+
|
175
|
+
case res
|
176
|
+
when Net::HTTPSuccess
|
177
|
+
roles = JSON.parse(res.body)
|
178
|
+
roles.map{ |role| Role.new(role['roleId'], role['name'], role['description']) }
|
109
179
|
else
|
110
180
|
APIOperations.raise_error(res)
|
111
|
-
end
|
181
|
+
end
|
112
182
|
end
|
113
183
|
|
114
184
|
# Assign a role to a user
|
@@ -116,35 +186,35 @@ module Warrant
|
|
116
186
|
# @param user_id [String] The user_id of the user you want to assign a role to.
|
117
187
|
# @param role_id [String] The role_id of the role you want to assign to a user.
|
118
188
|
#
|
119
|
-
# @return [
|
189
|
+
# @return [Role] assigned role
|
120
190
|
#
|
191
|
+
# @raise [Warrant::DuplicateRecordError]
|
121
192
|
# @raise [Warrant::InternalError]
|
122
|
-
# @raise [Warrant::
|
193
|
+
# @raise [Warrant::InvalidParameterError]
|
123
194
|
# @raise [Warrant::MissingRequiredParameterError]
|
124
195
|
# @raise [Warrant::NotFoundError]
|
125
196
|
# @raise [Warrant::UnauthorizedError]
|
126
|
-
# @raise [Warrant::WarrantError]
|
127
197
|
def self.assign_to_user(user_id, role_id)
|
128
198
|
res = APIOperations.post(URI.parse("#{::Warrant.config.api_base}/v1/users/#{user_id}/roles/#{role_id}"))
|
129
199
|
|
130
200
|
case res
|
131
201
|
when Net::HTTPSuccess
|
132
202
|
role = JSON.parse(res.body)
|
133
|
-
Role.new(role['
|
203
|
+
Role.new(role['roleId'], role['name'], role['description'])
|
134
204
|
else
|
135
205
|
APIOperations.raise_error(res)
|
136
|
-
end
|
206
|
+
end
|
137
207
|
end
|
138
208
|
|
139
209
|
# Remove a role from a user
|
140
210
|
#
|
141
|
-
# @param user_id [String] The user_id of the role you want to
|
142
|
-
# @param role_id [String] The role_id of the role you want to
|
211
|
+
# @param user_id [String] The user_id of the role you want to remove a role from.
|
212
|
+
# @param role_id [String] The role_id of the role you want to remove from a user.
|
143
213
|
#
|
144
214
|
# @return [nil] if remove was successful
|
145
215
|
#
|
216
|
+
# @raise [Warrant::ForbiddenError]
|
146
217
|
# @raise [Warrant::InternalError]
|
147
|
-
# @raise [Warrant::InvalidRequestError]
|
148
218
|
# @raise [Warrant::MissingRequiredParameterError]
|
149
219
|
# @raise [Warrant::NotFoundError]
|
150
220
|
# @raise [Warrant::UnauthorizedError]
|
@@ -157,33 +227,46 @@ module Warrant
|
|
157
227
|
return
|
158
228
|
else
|
159
229
|
APIOperations.raise_error(res)
|
160
|
-
end
|
230
|
+
end
|
231
|
+
end
|
232
|
+
|
233
|
+
# List assigned permissions for the role
|
234
|
+
#
|
235
|
+
# @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)
|
236
|
+
# @option filters [Integer] :limit A positive integer representing the max number of items to return in response. (optional)
|
237
|
+
#
|
238
|
+
# @return [Permission] assigned permissions
|
239
|
+
#
|
240
|
+
# @raise [Warrant::InternalError]
|
241
|
+
# @raise [Warrant::MissingRequiredParameterError]
|
242
|
+
# @raise [Warrant::UnauthorizedError]
|
243
|
+
def list_permissions(filters = {})
|
244
|
+
return Permission.list_for_role(role_id, filters)
|
161
245
|
end
|
162
246
|
|
163
247
|
# Assign a permission to a role
|
164
248
|
#
|
165
|
-
# @param permission_id [String] The permission_id of the permission you want to assign to
|
249
|
+
# @param permission_id [String] The permission_id of the permission you want to assign to the role.
|
166
250
|
#
|
167
251
|
# @return [Permission] assigned permission
|
168
252
|
#
|
253
|
+
# @raise [Warrant::DuplicateRecordError]
|
169
254
|
# @raise [Warrant::InternalError]
|
170
|
-
# @raise [Warrant::
|
255
|
+
# @raise [Warrant::InvalidParameterError]
|
171
256
|
# @raise [Warrant::MissingRequiredParameterError]
|
172
257
|
# @raise [Warrant::NotFoundError]
|
173
258
|
# @raise [Warrant::UnauthorizedError]
|
174
|
-
# @raise [Warrant::WarrantError]
|
175
259
|
def assign_permission(permission_id)
|
176
260
|
return Permission.assign_to_role(role_id, permission_id)
|
177
261
|
end
|
178
262
|
|
179
263
|
# Remove a permission from a role
|
180
264
|
#
|
181
|
-
# @param permission_id [String] The permission_id of the permission you want to
|
265
|
+
# @param permission_id [String] The permission_id of the permission you want to remove from the role.
|
182
266
|
#
|
183
267
|
# @return [nil] if remove was successful
|
184
268
|
#
|
185
269
|
# @raise [Warrant::InternalError]
|
186
|
-
# @raise [Warrant::InvalidRequestError]
|
187
270
|
# @raise [Warrant::MissingRequiredParameterError]
|
188
271
|
# @raise [Warrant::NotFoundError]
|
189
272
|
# @raise [Warrant::UnauthorizedError]
|
@@ -191,5 +274,13 @@ module Warrant
|
|
191
274
|
def remove_permission(permission_id)
|
192
275
|
return Permission.remove_from_role(role_id, permission_id)
|
193
276
|
end
|
277
|
+
|
278
|
+
def warrant_object_type
|
279
|
+
"role"
|
280
|
+
end
|
281
|
+
|
282
|
+
def warrant_object_id
|
283
|
+
role_id
|
284
|
+
end
|
194
285
|
end
|
195
286
|
end
|
@@ -6,7 +6,7 @@ module Warrant
|
|
6
6
|
#
|
7
7
|
# @option params [String] :user_id Id of the user to create a session for.
|
8
8
|
# @option params [Integer] :ttl Number of seconds a session should live for. By default session tokens live for 24 hours and self service tokens live for 30 minutes.
|
9
|
-
#
|
9
|
+
#
|
10
10
|
# @return [String] Session token
|
11
11
|
#
|
12
12
|
# @raise [Warrant::InternalError]
|
@@ -15,7 +15,6 @@ module Warrant
|
|
15
15
|
# @raise [Warrant::MissingRequiredParameterError]
|
16
16
|
# @raise [Warrant::NotFoundError]
|
17
17
|
# @raise [Warrant::UnauthorizedError]
|
18
|
-
# @raise [Warrant::WarrantError]
|
19
18
|
def self.create_authorization_session(params = {})
|
20
19
|
params = params.merge(type: "sess")
|
21
20
|
res = APIOperations.post(URI.parse("#{::Warrant.config.api_base}/v1/sessions"), Util.normalize_params(params))
|
@@ -36,15 +35,15 @@ module Warrant
|
|
36
35
|
# @option params [String] :tenant_id Id of the tenant to create a session for
|
37
36
|
# @option params [Integer] :ttl Number of seconds a session should live for. By default session tokens live for 24 hours and self service tokens live for 30 minutes.
|
38
37
|
#
|
39
|
-
# @return [String] URL to the self service dashboard
|
40
|
-
#
|
38
|
+
# @return [String] URL to the self service dashboard
|
39
|
+
#
|
40
|
+
# @raise [Warrant::ForbiddenError]
|
41
41
|
# @raise [Warrant::InternalError]
|
42
42
|
# @raise [Warrant::InvalidParameterError]
|
43
43
|
# @raise [Warrant::InvalidRequestError]
|
44
44
|
# @raise [Warrant::MissingRequiredParameterError]
|
45
45
|
# @raise [Warrant::NotFoundError]
|
46
46
|
# @raise [Warrant::UnauthorizedError]
|
47
|
-
# @raise [Warrant::WarrantError]
|
48
47
|
def self.create_self_service_session(redirect_url, params = {})
|
49
48
|
params = params.merge(type: "ssdash")
|
50
49
|
res = APIOperations.post(URI.parse("#{::Warrant.config.api_base}/v1/sessions"), Util.normalize_params(params))
|