keycloak-ruby-client 0.0.18 → 0.0.19
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 +25 -0
- data/lib/keycloak/graphql.rb +3 -0
- data/lib/keycloak/graphql/keycloak_representation_iterator_connection.rb +101 -0
- data/lib/keycloak/version.rb +1 -1
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a21f53bd4b432715baed464f6a40ac5133c9b272
|
4
|
+
data.tar.gz: 473bcc4c2965d6cd0c4355fc74a8c336c7d48457
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 10f49dc6b19beb1f516963252159e7250f5d3362bb4e4613646e8e57f9a753d288ef2f303535cb28bd7d3d3dec756988f7669b82db1dafd25fc131ae65daa72f
|
7
|
+
data.tar.gz: a2e7c8b5ec06e0564f0ef59cd7cd53d18ca0cad799a8ed624c733cb1b6e17f4ab294904eaa69561497e69db6c3f2d16751bc32dc512b231fe33e2cd51340f1b6
|
data/README.md
CHANGED
@@ -152,6 +152,31 @@ puts user.user_info
|
|
152
152
|
puts user.realm_roles
|
153
153
|
```
|
154
154
|
|
155
|
+
### GraphQL (optional)
|
156
|
+
|
157
|
+
Integrate `RepresentationIterator` into `graphql` to support GraphQL Connections
|
158
|
+
|
159
|
+
```ruby
|
160
|
+
require 'keycloak/graphql'
|
161
|
+
```
|
162
|
+
|
163
|
+
Now you can implement a GraphQL API to find users as the following:
|
164
|
+
|
165
|
+
```ruby
|
166
|
+
field :users, Types::KeycloakUserRepresentationType.connection_type, null: true, max_page_size: 30 do
|
167
|
+
argument :briefRepresentation, Boolean, required: false
|
168
|
+
argument :email, String, required: false
|
169
|
+
argument :firstName, String, required: false
|
170
|
+
argument :lastName, String, required: false
|
171
|
+
argument :search, String, required: false
|
172
|
+
argument :username, String, required: false
|
173
|
+
end
|
174
|
+
|
175
|
+
def users(**kwargs)
|
176
|
+
Keycloak::Realm.your_realm.client.find_users(**kwargs)
|
177
|
+
end
|
178
|
+
```
|
179
|
+
|
155
180
|
## Development
|
156
181
|
|
157
182
|
After checking out the repo, run `bin/setup` to install dependencies. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
@@ -0,0 +1,101 @@
|
|
1
|
+
module GraphQL
|
2
|
+
module Relay
|
3
|
+
class KeycloakRepresentationIteratorConnection < BaseConnection
|
4
|
+
def cursor_from_node(item)
|
5
|
+
item_index = paged_nodes.index(item)
|
6
|
+
if item_index.nil?
|
7
|
+
raise("Can't generate cursor, item not found in connection: #{item}")
|
8
|
+
else
|
9
|
+
offset = item_index + (paged_nodes_offset || 0)
|
10
|
+
|
11
|
+
encode(offset.to_s)
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
# TODO: support `before`
|
16
|
+
def has_next_page
|
17
|
+
sliced_nodes_count >= (first || max_page_size)
|
18
|
+
end
|
19
|
+
|
20
|
+
# TODO: support `before`
|
21
|
+
def has_previous_page
|
22
|
+
false
|
23
|
+
end
|
24
|
+
|
25
|
+
def first
|
26
|
+
return @first if defined? @first
|
27
|
+
|
28
|
+
@first = get_limited_arg(:first)
|
29
|
+
@first = max_page_size if @first && max_page_size && @first > max_page_size
|
30
|
+
@first
|
31
|
+
end
|
32
|
+
|
33
|
+
def last
|
34
|
+
return @last if defined? @last
|
35
|
+
|
36
|
+
@last = get_limited_arg(:last)
|
37
|
+
@last = max_page_size if @last && max_page_size && @last > max_page_size
|
38
|
+
@last
|
39
|
+
end
|
40
|
+
|
41
|
+
private
|
42
|
+
|
43
|
+
# apply first / last limit results
|
44
|
+
# @return [Array]
|
45
|
+
def paged_nodes
|
46
|
+
return @paged_nodes if defined? @paged_nodes
|
47
|
+
|
48
|
+
items = sliced_nodes
|
49
|
+
|
50
|
+
if first
|
51
|
+
items.till = items.first + first
|
52
|
+
end
|
53
|
+
|
54
|
+
if max_page_size && !first && !last
|
55
|
+
items.till = items.first + max_page_size
|
56
|
+
end
|
57
|
+
|
58
|
+
@paged_nodes_offset = items.first
|
59
|
+
|
60
|
+
@paged_nodes = items.to_a
|
61
|
+
end
|
62
|
+
|
63
|
+
def paged_nodes_offset
|
64
|
+
paged_nodes && @paged_nodes_offset
|
65
|
+
end
|
66
|
+
|
67
|
+
def relation_offset(iterator)
|
68
|
+
iterator.first
|
69
|
+
end
|
70
|
+
|
71
|
+
def relation_limit(iterator)
|
72
|
+
iterator.till
|
73
|
+
end
|
74
|
+
|
75
|
+
# Apply cursors to edges
|
76
|
+
def sliced_nodes
|
77
|
+
return @sliced_nodes if defined? @sliced_nodes
|
78
|
+
|
79
|
+
@sliced_nodes = nodes
|
80
|
+
|
81
|
+
if after
|
82
|
+
@sliced_nodes.first = offset_from_cursor(after) + 1
|
83
|
+
end
|
84
|
+
|
85
|
+
@sliced_nodes
|
86
|
+
end
|
87
|
+
|
88
|
+
def sliced_nodes_count
|
89
|
+
return @sliced_nodes_count if defined? @sliced_nodes_count
|
90
|
+
|
91
|
+
@sliced_nodes_count = paged_nodes.size
|
92
|
+
end
|
93
|
+
|
94
|
+
def offset_from_cursor(cursor)
|
95
|
+
decode(cursor).to_i
|
96
|
+
end
|
97
|
+
end
|
98
|
+
|
99
|
+
BaseConnection.register_connection_implementation(Keycloak::Utils::RepresentationIterator, KeycloakRepresentationIteratorConnection)
|
100
|
+
end
|
101
|
+
end
|
data/lib/keycloak/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: keycloak-ruby-client
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.19
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Fuxin Hao
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2020-01-02 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
@@ -151,6 +151,8 @@ files:
|
|
151
151
|
- lib/keycloak/client.rb
|
152
152
|
- lib/keycloak/concerns.rb
|
153
153
|
- lib/keycloak/concerns/api_util.rb
|
154
|
+
- lib/keycloak/graphql.rb
|
155
|
+
- lib/keycloak/graphql/keycloak_representation_iterator_connection.rb
|
154
156
|
- lib/keycloak/model.rb
|
155
157
|
- lib/keycloak/model/base_representation.rb
|
156
158
|
- lib/keycloak/model/client_representation.rb
|