sdr-client 0.69.1 → 0.71.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: 2870c101632d6b75859ea1a800d0a13c1bb8ab58ff06b26fd377bf3228bed18a
4
- data.tar.gz: a240a7cb5d0d4d46daafc39f3704e1aca0c64439b2e2c838d85a9589b1591680
3
+ metadata.gz: 4e12d569ac9f642a42311a80b9594a64398742274be65bd2298ddea5806aaa62
4
+ data.tar.gz: ba7c87706cf15a5904a44ac58f2d4303023eda9cef43224ad74e4b3e4ab4957b
5
5
  SHA512:
6
- metadata.gz: b0f05d1442009afd8bee7de161697b6dac8fb777d7e32c04b182775b080f87d1c93a8a5abc10145b598a6965a17a248a56e035bc6dca45181d35d96f18ab671a
7
- data.tar.gz: 4af54e4f254ee257d084b3ecdf2b41ae4594c4443ba7684c098a114a735b17d2af4355f0e16f0c4e0ddfb02a0800600d90ba7b2b5df93683725433b66a8624be
6
+ metadata.gz: 3f64850d5858f86b66a3cc1db3d38723ed35c78c4010f59e92af3affe945cc5bdc43dd13ff473f0e44ba256abb3a6ad1b7fac7bff8c76edca908271b64037bb7
7
+ data.tar.gz: 6b31ab8f77403f370e0ce7d520f98ec989e670bcb9700c779e039c3a19f84022411fb03e3d6d4ed057ee414f58229526722ae8b219d2285359bc2e99c0ef2d14
data/.rubocop.yml CHANGED
@@ -137,3 +137,7 @@ RSpec/FactoryBot/SyntaxMethods: # new in 2.7
137
137
  Enabled: true
138
138
  RSpec/Rails/AvoidSetupHook: # new in 2.4
139
139
  Enabled: true
140
+ RSpec/BeEq: # new in 2.9.0
141
+ Enabled: true
142
+ RSpec/BeNil: # new in 2.9.0
143
+ Enabled: true
data/.rubocop_todo.yml CHANGED
@@ -1,6 +1,6 @@
1
1
  # This configuration was generated by
2
2
  # `rubocop --auto-gen-config --auto-gen-only-exclude`
3
- # on 2022-02-15 02:08:38 UTC using RuboCop version 1.25.1.
3
+ # on 2022-03-08 23:08:23 UTC using RuboCop version 1.25.1.
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
@@ -26,7 +26,19 @@ Lint/UnusedMethodArgument:
26
26
  - 'lib/sdr_client/deposit/file_type_file_set_strategy.rb'
27
27
  - 'lib/sdr_client/deposit/image_file_set_strategy.rb'
28
28
 
29
- # Offense count: 10
29
+ # Offense count: 1
30
+ # Configuration parameters: IgnoredMethods, CountRepeatedAttributes, Max.
31
+ Metrics/AbcSize:
32
+ Exclude:
33
+ - 'lib/sdr_client/cli.rb'
34
+
35
+ # Offense count: 1
36
+ # Configuration parameters: IgnoredMethods, Max.
37
+ Metrics/CyclomaticComplexity:
38
+ Exclude:
39
+ - 'lib/sdr_client/cli.rb'
40
+
41
+ # Offense count: 11
30
42
  # Configuration parameters: CountComments, Max, CountAsOne, ExcludedMethods, IgnoredMethods.
31
43
  Metrics/MethodLength:
32
44
  Exclude:
@@ -36,8 +48,9 @@ Metrics/MethodLength:
36
48
  - 'lib/sdr_client/deposit/process.rb'
37
49
  - 'lib/sdr_client/deposit/request.rb'
38
50
  - 'lib/sdr_client/login.rb'
51
+ - 'lib/sdr_client/update.rb'
39
52
 
40
- # Offense count: 6
53
+ # Offense count: 8
41
54
  # Configuration parameters: Max, CountAsOne.
42
55
  RSpec/ExampleLength:
43
56
  Exclude:
@@ -60,7 +73,7 @@ RSpec/MessageSpies:
60
73
  Exclude:
61
74
  - 'spec/sdr_client/deposit_spec.rb'
62
75
 
63
- # Offense count: 10
76
+ # Offense count: 12
64
77
  # Configuration parameters: Max.
65
78
  RSpec/MultipleExpectations:
66
79
  Exclude:
data/README.md CHANGED
@@ -5,20 +5,21 @@
5
5
 
6
6
  # Sdr::Client
7
7
 
8
- This is a CLI for interacting with the Stanford Digital Repository API.
9
- The code for the SDR API server is at https://github.com/sul-dlss/sdr-api
8
+ This is a Ruby-based CLI for interacting with the Stanford Digital Repository API. The code for the SDR API server is at https://github.com/sul-dlss/sdr-api
10
9
 
11
10
  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
12
  ## Install
14
13
 
14
+ We recommend using the latest 3.x release of Ruby.
15
+
15
16
  `gem install sdr-client`
16
17
 
17
18
  ## Usage
18
19
 
19
20
  Log in:
20
21
  ```
21
- sdr --service-url http://sdr-api-server:3000 login
22
+ sdr --service-url https://sdr-api-server:3000 login
22
23
  ```
23
24
 
24
25
  Register a new object:
@@ -56,3 +57,15 @@ Display version of sdr-client:
56
57
  ```
57
58
  sdr version
58
59
  ```
60
+
61
+ Update an object, changing its admin policy object (APO):
62
+ ```
63
+ sdr --service-url https://sdr-api-server:3000 update --admin-policy druid:bx911tp9024 druid:bb408qn5061
64
+ ```
65
+
66
+
67
+ ## Testing
68
+
69
+ To test running sdr-client against the SDR API, which itself has dependencies on other SDR services, we tend to test against our running SDR QA environment. Make sure you are connected to VPN throughout your testing, and pass `https://sdr-api-qa.stanford.edu` as the value to the `--service-url` flag for the commands above.
70
+
71
+ **WARNING**: if you omit the `--service-url` flag, the sdr-client CLI by default operates against the production environment.
data/exe/sdr CHANGED
@@ -91,13 +91,27 @@ deposit_options = OptionParser.new do |opts|
91
91
  end
92
92
  end
93
93
 
94
+ update_options = OptionParser.new do |opts|
95
+ opts.banner = "Usage: sdr #{command} [options]"
96
+
97
+ opts.on('--admin-policy ADMIN_POLICY', 'The druid identifier of the admin policy object') do |apo|
98
+ options[:apo] = apo
99
+ end
100
+
101
+ opts.on('-h', '--help', 'Display this screen') do
102
+ puts opts
103
+ exit
104
+ end
105
+ end
106
+
94
107
  SdrClient::CLI.help unless command
95
108
 
96
109
  subcommands = {
97
- 'get' => OptionParser.new,
98
110
  'deposit' => deposit_options,
99
- 'register' => deposit_options,
111
+ 'get' => OptionParser.new,
100
112
  'login' => OptionParser.new,
113
+ 'register' => deposit_options,
114
+ 'update' => update_options,
101
115
  'version' => OptionParser.new
102
116
  }
103
117
 
@@ -16,7 +16,7 @@ module SdrClient
16
16
 
17
17
  OPTIONS:
18
18
  --service-url (string)
19
- Override the command's default URL with the given URL.
19
+ Override the command's default URL with the given URL. Default: https://sdr-api-prod.stanford.edu
20
20
 
21
21
  -h, --help
22
22
  Displays this screen
@@ -30,10 +30,13 @@ module SdrClient
30
30
  Accession an object into the SDR
31
31
 
32
32
  register
33
- Create a draft object in SDR and retrieve a Druid identifier.
33
+ Create a draft object in the SDR and retrieve a Druid identifier
34
+
35
+ update
36
+ Update an object in the SDR
34
37
 
35
38
  login
36
- Will prompt for email & password and exchange it for an login token, which it saves in ~/.sdr/token
39
+ Will prompt for email & password and exchange it for an login token (saved in ~/.sdr/token)
37
40
 
38
41
  version
39
42
  Display the sdr-client version
@@ -46,8 +49,15 @@ module SdrClient
46
49
  puts SdrClient::Find.run(arguments.first, **options)
47
50
  when 'deposit', 'register'
48
51
  deposit(command, options, arguments)
52
+ when 'update'
53
+ if arguments.size != 1 || !arguments.first.is_a?(String)
54
+ raise "Expected a single druid argument, received #{arguments}"
55
+ end
56
+
57
+ job_id = SdrClient::Update.run(arguments.first, **options)
58
+ poll_for_job_complete(job_id: job_id, url: options[:url]) # TODO: add an option that skips this
49
59
  when 'login'
50
- status = SdrClient::Login.run(options)
60
+ status = SdrClient::Login.run(**options)
51
61
  puts status.failure if status.failure?
52
62
  when 'version'
53
63
  puts SdrClient::VERSION
@@ -26,12 +26,12 @@ module SdrClient
26
26
 
27
27
  def as_json
28
28
  {
29
- type: 'http://cocina.sul.stanford.edu/models/file.jsonld',
29
+ type: Cocina::Models::ObjectType.file,
30
30
  label: @label,
31
31
  filename: @filename,
32
32
  externalIdentifier: @external_identifier,
33
33
  access: {
34
- access: @access,
34
+ view: @access,
35
35
  download: @download
36
36
  },
37
37
  administrative: {
@@ -7,7 +7,7 @@ module SdrClient
7
7
  # @param [Array<SdrClient::Deposit::Files>] files the files that are part of this strategy
8
8
  # @return [String] The URI that represents the type of file_set
9
9
  def self.run(files: [])
10
- Cocina::Models::Vocab::Resources.file
10
+ Cocina::Models::FileSetType.file
11
11
  end
12
12
  end
13
13
  end
@@ -7,7 +7,7 @@ module SdrClient
7
7
  # @param [Array<SdrClient::Deposit::Files>] files the files that are part of this strategy
8
8
  # @return [String] The URI that represents the type of file_set
9
9
  def self.run(files: [])
10
- Cocina::Models::Vocab::Resources.image
10
+ Cocina::Models::FileSetType.image
11
11
  end
12
12
  end
13
13
  end
@@ -7,7 +7,7 @@ module SdrClient
7
7
  # @param [String] label the required object label
8
8
  # @param [Time|nil] embargo_release_date when the item should be released from embargo or nil if no embargo
9
9
  # @param [String] embargo_access access after embargo has expired if embargoed
10
- # @param [String] type (http://cocina.sul.stanford.edu/models/object.jsonld) the required object type.
10
+ # @param [String] type (https://cocina.sul.stanford.edu/models/object) the required object type.
11
11
  # @param [Array<FileSet>] file_sets the file sets to attach.
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
@@ -24,7 +24,7 @@ module SdrClient
24
24
  embargo_release_date: nil,
25
25
  embargo_access: 'world',
26
26
  embargo_download: 'world',
27
- type: 'http://cocina.sul.stanford.edu/models/object.jsonld',
27
+ type: Cocina::Models::ObjectType.object,
28
28
  viewing_direction: nil,
29
29
  file_sets: [],
30
30
  files_metadata: {})
@@ -118,7 +118,7 @@ module SdrClient
118
118
 
119
119
  def access_struct
120
120
  {
121
- access: access,
121
+ view: access,
122
122
  download: download
123
123
  }.tap do |json|
124
124
  json[:useAndReproductionStatement] = use_statement if use_statement
@@ -127,7 +127,7 @@ module SdrClient
127
127
  if embargo_release_date
128
128
  json[:embargo] = {
129
129
  releaseDate: embargo_release_date.strftime('%FT%T%:z'),
130
- access: embargo_access,
130
+ view: embargo_access,
131
131
  download: embargo_download
132
132
  }
133
133
  end
@@ -35,7 +35,7 @@ module SdrClient
35
35
 
36
36
  def metadata_request
37
37
  json = metadata.to_json
38
- logger.debug("Starting upload metadata: #{json}")
38
+ logger.debug("Starting update metadata: #{json}")
39
39
 
40
40
  connection.put(path(metadata), json,
41
41
  'Content-Type' => 'application/json',
@@ -5,7 +5,7 @@ require 'logger'
5
5
  module SdrClient
6
6
  # The namespace for the "deposit" command
7
7
  module Deposit
8
- BOOK_TYPE = 'http://cocina.sul.stanford.edu/models/book.jsonld'
8
+ BOOK_TYPE = Cocina::Models::ObjectType.book
9
9
  # rubocop:disable Metrics/ParameterLists
10
10
  # rubocop:disable Metrics/MethodLength
11
11
  # @return [String] job id for the background job result
@@ -6,12 +6,15 @@ module SdrClient
6
6
  # The namespace for the "get" command
7
7
  module Find
8
8
  DRO_PATH = '/v1/resources/%<id>s'
9
- # @return [String] job id for the background job result
9
+ # @return [String] JSON for the given Cocina object or an error
10
10
  def self.run(druid, url:, logger: Logger.new($stdout))
11
11
  connection = Connection.new(url: url)
12
12
  path = format(DRO_PATH, id: druid)
13
13
  logger.info("Retrieving metadata from: #{path}")
14
14
  response = connection.get(path)
15
+ unless response.success?
16
+ logger.error("There was an HTTP #{response.status} error making the request: #{response.body}")
17
+ end
15
18
  response.body
16
19
  end
17
20
  end
@@ -0,0 +1,25 @@
1
+ # frozen_string_literal: true
2
+
3
+ module SdrClient
4
+ # The namespace for the "update" command
5
+ module Update
6
+ # @return [String] job id for the background job result
7
+ def self.run(druid, apo:, url:, logger: Logger.new($stdout))
8
+ cocina_item = Cocina::Models.build(
9
+ JSON.parse(
10
+ SdrClient::Find.run(druid, url: url)
11
+ )
12
+ )
13
+
14
+ SdrClient::Deposit::UpdateResource.run(
15
+ metadata: cocina_item.new(
16
+ administrative: cocina_item.administrative.new(
17
+ hasAdminPolicy: apo
18
+ )
19
+ ),
20
+ logger: logger,
21
+ connection: Connection.new(url: url)
22
+ )
23
+ end
24
+ end
25
+ end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module SdrClient
4
- VERSION = '0.69.1'
4
+ VERSION = '0.71.0'
5
5
  end
data/lib/sdr_client.rb CHANGED
@@ -10,6 +10,7 @@ require 'cocina/models'
10
10
 
11
11
  require 'sdr_client/version'
12
12
  require 'sdr_client/deposit'
13
+ require 'sdr_client/update'
13
14
  require 'sdr_client/credentials'
14
15
  require 'sdr_client/find'
15
16
  require 'sdr_client/login'
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.67.1'
31
+ spec.add_dependency 'cocina-models', '~> 0.68.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.69.1
4
+ version: 0.71.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: 2022-03-03 00:00:00.000000000 Z
11
+ date: 2022-03-09 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.67.1
33
+ version: 0.68.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.67.1
40
+ version: 0.68.0
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: dry-monads
43
43
  requirement: !ruby/object:Gem::Requirement
@@ -232,6 +232,7 @@ files:
232
232
  - lib/sdr_client/find.rb
233
233
  - lib/sdr_client/login.rb
234
234
  - lib/sdr_client/login_prompt.rb
235
+ - lib/sdr_client/update.rb
235
236
  - lib/sdr_client/version.rb
236
237
  - sdr-client.gemspec
237
238
  homepage: https://github.com/sul-dlss/sdr-client