sdr-client 0.23.1 → 0.27.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: ef6a0e67af5c582f3b632f331026fad31f94076dc4801c12757f768f4ea62498
4
- data.tar.gz: 1bde2dc32b1e498e5262b8eae90fdfb6656230e7be0cd22f3014b6f01eab24b6
3
+ metadata.gz: 0b57004bc33af516fb892a3d1cd317c1549319e97e4ca4ccc7c9ea82a00f81c0
4
+ data.tar.gz: 808661eb382c5a6f3098a96a473fa8396f29d413e290d822d32739f9fe34db49
5
5
  SHA512:
6
- metadata.gz: b63ab57e61e0576862ac5f256009489d2eda0c383e92e2ccf0869b205f7f452bb8e1099daeddcfd58809a85b929a51da986c1944146ee69d23a6b065d6510ac1
7
- data.tar.gz: 9cb2e996ffcef442079961310c3185b5780561f1046dd5f5b5da682edd2a0703729fb39964c69160cc0467683ac65ca54cec43954ee2201573b45cff39b43ef6
6
+ metadata.gz: 343d5374e9e2b12731ff06111d71646fcca815c030e67e4fd29b65477440b9bc1fde6a04b2d597ccb17c37ec56ff5a6cdc4010ad05bfaba30c7eed569ecf94b3
7
+ data.tar.gz: 356c88775241392487f41a31733169625f43f745e6e0c9e432a464e581b6c366a13148cd22495877972db75808e402efbf5929761adac1ad4445b35c12bc3fa9
@@ -2,4 +2,11 @@
2
2
 
3
3
 
4
4
 
5
- ## Was the documentation (README, wiki) updated?
5
+ ## How was this change tested?
6
+
7
+
8
+
9
+ ## Which documentation and/or configurations were updated?
10
+
11
+
12
+
@@ -1,16 +1,17 @@
1
1
  # This configuration was generated by
2
2
  # `rubocop --auto-gen-config`
3
- # on 2020-03-02 15:54:47 -0600 using RuboCop version 0.79.0.
3
+ # on 2020-04-27 08:24:29 -0400 using RuboCop version 0.82.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
- # Offense count: 1
9
+ # Offense count: 2
10
+ # Configuration parameters: IgnoredMethods.
10
11
  Metrics/AbcSize:
11
12
  Max: 16
12
13
 
13
- # Offense count: 4
14
+ # Offense count: 7
14
15
  # Configuration parameters: CountComments, ExcludedMethods.
15
16
  Metrics/MethodLength:
16
- Max: 14
17
+ Max: 15
@@ -2,7 +2,7 @@
2
2
  # frozen_string_literal: true
3
3
 
4
4
  require 'bundler/setup'
5
- require 'sdr/client'
5
+ require 'sdr_client'
6
6
 
7
7
  # You can add fixtures and/or initialization code here to make experimenting
8
8
  # with your gem easier. You can also use a different console, if you like.
data/exe/sdr CHANGED
@@ -6,37 +6,13 @@ require 'optparse'
6
6
  require 'sdr_client'
7
7
 
8
8
  options = {}
9
+
9
10
  global = OptionParser.new do |opts|
10
11
  opts.on('--service-url URL', 'Connect to the host at this URL') do |url|
11
12
  options[:url] = url
12
13
  end
13
14
  opts.on('-h', '--help', 'Display this screen') do
14
- puts <<~HELP
15
- DESCRIPTION:
16
- The SDR Command Line Interface is a tool to interact with the Stanford Digital Repository.
17
-
18
- SYNOPSIS:
19
- sdr [options] <command>
20
-
21
- OPTIONS:
22
- --service-url (string)
23
- Override the command's default URL with the given URL.
24
-
25
- -h, --help
26
- Displays this screen
27
-
28
- COMMANDS
29
- deposit
30
- accession object into the SDR
31
-
32
- register
33
- create a draft object in SDR
34
-
35
- login
36
- Will prompt for email & password and exchange it for an login token, which it saves in ~/.sdr/token
37
-
38
- HELP
39
- exit
15
+ SdrClient::CLI.help
40
16
  end
41
17
  end
42
18
 
@@ -44,6 +20,7 @@ global.order!
44
20
  command = ARGV.shift
45
21
 
46
22
  deposit_options = OptionParser.new do |opts|
23
+ opts.banner = "Usage: sdr #{command} [options]"
47
24
  opts.on('--label LABEL', 'The object label') do |label|
48
25
  options[:label] = label
49
26
  end
@@ -114,6 +91,8 @@ deposit_options = OptionParser.new do |opts|
114
91
  end
115
92
  end
116
93
 
94
+ SdrClient::CLI.help unless command
95
+
117
96
  subcommands = {
118
97
  'deposit' => deposit_options,
119
98
  'register' => deposit_options,
@@ -122,10 +101,19 @@ subcommands = {
122
101
 
123
102
  unless subcommands.key?(command)
124
103
  puts "unknown command '#{command}'"
125
- exit
104
+ SdrClient::CLI.help
126
105
  end
127
106
 
128
107
  subcommands[command].order!
129
108
 
130
109
  options[:files] = ARGV unless ARGV.empty?
131
- SdrClient::CLI.start(command, options)
110
+ options[:url] ||= 'https://sdr-api-prod.stanford.edu'
111
+
112
+ begin
113
+ SdrClient::CLI.start(command, options)
114
+ rescue StandardError => e
115
+ warn "There was a problem making your request:\n\n"
116
+ warn e.message
117
+ puts
118
+ puts subcommands[command].help
119
+ end
@@ -9,12 +9,12 @@ require 'cocina/models'
9
9
 
10
10
  require 'sdr_client/version'
11
11
  require 'sdr_client/deposit'
12
- require 'sdr_client/model_deposit'
13
12
  require 'sdr_client/credentials'
14
13
  require 'sdr_client/login'
15
14
  require 'sdr_client/login_prompt'
16
15
  require 'sdr_client/cli'
17
16
  require 'sdr_client/connection'
17
+ require 'sdr_client/background_job_results'
18
18
 
19
19
  module SdrClient
20
20
  class Error < StandardError; end
@@ -0,0 +1,21 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'json'
4
+
5
+ module SdrClient
6
+ # API calls around background job results from dor-services-app
7
+ module BackgroundJobResults
8
+ # Get status/result of a background job
9
+ # @param url [String] url for the service
10
+ # @param job_id [String] required string representing a job identifier
11
+ # @return [Hash] result of background job
12
+ def self.show(url:, job_id:)
13
+ connection = Connection.new(url: "#{url}/v1/background_job_results/#{job_id}").connection
14
+ resp = connection.get
15
+
16
+ raise "unexpected response: #{resp.status} #{resp.body}" unless resp.success?
17
+
18
+ JSON.parse(resp.body).with_indifferent_access
19
+ end
20
+ end
21
+ end
@@ -3,15 +3,46 @@
3
3
  module SdrClient
4
4
  # The command line interface
5
5
  module CLI
6
+ HELP = <<~HELP
7
+ DESCRIPTION:
8
+ The SDR Command Line Interface is a tool to interact with the Stanford Digital Repository.
9
+
10
+ SYNOPSIS:
11
+ sdr [options] <command>
12
+
13
+ To see help text for each command you can run:
14
+
15
+ sdr [options] <command> help
16
+
17
+ OPTIONS:
18
+ --service-url (string)
19
+ Override the command's default URL with the given URL.
20
+
21
+ -h, --help
22
+ Displays this screen
23
+
24
+
25
+ COMMANDS:
26
+ deposit
27
+ Accession an object into the SDR
28
+
29
+ register
30
+ Create a draft object in SDR and retrieve a Druid identifier.
31
+
32
+ login
33
+ Will prompt for email & password and exchange it for an login token, which it saves in ~/.sdr/token
34
+
35
+ HELP
36
+
6
37
  def self.start(command, options)
7
38
  case command
8
- when 'deposit'
9
- SdrClient::Deposit.run(accession: true, **options)
10
- when 'register'
11
- SdrClient::Deposit.run(accession: false, **options)
39
+ when 'deposit', 'register'
40
+ display_errors(validate_deposit_options(options))
41
+ job_id = SdrClient::Deposit.run(accession: command == 'deposit', **options)
42
+ poll_for_job_complete(job_id: job_id, url: options[:url]) # TODO: add an option that skips this
12
43
  when 'login'
13
44
  status = SdrClient::Login.run(options)
14
- puts status.value if status.failure?
45
+ puts status.failure if status.failure?
15
46
  else
16
47
  raise "Unknown command #{command}"
17
48
  end
@@ -19,5 +50,38 @@ module SdrClient
19
50
  puts 'Log in first'
20
51
  exit(1)
21
52
  end
53
+
54
+ def self.display_errors(errors)
55
+ return if errors.empty?
56
+
57
+ raise errors.map { |k, v| "#{k} #{v}" }.join("\n")
58
+ end
59
+
60
+ def self.validate_deposit_options(options)
61
+ {}.tap do |errors|
62
+ errors['admin-policy'] = 'is a required argument' unless options[:apo]
63
+ errors['source-id'] = 'is a required argument' unless options[:source_id]
64
+ end
65
+ end
66
+
67
+ def self.help
68
+ puts HELP
69
+ exit
70
+ end
71
+
72
+ def self.poll_for_job_complete(job_id:, url:)
73
+ result = nil
74
+ 1.upto(5) do |_n|
75
+ result = SdrClient::BackgroundJobResults.show(url: url, job_id: job_id)
76
+ break unless %w[pending processing].include? result['status']
77
+
78
+ sleep 5
79
+ end
80
+ if result['status'] == 'complete'
81
+ puts result.dig('output', 'druid')
82
+ else
83
+ warn "Job #{job_id} did not complete\n#{result.inspect}"
84
+ end
85
+ end
22
86
  end
23
87
  end
@@ -8,10 +8,12 @@ module SdrClient
8
8
  BOOK_TYPE = 'http://cocina.sul.stanford.edu/models/book.jsonld'
9
9
  # rubocop:disable Metrics/ParameterLists
10
10
  # rubocop:disable Metrics/MethodLength
11
+ # @return [String] job id for the background job result
11
12
  def self.run(label: nil,
12
13
  type: BOOK_TYPE,
13
14
  viewing_direction: nil,
14
15
  access: 'dark',
16
+ download: 'none',
15
17
  use_statement: nil,
16
18
  copyright: nil,
17
19
  apo:,
@@ -30,6 +32,7 @@ module SdrClient
30
32
  metadata = Request.new(label: label,
31
33
  type: type,
32
34
  access: access,
35
+ download: download,
33
36
  apo: apo,
34
37
  use_statement: use_statement,
35
38
  copyright: copyright,
@@ -48,6 +51,19 @@ module SdrClient
48
51
  end
49
52
  # rubocop:enable Metrics/MethodLength
50
53
  # rubocop:enable Metrics/ParameterLists
54
+
55
+ def self.model_run(request_dro:,
56
+ files: [],
57
+ url:,
58
+ accession:,
59
+ logger: Logger.new(STDOUT))
60
+ connection = Connection.new(url: url)
61
+ ModelProcess.new(request_dro: request_dro,
62
+ connection: connection,
63
+ files: files,
64
+ logger: logger,
65
+ accession: accession).run
66
+ end
51
67
  end
52
68
  end
53
69
  require 'json'
@@ -60,6 +76,7 @@ require 'sdr_client/deposit/file_metadata_builder'
60
76
  require 'sdr_client/deposit/file_set'
61
77
  require 'sdr_client/deposit/request'
62
78
  require 'sdr_client/deposit/metadata_builder'
79
+ require 'sdr_client/deposit/model_process'
63
80
  require 'sdr_client/deposit/process'
64
81
  require 'sdr_client/deposit/upload_files'
65
82
  require 'sdr_client/deposit/upload_resource'
@@ -6,7 +6,7 @@ module SdrClient
6
6
  class File
7
7
  # rubocop:disable Metrics/ParameterLists
8
8
  def initialize(external_identifier:, label:, filename:,
9
- access: 'dark', preserve: false, shelve: false,
9
+ access: 'world', preserve: true, shelve: true,
10
10
  mime_type: nil, md5: nil, sha1: nil, use: nil)
11
11
  @external_identifier = external_identifier
12
12
  @label = label
@@ -26,6 +26,7 @@ module SdrClient
26
26
  # rubocop:enable Metrics/ParameterLists
27
27
 
28
28
  # rubocop:disable Metrics/AbcSize
29
+ # @return [String] job id for the background job result
29
30
  def run
30
31
  check_files_exist
31
32
  upload_responses = UploadFiles.new(files: files,
@@ -14,6 +14,7 @@ module SdrClient
14
14
  # rubocop:disable Metrics/ParameterLists
15
15
  def initialize(label: nil,
16
16
  access: 'dark',
17
+ download: 'none',
17
18
  use_statement: nil,
18
19
  copyright: nil,
19
20
  apo:,
@@ -34,6 +35,7 @@ module SdrClient
34
35
  @embargo_release_date = embargo_release_date
35
36
  @embargo_access = embargo_access
36
37
  @access = access
38
+ @download = download
37
39
  @use_statement = use_statement
38
40
  @copyright = copyright
39
41
  @apo = apo
@@ -59,6 +61,7 @@ module SdrClient
59
61
  def with_file_sets(file_sets)
60
62
  Request.new(label: label,
61
63
  access: access,
64
+ download: download,
62
65
  apo: apo,
63
66
  collection: collection,
64
67
  copyright: copyright,
@@ -85,7 +88,7 @@ module SdrClient
85
88
 
86
89
  attr_reader :access, :label, :file_sets, :source_id, :catkey, :apo, :collection,
87
90
  :files_metadata, :embargo_release_date, :embargo_access,
88
- :viewing_direction, :use_statement, :copyright
91
+ :viewing_direction, :use_statement, :copyright, :download
89
92
 
90
93
  def administrative
91
94
  {
@@ -108,7 +111,10 @@ module SdrClient
108
111
  end
109
112
 
110
113
  def access_struct
111
- { access: access }.tap do |json|
114
+ {
115
+ access: access,
116
+ download: download
117
+ }.tap do |json|
112
118
  json[:useAndReproductionStatement] = use_statement if use_statement
113
119
  json[:copyright] = copyright if copyright
114
120
 
@@ -21,14 +21,14 @@ module SdrClient
21
21
  end
22
22
 
23
23
  # @param [Hash<Symbol,String>] the result of the metadata call
24
- # @return [Hash<Symbol,String>] the result of the metadata call
24
+ # @return [String] job id for the background job result
25
25
  def run
26
26
  response = metadata_request
27
27
  unexpected_response(response) unless response.status == 201
28
28
 
29
29
  logger.info("Response from server: #{response.body}")
30
30
 
31
- { druid: JSON.parse(response.body)['druid'], background_job: response.headers['Location'] }
31
+ JSON.parse(response.body)['jobId']
32
32
  end
33
33
 
34
34
  private
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module SdrClient
4
- VERSION = '0.23.1'
4
+ VERSION = '0.27.0'
5
5
  end
@@ -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.0'
31
+ spec.add_dependency 'cocina-models', '~> 0.33.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.23.1
4
+ version: 0.27.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-04-21 00:00:00.000000000 Z
11
+ date: 2020-06-11 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.31.0
33
+ version: 0.33.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.31.0
40
+ version: 0.33.0
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: dry-monads
43
43
  requirement: !ruby/object:Gem::Requirement
@@ -188,6 +188,7 @@ files:
188
188
  - exe/sdr
189
189
  - lib/sdr-client.rb
190
190
  - lib/sdr_client.rb
191
+ - lib/sdr_client/background_job_results.rb
191
192
  - lib/sdr_client/cli.rb
192
193
  - lib/sdr_client/connection.rb
193
194
  - lib/sdr_client/credentials.rb
@@ -210,7 +211,6 @@ files:
210
211
  - lib/sdr_client/deposit/upload_resource.rb
211
212
  - lib/sdr_client/login.rb
212
213
  - lib/sdr_client/login_prompt.rb
213
- - lib/sdr_client/model_deposit.rb
214
214
  - lib/sdr_client/version.rb
215
215
  - sdr-client.gemspec
216
216
  homepage: https://github.com/sul-dlss/sdr-client
@@ -1,22 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'logger'
4
-
5
- module SdrClient
6
- # The namespace for the "deposit" command
7
- module Deposit
8
- def self.model_run(request_dro:,
9
- files: [],
10
- url:,
11
- accession:,
12
- logger: Logger.new(STDOUT))
13
- connection = Connection.new(url: url)
14
- ModelProcess.new(request_dro: request_dro,
15
- connection: connection,
16
- files: files,
17
- logger: logger,
18
- accession: accession).run
19
- end
20
- end
21
- end
22
- require 'sdr_client/deposit/model_process'