clonk 1.0.0alpha → 1.0.0alpha3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/clonk.rb +37 -4
- 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: c0c722bf99f97acd973f4cf92eeaa6823b92abc6cdd99cf77f7e32cac22915e7
|
4
|
+
data.tar.gz: d0af13e57c50e1baca63d908dfee9d3c1a5dbec49b890899fdb7451262b3af36
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 392a00ab4d0805bc945b4f0cc45901bc98f51dbf79e2a068812e711e106943496dddba917b7cc13b5f1f4ce211926c36969515c47e51deb2107a02ac28e48adb
|
7
|
+
data.tar.gz: edea7bd7824a35e0e7161a543cff8fb773288c7513c6152b2379c3ee2b17e1bdef181149d1007073b48ae9f131473e37488f7ac1ead6a9d8f8a75c7e1caab63b
|
data/lib/clonk.rb
CHANGED
@@ -13,6 +13,10 @@ REALM = ENV.fetch('SSO_REALM')
|
|
13
13
|
|
14
14
|
module Clonk
|
15
15
|
class << self
|
16
|
+
|
17
|
+
##
|
18
|
+
# Defines a Faraday::Connection object linked to the SSO instance.
|
19
|
+
|
16
20
|
def connection(token: nil, raise_error: true, json: true)
|
17
21
|
Faraday.new(url: BASE_URL) do |faraday|
|
18
22
|
faraday.request(json ? :json : :url_encoded)
|
@@ -22,10 +26,16 @@ module Clonk
|
|
22
26
|
end
|
23
27
|
end
|
24
28
|
|
29
|
+
##
|
30
|
+
# Returns the admin API root for the realm.
|
31
|
+
|
25
32
|
def realm_admin_root(realm = REALM)
|
26
33
|
"#{BASE_URL}/auth/admin/realms/#{realm}"
|
27
34
|
end
|
28
35
|
|
36
|
+
##
|
37
|
+
# Retrieves a token for the admin user.
|
38
|
+
|
29
39
|
def admin_token
|
30
40
|
data = {
|
31
41
|
username: USERNAME,
|
@@ -40,12 +50,28 @@ module Clonk
|
|
40
50
|
)['access_token']
|
41
51
|
end
|
42
52
|
|
53
|
+
##
|
54
|
+
# Returns a Faraday::Response for an API call via the given method.
|
55
|
+
# Always uses an admin token.
|
56
|
+
#--
|
57
|
+
# FIXME: Rename protocol to method - more descriptive
|
58
|
+
#++
|
59
|
+
|
43
60
|
def response(protocol: :get, path: '/', data: nil, token: admin_token)
|
44
61
|
return unless %i[get post put delete].include?(protocol)
|
45
62
|
|
46
63
|
conn = connection(token: token).public_send(protocol, path, data)
|
47
64
|
end
|
48
65
|
|
66
|
+
##
|
67
|
+
# Returns a parsed JSON response for an API call via the given method.
|
68
|
+
# Useful in instances where only the data is necessary, and not
|
69
|
+
# HTTP status confirmation that the desired effect was caused.
|
70
|
+
# Always uses an admin token.
|
71
|
+
#--
|
72
|
+
# FIXME: Rename protocol to method - more descriptive
|
73
|
+
#++
|
74
|
+
|
49
75
|
def parsed_response(protocol: :get, path: '/', data: nil, token: admin_token)
|
50
76
|
resp = response(protocol: protocol, path: path, data: data, token: token)
|
51
77
|
|
@@ -54,6 +80,12 @@ module Clonk
|
|
54
80
|
resp.body
|
55
81
|
end
|
56
82
|
|
83
|
+
##
|
84
|
+
# Enables permissions for the given object.
|
85
|
+
#--
|
86
|
+
# TODO: Add this method to other models that need it, if any
|
87
|
+
#++
|
88
|
+
|
57
89
|
def set_permissions(object: nil, type: nil, enabled: true, realm: REALM)
|
58
90
|
parsed_response(
|
59
91
|
protocol: :put,
|
@@ -63,6 +95,11 @@ module Clonk
|
|
63
95
|
)
|
64
96
|
end
|
65
97
|
|
98
|
+
##
|
99
|
+
# Returns the data for the permission with the given ID.
|
100
|
+
#--
|
101
|
+
# TODO: Move this method into Permission
|
102
|
+
#++
|
66
103
|
|
67
104
|
def get_permission(id: nil, realm: REALM)
|
68
105
|
parsed_response(
|
@@ -70,10 +107,6 @@ module Clonk
|
|
70
107
|
path: "#{client_url(client: @realm_management, realm: realm)}/authz/resource-server/permission/scope/#{id}"
|
71
108
|
)
|
72
109
|
end
|
73
|
-
|
74
|
-
# getPermissionScopes???
|
75
|
-
# getPermissionResources???
|
76
|
-
|
77
110
|
end
|
78
111
|
end
|
79
112
|
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: clonk
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.0alpha3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Simon Fish
|
@@ -48,7 +48,8 @@ files:
|
|
48
48
|
- lib/clonk.rb
|
49
49
|
homepage:
|
50
50
|
licenses: []
|
51
|
-
metadata:
|
51
|
+
metadata:
|
52
|
+
yard.run: yardoc
|
52
53
|
post_install_message:
|
53
54
|
rdoc_options: []
|
54
55
|
require_paths:
|