sdr-client 0.88.0 → 0.91.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: 306e1af071e673f1d0c15b8158d49e25b83266ffa46282034774a07a54a7ff1e
4
- data.tar.gz: 98bc8d20f6a46e3f89e7f8250c56962944ae74fc19b028a8d7df06323d3d5e48
3
+ metadata.gz: f8233c4bc5f385175264ff828603971ecf6f0e65e5ed5d973ce8eed2bf42be8e
4
+ data.tar.gz: 63cbe0407ada26d325730ad992a74964ae83cc3390a2a2ccd3b446b070c78969
5
5
  SHA512:
6
- metadata.gz: 57312c7aa2947b0233f080030de611344dd6d3fffbca9af480c14eeb93b53f70f0dcce20a31721e1a92ca7f22efa87595bbbdff917b8e21bc8f6ee7142af32cb
7
- data.tar.gz: 7ab17c0b16f0c44a35c7cfa1418363fa108c2061b3d78b209c8bcb314761bcbaf83a4541151adb5d92a86af2c6c70285f384a94c0d111a2b163af730c8cc6e9e
6
+ metadata.gz: 3b7fa91c363c8d88d53f168e17e9627cb773bdea6d51c2e3891e1ed5fdbcd57db731e9f021e7edc40b2426834e3d1c962627769126d605ba1f99134069dcdbb7
7
+ data.tar.gz: fbdbc1fafad4c9c1a47379fe697b8573b44cbd368b4a76ccdb7998898a93c3e9898286c8abf4b46326bd1c30ceed9ea1608fb3ba748e5cc44bb4415b8bb4581a
data/.circleci/config.yml CHANGED
@@ -1,6 +1,6 @@
1
1
  version: 2.1
2
2
  orbs:
3
- ruby-rails: sul-dlss/ruby-rails@2.0.0
3
+ ruby-rails: sul-dlss/ruby-rails@3.1.2
4
4
  workflows:
5
5
  build:
6
6
  jobs:
data/.rubocop.yml CHANGED
@@ -157,3 +157,21 @@ RSpec/BeNil: # new in 2.9.0
157
157
  Enabled: true
158
158
  RSpec/VerifiedDoubleReference: # new in 2.10.0
159
159
  Enabled: true
160
+ Layout/LineContinuationLeadingSpace: # new in 1.31
161
+ Enabled: true
162
+ Layout/LineContinuationSpacing: # new in 1.31
163
+ Enabled: true
164
+ Lint/ConstantOverwrittenInRescue: # new in 1.31
165
+ Enabled: true
166
+ Lint/NonAtomicFileOperation: # new in 1.31
167
+ Enabled: true
168
+ Style/EnvHome: # new in 1.29
169
+ Enabled: true
170
+ Style/MapCompactWithConditionalBlock: # new in 1.30
171
+ Enabled: true
172
+ RSpec/ChangeByZero: # new in 2.11.0
173
+ Enabled: true
174
+ RSpec/Capybara/SpecificMatcher: # new in 2.12
175
+ Enabled: true
176
+ RSpec/Rails/HaveHttpStatus: # new in 2.12
177
+ Enabled: true
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- sdr-client (0.88.0)
4
+ sdr-client (0.91.0)
5
5
  activesupport
6
6
  cocina-models (~> 0.83.0)
7
7
  dry-monads
@@ -10,7 +10,7 @@ PATH
10
10
  GEM
11
11
  remote: https://rubygems.org/
12
12
  specs:
13
- activesupport (7.0.3)
13
+ activesupport (7.0.3.1)
14
14
  concurrent-ruby (~> 1.0, >= 1.0.2)
15
15
  i18n (>= 1.6, < 2)
16
16
  minitest (>= 5.1)
@@ -43,15 +43,11 @@ GEM
43
43
  activesupport
44
44
  diff-lcs (1.5.0)
45
45
  docile (1.4.0)
46
- dry-configurable (0.15.0)
46
+ dry-container (0.10.1)
47
47
  concurrent-ruby (~> 1.0)
48
- dry-core (~> 0.6)
49
- dry-container (0.9.0)
48
+ dry-core (0.8.1)
50
49
  concurrent-ruby (~> 1.0)
51
- dry-configurable (~> 0.13, >= 0.13.0)
52
- dry-core (0.7.1)
53
- concurrent-ruby (~> 1.0)
54
- dry-inflector (0.2.1)
50
+ dry-inflector (0.3.0)
55
51
  dry-logic (1.2.0)
56
52
  concurrent-ruby (~> 1.0)
57
53
  dry-core (~> 0.5, >= 0.5)
@@ -68,31 +64,35 @@ GEM
68
64
  dry-core (~> 0.5, >= 0.5)
69
65
  dry-inflector (~> 0.1, >= 0.1.2)
70
66
  dry-logic (~> 1.0, >= 1.0.2)
71
- edtf (3.0.8)
67
+ edtf (3.1.0)
72
68
  activesupport (>= 3.0, < 8.0)
73
69
  equivalent-xml (0.6.0)
74
70
  nokogiri (>= 1.4.3)
75
- faraday (2.3.0)
76
- faraday-net_http (~> 2.0)
71
+ faraday (2.5.2)
72
+ faraday-net_http (>= 2.0, < 3.1)
77
73
  ruby2_keywords (>= 0.0.4)
78
- faraday-net_http (2.0.3)
74
+ faraday-net_http (3.0.0)
79
75
  hashdiff (1.0.1)
80
- i18n (1.10.0)
76
+ i18n (1.12.0)
81
77
  concurrent-ruby (~> 1.0)
82
78
  ice_nine (0.11.2)
83
79
  json (2.6.2)
84
80
  jsonpath (1.1.2)
85
81
  multi_json
82
+ mini_portile2 (2.8.0)
86
83
  minitest (5.16.2)
87
84
  multi_json (1.15.0)
88
- nokogiri (1.13.6-x86_64-darwin)
85
+ nokogiri (1.13.8)
86
+ mini_portile2 (~> 2.8.0)
87
+ racc (~> 1.4)
88
+ nokogiri (1.13.8-x86_64-darwin)
89
89
  racc (~> 1.4)
90
90
  openapi3_parser (0.9.2)
91
91
  commonmarker (~> 0.17)
92
92
  openapi_parser (0.15.0)
93
93
  optimist (3.0.1)
94
94
  parallel (1.22.1)
95
- parser (3.1.2.0)
95
+ parser (3.1.2.1)
96
96
  ast (~> 2.4.1)
97
97
  patience_diff (1.2.0)
98
98
  optimist (~> 3.0)
@@ -119,17 +119,17 @@ GEM
119
119
  rspec-core (>= 2, < 4, != 2.12.0)
120
120
  rss (0.2.9)
121
121
  rexml
122
- rubocop (1.31.1)
122
+ rubocop (1.35.0)
123
123
  json (~> 2.3)
124
124
  parallel (~> 1.10)
125
- parser (>= 3.1.0.0)
125
+ parser (>= 3.1.2.1)
126
126
  rainbow (>= 2.2.2, < 4.0)
127
127
  regexp_parser (>= 1.8, < 3.0)
128
128
  rexml (>= 3.2.5, < 4.0)
129
- rubocop-ast (>= 1.18.0, < 2.0)
129
+ rubocop-ast (>= 1.20.1, < 2.0)
130
130
  ruby-progressbar (~> 1.7)
131
131
  unicode-display_width (>= 1.4.0, < 3.0)
132
- rubocop-ast (1.18.0)
132
+ rubocop-ast (1.21.0)
133
133
  parser (>= 3.1.1.0)
134
134
  rubocop-rake (0.6.0)
135
135
  rubocop (~> 1.0)
@@ -148,10 +148,10 @@ GEM
148
148
  diff-lcs
149
149
  patience_diff
150
150
  thor (1.2.1)
151
- tzinfo (2.0.4)
151
+ tzinfo (2.0.5)
152
152
  concurrent-ruby (~> 1.0)
153
153
  unicode-display_width (2.2.0)
154
- webmock (3.14.0)
154
+ webmock (3.17.1)
155
155
  addressable (>= 2.8.0)
156
156
  crack (>= 0.3.2)
157
157
  hashdiff (>= 0.4.0, < 2.0.0)
@@ -159,6 +159,7 @@ GEM
159
159
 
160
160
  PLATFORMS
161
161
  x86_64-darwin-21
162
+ x86_64-linux
162
163
 
163
164
  DEPENDENCIES
164
165
  bundler (~> 2.0)
data/README.md CHANGED
@@ -95,9 +95,12 @@ sdr update druid:bb408qn5061 --url https://sdr-api-server:3000 --license "https:
95
95
  # Change access controls
96
96
  sdr update druid:bb408qn5061 --url https://sdr-api-server:3000 --view "location-based" --download "none" --location "music" --cdl false
97
97
 
98
- # Change Cocina wholesale from a file (note that you can use this flag with the
99
- # others above, and the flags above will replace what's supplied in the cocina file)
98
+ # Change Cocina wholesale, either:
99
+ # 1. From a file
100
100
  sdr update druid:bb408qn5061 --url https://sdr-api-server:3000 --cocina-file bb408qn5061.json
101
+ # 2. Piped in on the command-line
102
+ sdr get druid:b408qn5061 --url https://sdr-api-server:3000 | exe/remove_w3cdtf_encoding_from_event_dates | sdr update druid:bb408qn5061 --url https://sdr-api-server:3000 --cocina-pipe
103
+ # Note that you can use either of these flags with the others above, and the flags above will replace what's supplied in the cocina file or pipe
101
104
  ```
102
105
 
103
106
  ## Testing
@@ -0,0 +1,16 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ $LOAD_PATH.unshift 'lib'
5
+
6
+ require 'sdr_client'
7
+
8
+ output = JSON.parse($stdin.read).tap do |hash|
9
+ hash.dig('description', 'event').each do |event|
10
+ event['date'].each do |event_date|
11
+ event_date.delete('encoding') if event_date.dig('encoding', 'code') == 'w3cdtf'
12
+ end
13
+ end
14
+ end.to_json
15
+
16
+ puts output
@@ -31,7 +31,7 @@ module SdrClient
31
31
 
32
32
  desc 'get DRUID', 'Retrieve an object from the SDR'
33
33
  def get(druid)
34
- say SdrClient::Find.run(druid, url: options[:url])
34
+ say SdrClient::Find.run(druid, url: options[:url], logger: Logger.new($stderr))
35
35
  rescue SdrClient::Credentials::NoCredentialsError
36
36
  say_error 'Log in first'
37
37
  exit(1)
@@ -71,10 +71,11 @@ module SdrClient
71
71
  option :location, enum: %w[spec music ars art hoover m&m], desc: 'Access location for the object'
72
72
  option :cdl, type: :boolean, default: false, desc: 'Controlled digital lending'
73
73
  option :cocina_file, desc: 'Path to a file containing Cocina JSON'
74
+ option :cocina_pipe, type: :boolean, default: false, desc: 'Indicate Cocina JSON is being piped in'
74
75
  def update(druid)
75
76
  validate_druid!(druid)
76
77
  job_id = SdrClient::Update.run(druid, **options)
77
- poll_for_job_complete(job_id: job_id, url: options[:url]) # TODO: add an option that skips this
78
+ poll_for_job_complete(job_id: job_id, url: options[:url])
78
79
  rescue SdrClient::Credentials::NoCredentialsError
79
80
  say_error 'Log in first'
80
81
  exit(1)
@@ -156,7 +157,7 @@ module SdrClient
156
157
  # the extra args to `say` prevent appending a newline
157
158
  say('SDR is processing your request.', nil, false)
158
159
  result = nil
159
- (1).upto(60) do
160
+ 1.upto(60) do
160
161
  result = SdrClient::BackgroundJobResults.show(url: url, job_id: job_id)
161
162
  break unless %w[pending processing].include?(result['status'])
162
163
 
@@ -8,7 +8,7 @@ module SdrClient
8
8
  # @param [String] a json string that contains a field 'token'
9
9
  def self.write(body)
10
10
  json = JSON.parse(body)
11
- Dir.mkdir(credentials_path, 0o700) unless Dir.exist?(credentials_path)
11
+ FileUtils.mkdir_p(credentials_path, mode: 0o700)
12
12
  File.atomic_write(credentials_file) do |file|
13
13
  file.write(json.fetch('token'))
14
14
  end
@@ -5,26 +5,26 @@ module SdrClient
5
5
  # Creates a resource (metadata) in SDR
6
6
  class CreateResource
7
7
  DRO_PATH = '/v1/resources'
8
-
9
- def self.run(accession:, metadata:, logger:, connection:, assign_doi: false)
10
- new(accession: accession,
11
- assign_doi: assign_doi,
12
- metadata: metadata,
13
- logger: logger,
14
- connection: connection).run
8
+ def self.run(**args)
9
+ new(**args).run
15
10
  end
16
11
 
17
12
  # @param [Boolean] accession should the accessionWF be started
18
13
  # @param [Boolean] assign_doi should a DOI be assigned to this item
19
14
  # @param [Cocina::Models::RequestDRO, Cocina::Models::RequestCollection] metadata
20
15
  # @param [Hash<Symbol,String>] the result of the metadata call
21
- def initialize(accession:, assign_doi:, metadata:, logger:, connection:)
16
+ # @param [String] priority what processing priority should be used
17
+ # either 'low' or 'default'
18
+ # rubocop:disable Metrics/ParameterLists
19
+ def initialize(accession:, metadata:, logger:, connection:, assign_doi: false, priority: nil)
22
20
  @accession = accession
21
+ @priority = priority
23
22
  @assign_doi = assign_doi
24
23
  @metadata = metadata
25
24
  @logger = logger
26
25
  @connection = connection
27
26
  end
27
+ # rubocop:enable Metrics/ParameterLists
28
28
 
29
29
  # @param [Hash<Symbol,String>] the result of the metadata call
30
30
  # @return [String] job id for the background job result
@@ -39,7 +39,7 @@ module SdrClient
39
39
 
40
40
  private
41
41
 
42
- attr_reader :metadata, :logger, :connection
42
+ attr_reader :metadata, :logger, :connection, :priority
43
43
 
44
44
  def metadata_request
45
45
  json = metadata.to_json
@@ -60,6 +60,7 @@ module SdrClient
60
60
 
61
61
  def path
62
62
  params = { accession: accession? }
63
+ params[:priority] = priority if priority
63
64
  params[:assign_doi] = true if assign_doi? # false is default
64
65
  DRO_PATH + '?' + params.map { |k, v| "#{k}=#{v}" }.join('&')
65
66
  end
@@ -9,12 +9,15 @@ module SdrClient
9
9
  # @param [Cocina::Model::RequestDRO] request_dro for depositing
10
10
  # @param [Connection] connection the connection to use
11
11
  # @param [Boolean] accession should the accessionWF be started
12
+ # @param [String] priority (nil) what processing priority should be used
13
+ # either 'low' or 'default'
12
14
  # @param [Array<String>] files a list of file names to upload
13
15
  # @param [Boolean] assign_doi should a DOI be assigned to this item
14
16
  # @param [Logger] logger the logger to use
15
17
  def initialize(request_dro:, # rubocop:disable Metrics/ParameterLists
16
18
  connection:,
17
19
  accession:,
20
+ priority: nil,
18
21
  files: [],
19
22
  assign_doi: false,
20
23
  logger: Logger.new($stdout))
@@ -23,6 +26,7 @@ module SdrClient
23
26
  @request_dro = request_dro
24
27
  @logger = logger
25
28
  @accession = accession
29
+ @priority = priority
26
30
  @assign_doi = assign_doi
27
31
  end
28
32
 
@@ -36,6 +40,7 @@ module SdrClient
36
40
  connection: connection)
37
41
  new_request_dro = UpdateDroWithFileIdentifiers.update(request_dro: request_dro, upload_responses: upload_responses)
38
42
  CreateResource.run(accession: @accession,
43
+ priority: @priority,
39
44
  assign_doi: @assign_doi,
40
45
  metadata: new_request_dro,
41
46
  logger: logger,
@@ -9,6 +9,8 @@ module SdrClient
9
9
  # @param [Request] metadata information about the object
10
10
  # @param [String] connection the server connection to use
11
11
  # @param [Boolean] accession should the accessionWF be started
12
+ # @param [String] priority (nil) what processing priority should be used
13
+ # either 'low' or 'default'
12
14
  # @param [Class] grouping_strategy class whose run method groups an array of uploads
13
15
  # @param [Class] file_set_type_strategy class whose run method determines file_set type
14
16
  # @param [Array<String>] files a list of file names to upload
@@ -19,6 +21,7 @@ module SdrClient
19
21
  def initialize(metadata:,
20
22
  connection:,
21
23
  accession:,
24
+ priority: nil,
22
25
  grouping_strategy: SingleFileGroupingStrategy,
23
26
  file_set_type_strategy: FileTypeFileSetStrategy,
24
27
  files: [],
@@ -31,6 +34,7 @@ module SdrClient
31
34
  @grouping_strategy = grouping_strategy
32
35
  @file_set_type_strategy = file_set_type_strategy
33
36
  @accession = accession
37
+ @priority = priority
34
38
  @assign_doi = assign_doi
35
39
  end
36
40
  # rubocop:enable Metrics/ParameterLists
@@ -51,6 +55,7 @@ module SdrClient
51
55
  request = metadata_builder.with_uploads(upload_responses)
52
56
  model = Cocina::Models.build_request(request.as_json.with_indifferent_access)
53
57
  CreateResource.run(accession: @accession,
58
+ priority: @priority,
54
59
  assign_doi: @assign_doi,
55
60
  metadata: model,
56
61
  logger: logger,
@@ -6,16 +6,18 @@ module SdrClient
6
6
  class UpdateResource
7
7
  DRO_PATH = '/v1/resources/%<id>s'
8
8
 
9
- def self.run(metadata:, logger:, connection:)
10
- new(metadata: metadata, logger: logger, connection: connection).run
9
+ def self.run(metadata:, logger:, connection:, version_description: nil)
10
+ new(metadata: metadata, logger: logger, connection: connection, version_description: version_description).run
11
11
  end
12
12
 
13
13
  # @param [Cocina::Models::DRO] metadata
14
14
  # @param [Hash<Symbol,String>] the result of the metadata call
15
- def initialize(metadata:, logger:, connection:)
15
+ # @param [String] version_description
16
+ def initialize(metadata:, logger:, connection:, version_description: nil)
16
17
  @metadata = metadata
17
18
  @logger = logger
18
19
  @connection = connection
20
+ @version_description = version_description
19
21
  end
20
22
 
21
23
  # @param [Hash<Symbol,String>] the result of the metadata call
@@ -31,7 +33,7 @@ module SdrClient
31
33
 
32
34
  private
33
35
 
34
- attr_reader :metadata, :logger, :connection
36
+ attr_reader :metadata, :logger, :connection, :version_description
35
37
 
36
38
  def metadata_request
37
39
  json = metadata.to_json
@@ -39,7 +41,9 @@ module SdrClient
39
41
 
40
42
  connection.put(path(metadata), json,
41
43
  'Content-Type' => 'application/json',
42
- 'X-Cocina-Models-Version' => Cocina::Models::VERSION)
44
+ 'X-Cocina-Models-Version' => Cocina::Models::VERSION) do |req|
45
+ req.params['versionDescription'] = version_description if version_description
46
+ end
43
47
  end
44
48
 
45
49
  def path(metadata)
@@ -27,6 +27,7 @@ module SdrClient
27
27
  files: [],
28
28
  files_metadata: {},
29
29
  accession: false,
30
+ priority: nil,
30
31
  grouping_strategy: SingleFileGroupingStrategy,
31
32
  file_set_type_strategy: FileTypeFileSetStrategy,
32
33
  logger: Logger.new($stdout))
@@ -51,24 +52,27 @@ module SdrClient
51
52
  grouping_strategy: grouping_strategy,
52
53
  file_set_type_strategy: file_set_type_strategy,
53
54
  accession: accession,
55
+ priority: priority,
54
56
  logger: logger).run
55
57
  end
56
58
  # rubocop:enable Metrics/MethodLength
57
- # rubocop:enable Metrics/ParameterLists
58
59
 
59
60
  # @param [Array<String>] files absolute paths to files
60
61
  def self.model_run(request_dro:,
61
62
  files: [],
62
63
  url:,
63
64
  accession:,
65
+ priority: nil,
64
66
  logger: Logger.new($stdout))
65
67
  connection = Connection.new(url: url)
66
68
  ModelProcess.new(request_dro: request_dro,
67
69
  connection: connection,
68
70
  files: files,
69
71
  logger: logger,
70
- accession: accession).run
72
+ accession: accession,
73
+ priority: priority).run
71
74
  end
75
+ # rubocop:enable Metrics/ParameterLists
72
76
  end
73
77
  end
74
78
  require 'json'
@@ -50,10 +50,22 @@ module SdrClient
50
50
  @cocina_hash_from_file ||= JSON.parse(File.read(options[:cocina_file]), symbolize_names: true)
51
51
  end
52
52
 
53
+ def cocina_hash_from_pipe
54
+ @cocina_hash_from_pipe ||= JSON.parse($stdin.read, symbolize_names: true)
55
+ end
56
+
53
57
  # Update the Cocina in full
54
58
  def update_cocina(cocina_object)
55
- return cocina_object unless options[:cocina_file]
59
+ if options[:cocina_file]
60
+ update_cocina_from_file(cocina_object)
61
+ elsif options[:cocina_pipe]
62
+ update_cocina_from_pipe(cocina_object)
63
+ else
64
+ cocina_object
65
+ end
66
+ end
56
67
 
68
+ def update_cocina_from_file(cocina_object)
57
69
  if !File.file?(options[:cocina_file]) || !File.readable?(options[:cocina_file])
58
70
  raise "File not found: #{options[:cocina_file]}"
59
71
  end
@@ -66,6 +78,17 @@ module SdrClient
66
78
  cocina_object.new(cocina_hash_from_file)
67
79
  end
68
80
 
81
+ def update_cocina_from_pipe(cocina_object)
82
+ raise 'No pipe provided' unless $stdin.stat.pipe?
83
+
84
+ # NOTE: We may want to add more checks later. For now, make sure the identifiers match.
85
+ if cocina_object.externalIdentifier != cocina_hash_from_pipe[:externalIdentifier]
86
+ raise "Cocina piped in has a different external identifier than #{cocina_object.externalIdentifier}: #{cocina_hash_from_pipe[:externalIdentifier]}"
87
+ end
88
+
89
+ cocina_object.new(cocina_hash_from_pipe)
90
+ end
91
+
69
92
  # Update the APO of a Cocina item if the options specify a new one, else return the original
70
93
  def update_apo(cocina_object)
71
94
  return cocina_object unless options[:apo]
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module SdrClient
4
- VERSION = '0.88.0'
4
+ VERSION = '0.91.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.88.0
4
+ version: 0.91.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-07-05 00:00:00.000000000 Z
11
+ date: 2022-08-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -197,6 +197,7 @@ description: This provides a way to deposit repository objects into the Stanford
197
197
  email:
198
198
  - jcoyne@justincoyne.com
199
199
  executables:
200
+ - remove_w3cdtf_encoding_from_event_dates
200
201
  - sdr
201
202
  extensions: []
202
203
  extra_rdoc_files: []
@@ -214,6 +215,7 @@ files:
214
215
  - Rakefile
215
216
  - bin/console
216
217
  - bin/setup
218
+ - exe/remove_w3cdtf_encoding_from_event_dates
217
219
  - exe/sdr
218
220
  - lib/sdr-client.rb
219
221
  - lib/sdr_client.rb