clonk 1.0.0alpha → 1.0.0alpha3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. checksums.yaml +4 -4
  2. data/lib/clonk.rb +37 -4
  3. metadata +3 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 1ae127e233c70507fde9f7a04c8aec698c74c3ad9d19712d80de703710e2af11
4
- data.tar.gz: 5a864090ca4dfbeeb171d7a1efd88aa1db1312ccb2d4cbadeae764b3b512dc9a
3
+ metadata.gz: c0c722bf99f97acd973f4cf92eeaa6823b92abc6cdd99cf77f7e32cac22915e7
4
+ data.tar.gz: d0af13e57c50e1baca63d908dfee9d3c1a5dbec49b890899fdb7451262b3af36
5
5
  SHA512:
6
- metadata.gz: eb6a3a1e48a07ed3207a4ac25b5a74d66b1b9249c2feb80c1c5a744b3910474a052c0597620137e6641be365cc0dceecaabb9c27efce3e37cfa72506146ce9f6
7
- data.tar.gz: 570835b981709c60280f8014d4d34ff486366a46c43c494d7b10b4e437e186fedb98047d24dca9db8134ef7eecc8881b8daa4948d0fac0a26553fc4f1efad815
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.0alpha
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: