sdr-client 0.17.1 → 0.21.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 67db5756bbb0378efa0f8fc14cf690b790ce8165142487e79b1449d497c30001
4
- data.tar.gz: 4c6d3c6a5108eece153ebb3880129210423568025db785cbbd12b4c0988d4a3d
3
+ metadata.gz: 8dab3e033cd3f0fd0eae7045c3565f7c24300d99ebcd7141777eb0d005847497
4
+ data.tar.gz: 25a76561f9aafdcc4a575030ca9bb750e8cdf036b60c14cc92f413bbde4668d2
5
5
  SHA512:
6
- metadata.gz: 54da060f2498da93b90292f07ecb3e3076418acfbf19a2a233867a11a251075c1bb56a7b497f11ebe7194eb035285525f9948f90939acfc753bfd2f746b3ad63
7
- data.tar.gz: bb9a4281ea61338b4acccbca9c2af67801982202378172682e2d17f57d8027018644e1b54d2d3c19a1969328b818f1ce055c04d7040d14c50c7cdab026d572e1
6
+ metadata.gz: fa6080f541ce480fc8ca31f5f063404090235e8edce6849aa10c4f50f1a00ef83a166ea1c97ad579e094fbf9b5d8f24df73debc68ce567e1a7886dc7a491b643
7
+ data.tar.gz: a915029ed2f58221fe4c2418e8fef194f11eb6bde24af289dc9f52da438841a4bab90fec7a95a94eeaa22334e2e72897a6047f01c5909ed995d371473b1c0295
@@ -9,6 +9,8 @@ AllCops:
9
9
 
10
10
  Layout/LineLength:
11
11
  Max: 120
12
+ Exclude:
13
+ - 'spec/sdr_client/deposit/process_spec.rb'
12
14
 
13
15
  Metrics/BlockLength:
14
16
  Exclude:
@@ -4,6 +4,8 @@ require 'dry/monads'
4
4
  require 'faraday'
5
5
  require 'active_support'
6
6
  require 'active_support/core_ext/object/json'
7
+ require 'active_support/core_ext/hash/indifferent_access'
8
+ require 'cocina/models'
7
9
 
8
10
  require 'sdr_client/version'
9
11
  require 'sdr_client/deposit'
@@ -12,6 +14,7 @@ require 'sdr_client/credentials'
12
14
  require 'sdr_client/login'
13
15
  require 'sdr_client/login_prompt'
14
16
  require 'sdr_client/cli'
17
+ require 'sdr_client/connection'
15
18
 
16
19
  module SdrClient
17
20
  class Error < StandardError; end
@@ -0,0 +1,41 @@
1
+ # frozen_string_literal: true
2
+
3
+ module SdrClient
4
+ # The connection to the server
5
+ class Connection
6
+ include Dry::Monads[:result]
7
+
8
+ def initialize(url:, token: Credentials.read)
9
+ @url = url
10
+ @token = token
11
+ end
12
+
13
+ def connection
14
+ @connection ||= Faraday.new(url: url) do |conn|
15
+ conn.authorization :Bearer, token
16
+ conn.adapter :net_http
17
+ end
18
+ end
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
+
35
+ delegate :put, :post, to: :connection
36
+
37
+ private
38
+
39
+ attr_reader :url, :token
40
+ end
41
+ end
@@ -25,8 +25,6 @@ module SdrClient
25
25
  files_metadata: {},
26
26
  grouping_strategy: SingleFileGroupingStrategy,
27
27
  logger: Logger.new(STDOUT))
28
- token = Credentials.read
29
-
30
28
  augmented_metadata = FileMetadataBuilder.build(files: files, files_metadata: files_metadata)
31
29
  metadata = Request.new(label: label,
32
30
  type: type,
@@ -41,7 +39,8 @@ module SdrClient
41
39
  embargo_access: embargo_access,
42
40
  viewing_direction: viewing_direction,
43
41
  files_metadata: augmented_metadata)
44
- Process.new(metadata: metadata, url: url, token: token, files: files,
42
+ connection = Connection.new(url: url)
43
+ Process.new(metadata: metadata, connection: connection, files: files,
45
44
  grouping_strategy: grouping_strategy, logger: logger).run
46
45
  end
47
46
  # rubocop:enable Metrics/MethodLength
@@ -34,9 +34,10 @@ module SdrClient
34
34
  administrative: {
35
35
  sdrPreserve: @preserve,
36
36
  shelve: @shelve
37
- }
37
+ },
38
+ version: 1,
39
+ hasMessageDigests: message_digests
38
40
  }.tap do |json|
39
- json['hasMessageDigests'] = message_digests unless message_digests.empty?
40
41
  json['hasMimeType'] = @mime_type if @mime_type
41
42
  json['use'] = @use if @use
42
43
  end
@@ -25,7 +25,8 @@ module SdrClient
25
25
  "label": label,
26
26
  structural: {
27
27
  contains: files.map(&:as_json)
28
- }
28
+ },
29
+ version: 1
29
30
  }
30
31
  end
31
32
 
@@ -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 [String] url the server to send to
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:, url:,
16
- token:, files: [], logger: Logger.new(STDOUT))
14
+ def initialize(request_dro:, connection:, files: [], logger: Logger.new(STDOUT))
17
15
  @files = files
18
- @url = url
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, :url, :token, :logger
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 ||=
@@ -9,22 +9,19 @@ module SdrClient
9
9
  DRO_PATH = '/v1/resources'
10
10
  # @param [Request] metadata information about the object
11
11
  # @param [Class] grouping_strategy class whose run method groups an array of uploads
12
- # @param [String] url the server to send to
13
- # @param [String] token the bearer auth token for the server
12
+ # @param [String] connection the server connection to use
14
13
  # @param [Array<String>] files a list of file names to upload
15
14
  # @param [Logger] logger the logger to use
16
- # rubocop:disable Metrics/ParameterLists
17
- def initialize(metadata:, grouping_strategy: SingleFileGroupingStrategy, url:,
18
- token:, files: [], logger: Logger.new(STDOUT))
15
+ def initialize(metadata:, grouping_strategy: SingleFileGroupingStrategy,
16
+ connection:, files: [], logger: Logger.new(STDOUT))
19
17
  @files = files
20
- @url = url
21
- @token = token
18
+ @connection = connection
22
19
  @metadata = metadata
23
20
  @logger = logger
24
21
  @grouping_strategy = grouping_strategy
25
22
  end
26
- # rubocop:enable Metrics/ParameterLists
27
23
 
24
+ # rubocop:disable Metrics/AbcSize
28
25
  def run
29
26
  check_files_exist
30
27
  upload_responses = UploadFiles.new(files: files,
@@ -35,12 +32,14 @@ module SdrClient
35
32
  grouping_strategy: grouping_strategy,
36
33
  logger: logger)
37
34
  request = metadata_builder.with_uploads(upload_responses)
38
- upload_metadata(request.as_json)
35
+ model = Cocina::Models.build_request(request.as_json.with_indifferent_access)
36
+ upload_metadata(model.to_h)
39
37
  end
38
+ # rubocop:enable Metrics/AbcSize
40
39
 
41
40
  private
42
41
 
43
- attr_reader :metadata, :files, :url, :token, :logger, :grouping_strategy
42
+ attr_reader :metadata, :files, :connection, :logger, :grouping_strategy
44
43
 
45
44
  def check_files_exist
46
45
  logger.info('checking to see if files exist')
@@ -68,13 +67,6 @@ module SdrClient
68
67
  raise "unexpected response: #{response.status} #{response.body}"
69
68
  end
70
69
 
71
- def connection
72
- @connection ||= Faraday.new(url: url) do |conn|
73
- conn.authorization :Bearer, token
74
- conn.adapter :net_http
75
- end
76
- end
77
-
78
70
  def mime_types
79
71
  @mime_types ||=
80
72
  Hash[
@@ -49,10 +49,10 @@ module SdrClient
49
49
  type: type,
50
50
  administrative: administrative,
51
51
  identification: identification,
52
- structural: structural
53
- }.tap do |json|
54
- json[:label] = label if label
55
- end
52
+ structural: structural,
53
+ version: 1,
54
+ label: label.nil? ? ':auto' : label
55
+ }
56
56
  end
57
57
 
58
58
  # @return [Request] a clone of this request with the file_sets added
@@ -9,7 +9,7 @@ module SdrClient
9
9
  BLOB_PATH = '/v1/direct_uploads'
10
10
  # @param [Array<String>] files a list of filepaths to upload
11
11
  # @param [Logger] logger the logger to use
12
- # @param [Faraday::Connection] connection
12
+ # @param [Connection] connection
13
13
  # @param [Hash<String,String] mime_types a map of filenames to mime types
14
14
  def initialize(files:, mime_types:, logger:, connection:)
15
15
  @files = files
@@ -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
- Credentials.write(response.body)
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
- token = Credentials.read
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
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module SdrClient
4
- VERSION = '0.17.1'
4
+ VERSION = '0.21.0'
5
5
  end
@@ -28,11 +28,11 @@ 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.0'
31
32
  spec.add_dependency 'dry-monads'
32
33
  spec.add_dependency 'faraday', '>= 0.16'
33
34
 
34
35
  spec.add_development_dependency 'bundler', '~> 2.0'
35
- spec.add_development_dependency 'cocina-models', '~> 0.28.0'
36
36
  spec.add_development_dependency 'rake', '~> 13.0'
37
37
  spec.add_development_dependency 'rspec', '~> 3.0'
38
38
  spec.add_development_dependency 'rubocop', '~> 0.79.0'
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.17.1
4
+ version: 0.21.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 00:00:00.000000000 Z
11
+ date: 2020-03-31 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -24,6 +24,20 @@ dependencies:
24
24
  - - ">="
25
25
  - !ruby/object:Gem::Version
26
26
  version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: cocina-models
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: 0.31.0
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: 0.31.0
27
41
  - !ruby/object:Gem::Dependency
28
42
  name: dry-monads
29
43
  requirement: !ruby/object:Gem::Requirement
@@ -66,20 +80,6 @@ dependencies:
66
80
  - - "~>"
67
81
  - !ruby/object:Gem::Version
68
82
  version: '2.0'
69
- - !ruby/object:Gem::Dependency
70
- name: cocina-models
71
- requirement: !ruby/object:Gem::Requirement
72
- requirements:
73
- - - "~>"
74
- - !ruby/object:Gem::Version
75
- version: 0.28.0
76
- type: :development
77
- prerelease: false
78
- version_requirements: !ruby/object:Gem::Requirement
79
- requirements:
80
- - - "~>"
81
- - !ruby/object:Gem::Version
82
- version: 0.28.0
83
83
  - !ruby/object:Gem::Dependency
84
84
  name: rake
85
85
  requirement: !ruby/object:Gem::Requirement
@@ -189,6 +189,7 @@ files:
189
189
  - lib/sdr-client.rb
190
190
  - lib/sdr_client.rb
191
191
  - lib/sdr_client/cli.rb
192
+ - lib/sdr_client/connection.rb
192
193
  - lib/sdr_client/credentials.rb
193
194
  - lib/sdr_client/deposit.rb
194
195
  - lib/sdr_client/deposit/file.rb