sdr-client 0.55.1 → 0.59.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: 6bbde1ddcec86f8c2368ce9b336dae6dc1f52dbcf774bd0e51df25f2ffb15256
4
- data.tar.gz: 73b363c29c6b51383379eee5772eaf28b87ab98be850a848194a73986ba91d2c
3
+ metadata.gz: dc628ea7480d2ef9102b3fa37f37fe23b0fa9ee11d7a883251b465b3f7518112
4
+ data.tar.gz: 8d0e09c1a92f0ee87be08efbbd359fd4499f671a0a3de9c7edde4afeaca70942
5
5
  SHA512:
6
- metadata.gz: dbfa9a16a0f897543c93efd08c5fc85de429cfa6457c0ba460361572f403c3b646bafed431eaa431e96ade03d5fe1c2ade8b62e08185df23069818bdb41e8e63
7
- data.tar.gz: aa384461001ec16966c6287c9e595005d80a3e9a19c783b1793726ed7551190b4983fca8289f41bb9b2f336332b3732fea64d295249d5338664b593617876ba8
6
+ metadata.gz: 560557769b5867a0dbcb5c5f7ba9f5bb4ccb3b6e93637fc35df4e5a8f389dc9d4ab06bdacbb220d06d5a4f0af30761836740febe7be516a72355854fd834f581
7
+ data.tar.gz: 38a5f18f6f4bb293731058f08407dc42790ab2932c0d8ff0d9bcdaeedfb79cb880ae065756953411a2f9a7839539310fdb40982ac212a643fc0c08d789b38f46
data/.rubocop.yml CHANGED
@@ -13,6 +13,10 @@ Metrics/BlockLength:
13
13
  ExcludedMethods:
14
14
  - 'OptionParser.new'
15
15
 
16
+ Metrics/ClassLength:
17
+ Exclude:
18
+ - 'lib/sdr_client/deposit/request.rb'
19
+
16
20
  Naming/FileName:
17
21
  Exclude:
18
22
  - 'lib/sdr-client.rb'
data/.rubocop_todo.yml CHANGED
@@ -1,19 +1,33 @@
1
1
  # This configuration was generated by
2
- # `rubocop --auto-gen-config`
3
- # on 2021-03-12 13:21:16 -0600 using RuboCop version 0.79.0.
2
+ # `rubocop --auto-gen-config --auto-gen-only-exclude`
3
+ # on 2021-04-15 12:18:21 -0700 using RuboCop version 0.79.0.
4
4
  # The point is for the user to remove these configuration records
5
5
  # one by one as the offenses are removed from the code base.
6
6
  # Note that changes in the inspected code, or installation of new
7
7
  # versions of RuboCop, may require this file to be generated again.
8
8
 
9
9
  # Offense count: 1
10
+ # Configuration parameters: Max.
10
11
  Metrics/AbcSize:
11
- Max: 16
12
+ Exclude:
13
+ - 'lib/sdr_client/deposit/model_process.rb'
14
+
15
+ # Offense count: 1
16
+ # Configuration parameters: Max.
17
+ Metrics/CyclomaticComplexity:
18
+ Exclude:
19
+ - 'lib/sdr_client/cli.rb'
12
20
 
13
21
  # Offense count: 9
14
- # Configuration parameters: CountComments, ExcludedMethods.
22
+ # Configuration parameters: CountComments, Max, ExcludedMethods.
15
23
  Metrics/MethodLength:
16
- Max: 15
24
+ Exclude:
25
+ - 'lib/sdr_client/cli.rb'
26
+ - 'lib/sdr_client/deposit/file.rb'
27
+ - 'lib/sdr_client/deposit/model_process.rb'
28
+ - 'lib/sdr_client/deposit/process.rb'
29
+ - 'lib/sdr_client/deposit/request.rb'
30
+ - 'lib/sdr_client/login.rb'
17
31
 
18
32
  # Offense count: 231
19
33
  # Cop supports --auto-correct.
data/README.md CHANGED
@@ -51,3 +51,8 @@ View the object:
51
51
  sdr --service-url https://sdr-api-server:3000 get druid:bw581ng3176
52
52
  {"type":"http://cocina.sul.stanford.edu/models/document.jsonld","externalIdentifier":"druid:bw581ng3176","label":"Something something better title","version":1,"access":{"access":"stanford","copyright":"This work is copyrighted by the creator.","download":"stanford","useAndReproductionStatement":"This document is available only to the Stanford faculty, staff and student community."},"administrative":{"hasAdminPolicy":"druid:zx485kb6348"},"description":{"title":[{"value":"Something something better title"}],"contributor":[{"name":[{"value":"Hodge, Amy"}],"type":"person","role":[{"value":"Author"},{"value":"author","uri":"http://id.loc.gov/vocabulary/relators/aut","source":{"code":"marcrelator","uri":"http://id.loc.gov/vocabulary/relators/"}},{"value":"Creator"}]}],"form":[{"structuredValue":[{"value":"Text","type":"type"},{"value":"Report","type":"subtype"}],"type":"resource type","source":{"value":"Stanford self-deposit resource types"}},{"value":"reports","type":"genre","uri":"http://vocab.getty.edu/aat/300027267","source":{"code":"aat"}},{"value":"text","type":"resource type","source":{"value":"MODS resource types"}}],"note":[{"value":";alkdfjlsadkjf;l","type":"summary"},{"value":"amyhodge@stanford.edu","type":"contact","displayLabel":"Contact"}],"subject":[{"value":"lkfj","type":"topic"},{"value":";kfj","type":"topic"},{"value":"fjwelkb","type":"topic"}]},"identification":{"sourceId":"hydrus:20"},"structural":{"contains":[{"type":"http://cocina.sul.stanford.edu/models/resources/file.jsonld","externalIdentifier":"bw581ng3176_1","label":"Test file","version":1,"structural":{"contains":[{"type":"http://cocina.sul.stanford.edu/models/file.jsonld","externalIdentifier":"druid:bw581ng3176/test.txt","label":"test.txt","filename":"test.txt","size":11,"version":1,"hasMimeType":"text/plain","hasMessageDigests":[{"type":"sha1","digest":"5d39343e4bb48abd97f759828282f5ebbac56c5e"},{"type":"md5","digest":"63b8812b0c05722a9d6c51cbd2bfb54b"}],"access":{"access":"world","download":"world"},"administrative":{"sdrPreserve":true,"shelve":true}}]}}]}}
53
53
  ```
54
+
55
+ Display version of sdr-client:
56
+ ```
57
+ sdr version
58
+ ```
data/exe/sdr CHANGED
@@ -19,9 +19,6 @@ end
19
19
  global.order!
20
20
  command = ARGV.shift
21
21
 
22
- retrieve_options = OptionParser.new do |opts|
23
- end
24
-
25
22
  deposit_options = OptionParser.new do |opts|
26
23
  opts.banner = "Usage: sdr #{command} [options]"
27
24
  opts.on('--label LABEL', 'The object label') do |label|
@@ -97,10 +94,11 @@ end
97
94
  SdrClient::CLI.help unless command
98
95
 
99
96
  subcommands = {
100
- 'get' => retrieve_options,
97
+ 'get' => OptionParser.new,
101
98
  'deposit' => deposit_options,
102
99
  'register' => deposit_options,
103
- 'login' => OptionParser.new
100
+ 'login' => OptionParser.new,
101
+ 'version' => OptionParser.new
104
102
  }
105
103
 
106
104
  unless subcommands.key?(command)
@@ -35,6 +35,9 @@ module SdrClient
35
35
  login
36
36
  Will prompt for email & password and exchange it for an login token, which it saves in ~/.sdr/token
37
37
 
38
+ version
39
+ Display the sdr-client version
40
+
38
41
  HELP
39
42
 
40
43
  def self.start(command, options, arguments = [])
@@ -46,6 +49,8 @@ module SdrClient
46
49
  when 'login'
47
50
  status = SdrClient::Login.run(options)
48
51
  puts status.failure if status.failure?
52
+ when 'version'
53
+ puts SdrClient::VERSION
49
54
  else
50
55
  raise "Unknown command #{command}"
51
56
  end
@@ -21,6 +21,7 @@ module SdrClient
21
21
  catkey: nil,
22
22
  embargo_release_date: nil,
23
23
  embargo_access: 'world',
24
+ embargo_download: 'world',
24
25
  source_id:,
25
26
  url:,
26
27
  files: [],
@@ -41,6 +42,7 @@ module SdrClient
41
42
  catkey: catkey,
42
43
  embargo_release_date: embargo_release_date,
43
44
  embargo_access: embargo_access,
45
+ embargo_download: embargo_download,
44
46
  viewing_direction: viewing_direction,
45
47
  files_metadata: augmented_metadata)
46
48
  connection = Connection.new(url: url)
@@ -6,15 +6,21 @@ module SdrClient
6
6
  class CreateResource
7
7
  DRO_PATH = '/v1/resources'
8
8
 
9
- def self.run(accession:, metadata:, logger:, connection:)
10
- new(accession: accession, metadata: metadata, logger: logger, connection: connection).run
9
+ def self.run(accession:, assign_doi: false, metadata:, logger:, connection:)
10
+ new(accession: accession,
11
+ assign_doi: assign_doi,
12
+ metadata: metadata,
13
+ logger: logger,
14
+ connection: connection).run
11
15
  end
12
16
 
13
17
  # @param [Boolean] accession should the accessionWF be started
18
+ # @param [Boolean] assign_doi should a DOI be assigned to this item
14
19
  # @param [Cocina::Models::RequestDRO, Cocina::Models::RequestCollection] metadata
15
20
  # @param [Hash<Symbol,String>] the result of the metadata call
16
- def initialize(accession:, metadata:, logger:, connection:)
21
+ def initialize(accession:, assign_doi:, metadata:, logger:, connection:)
17
22
  @accession = accession
23
+ @assign_doi = assign_doi
18
24
  @metadata = metadata
19
25
  @logger = logger
20
26
  @connection = connection
@@ -39,15 +45,23 @@ module SdrClient
39
45
  json = metadata.to_json
40
46
  logger.debug("Starting upload metadata: #{json}")
41
47
 
42
- connection.post(path, json, 'Content-Type' => 'application/json')
48
+ connection.post(path, json,
49
+ 'Content-Type' => 'application/json',
50
+ 'X-Cocina-Models-Version' => Cocina::Models::VERSION)
43
51
  end
44
52
 
45
53
  def accession?
46
54
  @accession
47
55
  end
48
56
 
57
+ def assign_doi?
58
+ @assign_doi
59
+ end
60
+
49
61
  def path
50
- "#{DRO_PATH}?accession=#{accession?}"
62
+ params = { accession: accession? }
63
+ params[:assign_doi] = true if assign_doi? # false is default
64
+ DRO_PATH + '?' + params.map { |k, v| "#{k}=#{v}" }.join('&')
51
65
  end
52
66
  end
53
67
  end
@@ -6,15 +6,16 @@ module SdrClient
6
6
  class File
7
7
  # rubocop:disable Metrics/ParameterLists
8
8
  def initialize(external_identifier:, label:, filename:,
9
- access: 'world', preserve: true, shelve: true,
9
+ access: 'dark', download: 'none', preserve: true, shelve: true,
10
10
  publish: true, mime_type: nil, md5: nil, sha1: nil,
11
11
  use: nil)
12
12
  @external_identifier = external_identifier
13
13
  @label = label
14
14
  @filename = filename
15
15
  @access = access
16
+ @download = download
16
17
  @preserve = preserve
17
- @shelve = shelve
18
+ @shelve = access == 'dark' ? false : shelve
18
19
  @publish = publish
19
20
  @mime_type = mime_type
20
21
  @md5 = md5
@@ -23,7 +24,6 @@ module SdrClient
23
24
  end
24
25
  # rubocop:enable Metrics/ParameterLists
25
26
 
26
- # rubocop:disable Metrics/MethodLength
27
27
  def as_json
28
28
  {
29
29
  "type": 'http://cocina.sul.stanford.edu/models/file.jsonld',
@@ -31,7 +31,8 @@ module SdrClient
31
31
  filename: @filename,
32
32
  externalIdentifier: @external_identifier,
33
33
  access: {
34
- access: @access
34
+ access: @access,
35
+ download: @download
35
36
  },
36
37
  administrative: {
37
38
  sdrPreserve: @preserve,
@@ -45,7 +46,6 @@ module SdrClient
45
46
  json['use'] = @use if @use
46
47
  end
47
48
  end
48
- # rubocop:enable Metrics/MethodLength
49
49
 
50
50
  private
51
51
 
@@ -5,7 +5,7 @@ module SdrClient
5
5
  # This represents the FileSet metadata that we send to the server for doing a deposit
6
6
  class FileSet
7
7
  # @param [Array] uploads
8
- # @param [Hash<String,Hash<String,String>>] the file level metadata
8
+ # @param [Hash<String,Hash<String,String>>] uploads_metadata the file level metadata
9
9
  # @param [Array] files
10
10
  # @param [String] label
11
11
  def initialize(uploads: [], uploads_metadata: {}, files: [], label:)
@@ -10,14 +10,19 @@ module SdrClient
10
10
  # @param [Connection] connection the connection to use
11
11
  # @param [Array<String>] files a list of file names to upload
12
12
  # @param [Boolean] accession should the accessionWF be started
13
+ # @param [Boolean] assign_doi should a DOI be assigned to this item
13
14
  # @param [Logger] logger the logger to use
14
- def initialize(request_dro:, connection:,
15
- files: [], accession:, logger: Logger.new(STDOUT))
15
+ def initialize(request_dro:, # rubocop:disable Metrics/ParameterLists
16
+ connection:,
17
+ files: [], accession:,
18
+ assign_doi: false,
19
+ logger: Logger.new(STDOUT))
16
20
  @files = files
17
21
  @connection = connection
18
22
  @request_dro = request_dro
19
23
  @logger = logger
20
24
  @accession = accession
25
+ @assign_doi = assign_doi
21
26
  end
22
27
 
23
28
  def run
@@ -30,6 +35,7 @@ module SdrClient
30
35
  connection: connection)
31
36
  new_request_dro = UpdateDroWithFileIdentifiers.update(request_dro: request_dro, upload_responses: upload_responses)
32
37
  CreateResource.run(accession: @accession,
38
+ assign_doi: @assign_doi,
33
39
  metadata: new_request_dro,
34
40
  logger: logger,
35
41
  connection: connection)
@@ -10,18 +10,21 @@ module SdrClient
10
10
  # @param [Class] grouping_strategy class whose run method groups an array of uploads
11
11
  # @param [String] connection the server connection to use
12
12
  # @param [Array<String>] files a list of file names to upload
13
+ # @param [Boolean] assign_doi should a DOI be assigned to this item
13
14
  # @param [Boolean] accession should the accessionWF be started
14
15
  # @param [Logger] logger the logger to use
15
16
  #
16
17
  # rubocop:disable Metrics/ParameterLists
17
18
  def initialize(metadata:, grouping_strategy: SingleFileGroupingStrategy,
18
- connection:, files: [], accession:, logger: Logger.new(STDOUT))
19
+ connection:, files: [], accession:, assign_doi: false,
20
+ logger: Logger.new(STDOUT))
19
21
  @files = files
20
22
  @connection = connection
21
23
  @metadata = metadata
22
24
  @logger = logger
23
25
  @grouping_strategy = grouping_strategy
24
26
  @accession = accession
27
+ @assign_doi = assign_doi
25
28
  end
26
29
  # rubocop:enable Metrics/ParameterLists
27
30
 
@@ -40,6 +43,7 @@ module SdrClient
40
43
  request = metadata_builder.with_uploads(upload_responses)
41
44
  model = Cocina::Models.build_request(request.as_json.with_indifferent_access)
42
45
  CreateResource.run(accession: @accession,
46
+ assign_doi: @assign_doi,
43
47
  metadata: model,
44
48
  logger: logger,
45
49
  connection: connection)
@@ -12,6 +12,7 @@ module SdrClient
12
12
  # @param [Hash<String, Hash<String, String>>] files_metadata file name, hash of additional file metadata
13
13
  # Additional metadata includes access, preserve, shelve, publish, md5, sha1
14
14
  # rubocop:disable Metrics/ParameterLists
15
+ # rubocop:disable Metrics/AbcSize
15
16
  def initialize(label: nil,
16
17
  access: 'dark',
17
18
  download: 'none',
@@ -23,6 +24,7 @@ module SdrClient
23
24
  catkey: nil,
24
25
  embargo_release_date: nil,
25
26
  embargo_access: 'world',
27
+ embargo_download: 'world',
26
28
  type: 'http://cocina.sul.stanford.edu/models/object.jsonld',
27
29
  viewing_direction: nil,
28
30
  file_sets: [],
@@ -34,6 +36,7 @@ module SdrClient
34
36
  @catkey = catkey
35
37
  @embargo_release_date = embargo_release_date
36
38
  @embargo_access = embargo_access
39
+ @embargo_download = embargo_download
37
40
  @access = access
38
41
  @download = download
39
42
  @use_statement = use_statement
@@ -44,6 +47,7 @@ module SdrClient
44
47
  @viewing_direction = viewing_direction
45
48
  end
46
49
  # rubocop:enable Metrics/ParameterLists
50
+ # rubocop:enable Metrics/AbcSize
47
51
 
48
52
  def as_json
49
53
  {
@@ -58,6 +62,7 @@ module SdrClient
58
62
  end
59
63
 
60
64
  # @return [Request] a clone of this request with the file_sets added
65
+ # rubocop:disable Metrics/AbcSize
61
66
  def with_file_sets(file_sets)
62
67
  Request.new(label: label,
63
68
  access: access,
@@ -69,17 +74,22 @@ module SdrClient
69
74
  catkey: catkey,
70
75
  embargo_release_date: embargo_release_date,
71
76
  embargo_access: embargo_access,
77
+ embargo_download: embargo_download,
72
78
  type: type,
73
79
  use_statement: use_statement,
74
80
  viewing_direction: viewing_direction,
75
81
  file_sets: file_sets,
76
82
  files_metadata: files_metadata)
77
83
  end
84
+ # rubocop:enable Metrics/AbcSize
78
85
 
79
86
  # @param [String] filename
80
87
  # @return [Hash] the metadata for the file
81
88
  def for(filename)
82
- files_metadata.fetch(filename, {})
89
+ metadata = files_metadata.fetch(filename, {}).with_indifferent_access
90
+ metadata[:access] = access unless metadata.key?(:access)
91
+ metadata[:download] = download unless metadata.key?(:download)
92
+ metadata
83
93
  end
84
94
 
85
95
  attr_reader :type
@@ -87,7 +97,7 @@ module SdrClient
87
97
  private
88
98
 
89
99
  attr_reader :access, :label, :file_sets, :source_id, :catkey, :apo, :collection,
90
- :files_metadata, :embargo_release_date, :embargo_access,
100
+ :files_metadata, :embargo_release_date, :embargo_access, :embargo_download,
91
101
  :viewing_direction, :use_statement, :copyright, :download
92
102
 
93
103
  def administrative
@@ -121,7 +131,8 @@ module SdrClient
121
131
  if embargo_release_date
122
132
  json[:embargo] = {
123
133
  releaseDate: embargo_release_date.strftime('%FT%T%:z'),
124
- access: embargo_access
134
+ access: embargo_access,
135
+ download: embargo_download
125
136
  }
126
137
  end
127
138
  end
@@ -37,7 +37,9 @@ module SdrClient
37
37
  json = metadata.to_json
38
38
  logger.debug("Starting upload metadata: #{json}")
39
39
 
40
- connection.put(path(metadata), json, 'Content-Type' => 'application/json')
40
+ connection.put(path(metadata), json,
41
+ 'Content-Type' => 'application/json',
42
+ 'X-Cocina-Models-Version' => Cocina::Models::VERSION)
41
43
  end
42
44
 
43
45
  def path(metadata)
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module SdrClient
4
- VERSION = '0.55.1'
4
+ VERSION = '0.59.0'
5
5
  end
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.58.1'
31
+ spec.add_dependency 'cocina-models', '~> 0.61.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.55.1
4
+ version: 0.59.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: 2021-03-31 00:00:00.000000000 Z
11
+ date: 2021-07-14 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.58.1
33
+ version: 0.61.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.58.1
40
+ version: 0.61.0
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: dry-monads
43
43
  requirement: !ruby/object:Gem::Requirement