warrant 2.1.0 → 2.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/warrant.rb +47 -9
- data/lib/warrant/version.rb +1 -1
- data/lib/warrant/warrant_query.rb +67 -0
- data/lib/warrant.rb +1 -0
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b2de57e7f6362b34f03718a734f921659060d75eb720068cb4b891dfd0b54040
|
4
|
+
data.tar.gz: d410a14ae055941fd09cfc8476d6faf9d228f39596e5b6414b58a38520cf50ac
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ebd8297df53e8f8e2baa67bd602587344ef8ad2ffcc1db03a8e247a3a4cf2e41f55dd90916dd93196398a21a39a726ec8d4871cb3cd7f3f3c14ba9e6dd27ca14
|
7
|
+
data.tar.gz: 3e6b64ac8e89d4282f235190d9873045d608ce2a1eea4f4adbf0bf95924fbe2046321340d05b73c65eeffbfcd5c9d702ebdfed238af56cceb11aaa943b463ec3
|
@@ -88,29 +88,67 @@ module Warrant
|
|
88
88
|
end
|
89
89
|
end
|
90
90
|
|
91
|
-
# Query to find all warrants for a given subject.
|
91
|
+
# Query to find all warrants for a given object or subject.
|
92
92
|
#
|
93
|
-
# @
|
94
|
-
# @option
|
95
|
-
# @option
|
93
|
+
# @param warrant_query [WarrantQuery] Query to run for a set of warrants.
|
94
|
+
# @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)
|
95
|
+
# @option filters [Integer] :limit A positive integer representing the max number of items to return in response. (optional)
|
96
96
|
#
|
97
|
-
# @return [
|
97
|
+
# @return [Hash] Query result with `result` listing warrants returned and `meta` with metadata for the selected object types.
|
98
98
|
#
|
99
99
|
# @raise [Warrant::InternalError]
|
100
100
|
# @raise [Warrant::InvalidParameterError]
|
101
101
|
# @raise [Warrant::MissingRequiredParameterError]
|
102
102
|
# @raise [Warrant::UnauthorizedError]
|
103
103
|
# @raise [Warrant::WarrantError]
|
104
|
-
def self.query(
|
105
|
-
res = APIOperations.get(URI.parse("#{::Warrant.config.api_base}/v1/query"),
|
104
|
+
def self.query(warrant_query = WarrantQuery.new, filters = {})
|
105
|
+
res = APIOperations.get(URI.parse("#{::Warrant.config.api_base}/v1/query"), { "q": warrant_query.to_query_param, **filters })
|
106
106
|
|
107
107
|
case res
|
108
108
|
when Net::HTTPSuccess
|
109
|
-
|
110
|
-
|
109
|
+
query_result = JSON.parse(res.body)
|
110
|
+
query_result['result'] = query_result['result'].map{ |warrant|
|
111
111
|
subject = Subject.new(warrant['subject']['objectType'], warrant['subject']['objectId'], warrant['subject']['relation'])
|
112
112
|
Warrant.new(warrant['objectType'], warrant['objectId'], warrant['relation'], subject, warrant['context'], warrant['isImplicit'])
|
113
113
|
}
|
114
|
+
|
115
|
+
if query_result['meta']['feature']
|
116
|
+
query_result['meta']['feature'].each{ |featureId, feature|
|
117
|
+
query_result['meta']['feature'][featureId] = Feature.new(feature['featureId'])
|
118
|
+
}
|
119
|
+
end
|
120
|
+
|
121
|
+
if query_result['meta']['pricing-tier']
|
122
|
+
query_result['meta']['pricing-tier'].each{ |pricingTierId, pricingTier|
|
123
|
+
query_result['meta']['pricing-tier'][pricingTierId] = PricingTier.new(pricingTier['pricingTierId'])
|
124
|
+
}
|
125
|
+
end
|
126
|
+
|
127
|
+
if query_result['meta']['permission']
|
128
|
+
query_result['meta']['permission'].each{ |permissionId, permission|
|
129
|
+
query_result['meta']['permission'][permissionId] = Permission.new(permission['permissionId'], permission['name'], permission['description'])
|
130
|
+
}
|
131
|
+
end
|
132
|
+
|
133
|
+
if query_result['meta']['role']
|
134
|
+
query_result['meta']['role'].each{ |roleId, role|
|
135
|
+
query_result['meta']['role'][roleId] = Role.new(role['roleId'], role['name'], role['description'])
|
136
|
+
}
|
137
|
+
end
|
138
|
+
|
139
|
+
if query_result['meta']['user']
|
140
|
+
query_result['meta']['user'].each{ |userId, user|
|
141
|
+
query_result['meta']['user'][userId] = User.new(user['userId'], user['email'], user['createdAt'])
|
142
|
+
}
|
143
|
+
end
|
144
|
+
|
145
|
+
if query_result['meta']['tenant']
|
146
|
+
query_result['meta']['tenant'].each{ |tenantId, tenant|
|
147
|
+
query_result['meta']['tenant'][tenantId] = Tenant.new(tenant['tenantId'], tenant['name'], tenant['createdAt'])
|
148
|
+
}
|
149
|
+
end
|
150
|
+
|
151
|
+
query_result
|
114
152
|
else
|
115
153
|
APIOperations.raise_error(res)
|
116
154
|
end
|
data/lib/warrant/version.rb
CHANGED
@@ -0,0 +1,67 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Warrant
|
4
|
+
class WarrantQuery
|
5
|
+
attr_accessor :select_clause, :for_clause, :where_clause
|
6
|
+
|
7
|
+
def initialize
|
8
|
+
@select_clause = []
|
9
|
+
@for_clause = {}
|
10
|
+
@where_clause = {}
|
11
|
+
end
|
12
|
+
|
13
|
+
def select(*object_types)
|
14
|
+
@select_clause = object_types
|
15
|
+
self
|
16
|
+
end
|
17
|
+
|
18
|
+
def select_explicit(*object_types)
|
19
|
+
@select_clause = "explicit #{object_types}"
|
20
|
+
self
|
21
|
+
end
|
22
|
+
|
23
|
+
def for(for_filters)
|
24
|
+
@for_clause = @for_clause.merge(for_filters)
|
25
|
+
self
|
26
|
+
end
|
27
|
+
|
28
|
+
def where(where_filters)
|
29
|
+
@where_clause = @where_clause.merge(where_filters)
|
30
|
+
self
|
31
|
+
end
|
32
|
+
|
33
|
+
def to_query_param
|
34
|
+
if @select_clause.length == 0 || @for_clause.empty?
|
35
|
+
raise "Must have a select and for clause"
|
36
|
+
end
|
37
|
+
|
38
|
+
query = "SELECT #{@select_clause.join(",")} FOR #{filters_hash_to_string(@for_clause)}"
|
39
|
+
query += " WHERE #{filters_hash_to_string(@where_clause)}" unless @where_clause.empty?
|
40
|
+
|
41
|
+
query
|
42
|
+
end
|
43
|
+
|
44
|
+
private
|
45
|
+
|
46
|
+
def filters_hash_to_string(filters)
|
47
|
+
filter_string = ""
|
48
|
+
|
49
|
+
if filters[:object]
|
50
|
+
filter_string += "object=#{filters[:object]}"
|
51
|
+
elsif filters[:subject]
|
52
|
+
filter_string += "subject=#{filters[:subject]}"
|
53
|
+
end
|
54
|
+
|
55
|
+
if filters[:context]
|
56
|
+
context_values = []
|
57
|
+
filters[:context].each{ |k, v|
|
58
|
+
context_values.push("#{k}=#{v}")
|
59
|
+
}
|
60
|
+
|
61
|
+
filter_string += " AND context=[#{context_values.join(" ")}]"
|
62
|
+
end
|
63
|
+
|
64
|
+
filter_string
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
data/lib/warrant.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: 2.
|
4
|
+
version: 2.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: 2023-01-
|
11
|
+
date: 2023-01-27 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
|
@@ -41,6 +41,7 @@ files:
|
|
41
41
|
- lib/warrant/version.rb
|
42
42
|
- lib/warrant/warrant_configuration.rb
|
43
43
|
- lib/warrant/warrant_object.rb
|
44
|
+
- lib/warrant/warrant_query.rb
|
44
45
|
homepage: https://github.com/warrant-dev/warrant-ruby
|
45
46
|
licenses:
|
46
47
|
- MIT
|