preservation-client 3.0.0 → 3.3.1

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: dfb058593a0636a69c8a496a846dbfdcee34ebe79475545c80999642dffc5ffd
4
- data.tar.gz: c0c4a0d3c0994116ff61648fcba67575adcc144edaacac0e6986dc81cf4fd117
3
+ metadata.gz: cd8382e6e4993d58f70000d22aa01ed1445ce9e04c936b925c8c7d95ba0aa082
4
+ data.tar.gz: c8d2c619e732d4d2767f565df028b24cdd68d7f6c08a22213bb60be74302756f
5
5
  SHA512:
6
- metadata.gz: d742c45557b5bd9e2c8bcdee76bd24149ab6b4b225772cbbbcb7ab1f1e35a28b6f6951869c9a4e3443970562824a824dd9cdc83f06a4499fbdcdf560f992d79a
7
- data.tar.gz: 8d0983ba3bc0d3c0def903983a118a462b496b1397d5b235c08bca37a63186a3a169fca293657acaa0c8039b52480d13f7485d2d29ba65bbba48248510e70f22
6
+ metadata.gz: d615d2d61a5beaa03c21a43e3df4808fc3b7fec90a674c5cfdb82dd8438801eb72e66f863424852717eaaf51fe8891736599aed0a21c2dc571b9d8b59bfde6c6
7
+ data.tar.gz: 0cfa10e23ab7a1baa0d0748df1189b31d95a44f1711ceab5ece29ee61c19a8e056dd1eaabfa73dd492c96e66fefa56297ba1f795b276d57f3fba8f65961d9bc1
@@ -0,0 +1,35 @@
1
+ version: 2.1
2
+
3
+ jobs:
4
+ build:
5
+ docker:
6
+ - image: circleci/ruby:2.7.1
7
+ environment:
8
+ CC_TEST_REPORTER_ID: 02e8afad8d0b699828dd69b6f45b598e7317b2d9828ea23380c3a97113068a0c
9
+ RAILS_ENV: test
10
+ steps:
11
+ - checkout
12
+ - run:
13
+ name: Install Bundler
14
+ command: gem install bundler
15
+ - run:
16
+ name: Which bundler?
17
+ command: bundle -v
18
+ - run:
19
+ name: Bundle Install
20
+ command: bundle check || bundle install
21
+ - run:
22
+ name: Lint using rubocop
23
+ command: bundle exec rubocop
24
+ - run:
25
+ name: Setup Code Climate test-reporter
26
+ command: |
27
+ curl -L https://codeclimate.com/downloads/test-reporter/test-reporter-latest-linux-amd64 > ./cc-test-reporter
28
+ chmod +x ./cc-test-reporter
29
+ ./cc-test-reporter before-build
30
+ - run:
31
+ name: rspec
32
+ command: bundle exec rspec
33
+ - run:
34
+ name: upload test coverage report to Code Climate
35
+ command: ./cc-test-reporter after-build --coverage-input-type simplecov --exit-code $?
@@ -1,4 +1,12 @@
1
1
  ## Why was this change made?
2
2
 
3
3
 
4
- ## Was the documentation (README, API, wiki, consul, etc.) updated?
4
+
5
+ ## How was this change tested?
6
+
7
+
8
+
9
+ ## Which documentation and/or configurations were updated?
10
+
11
+
12
+
data/.rubocop.yml CHANGED
@@ -24,6 +24,5 @@ Style/Documentation:
24
24
  Exclude:
25
25
  - 'spec/**/*'
26
26
 
27
-
28
27
  Style/WordArray:
29
28
  Enabled: false
data/.rubocop_todo.yml CHANGED
@@ -1,11 +1,15 @@
1
1
  # This configuration was generated by
2
2
  # `rubocop --auto-gen-config`
3
- # on 2019-12-03 15:41:39 -0800 using RuboCop version 0.74.0.
3
+ # on 2020-01-27 18:06:55 -0800 using RuboCop version 0.77.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: 3
9
+ # Offense count: 2
10
10
  Metrics/AbcSize:
11
11
  Max: 34
12
+
13
+ # Offense count: 1
14
+ Metrics/CyclomaticComplexity:
15
+ Max: 7
data/README.md CHANGED
@@ -1,5 +1,5 @@
1
1
  [![Gem Version](https://badge.fury.io/rb/preservation-client.svg)](https://badge.fury.io/rb/preservation-client)
2
- [![Build Status](https://travis-ci.org/sul-dlss/preservation-client.svg?branch=master)](https://travis-ci.org/sul-dlss/preservation-client)
2
+ [![CircleCI](https://circleci.com/gh/sul-dlss/preservation-client.svg?style=svg)](https://circleci.com/gh/sul-dlss/preservation-client)
3
3
  [![Maintainability](https://api.codeclimate.com/v1/badges/00d2d8957226777105b3/maintainability)](https://codeclimate.com/github/sul-dlss/preservation-client/maintainability)
4
4
  [![Test Coverage](https://api.codeclimate.com/v1/badges/00d2d8957226777105b3/test_coverage)](https://codeclimate.com/github/sul-dlss/preservation-client/test_coverage)
5
5
 
@@ -88,6 +88,14 @@ Note that the preservation service is behind a firewall.
88
88
  - `client.objects.metadata(druid: 'oo000oo0000', filepath: 'identityMetadata.xml', version: '8')` - returns contents of identityMetadata.xml in version 8 of Moab object
89
89
  - `client.objects.signature_catalog('oo000oo0000')` - returns latest Moab::SignatureCatalog from Moab
90
90
 
91
+ ### Retrieve the primary moab storage location
92
+
93
+ - `client.objects.primary_moab_location(druid: 'ooo000oo0000')` - returns the path to the storage location for the primary moab
94
+
95
+ ### Validate the Moab
96
+
97
+ - `client.objects.validate_moab(druid: 'ooo000oo0000')` - validates that the Moab object, used by preservationWF to ensure we have a valid Moab before replicating to various preservation endpoints
98
+
91
99
  ### Get difference information between passed contentMetadata.xml and files in the Moab
92
100
 
93
101
  - `client.objects.content_inventory_diff(druid: 'oo000oo0000', content_metadata: '<contentMetadata>...</contentMetadata>')` - returns Moab::FileInventoryDifference containing differences between passed content metadata and latest version for subset 'all'
@@ -17,13 +17,18 @@ module Preservation
17
17
  class Client
18
18
  class Error < StandardError; end
19
19
 
20
- # Error that is raised when the remote server returns a 404 Not Found
20
+ # Error raised when server returns 404 Not Found
21
21
  class NotFoundError < Error; end
22
22
 
23
- # Error that is raised when the remote server returns some unexpected response
24
- # e.g. 4xx or 5xx status
23
+ # Error raised when server returns 423 Locked
24
+ class LockedError < Error; end
25
+
26
+ # Error raised when server returns an unexpected response
27
+ # e.g., 4xx or 5xx status not otherwise handled
25
28
  class UnexpectedResponseError < Error; end
26
29
 
30
+ # Error raised when Faraday gem fails to connect, e.g., on SSL errors or
31
+ # timeouts
27
32
  class ConnectionFailedError < Error; end
28
33
 
29
34
  DEFAULT_API_VERSION = 'v1'
@@ -50,8 +50,9 @@ module Preservation
50
50
  # @param [String] druid - with or without prefix: 'druid:ab123cd4567' OR 'ab123cd4567'
51
51
  # @param [String] filepath - the path of the file relative to the moab content directory
52
52
  # @param [String] version - the version of the file requested (defaults to nil for latest version)
53
- def content(druid:, filepath:, version: nil)
54
- file(druid, 'content', filepath, version)
53
+ # @param [Proc] on_data a block, if provided is called to do streaming responses
54
+ def content(druid:, filepath:, version: nil, on_data: nil)
55
+ file(druid, 'content', filepath, version, on_data: on_data)
55
56
  end
56
57
 
57
58
  # retrieve a manifest file from a Moab object
@@ -70,6 +71,24 @@ module Preservation
70
71
  file(druid, 'metadata', filepath, version)
71
72
  end
72
73
 
74
+ # calls the endpoint to queue a ValidateMoab job for a specific druid
75
+ # typically called by a preservationIngestWF robot
76
+ # @param [String] druid - with or without prefix: 'druid:ab123cd4567' or 'ab123cd4567'
77
+ # @return [String] "ok" when job queued
78
+ # @raise [Preservation::Client::NotFoundError] when druid is not found
79
+ def validate_moab(druid:)
80
+ get("objects/#{druid}/validate_moab", {}, on_data: nil)
81
+ end
82
+
83
+ # retrieve the storage location for the primary moab of the given druid
84
+ # @param [String] druid - with or without prefix: 'druid:ab123cd4567' or 'ab123cd4567'
85
+ # @return [String] the storage location of the primary moab for the given druid
86
+ # @raise [Preservation::Client::NotFoundError] when druid is not found
87
+ # @raise [Preservation::Client::LockedError] when druid is in locked state (not available for versioning)
88
+ def primary_moab_location(druid:)
89
+ get("objects/#{druid}/primary_moab_location", {}, on_data: nil)
90
+ end
91
+
73
92
  # convenience method for retrieving latest Moab::SignatureCatalog from a Moab object,
74
93
  # @param [String] druid - with or without prefix: 'druid:ab123cd4567' OR 'ab123cd4567'
75
94
  # @return [Moab::SignatureCatalog] the manifest of all files previously ingested
@@ -83,10 +102,11 @@ module Preservation
83
102
  # @param [String] druid - with or without prefix: 'druid:ab123cd4567' OR 'ab123cd4567'
84
103
  # @param [String] category - one of 'manifest', 'metadata' or 'content'
85
104
  # @param [String] filepath - the path of the file relative to the moab category directory
86
- # @param [String] version - the version of the file requested (defaults to nil for latest version)
105
+ # @param [String] version - the version of the file requested
106
+ # @param [Proc] on_data a block, if provided is called to do streaming responses
87
107
  # @return the retrieved file
88
- def file(druid, category, filepath, version = nil)
89
- get("objects/#{druid}/file", category: category, filepath: filepath, version: version)
108
+ def file(druid, category, filepath, version, on_data: nil)
109
+ get("objects/#{druid}/file", { category: category, filepath: filepath, version: version }, on_data: on_data)
90
110
  end
91
111
  end
92
112
  end
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Preservation
4
4
  class Client
5
- VERSION = '3.0.0'
5
+ VERSION = '3.3.1'
6
6
  end
7
7
  end
@@ -15,7 +15,7 @@ module Preservation
15
15
 
16
16
  # @param path [String] path to be appended to connection url (no leading slash)
17
17
  def get_json(path, object_id)
18
- req_url = api_version.present? ? "#{api_version}/#{path}" : path
18
+ req_url = "#{api_version}/#{path}"
19
19
  resp = connection.get do |req|
20
20
  req.url req_url
21
21
  req.headers['Content-Type'] = 'application/json'
@@ -25,46 +25,78 @@ module Preservation
25
25
 
26
26
  errmsg = ResponseErrorFormatter
27
27
  .format(response: resp, object_id: object_id, client_method_name: caller_locations.first.label)
28
- raise Preservation::Client::UnexpectedResponseError, errmsg
28
+ raise UnexpectedResponseError, errmsg
29
29
  rescue Faraday::ResourceNotFound
30
30
  errmsg = "#{object_id} not found in Preservation at #{connection.url_prefix}#{req_url}"
31
- raise Preservation::Client::NotFoundError, errmsg
31
+ raise NotFoundError, errmsg
32
32
  rescue Faraday::Error => e
33
33
  errmsg = "Preservation::Client.#{caller_locations.first.label} for #{object_id} " \
34
34
  "got #{e.response[:status]} from Preservation at #{req_url}: #{e.response[:body]}"
35
- raise Preservation::Client::UnexpectedResponseError, errmsg
35
+ raise UnexpectedResponseError, errmsg
36
36
  end
37
37
 
38
38
  # @param path [String] path to be appended to connection url (no leading slash)
39
- # @param params [Hash] optional params
40
- def get(path, params)
41
- http_response(:get, path, params)
39
+ # @param params [Hash] optional request parameters
40
+ # @param on_data [Proc] a callback to use when a streaming response is desired.
41
+ def get(path, params, on_data:)
42
+ return http_response(:get, path, params) unless on_data
43
+
44
+ connection.get("#{api_version}/#{path}", params) do |req|
45
+ req.options.on_data = on_data
46
+ end
42
47
  end
43
48
 
44
49
  # @param path [String] path to be appended to connection url (no leading slash)
45
- # @param params [Hash] optional params
50
+ # @param params [Hash] optional request parameters
46
51
  def post(path, params)
47
52
  http_response(:post, path, params)
48
53
  end
49
54
 
50
- # @param method [Symbol] :get or :post
51
55
  # @param path [String] path to be appended to connection url (no leading slash)
52
- # @param params [Hash] optional params
56
+ # @param params [Hash] optional request parameters
57
+ def patch(path, params)
58
+ http_response(:patch, path, params)
59
+ end
60
+
61
+ # @param path [String] path to be appended to connection url (no leading slash)
62
+ # @param params [Hash] optional request parameters
63
+ def put(path, params)
64
+ http_response(:put, path, params)
65
+ end
66
+
67
+ # @param path [String] path to be appended to connection url (no leading slash)
68
+ # @param params [Hash] optional request parameters
69
+ def delete(path, params)
70
+ http_response(:delete, path, params)
71
+ end
72
+
73
+ # @param method [Symbol] a symbol representing an HTTP method: :get, :post, :patch, :put, :delete
74
+ # @param path [String] path to be appended to connection url (no leading slash)
75
+ # @param params [Hash] optional request parameters
53
76
  def http_response(method, path, params)
54
- req_url = api_version.present? ? "#{api_version}/#{path}" : path
55
- resp = connection.send(method, req_url, params)
77
+ req_url = "#{api_version}/#{path}"
78
+ resp =
79
+ case method
80
+ when :delete, :get
81
+ connection.public_send(method, req_url, params)
82
+ when :patch, :post, :put
83
+ request_json = params.to_json if params&.any?
84
+ connection.public_send(method, req_url, request_json, 'Content-Type' => 'application/json')
85
+ end
86
+
56
87
  return resp.body if resp.success?
57
88
 
58
89
  errmsg = ResponseErrorFormatter.format(response: resp, client_method_name: caller_locations.first.label)
59
- raise Preservation::Client::UnexpectedResponseError, errmsg
90
+ raise UnexpectedResponseError, errmsg
60
91
  rescue Faraday::ResourceNotFound => e
61
92
  errmsg = "Preservation::Client.#{caller_locations.first.label} " \
62
93
  "got #{e.response[:status]} from Preservation at #{req_url}: #{e.response[:body]}"
63
- raise Preservation::Client::NotFoundError, errmsg
94
+ raise NotFoundError, errmsg
64
95
  rescue Faraday::Error => e
65
96
  errmsg = "Preservation::Client.#{caller_locations.first.label} " \
66
97
  "got #{e.response[:status]} from Preservation at #{req_url}: #{e.response[:body]}"
67
- raise Preservation::Client::UnexpectedResponseError, errmsg
98
+ exception_class = e.response[:status] == 423 ? LockedError : UnexpectedResponseError
99
+ raise exception_class, errmsg
68
100
  end
69
101
  end
70
102
  end
@@ -35,9 +35,9 @@ Gem::Specification.new do |spec|
35
35
 
36
36
  spec.add_development_dependency 'bundler', '~> 2.0'
37
37
  spec.add_development_dependency 'pry-byebug'
38
- spec.add_development_dependency 'rake', '~> 10.0'
38
+ spec.add_development_dependency 'rake', '>= 12.3.3'
39
39
  spec.add_development_dependency 'rspec', '~> 3.0'
40
40
  spec.add_development_dependency 'rubocop', '~> 0.77.0'
41
- spec.add_development_dependency 'simplecov'
41
+ spec.add_development_dependency 'simplecov', '~> 0.17.0' # For CodeClimate
42
42
  spec.add_development_dependency 'webmock'
43
43
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: preservation-client
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.0.0
4
+ version: 3.3.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Naomi Dushay
8
- autorequire:
8
+ autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2020-01-17 00:00:00.000000000 Z
11
+ date: 2021-06-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -110,16 +110,16 @@ dependencies:
110
110
  name: rake
111
111
  requirement: !ruby/object:Gem::Requirement
112
112
  requirements:
113
- - - "~>"
113
+ - - ">="
114
114
  - !ruby/object:Gem::Version
115
- version: '10.0'
115
+ version: 12.3.3
116
116
  type: :development
117
117
  prerelease: false
118
118
  version_requirements: !ruby/object:Gem::Requirement
119
119
  requirements:
120
- - - "~>"
120
+ - - ">="
121
121
  - !ruby/object:Gem::Version
122
- version: '10.0'
122
+ version: 12.3.3
123
123
  - !ruby/object:Gem::Dependency
124
124
  name: rspec
125
125
  requirement: !ruby/object:Gem::Requirement
@@ -152,16 +152,16 @@ dependencies:
152
152
  name: simplecov
153
153
  requirement: !ruby/object:Gem::Requirement
154
154
  requirements:
155
- - - ">="
155
+ - - "~>"
156
156
  - !ruby/object:Gem::Version
157
- version: '0'
157
+ version: 0.17.0
158
158
  type: :development
159
159
  prerelease: false
160
160
  version_requirements: !ruby/object:Gem::Requirement
161
161
  requirements:
162
- - - ">="
162
+ - - "~>"
163
163
  - !ruby/object:Gem::Version
164
- version: '0'
164
+ version: 0.17.0
165
165
  - !ruby/object:Gem::Dependency
166
166
  name: webmock
167
167
  requirement: !ruby/object:Gem::Requirement
@@ -184,12 +184,12 @@ executables: []
184
184
  extensions: []
185
185
  extra_rdoc_files: []
186
186
  files:
187
+ - ".circleci/config.yml"
187
188
  - ".github/pull_request_template.md"
188
189
  - ".gitignore"
189
190
  - ".rspec"
190
191
  - ".rubocop.yml"
191
192
  - ".rubocop_todo.yml"
192
- - ".travis.yml"
193
193
  - Gemfile
194
194
  - LICENSE
195
195
  - README.md
@@ -210,7 +210,7 @@ metadata:
210
210
  allowed_push_host: https://rubygems.org/
211
211
  homepage_uri: https://github.com/sul-dlss/preservation-client
212
212
  source_code_uri: https://github.com/sul-dlss/preservation-client.
213
- post_install_message:
213
+ post_install_message:
214
214
  rdoc_options: []
215
215
  require_paths:
216
216
  - lib
@@ -225,8 +225,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
225
225
  - !ruby/object:Gem::Version
226
226
  version: '0'
227
227
  requirements: []
228
- rubygems_version: 3.1.2
229
- signing_key:
228
+ rubygems_version: 3.2.19
229
+ signing_key:
230
230
  specification_version: 4
231
231
  summary: A thin client for getting info from SDR preservation.
232
232
  test_files: []
data/.travis.yml DELETED
@@ -1,21 +0,0 @@
1
- language: ruby
2
- cache: bundler
3
- rvm:
4
- - 2.5.3
5
- - 2.6.4
6
-
7
- env:
8
- - "RAILS_VERSION=5.2.3"
9
- - "RAILS_VERSION=6.0.0"
10
-
11
- before_install: gem install bundler -v 2.1.2
12
-
13
- before_script:
14
- - curl -L https://codeclimate.com/downloads/test-reporter/test-reporter-latest-linux-amd64 > ./cc-test-reporter
15
- - chmod +x ./cc-test-reporter
16
- - ./cc-test-reporter before-build
17
- after_script:
18
- - ./cc-test-reporter after-build --exit-code $TRAVIS_TEST_RESULT
19
-
20
- notifications:
21
- email: false