preservation-client 2.0.0 → 2.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +3 -0
- data/lib/preservation/client.rb +10 -16
- data/lib/preservation/client/catalog.rb +41 -0
- data/lib/preservation/client/version.rb +1 -1
- data/lib/preservation/client/versioned_api_service.rb +13 -19
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: cb9503d9df7485a439b8f65ae7eb319dab3386e6cf316edc4c9d7f04793a8880
|
4
|
+
data.tar.gz: 39c772d761d5309ca4f8bf7910b044fdc6b11c079a9ccadb61e48b62e522f136
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d41e1ab66f52b1746a972983512321637de9081578cee2810214fe9d454337342d6903bef283172c4be934005cbc3109201ccfed3d19a9ab265f3a6c8684ab0d
|
7
|
+
data.tar.gz: 88d29967a9630ba8b693a4b551f6460233e8994b06365b1c6101f06c4239ed2d3e0ddb33ac2cd494931130aacd372135b5875e3e29b5eae6e39b54b1acef6583
|
data/README.md
CHANGED
@@ -94,6 +94,9 @@ Note that the preservation service is behind a firewall.
|
|
94
94
|
|
95
95
|
- `client.objects.shelve_content_diff(druid: 'oo000oo0000', content_metadata: '<contentMetadata>...</contentMetadata>')` - returns Moab::FileGroupDifference containing differences between passed content metadata and latest version for subset 'shelve'
|
96
96
|
|
97
|
+
### Alert the catalog that an object has been changed and needs to be updated
|
98
|
+
|
99
|
+
- `client.update(druid: 'oo000oo0000', version: 3, size: 2342, storage_location: 'some/storage/location')` - returns true if it worked
|
97
100
|
## Development
|
98
101
|
|
99
102
|
After checking out the repo, run `bundle` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
data/lib/preservation/client.rb
CHANGED
@@ -7,20 +7,8 @@ require 'faraday'
|
|
7
7
|
require 'singleton'
|
8
8
|
require 'zeitwerk'
|
9
9
|
|
10
|
-
# Provides version exception to camels-case conversion
|
11
|
-
class PreservationClientInflector < Zeitwerk::Inflector
|
12
|
-
def camelize(basename, _abspath)
|
13
|
-
case basename
|
14
|
-
when 'version'
|
15
|
-
'VERSION'
|
16
|
-
else
|
17
|
-
super
|
18
|
-
end
|
19
|
-
end
|
20
|
-
end
|
21
|
-
|
22
10
|
loader = Zeitwerk::Loader.new
|
23
|
-
loader.inflector =
|
11
|
+
loader.inflector = Zeitwerk::GemInflector.new(__FILE__)
|
24
12
|
loader.push_dir(File.absolute_path("#{__FILE__}/../.."))
|
25
13
|
loader.setup
|
26
14
|
|
@@ -38,7 +26,7 @@ module Preservation
|
|
38
26
|
|
39
27
|
class ConnectionFailedError < Error; end
|
40
28
|
|
41
|
-
DEFAULT_API_VERSION = ''
|
29
|
+
DEFAULT_API_VERSION = 'v1'
|
42
30
|
|
43
31
|
include Singleton
|
44
32
|
|
@@ -47,6 +35,11 @@ module Preservation
|
|
47
35
|
@objects ||= Objects.new(connection: connection, api_version: DEFAULT_API_VERSION)
|
48
36
|
end
|
49
37
|
|
38
|
+
# @return [Preservation::Client::Catalog] an instance of the `Client::Catalog` class
|
39
|
+
def catalog
|
40
|
+
@catalog ||= Catalog.new(connection: connection, api_version: DEFAULT_API_VERSION)
|
41
|
+
end
|
42
|
+
|
50
43
|
class << self
|
51
44
|
# @param [String] url
|
52
45
|
def configure(url:)
|
@@ -58,10 +51,11 @@ module Preservation
|
|
58
51
|
self
|
59
52
|
end
|
60
53
|
|
61
|
-
delegate :objects, to: :instance
|
54
|
+
delegate :objects, :update, to: :instance
|
62
55
|
end
|
63
56
|
|
64
57
|
attr_writer :url, :connection
|
58
|
+
delegate :update, to: :catalog
|
65
59
|
|
66
60
|
private
|
67
61
|
|
@@ -73,7 +67,7 @@ module Preservation
|
|
73
67
|
@connection ||= Faraday.new(url) do |builder|
|
74
68
|
builder.use ErrorFaradayMiddleware
|
75
69
|
builder.use Faraday::Request::UrlEncoded
|
76
|
-
|
70
|
+
builder.use Faraday::Response::RaiseError # raise exceptions on 40x, 50x responses
|
77
71
|
builder.adapter Faraday.default_adapter
|
78
72
|
builder.headers[:user_agent] = user_agent
|
79
73
|
end
|
@@ -0,0 +1,41 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module Preservation
|
4
|
+
class Client
|
5
|
+
# API calls that are about the catalog
|
6
|
+
class Catalog < VersionedApiService
|
7
|
+
# @param [String] druid the object identifierx
|
8
|
+
# @param [Integer] version the version of the object
|
9
|
+
# @param [Integer] size the size of the object
|
10
|
+
# @param [String] storage_location the location of storage
|
11
|
+
def update(druid:, version:, size:, storage_location:)
|
12
|
+
http_args = {
|
13
|
+
druid: druid,
|
14
|
+
incoming_version: version,
|
15
|
+
incoming_size: size,
|
16
|
+
storage_location: storage_location,
|
17
|
+
checksums_validated: true
|
18
|
+
}
|
19
|
+
|
20
|
+
request(druid: druid, version: version, http_args: http_args)
|
21
|
+
end
|
22
|
+
|
23
|
+
private
|
24
|
+
|
25
|
+
def request(druid:, version:, http_args:)
|
26
|
+
result = if version == 1
|
27
|
+
connection.post "/#{api_version}/catalog", http_args
|
28
|
+
else
|
29
|
+
connection.patch "/#{api_version}/catalog/#{druid}", http_args
|
30
|
+
end
|
31
|
+
unless result.success?
|
32
|
+
raise UnexpectedResponseError, "response was not successful. Received status #{result.status}"
|
33
|
+
end
|
34
|
+
|
35
|
+
true
|
36
|
+
rescue Faraday::ClientError => e
|
37
|
+
raise UnexpectedResponseError, e
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
@@ -2,8 +2,6 @@
|
|
2
2
|
|
3
3
|
module Preservation
|
4
4
|
class Client
|
5
|
-
DEFAULT_API_VERSION = 'v1'
|
6
|
-
|
7
5
|
# @abstract API calls to a versioned endpoint
|
8
6
|
class VersionedApiService
|
9
7
|
def initialize(connection:, api_version: DEFAULT_API_VERSION)
|
@@ -25,19 +23,15 @@ module Preservation
|
|
25
23
|
end
|
26
24
|
return JSON.parse(resp.body).with_indifferent_access if resp.success?
|
27
25
|
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
.format(response: resp, object_id: object_id, client_method_name: caller_locations.first.label)
|
34
|
-
raise Preservation::Client::UnexpectedResponseError, errmsg
|
35
|
-
end
|
36
|
-
rescue Faraday::ResourceNotFound => e
|
37
|
-
errmsg = "HTTP GET to #{connection.url_prefix}#{req_url} failed with #{e.class}: #{e.message}"
|
26
|
+
errmsg = ResponseErrorFormatter
|
27
|
+
.format(response: resp, object_id: object_id, client_method_name: caller_locations.first.label)
|
28
|
+
raise Preservation::Client::UnexpectedResponseError, errmsg
|
29
|
+
rescue Faraday::ResourceNotFound
|
30
|
+
errmsg = "#{object_id} not found in Preservation at #{connection.url_prefix}#{req_url}"
|
38
31
|
raise Preservation::Client::NotFoundError, errmsg
|
39
32
|
rescue Faraday::Error => e
|
40
|
-
errmsg = "
|
33
|
+
errmsg = "Preservation::Client.#{caller_locations.first.label} for #{object_id} " \
|
34
|
+
"got #{e.response[:status]} from Preservation at #{req_url}: #{e.response[:body]}"
|
41
35
|
raise Preservation::Client::UnexpectedResponseError, errmsg
|
42
36
|
end
|
43
37
|
|
@@ -57,19 +51,19 @@ module Preservation
|
|
57
51
|
# @param path [String] path to be appended to connection url (no leading slash)
|
58
52
|
# @param params [Hash] optional params
|
59
53
|
def http_response(method, path, params)
|
60
|
-
|
61
|
-
resp = connection.send(method,
|
54
|
+
req_url = api_version.present? ? "#{api_version}/#{path}" : path
|
55
|
+
resp = connection.send(method, req_url, params)
|
62
56
|
return resp.body if resp.success?
|
63
57
|
|
64
58
|
errmsg = ResponseErrorFormatter.format(response: resp, client_method_name: caller_locations.first.label)
|
65
|
-
raise Preservation::Client::NotFoundError, errmsg if resp.status == 404
|
66
|
-
|
67
59
|
raise Preservation::Client::UnexpectedResponseError, errmsg
|
68
60
|
rescue Faraday::ResourceNotFound => e
|
69
|
-
errmsg = "
|
61
|
+
errmsg = "Preservation::Client.#{caller_locations.first.label} " \
|
62
|
+
"got #{e.response[:status]} from Preservation at #{req_url}: #{e.response[:body]}"
|
70
63
|
raise Preservation::Client::NotFoundError, errmsg
|
71
64
|
rescue Faraday::Error => e
|
72
|
-
errmsg = "
|
65
|
+
errmsg = "Preservation::Client.#{caller_locations.first.label} " \
|
66
|
+
"got #{e.response[:status]} from Preservation at #{req_url}: #{e.response[:body]}"
|
73
67
|
raise Preservation::Client::UnexpectedResponseError, errmsg
|
74
68
|
end
|
75
69
|
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: 2.
|
4
|
+
version: 2.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Naomi Dushay
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-12-
|
11
|
+
date: 2019-12-20 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -191,6 +191,7 @@ files:
|
|
191
191
|
- bin/console
|
192
192
|
- bin/setup
|
193
193
|
- lib/preservation/client.rb
|
194
|
+
- lib/preservation/client/catalog.rb
|
194
195
|
- lib/preservation/client/error_faraday_middleware.rb
|
195
196
|
- lib/preservation/client/objects.rb
|
196
197
|
- lib/preservation/client/response_error_formatter.rb
|