sdr-client 0.19.0 → 0.20.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/lib/sdr_client/connection.rb +17 -0
- data/lib/sdr_client/deposit/model_process.rb +4 -14
- data/lib/sdr_client/login.rb +2 -2
- data/lib/sdr_client/model_deposit.rb +2 -3
- data/lib/sdr_client/version.rb +1 -1
- data/sdr-client.gemspec +1 -1
- metadata +4 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e40c3f7aec5b647a05dd4c2e3289a7ed3173c2b18ac57fb74dd218cb7226db0f
|
4
|
+
data.tar.gz: 9c5029ae7bdcde2e2fd2d9261a4a282b46fc6dff09be20c7622f80413bbccb01
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9d270769997103bac784faaba63e49616c980170696de6aaa6d5c428f3fa97a5e6d14ab53572cb0b61a05efb1398d819b3b5d1caa116c7138555f4f95f6bcf99
|
7
|
+
data.tar.gz: 791d45aa87675605a7facb2ccee548780e9a6863c4c62f8f428d0b182dfdbc4c087b546e71c60a868765ab47736acb048d23fdcc46b572b47ab769946d9c19cb
|
@@ -3,6 +3,8 @@
|
|
3
3
|
module SdrClient
|
4
4
|
# The connection to the server
|
5
5
|
class Connection
|
6
|
+
include Dry::Monads[:result]
|
7
|
+
|
6
8
|
def initialize(url:, token: Credentials.read)
|
7
9
|
@url = url
|
8
10
|
@token = token
|
@@ -15,6 +17,21 @@ module SdrClient
|
|
15
17
|
end
|
16
18
|
end
|
17
19
|
|
20
|
+
# This is only available to certain blessed accounts (argo) as it gives the
|
21
|
+
# token that allows you to act as any other user. Thus the caller must authenticate
|
22
|
+
# the user (e.g. using Shibboleth) before calling this method with their email address.
|
23
|
+
# @param [String] the email address of the person to proxy to.
|
24
|
+
# @return [Result] the token for the account
|
25
|
+
def proxy(to)
|
26
|
+
response = connection.post("/v1/auth/proxy?to=#{to}")
|
27
|
+
case response.status
|
28
|
+
when 200
|
29
|
+
Success(response.body)
|
30
|
+
else
|
31
|
+
Failure("Status: #{response.status}\n#{response.body}")
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
18
35
|
delegate :put, :post, to: :connection
|
19
36
|
|
20
37
|
private
|
@@ -8,15 +8,12 @@ module SdrClient
|
|
8
8
|
class ModelProcess
|
9
9
|
DRO_PATH = '/v1/resources'
|
10
10
|
# @param [Cocina::Model::RequestDRO] request_dro for depositing
|
11
|
-
# @param [
|
12
|
-
# @param [String] token the bearer auth token for the server
|
11
|
+
# @param [Connection] connection the connection to use
|
13
12
|
# @param [Array<String>] files a list of file names to upload
|
14
13
|
# @param [Logger] logger the logger to use
|
15
|
-
def initialize(request_dro:,
|
16
|
-
token:, files: [], logger: Logger.new(STDOUT))
|
14
|
+
def initialize(request_dro:, connection:, files: [], logger: Logger.new(STDOUT))
|
17
15
|
@files = files
|
18
|
-
@
|
19
|
-
@token = token
|
16
|
+
@connection = connection
|
20
17
|
@request_dro = request_dro
|
21
18
|
@logger = logger
|
22
19
|
end
|
@@ -35,7 +32,7 @@ module SdrClient
|
|
35
32
|
|
36
33
|
private
|
37
34
|
|
38
|
-
attr_reader :request_dro, :files, :
|
35
|
+
attr_reader :request_dro, :files, :logger, :connection
|
39
36
|
|
40
37
|
def check_files_exist
|
41
38
|
logger.info('checking to see if files exist')
|
@@ -77,13 +74,6 @@ module SdrClient
|
|
77
74
|
raise "unexpected response: #{response.status} #{response.body}"
|
78
75
|
end
|
79
76
|
|
80
|
-
def connection
|
81
|
-
@connection ||= Faraday.new(url: url) do |conn|
|
82
|
-
conn.authorization :Bearer, token
|
83
|
-
conn.adapter :net_http
|
84
|
-
end
|
85
|
-
end
|
86
|
-
|
87
77
|
# Map of filenames to mimetypes
|
88
78
|
def mime_types
|
89
79
|
@mime_types ||=
|
data/lib/sdr_client/login.rb
CHANGED
@@ -7,12 +7,12 @@ module SdrClient
|
|
7
7
|
extend Dry::Monads[:result]
|
8
8
|
|
9
9
|
# @return [Result] the status of the call
|
10
|
-
def self.run(url:, login_service: LoginPrompt)
|
10
|
+
def self.run(url:, login_service: LoginPrompt, credential_store: Credentials)
|
11
11
|
request_json = JSON.generate(login_service.run)
|
12
12
|
response = Faraday.post(url + LOGIN_PATH, request_json, 'Content-Type' => 'application/json')
|
13
13
|
case response.status
|
14
14
|
when 200
|
15
|
-
|
15
|
+
credential_store.write(response.body)
|
16
16
|
Success()
|
17
17
|
when 400
|
18
18
|
Failure('Email address is not a valid email')
|
@@ -9,9 +9,8 @@ module SdrClient
|
|
9
9
|
files: [],
|
10
10
|
url:,
|
11
11
|
logger: Logger.new(STDOUT))
|
12
|
-
|
13
|
-
|
14
|
-
ModelProcess.new(request_dro: request_dro, url: url, token: token, files: files, logger: logger).run
|
12
|
+
connection = Connection.new(url: url)
|
13
|
+
ModelProcess.new(request_dro: request_dro, connection: connection, files: files, logger: logger).run
|
15
14
|
end
|
16
15
|
end
|
17
16
|
end
|
data/lib/sdr_client/version.rb
CHANGED
data/sdr-client.gemspec
CHANGED
@@ -28,7 +28,7 @@ Gem::Specification.new do |spec|
|
|
28
28
|
spec.require_paths = ['lib']
|
29
29
|
|
30
30
|
spec.add_dependency 'activesupport'
|
31
|
-
spec.add_dependency 'cocina-models', '~> 0.
|
31
|
+
spec.add_dependency 'cocina-models', '~> 0.31.0'
|
32
32
|
spec.add_dependency 'dry-monads'
|
33
33
|
spec.add_dependency 'faraday', '>= 0.16'
|
34
34
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sdr-client
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.20.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Justin Coyne
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-03-
|
11
|
+
date: 2020-03-24 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -30,14 +30,14 @@ dependencies:
|
|
30
30
|
requirements:
|
31
31
|
- - "~>"
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version: 0.
|
33
|
+
version: 0.31.0
|
34
34
|
type: :runtime
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
38
|
- - "~>"
|
39
39
|
- !ruby/object:Gem::Version
|
40
|
-
version: 0.
|
40
|
+
version: 0.31.0
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: dry-monads
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|