psu_identity 0.3.0 → 0.4.0
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/.circleci/config.yml +2 -0
- data/.gitignore +2 -1
- data/.rubocop.yml +1 -0
- data/Gemfile.lock +13 -2
- data/lib/psu_identity/directory_service/client.rb +73 -0
- data/lib/psu_identity/string_helpers.rb +13 -0
- data/lib/psu_identity/version.rb +1 -1
- data/lib/psu_identity.rb +2 -0
- data/psu_identity.gemspec +1 -0
- metadata +18 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 71486dc8c78a516d121f540ce6966457d863c725c2ab6ada88f7d6090267c8b8
|
4
|
+
data.tar.gz: 1ccd98e5c98644f8d1d44999ae2ff7c88284203d3666f241f6422f4a0c122c53
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2a4e22f4667d2163fd0f9ad4f32425cf78b116b4e8db4357493c15f533d8cdddbc70ae55ebc7752c47d4891d3f4d1e69cd351b0b38e3c89da19735deb06b6f91
|
7
|
+
data.tar.gz: 19911fbf7bd37ff89bb1b508c43bb3e2fa4142d0a88df670a8a5cfae347b13993bcf15dd55000a50661ede2982fbd39c9329c48dcd9f0938480389b3b7737c91
|
data/.circleci/config.yml
CHANGED
@@ -35,6 +35,8 @@ jobs:
|
|
35
35
|
- run:
|
36
36
|
name: "Rspec"
|
37
37
|
command: |
|
38
|
+
export PSU_ID_OAUTH_CLIENT_ID=foo
|
39
|
+
export PSU_ID_OAUTH_CLIENT_SECRET=bar
|
38
40
|
RAILS_ENV=test bundle exec rspec &&
|
39
41
|
bin/cc-test-reporter format-coverage -t simplecov -o coverage/codeclimate.json coverage/.resultset.json &&
|
40
42
|
bin/cc-test-reporter upload-coverage
|
data/.gitignore
CHANGED
data/.rubocop.yml
CHANGED
data/Gemfile.lock
CHANGED
@@ -1,9 +1,10 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
psu_identity (0.
|
4
|
+
psu_identity (0.4.0)
|
5
5
|
faraday (~> 1.0)
|
6
6
|
json
|
7
|
+
oauth2
|
7
8
|
rake (>= 12.0)
|
8
9
|
|
9
10
|
GEM
|
@@ -43,8 +44,17 @@ GEM
|
|
43
44
|
faraday-retry (1.0.3)
|
44
45
|
hashdiff (1.0.1)
|
45
46
|
json (2.5.1)
|
47
|
+
jwt (2.3.0)
|
46
48
|
method_source (1.0.0)
|
49
|
+
multi_json (1.15.0)
|
50
|
+
multi_xml (0.6.0)
|
47
51
|
multipart-post (2.1.1)
|
52
|
+
oauth2 (1.4.7)
|
53
|
+
faraday (>= 0.8, < 2.0)
|
54
|
+
jwt (>= 1.0, < 3.0)
|
55
|
+
multi_json (~> 1.3)
|
56
|
+
multi_xml (~> 0.5)
|
57
|
+
rack (>= 1.2, < 3)
|
48
58
|
parallel (1.21.0)
|
49
59
|
parser (3.0.2.0)
|
50
60
|
ast (~> 2.4.1)
|
@@ -55,6 +65,7 @@ GEM
|
|
55
65
|
byebug (~> 11.0)
|
56
66
|
pry (~> 0.13.0)
|
57
67
|
public_suffix (4.0.6)
|
68
|
+
rack (2.2.3)
|
58
69
|
rainbow (3.0.0)
|
59
70
|
rake (13.0.6)
|
60
71
|
regexp_parser (2.1.1)
|
@@ -121,4 +132,4 @@ DEPENDENCIES
|
|
121
132
|
webmock
|
122
133
|
|
123
134
|
BUNDLED WITH
|
124
|
-
2.
|
135
|
+
2.3.6
|
@@ -0,0 +1,73 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'oauth2'
|
4
|
+
require 'ostruct'
|
5
|
+
|
6
|
+
# @abstract Client for querying Penn State's directory-service API: https://directory-service.k8s.psu.edu/directory-service-web/resources
|
7
|
+
module PsuIdentity::DirectoryService
|
8
|
+
class Error < StandardError; end
|
9
|
+
|
10
|
+
class NotFound < StandardError; end
|
11
|
+
|
12
|
+
class Client
|
13
|
+
attr_reader :base_url
|
14
|
+
|
15
|
+
# @param [String] base_url
|
16
|
+
def initialize(base_url: '/directory-service-web/resources')
|
17
|
+
@base_url = base_url
|
18
|
+
end
|
19
|
+
|
20
|
+
# @param [Hash] args of options to pass to the endpoint
|
21
|
+
# @option args [String] :userid of the person
|
22
|
+
def userid(userid)
|
23
|
+
process_userid_response connection.get("#{base_url}/people/#{userid}")
|
24
|
+
end
|
25
|
+
|
26
|
+
private
|
27
|
+
|
28
|
+
def process_userid_response(response)
|
29
|
+
raise NotFound if response.status == 404
|
30
|
+
|
31
|
+
raise Error.new(response.body) unless response.success?
|
32
|
+
|
33
|
+
snake_cased_response = JSON.parse(response.body).transform_keys { |str| StringHelpers.underscore(str) }
|
34
|
+
OpenStruct.new(snake_cased_response)
|
35
|
+
rescue JSON::ParserError
|
36
|
+
end
|
37
|
+
|
38
|
+
def connection
|
39
|
+
@connection ||= Faraday.new(url: endpoint, headers: auth_headers) do |conn|
|
40
|
+
conn.adapter :net_http
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
def auth_headers
|
45
|
+
{ 'Authorization' => "Bearer #{token}" }
|
46
|
+
end
|
47
|
+
|
48
|
+
def token
|
49
|
+
oauth_client = OAuth2::Client.new(client_id,
|
50
|
+
client_secret, site: oauth_endpoint,
|
51
|
+
authorize_url: '/oauth/api/authz',
|
52
|
+
token_url: '/oauth/api/token')
|
53
|
+
oauth_token = oauth_client.client_credentials.get_token
|
54
|
+
oauth_token.token
|
55
|
+
end
|
56
|
+
|
57
|
+
def client_id
|
58
|
+
@client_id ||= ENV.fetch('PSU_ID_OAUTH_CLIENT_ID')
|
59
|
+
end
|
60
|
+
|
61
|
+
def client_secret
|
62
|
+
@client_secret ||= ENV.fetch('PSU_ID_OAUTH_CLIENT_SECRET')
|
63
|
+
end
|
64
|
+
|
65
|
+
def oauth_endpoint
|
66
|
+
@oauth_endpoint ||= ENV.fetch('PSU_ID_OAUTH_ENDPOINT', 'https://acceptance-oauth2-server.qa.k8s.psu.edu')
|
67
|
+
end
|
68
|
+
|
69
|
+
def endpoint
|
70
|
+
@endpoint ||= ENV.fetch('DIRECTORY_SERVICE_ENDPOINT', 'https://acceptance-directory-service.qa.k8s.psu.edu')
|
71
|
+
end
|
72
|
+
end
|
73
|
+
end
|
data/lib/psu_identity/version.rb
CHANGED
data/lib/psu_identity.rb
CHANGED
@@ -7,8 +7,10 @@ require 'ostruct'
|
|
7
7
|
module PsuIdentity
|
8
8
|
class Error < StandardError; end
|
9
9
|
|
10
|
+
require 'psu_identity/directory_service/client'
|
10
11
|
require 'psu_identity/search_service/atomic_link'
|
11
12
|
require 'psu_identity/search_service/client'
|
12
13
|
require 'psu_identity/search_service/person'
|
14
|
+
require 'psu_identity/string_helpers'
|
13
15
|
require 'psu_identity/version'
|
14
16
|
end
|
data/psu_identity.gemspec
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: psu_identity
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Alex Kiessling
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2022-
|
11
|
+
date: 2022-02-02 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: faraday
|
@@ -38,6 +38,20 @@ dependencies:
|
|
38
38
|
- - ">="
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: oauth2
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
41
55
|
- !ruby/object:Gem::Dependency
|
42
56
|
name: rake
|
43
57
|
requirement: !ruby/object:Gem::Requirement
|
@@ -207,9 +221,11 @@ files:
|
|
207
221
|
- bin/console
|
208
222
|
- bin/setup
|
209
223
|
- lib/psu_identity.rb
|
224
|
+
- lib/psu_identity/directory_service/client.rb
|
210
225
|
- lib/psu_identity/search_service/atomic_link.rb
|
211
226
|
- lib/psu_identity/search_service/client.rb
|
212
227
|
- lib/psu_identity/search_service/person.rb
|
228
|
+
- lib/psu_identity/string_helpers.rb
|
213
229
|
- lib/psu_identity/version.rb
|
214
230
|
- psu_identity.gemspec
|
215
231
|
homepage: https://github.com/psu-libraries/psu_identity
|