warrant 1.1.0 → 1.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/warrant/models/subject.rb +8 -0
- data/lib/warrant/models/user.rb +11 -11
- data/lib/warrant/models/warrant.rb +37 -4
- data/lib/warrant/util.rb +2 -0
- data/lib/warrant/version.rb +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d3ba7f4c3cde89c03aa17c15bfe00fa553172b27365b2e25548e7f349f38d799
|
4
|
+
data.tar.gz: 0fbc797a1768ca2aa47a08a7b2864a4398c25ed3deb2ff26f45e113855961c8c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9240a10a74f6cf277e2a94d392181dbb66f89b5a970b6d4688c3fd6582ecde03fdfdf9dca63294be48f9de48d03d5c2bf0f5b1d5fc9bc689d87876365fde0192
|
7
|
+
data.tar.gz: 5950abb71082b36b859c8679952a1055b6726588353db03df292e036ee11e239c41cdf0abf76995bb1a2c82d34aa21e3bf6643832ba9315e7810a6261c2938c3
|
@@ -9,5 +9,13 @@ module Warrant
|
|
9
9
|
@object_id = object_id
|
10
10
|
@relation = relation
|
11
11
|
end
|
12
|
+
|
13
|
+
def self.new_from_hash(attributes)
|
14
|
+
object_type = attributes.fetch(:object_type)
|
15
|
+
object_id = attributes.fetch(:object_id)
|
16
|
+
relation = attributes.fetch(:relation, nil)
|
17
|
+
|
18
|
+
self.new(object_type, object_id, relation)
|
19
|
+
end
|
12
20
|
end
|
13
21
|
end
|
data/lib/warrant/models/user.rb
CHANGED
@@ -87,7 +87,7 @@ module Warrant
|
|
87
87
|
users.map{ |user| User.new(user['userId'], user['email'], user['createdAt']) }
|
88
88
|
else
|
89
89
|
APIOperations.raise_error(res)
|
90
|
-
end
|
90
|
+
end
|
91
91
|
end
|
92
92
|
|
93
93
|
# Get a user with the given user_id
|
@@ -111,7 +111,7 @@ module Warrant
|
|
111
111
|
User.new(user['userId'], user['email'], user['createdAt'])
|
112
112
|
else
|
113
113
|
APIOperations.raise_error(res)
|
114
|
-
end
|
114
|
+
end
|
115
115
|
end
|
116
116
|
|
117
117
|
# Updates a user with the given user_id and params
|
@@ -182,7 +182,7 @@ module Warrant
|
|
182
182
|
roles.map{ |role| Role.new(role['roleId']) }
|
183
183
|
else
|
184
184
|
APIOperations.raise_error(res)
|
185
|
-
end
|
185
|
+
end
|
186
186
|
end
|
187
187
|
|
188
188
|
# Assign a role to a user
|
@@ -227,7 +227,7 @@ module Warrant
|
|
227
227
|
return Role.remove_from_user(user_id, role_id)
|
228
228
|
end
|
229
229
|
|
230
|
-
# List all permissions for a user
|
230
|
+
# List all permissions for a user
|
231
231
|
#
|
232
232
|
# @return [Array<Permission>] all permissions for the user
|
233
233
|
#
|
@@ -244,7 +244,7 @@ module Warrant
|
|
244
244
|
permissions.map{ |permission| Permission.new(permission['permissionId']) }
|
245
245
|
else
|
246
246
|
APIOperations.raise_error(res)
|
247
|
-
end
|
247
|
+
end
|
248
248
|
end
|
249
249
|
|
250
250
|
# Assign a permission to a user
|
@@ -337,11 +337,11 @@ module Warrant
|
|
337
337
|
case res
|
338
338
|
when Net::HTTPSuccess
|
339
339
|
res_json = JSON.parse(res.body)
|
340
|
-
subject = Subject.new(res_json['subject']['objectType'], res_json['subject']['objectId'])
|
340
|
+
subject = Subject.new(res_json['subject']['objectType'], res_json['subject']['objectId'], res_json['subject']['relation'])
|
341
341
|
Warrant.new(res_json['objectType'], res_json['objectId'], res_json['relation'], subject)
|
342
342
|
else
|
343
343
|
APIOperations.raise_error(res)
|
344
|
-
end
|
344
|
+
end
|
345
345
|
end
|
346
346
|
|
347
347
|
# Remove a user from a tenant
|
@@ -365,10 +365,10 @@ module Warrant
|
|
365
365
|
return
|
366
366
|
else
|
367
367
|
APIOperations.raise_error(res)
|
368
|
-
end
|
368
|
+
end
|
369
369
|
end
|
370
370
|
|
371
|
-
# List all users for a tenant
|
371
|
+
# List all users for a tenant
|
372
372
|
#
|
373
373
|
# @param tenant_id [String] The tenant_id of the tenant from which to fetch users
|
374
374
|
#
|
@@ -387,10 +387,10 @@ module Warrant
|
|
387
387
|
users.map{ |user| User.new(user['userId'], user['email'], user['createdAt']) }
|
388
388
|
else
|
389
389
|
APIOperations.raise_error(res)
|
390
|
-
end
|
390
|
+
end
|
391
391
|
end
|
392
392
|
|
393
|
-
# List all tenants for a user
|
393
|
+
# List all tenants for a user
|
394
394
|
#
|
395
395
|
# @return [Array<Tenant>] all tenants for the user
|
396
396
|
#
|
@@ -2,14 +2,15 @@
|
|
2
2
|
|
3
3
|
module Warrant
|
4
4
|
class Warrant
|
5
|
-
attr_reader :id, :object_type, :object_id, :relation, :subject
|
5
|
+
attr_reader :id, :object_type, :object_id, :relation, :subject, :is_direct_match
|
6
6
|
|
7
7
|
# @!visibility private
|
8
|
-
def initialize(object_type, object_id, relation, subject)
|
8
|
+
def initialize(object_type, object_id, relation, subject, is_direct_match = nil)
|
9
9
|
@object_type = object_type
|
10
10
|
@object_id = object_id
|
11
11
|
@relation = relation
|
12
12
|
@subject = subject
|
13
|
+
@is_direct_match = is_direct_match
|
13
14
|
end
|
14
15
|
|
15
16
|
# Create a new warrant that associates an object (object_type and object_id) to a subject via a relation.
|
@@ -38,7 +39,7 @@ module Warrant
|
|
38
39
|
|
39
40
|
case res
|
40
41
|
when Net::HTTPSuccess
|
41
|
-
subject = Subject.new(res_json['subject']['objectType'], res_json['subject']['objectId'])
|
42
|
+
subject = Subject.new(res_json['subject']['objectType'], res_json['subject']['objectId'], res_json['subject']['relation'])
|
42
43
|
Warrant.new(res_json['objectType'], res_json['objectId'], res_json['relation'], subject)
|
43
44
|
else
|
44
45
|
APIOperations.raise_error(res)
|
@@ -95,7 +96,7 @@ module Warrant
|
|
95
96
|
when Net::HTTPSuccess
|
96
97
|
warrants = JSON.parse(res.body)
|
97
98
|
warrants.map{ |warrant|
|
98
|
-
subject = Subject.new(warrant['subject']['objectType'], warrant['subject']['objectId'])
|
99
|
+
subject = Subject.new(warrant['subject']['objectType'], warrant['subject']['objectId'], warrant['subject']['relation'])
|
99
100
|
Warrant.new(warrant['objectType'], warrant['objectId'], warrant['relation'], subject)
|
100
101
|
}
|
101
102
|
else
|
@@ -103,6 +104,38 @@ module Warrant
|
|
103
104
|
end
|
104
105
|
end
|
105
106
|
|
107
|
+
# Query to find all warrants for a given subject.
|
108
|
+
#
|
109
|
+
# @option params [String] :object_type The type of object. Must be one of your system's existing object types. (optional)
|
110
|
+
# @option params [String] :relation The relation for this object to subject association. The relation must be valid as per the object type definition. (optional)
|
111
|
+
# @option params [String] :subject The subject to query warrants for. This should be in the format `OBJECT_TYPE:OBJECT_ID`, i.e. `user:8`
|
112
|
+
# * subject (Hash) - The specific subject for which warrants will be queried for.
|
113
|
+
# * object_type (String) - The type of object. Must be one of your system's existing object types.
|
114
|
+
# * object_id (String) - The id of the specific object.
|
115
|
+
#
|
116
|
+
# @return [Array<Warrant>] list of all warrants with provided params
|
117
|
+
#
|
118
|
+
# @raise [Warrant::InternalError]
|
119
|
+
# @raise [Warrant::InvalidRequestError]
|
120
|
+
# @raise [Warrant::NotFoundError]
|
121
|
+
# @raise [Warrant::UnauthorizedError]
|
122
|
+
# @raise [Warrant::WarrantError]
|
123
|
+
def self.query(params = {})
|
124
|
+
params[:subject] = Subject.new_from_hash(params[:subject])
|
125
|
+
res = APIOperations.get(URI.parse("#{::Warrant.config.api_base}/v1/query"), params)
|
126
|
+
|
127
|
+
case res
|
128
|
+
when Net::HTTPSuccess
|
129
|
+
warrants = JSON.parse(res.body)
|
130
|
+
warrants.map{ |warrant|
|
131
|
+
subject = Subject.new(warrant['subject']['objectType'], warrant['subject']['objectId'], warrant['subject']['relation'])
|
132
|
+
Warrant.new(warrant['objectType'], warrant['objectId'], warrant['relation'], subject, warrant['isDirectMatch'])
|
133
|
+
}
|
134
|
+
else
|
135
|
+
APIOperations.raise_error(res)
|
136
|
+
end
|
137
|
+
end
|
138
|
+
|
106
139
|
# Checks whether a specified access check is authorized or not.
|
107
140
|
# If you would like to check only one warrant, then you can exclude the op param and provide an array with one warrant.
|
108
141
|
#
|
data/lib/warrant/util.rb
CHANGED
data/lib/warrant/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: warrant
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Warrant
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2022-
|
11
|
+
date: 2022-12-12 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: Ruby library for the Warrant API at https://warrant.dev.
|
14
14
|
email: hello@warrant.dev
|
@@ -61,7 +61,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
61
61
|
- !ruby/object:Gem::Version
|
62
62
|
version: '0'
|
63
63
|
requirements: []
|
64
|
-
rubygems_version: 3.
|
64
|
+
rubygems_version: 3.2.32
|
65
65
|
signing_key:
|
66
66
|
specification_version: 4
|
67
67
|
summary: Warrant Ruby Library
|