sdr-client 0.26.1 → 0.27.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: f2f9928c696ecb5051e4f6ba708985a2448aaa3189f93df4fcd0b85ab733ea87
4
- data.tar.gz: 457989602bdece5c31cbcc95276531721a6c5682c040176de7645c1730be4326
3
+ metadata.gz: 0b57004bc33af516fb892a3d1cd317c1549319e97e4ca4ccc7c9ea82a00f81c0
4
+ data.tar.gz: 808661eb382c5a6f3098a96a473fa8396f29d413e290d822d32739f9fe34db49
5
5
  SHA512:
6
- metadata.gz: 94ed5ab0d789c3d2669979bb8753bd60d0f1a51f6434f6c8b28e210fc04dc4ffcd2af9125ef3b08e4e49996c5d05c2e53b5e8348794fbad351cc5dc57e4b0b0f
7
- data.tar.gz: a816a3c86dccc3f90939a81eecf5cf46ef659b3fcc5d4c97948e41796bf13a1b2d5da8de958c0f58c5a46d0ab16f56fa813ef3d3c796671d7dd4b04fd591168f
6
+ metadata.gz: 343d5374e9e2b12731ff06111d71646fcca815c030e67e4fd29b65477440b9bc1fde6a04b2d597ccb17c37ec56ff5a6cdc4010ad05bfaba30c7eed569ecf94b3
7
+ data.tar.gz: 356c88775241392487f41a31733169625f43f745e6e0c9e432a464e581b6c366a13148cd22495877972db75808e402efbf5929761adac1ad4445b35c12bc3fa9
@@ -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,7 +9,6 @@ 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'
@@ -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
@@ -51,6 +51,19 @@ module SdrClient
51
51
  end
52
52
  # rubocop:enable Metrics/MethodLength
53
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
54
67
  end
55
68
  end
56
69
  require 'json'
@@ -63,6 +76,7 @@ require 'sdr_client/deposit/file_metadata_builder'
63
76
  require 'sdr_client/deposit/file_set'
64
77
  require 'sdr_client/deposit/request'
65
78
  require 'sdr_client/deposit/metadata_builder'
79
+ require 'sdr_client/deposit/model_process'
66
80
  require 'sdr_client/deposit/process'
67
81
  require 'sdr_client/deposit/upload_files'
68
82
  require 'sdr_client/deposit/upload_resource'
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module SdrClient
4
- VERSION = '0.26.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.32.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.26.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-06-08 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.32.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.32.0
40
+ version: 0.33.0
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: dry-monads
43
43
  requirement: !ruby/object:Gem::Requirement
@@ -211,7 +211,6 @@ files:
211
211
  - lib/sdr_client/deposit/upload_resource.rb
212
212
  - lib/sdr_client/login.rb
213
213
  - lib/sdr_client/login_prompt.rb
214
- - lib/sdr_client/model_deposit.rb
215
214
  - lib/sdr_client/version.rb
216
215
  - sdr-client.gemspec
217
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'