sdr-client 0.13.2 → 0.16.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: 99655b642622c2a87d9021fb1a30b4ffad6cf50eafded596239a1e6a4c9e835e
4
- data.tar.gz: 240394c4ccb55140a986abd586a052f6e64ea3900b1df1da6b18e0a08fb93acb
3
+ metadata.gz: 51cea2d7a34db14a8fbef003f8e02b8db1483344724e2d1201fce2b3075f7fb7
4
+ data.tar.gz: 0654575a55dca1ee8bc9764c02a5d512e90cba6ad257780f1938643968e8dd58
5
5
  SHA512:
6
- metadata.gz: 6970ec37d84de3ec38011c5a84e1b5c18d0fa333435203d63f5624331e7f1fc8c6129766c81e66c90e320adb150782c7edc218c54ed9f55345a312b490cfc1d1
7
- data.tar.gz: 47b286e6ec4ebdcce13306ed2627fcb0f661447528b80bfafe371bb960cacb3018aaa6d565470be31254caffa9ff17e3cd0fd50e375f89725f842ccc2676c19b
6
+ metadata.gz: 6b304533c8b61c34b03a4e40875b2bd3c8d2e50bf5fba6c104327a769248aaaaace4151e5a8033f2b214e87316f8065b63c880057a0a631adb94a74ff779097a
7
+ data.tar.gz: b43e02b8160340b06bebf30642f65f885f73c25398d5f5190bd7453f0a99939f1d824535eefe83601b572f7e221b79069459d2959bef7401bd45bf5600ef2fd9
@@ -1,6 +1,6 @@
1
1
  # This configuration was generated by
2
2
  # `rubocop --auto-gen-config`
3
- # on 2020-01-10 17:16:01 -0600 using RuboCop version 0.79.0.
3
+ # on 2020-03-02 15:54:47 -0600 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
@@ -10,7 +10,7 @@
10
10
  Metrics/AbcSize:
11
11
  Max: 16
12
12
 
13
- # Offense count: 1
13
+ # Offense count: 4
14
14
  # Configuration parameters: CountComments, ExcludedMethods.
15
15
  Metrics/MethodLength:
16
- Max: 13
16
+ Max: 14
data/README.md CHANGED
@@ -8,6 +8,8 @@
8
8
  This is a CLI for interacting with the Stanford Digital Repository API.
9
9
  The code for the SDR API server is at https://github.com/sul-dlss/sdr-api
10
10
 
11
+ This provides a way for consumers to easily and correctly deposit files to the SDR without requiring access to the `/dor` NFS mount or to use Hydrus. A primary design goal was for this to have as few dependencies as possible so that it can be easily distributed by `gem install sdr-client` and then it can be used as a CLI.
12
+
11
13
  ## Install
12
14
 
13
15
  `gem install sdr-client`
data/exe/sdr CHANGED
@@ -70,11 +70,24 @@ subcommands = {
70
70
  options[:source_id] = source_id
71
71
  end
72
72
 
73
+ opts.on('--copyright COPYRIGHT', 'The copyright statement') do |copyright|
74
+ options[:copyright] = copyright
75
+ end
76
+
77
+ opts.on('--use-statement STATEMENT', 'The use and reproduction statement') do |use_statement|
78
+ options[:use_statement] = use_statement
79
+ end
80
+
73
81
  opts.on('--viewing-direction DIRECTION', 'The viewing direction (if a book). ' \
74
82
  'Either "left-to-right" or "right-to-left"') do |viewing_direction|
75
83
  options[:viewing_direction] = viewing_direction if %w[left-to-right right-to-left].include?(viewing_direction)
76
84
  end
77
85
 
86
+ opts.on('--access LEVEL', 'The access level for this object. ' \
87
+ 'Either "world", "stanford", "location-based", "citation-only" or "dark"') do |level|
88
+ options[:access] = level if %w[world stanford location-based citation-only dark].include?(level)
89
+ end
90
+
78
91
  opts.on('--files-metadata FILES_METADATA', 'A JSON object representing per-file metadata') do |files_metadata|
79
92
  options[:files_metadata] = JSON.parse(files_metadata)
80
93
  end
@@ -6,9 +6,13 @@ module SdrClient
6
6
  # The namespace for the "deposit" command
7
7
  module Deposit
8
8
  # rubocop:disable Metrics/ParameterLists
9
+ # rubocop:disable Metrics/MethodLength
9
10
  def self.run(label: nil,
10
11
  type: 'http://cocina.sul.stanford.edu/models/book.jsonld',
11
12
  viewing_direction: nil,
13
+ access: 'dark',
14
+ use_statement: nil,
15
+ copyright: nil,
12
16
  apo:,
13
17
  collection: nil,
14
18
  catkey: nil,
@@ -22,19 +26,24 @@ module SdrClient
22
26
  logger: Logger.new(STDOUT))
23
27
  token = Credentials.read
24
28
 
29
+ augmented_metadata = FileMetadataBuilder.build(files: files, files_metadata: files_metadata)
25
30
  metadata = Request.new(label: label,
26
31
  type: type,
32
+ access: access,
27
33
  apo: apo,
34
+ use_statement: use_statement,
35
+ copyright: copyright,
28
36
  collection: collection,
29
37
  source_id: source_id,
30
38
  catkey: catkey,
31
39
  embargo_release_date: embargo_release_date,
32
40
  embargo_access: embargo_access,
33
41
  viewing_direction: viewing_direction,
34
- files_metadata: files_metadata)
42
+ files_metadata: augmented_metadata)
35
43
  Process.new(metadata: metadata, url: url, token: token, files: files,
36
44
  grouping_strategy: grouping_strategy, logger: logger).run
37
45
  end
46
+ # rubocop:enable Metrics/MethodLength
38
47
  # rubocop:enable Metrics/ParameterLists
39
48
  end
40
49
  end
@@ -44,6 +53,7 @@ require 'sdr_client/deposit/matching_file_grouping_strategy'
44
53
  require 'sdr_client/deposit/files/direct_upload_request'
45
54
  require 'sdr_client/deposit/files/direct_upload_response'
46
55
  require 'sdr_client/deposit/file'
56
+ require 'sdr_client/deposit/file_metadata_builder'
47
57
  require 'sdr_client/deposit/file_set'
48
58
  require 'sdr_client/deposit/request'
49
59
  require 'sdr_client/deposit/upload_files'
@@ -0,0 +1,51 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'sdr_client/deposit/file_metadata_builder_operations/mime_type'
4
+ require 'sdr_client/deposit/file_metadata_builder_operations/md5'
5
+ require 'sdr_client/deposit/file_metadata_builder_operations/sha1'
6
+
7
+ module SdrClient
8
+ module Deposit
9
+ # Build basic metadata for files, iterating over a series of operations
10
+ # The available options are here: https://github.com/sul-dlss/sdr-client/blob/v0.8.1/lib/sdr_client/deposit/file.rb#L8-L10
11
+ class FileMetadataBuilder
12
+ OPERATIONS = [
13
+ FileMetadataBuilderOperations::MimeType,
14
+ FileMetadataBuilderOperations::MD5,
15
+ FileMetadataBuilderOperations::SHA1
16
+ ].freeze
17
+ private_constant :OPERATIONS
18
+
19
+ # @param (see #initialize)
20
+ # @return (see #build)
21
+ def self.build(files:, files_metadata:)
22
+ new(files: files, files_metadata: files_metadata.dup).build
23
+ end
24
+
25
+ # @param [Array<String>] files the list of files for which to generate metadata
26
+ def initialize(files:, files_metadata:)
27
+ @files = files
28
+ @files_metadata = files_metadata
29
+ end
30
+
31
+ # @return [Hash<String, Hash<String, String>>]
32
+ def build
33
+ files.each do |file_path|
34
+ file_key = ::File.basename(file_path)
35
+ OPERATIONS.each do |operation|
36
+ result = operation.for(file_path: file_path)
37
+ next if result.nil?
38
+
39
+ files_metadata[file_key] ||= {}
40
+ files_metadata[file_key][operation::NAME] = result
41
+ end
42
+ end
43
+ files_metadata
44
+ end
45
+
46
+ private
47
+
48
+ attr_reader :files, :files_metadata
49
+ end
50
+ end
51
+ end
@@ -0,0 +1,17 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'digest'
4
+
5
+ module SdrClient
6
+ module Deposit
7
+ module FileMetadataBuilderOperations
8
+ # MD5 for this file.
9
+ class MD5
10
+ NAME = 'md5'
11
+ def self.for(file_path:, **)
12
+ Digest::MD5.file(file_path).hexdigest
13
+ end
14
+ end
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,17 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'digest'
4
+
5
+ module SdrClient
6
+ module Deposit
7
+ module FileMetadataBuilderOperations
8
+ # Mime-type for this file.
9
+ class MimeType
10
+ NAME = 'mime_type'
11
+ def self.for(file_path:, **)
12
+ `file --mime-type -b #{file_path}`.chomp
13
+ end
14
+ end
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,17 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'digest'
4
+
5
+ module SdrClient
6
+ module Deposit
7
+ module FileMetadataBuilderOperations
8
+ # SHA1 for this file.
9
+ class SHA1
10
+ NAME = 'sha1'
11
+ def self.for(file_path:, **)
12
+ Digest::SHA1.file(file_path).hexdigest
13
+ end
14
+ end
15
+ end
16
+ end
17
+ end
@@ -30,9 +30,16 @@ module SdrClient
30
30
  def build_filesets(uploads:)
31
31
  grouped_uploads = grouping_strategy.run(uploads: uploads)
32
32
  grouped_uploads.map.with_index(1) do |upload_group, i|
33
- metadata_group = {}
34
- upload_group.each { |upload| metadata_group[upload.filename] = metadata.for(upload.filename) }
35
- FileSet.new(uploads: upload_group, uploads_metadata: metadata_group, label: "Object #{i}")
33
+ FileSet.new(uploads: upload_group,
34
+ uploads_metadata: metadata_group(upload_group),
35
+ label: "Object #{i}")
36
+ end
37
+ end
38
+
39
+ # Get the metadata for the files belonging to a fileset
40
+ def metadata_group(upload_group)
41
+ upload_group.each_with_object({}) do |upload, obj|
42
+ obj[upload.filename] = metadata.for(upload.filename)
36
43
  end
37
44
  end
38
45
  end
@@ -13,6 +13,9 @@ module SdrClient
13
13
  # Additional metadata includes access, preserve, shelve, md5, sha1
14
14
  # rubocop:disable Metrics/ParameterLists
15
15
  def initialize(label: nil,
16
+ access: 'dark',
17
+ use_statement: nil,
18
+ copyright: nil,
16
19
  apo:,
17
20
  collection: nil,
18
21
  source_id:,
@@ -30,6 +33,9 @@ module SdrClient
30
33
  @catkey = catkey
31
34
  @embargo_release_date = embargo_release_date
32
35
  @embargo_access = embargo_access
36
+ @access = access
37
+ @use_statement = use_statement
38
+ @copyright = copyright
33
39
  @apo = apo
34
40
  @file_sets = file_sets
35
41
  @files_metadata = files_metadata
@@ -39,7 +45,7 @@ module SdrClient
39
45
 
40
46
  def as_json
41
47
  {
42
- access: access,
48
+ access: access_struct,
43
49
  type: type,
44
50
  administrative: administrative,
45
51
  identification: identification,
@@ -52,13 +58,16 @@ module SdrClient
52
58
  # @return [Request] a clone of this request with the file_sets added
53
59
  def with_file_sets(file_sets)
54
60
  Request.new(label: label,
61
+ access: access,
55
62
  apo: apo,
56
63
  collection: collection,
64
+ copyright: copyright,
57
65
  source_id: source_id,
58
66
  catkey: catkey,
59
67
  embargo_release_date: embargo_release_date,
60
68
  embargo_access: embargo_access,
61
69
  type: type,
70
+ use_statement: use_statement,
62
71
  viewing_direction: viewing_direction,
63
72
  file_sets: file_sets,
64
73
  files_metadata: files_metadata)
@@ -72,9 +81,9 @@ module SdrClient
72
81
 
73
82
  private
74
83
 
75
- attr_reader :label, :file_sets, :source_id, :catkey, :apo, :collection,
84
+ attr_reader :access, :label, :file_sets, :source_id, :catkey, :apo, :collection,
76
85
  :type, :files_metadata, :embargo_release_date, :embargo_access,
77
- :viewing_direction
86
+ :viewing_direction, :use_statement, :copyright
78
87
 
79
88
  def administrative
80
89
  {
@@ -96,8 +105,11 @@ module SdrClient
96
105
  end
97
106
  end
98
107
 
99
- def access
100
- {}.tap do |json|
108
+ def access_struct
109
+ { access: access }.tap do |json|
110
+ json[:useAndReproductionStatement] = use_statement if use_statement
111
+ json[:copyright] = copyright if copyright
112
+
101
113
  if embargo_release_date
102
114
  json[:embargo] = {
103
115
  releaseDate: embargo_release_date.strftime('%FT%T%:z'),
@@ -35,7 +35,7 @@ module SdrClient
35
35
  file_name = ::File.basename(path)
36
36
  obj[path] = Files::DirectUploadRequest.from_file(path,
37
37
  file_name: file_name,
38
- content_type: metadata.for(file_name)[:mime_type])
38
+ content_type: metadata.for(file_name)['mime_type'])
39
39
  end
40
40
  end
41
41
 
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module SdrClient
4
- VERSION = '0.13.2'
4
+ VERSION = '0.16.0'
5
5
  end
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.13.2
4
+ version: 0.16.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-02-20 00:00:00.000000000 Z
11
+ date: 2020-03-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: dry-monads
@@ -164,6 +164,10 @@ files:
164
164
  - lib/sdr_client/credentials.rb
165
165
  - lib/sdr_client/deposit.rb
166
166
  - lib/sdr_client/deposit/file.rb
167
+ - lib/sdr_client/deposit/file_metadata_builder.rb
168
+ - lib/sdr_client/deposit/file_metadata_builder_operations/md5.rb
169
+ - lib/sdr_client/deposit/file_metadata_builder_operations/mime_type.rb
170
+ - lib/sdr_client/deposit/file_metadata_builder_operations/sha1.rb
167
171
  - lib/sdr_client/deposit/file_set.rb
168
172
  - lib/sdr_client/deposit/files/direct_upload_request.rb
169
173
  - lib/sdr_client/deposit/files/direct_upload_response.rb