preservation-client 3.1.0 → 3.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.circleci/config.yml +35 -0
- data/.github/pull_request_template.md +9 -1
- data/README.md +9 -1
- data/lib/preservation/client.rb +8 -3
- data/lib/preservation/client/objects.rb +25 -5
- data/lib/preservation/client/version.rb +1 -1
- data/lib/preservation/client/versioned_api_service.rb +43 -18
- data/preservation-client.gemspec +2 -2
- metadata +15 -15
- data/.travis.yml +0 -21
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 58f0246c9149fecf296ee74e4a533001fcc7d2d9c60cb656418a5bab7d0b7b14
|
4
|
+
data.tar.gz: 16c837b542784185434845ebe4543791cc323ff37c6eb697537b466d272797d8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b554bb4b533d2aaef5041b60b56f60f2726a303201e28b717428ac0682760bb19771bc7a0abc4c75ae1e601df5ec393d6d47af4d6d50c2864c0bc0b593f2b492
|
7
|
+
data.tar.gz: c25a0c266e67fc4535db19df660571eb5fe2c6b097379c876127452780f39df9375091f87be32784c7b82f0e3fe381e573d6261ae154693381d182944f7a2c23
|
@@ -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 $?
|
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
|
-
[![
|
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'
|
data/lib/preservation/client.rb
CHANGED
@@ -17,13 +17,18 @@ module Preservation
|
|
17
17
|
class Client
|
18
18
|
class Error < StandardError; end
|
19
19
|
|
20
|
-
# Error
|
20
|
+
# Error raised when server returns 404 Not Found
|
21
21
|
class NotFoundError < Error; end
|
22
22
|
|
23
|
-
# Error
|
24
|
-
|
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
|
-
|
54
|
-
|
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
|
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
|
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
|
@@ -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 =
|
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,53 +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
|
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
|
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
|
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
|
40
|
-
|
41
|
-
|
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
|
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
|
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 =
|
77
|
+
req_url = "#{api_version}/#{path}"
|
55
78
|
resp =
|
56
79
|
case method
|
57
|
-
when :get
|
58
|
-
connection.
|
59
|
-
when :post
|
80
|
+
when :delete, :get
|
81
|
+
connection.public_send(method, req_url, params)
|
82
|
+
when :patch, :post, :put
|
60
83
|
request_json = params.to_json if params&.any?
|
61
|
-
connection.
|
84
|
+
connection.public_send(method, req_url, request_json, 'Content-Type' => 'application/json')
|
62
85
|
end
|
86
|
+
|
63
87
|
return resp.body if resp.success?
|
64
88
|
|
65
89
|
errmsg = ResponseErrorFormatter.format(response: resp, client_method_name: caller_locations.first.label)
|
66
|
-
raise
|
90
|
+
raise UnexpectedResponseError, errmsg
|
67
91
|
rescue Faraday::ResourceNotFound => e
|
68
92
|
errmsg = "Preservation::Client.#{caller_locations.first.label} " \
|
69
93
|
"got #{e.response[:status]} from Preservation at #{req_url}: #{e.response[:body]}"
|
70
|
-
raise
|
94
|
+
raise NotFoundError, errmsg
|
71
95
|
rescue Faraday::Error => e
|
72
96
|
errmsg = "Preservation::Client.#{caller_locations.first.label} " \
|
73
97
|
"got #{e.response[:status]} from Preservation at #{req_url}: #{e.response[:body]}"
|
74
|
-
|
98
|
+
exception_class = e.response[:status] == 423 ? LockedError : UnexpectedResponseError
|
99
|
+
raise exception_class, errmsg
|
75
100
|
end
|
76
101
|
end
|
77
102
|
end
|
data/preservation-client.gemspec
CHANGED
@@ -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', '
|
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.
|
4
|
+
version: 3.4.0
|
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:
|
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:
|
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:
|
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:
|
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:
|
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.
|
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
|