sdr-client 0.26.1 → 0.28.3
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 +4 -4
- data/.rubocop.yml +1 -7
- data/.rubocop_todo.yml +15 -3
- data/bin/console +1 -1
- data/exe/sdr +18 -30
- data/lib/sdr_client.rb +0 -1
- data/lib/sdr_client/cli.rb +69 -5
- data/lib/sdr_client/credentials.rb +10 -1
- data/lib/sdr_client/deposit.rb +14 -0
- data/lib/sdr_client/deposit/file_metadata_builder_operations/mime_type.rb +3 -2
- data/lib/sdr_client/version.rb +1 -1
- data/sdr-client.gemspec +2 -2
- metadata +8 -9
- data/lib/sdr_client/model_deposit.rb +0 -22
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0cb04dd251d4bdc856e935f8f6ff157054973e51e703eac5cfec621d3ea9906c
|
4
|
+
data.tar.gz: cc254f2105f3499a6a219e93ce51dcdde7f9c05d8fcd729c6b3c04ad58141012
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: faa0bd4e365b80ce47f8860af6a6f24f0581428662a9ded8ea6b78523aa09b73a3bcebb5aff33e998152ab8b8e1d81d9883ddee53cf162a7bdbc047596437a76
|
7
|
+
data.tar.gz: afb9f79a157929f83ba886f679c0eaa11965d3e60b9aa730f29edcdcb552e18c7d76d55e064ff3cdced78cf05f5df704b5d87b019607424e7263ee1e7bbb98cf
|
data/.rubocop.yml
CHANGED
@@ -1,4 +1,3 @@
|
|
1
|
-
|
2
1
|
inherit_from: .rubocop_todo.yml
|
3
2
|
|
4
3
|
AllCops:
|
@@ -7,11 +6,6 @@ AllCops:
|
|
7
6
|
- 'bin/console'
|
8
7
|
- 'vendor/**/*'
|
9
8
|
|
10
|
-
Layout/LineLength:
|
11
|
-
Max: 120
|
12
|
-
Exclude:
|
13
|
-
- 'spec/sdr_client/deposit/process_spec.rb'
|
14
|
-
|
15
9
|
Metrics/BlockLength:
|
16
10
|
Exclude:
|
17
11
|
- 'spec/**/*'
|
@@ -21,4 +15,4 @@ Metrics/BlockLength:
|
|
21
15
|
|
22
16
|
Naming/FileName:
|
23
17
|
Exclude:
|
24
|
-
- 'lib/sdr-client.rb'
|
18
|
+
- 'lib/sdr-client.rb'
|
data/.rubocop_todo.yml
CHANGED
@@ -1,17 +1,29 @@
|
|
1
1
|
# This configuration was generated by
|
2
2
|
# `rubocop --auto-gen-config`
|
3
|
-
# on 2020-
|
3
|
+
# on 2020-06-24 17:02:25 -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: 2
|
10
|
-
# Configuration parameters: IgnoredMethods.
|
11
10
|
Metrics/AbcSize:
|
12
11
|
Max: 16
|
13
12
|
|
14
|
-
# Offense count:
|
13
|
+
# Offense count: 8
|
15
14
|
# Configuration parameters: CountComments, ExcludedMethods.
|
16
15
|
Metrics/MethodLength:
|
17
16
|
Max: 15
|
17
|
+
|
18
|
+
# Offense count: 1
|
19
|
+
# Cop supports --auto-correct.
|
20
|
+
Style/IfUnlessModifier:
|
21
|
+
Exclude:
|
22
|
+
- 'exe/sdr'
|
23
|
+
|
24
|
+
# Offense count: 187
|
25
|
+
# Cop supports --auto-correct.
|
26
|
+
# Configuration parameters: AutoCorrect, AllowHeredoc, AllowURI, URISchemes, IgnoreCopDirectives, IgnoredPatterns.
|
27
|
+
# URISchemes: http, https
|
28
|
+
Layout/LineLength:
|
29
|
+
Max: 1228
|
data/bin/console
CHANGED
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
|
-
|
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
|
@@ -54,8 +31,8 @@ deposit_options = OptionParser.new do |opts|
|
|
54
31
|
|
55
32
|
opts.on('--type TYPE', 'The object type to create. ' \
|
56
33
|
'One of: "image", "book", "document", "map", "manuscript", "media", ' \
|
57
|
-
'"three_dimensional", "collection", or "admin_policy"') do |type|
|
58
|
-
if %w[image book document map manuscript media three_dimensional collection admin_policy].include?(type)
|
34
|
+
'"three_dimensional", "object", "collection", or "admin_policy"') do |type|
|
35
|
+
if %w[image book document map manuscript media three_dimensional object collection admin_policy].include?(type)
|
59
36
|
options[:type] = "http://cocina.sul.stanford.edu/models/#{type}.jsonld"
|
60
37
|
end
|
61
38
|
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
|
-
|
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
|
-
|
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
|
data/lib/sdr_client.rb
CHANGED
data/lib/sdr_client/cli.rb
CHANGED
@@ -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
|
-
|
10
|
-
|
11
|
-
|
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.
|
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
|
@@ -10,14 +10,23 @@ module SdrClient
|
|
10
10
|
json = JSON.parse(body)
|
11
11
|
Dir.mkdir(credentials_path, 0o700) unless Dir.exist?(credentials_path)
|
12
12
|
File.open(credentials_file, 'w', 0o600) do |file|
|
13
|
+
file.flock(File::LOCK_EX)
|
13
14
|
file.write(json.fetch('token'))
|
15
|
+
file.flush
|
14
16
|
end
|
15
17
|
end
|
16
18
|
|
17
19
|
def self.read
|
18
20
|
raise NoCredentialsError unless ::File.exist?(credentials_file)
|
19
21
|
|
20
|
-
|
22
|
+
creds = nil
|
23
|
+
File.open(credentials_file, 'r') do |file|
|
24
|
+
file.flock(File::LOCK_EX)
|
25
|
+
creds = file.readlines(chomp: true).first
|
26
|
+
end
|
27
|
+
raise NoCredentialsError if creds.nil?
|
28
|
+
|
29
|
+
creds
|
21
30
|
end
|
22
31
|
|
23
32
|
def self.credentials_path
|
data/lib/sdr_client/deposit.rb
CHANGED
@@ -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,6 +1,6 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require '
|
3
|
+
require 'shellwords'
|
4
4
|
|
5
5
|
module SdrClient
|
6
6
|
module Deposit
|
@@ -9,7 +9,8 @@ module SdrClient
|
|
9
9
|
class MimeType
|
10
10
|
NAME = 'mime_type'
|
11
11
|
def self.for(file_path:, **)
|
12
|
-
|
12
|
+
argv = Shellwords.escape(file_path)
|
13
|
+
`file --mime-type -b #{argv}`.chomp
|
13
14
|
end
|
14
15
|
end
|
15
16
|
end
|
data/lib/sdr_client/version.rb
CHANGED
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.
|
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
|
|
@@ -37,6 +37,6 @@ Gem::Specification.new do |spec|
|
|
37
37
|
spec.add_development_dependency 'rspec', '~> 3.0'
|
38
38
|
spec.add_development_dependency 'rubocop', '~> 0.79.0'
|
39
39
|
spec.add_development_dependency 'rubocop-rspec', '~> 1.37.1'
|
40
|
-
spec.add_development_dependency 'simplecov'
|
40
|
+
spec.add_development_dependency 'simplecov', '~> 0.17.0' # CodeClimate cannot use SimpleCov >= 0.18.0 for generating test coverage
|
41
41
|
spec.add_development_dependency 'webmock', '~> 3.7'
|
42
42
|
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.
|
4
|
+
version: 0.28.3
|
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-
|
11
|
+
date: 2020-06-25 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.
|
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.
|
40
|
+
version: 0.33.0
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: dry-monads
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
@@ -140,16 +140,16 @@ dependencies:
|
|
140
140
|
name: simplecov
|
141
141
|
requirement: !ruby/object:Gem::Requirement
|
142
142
|
requirements:
|
143
|
-
- - "
|
143
|
+
- - "~>"
|
144
144
|
- !ruby/object:Gem::Version
|
145
|
-
version:
|
145
|
+
version: 0.17.0
|
146
146
|
type: :development
|
147
147
|
prerelease: false
|
148
148
|
version_requirements: !ruby/object:Gem::Requirement
|
149
149
|
requirements:
|
150
|
-
- - "
|
150
|
+
- - "~>"
|
151
151
|
- !ruby/object:Gem::Version
|
152
|
-
version:
|
152
|
+
version: 0.17.0
|
153
153
|
- !ruby/object:Gem::Dependency
|
154
154
|
name: webmock
|
155
155
|
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'
|