preservation-client 2.1.0 → 3.2.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 +4 -4
- data/.github/pull_request_template.md +9 -1
- data/.rubocop.yml +0 -1
- data/.rubocop_todo.yml +6 -2
- data/.travis.yml +7 -3
- data/README.md +9 -3
- data/lib/preservation/client.rb +10 -2
- data/lib/preservation/client/catalog.rb +1 -1
- data/lib/preservation/client/objects.rb +15 -5
- data/lib/preservation/client/version.rb +1 -1
- data/lib/preservation/client/versioned_api_service.rb +39 -9
- data/preservation-client.gemspec +3 -3
- metadata +19 -13
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 346519c8c530b30507578d91469ffd1f50cf08fe3b6b5f5e46905f35e6d870ab
|
4
|
+
data.tar.gz: 38afa1c113b86737ac3593101b3bfc1133de42bc58398de19250636bbdbefc05
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 81c98f1a410de28f6c8bf90dff39c5537670aa4c8ce4625779d21bd8fbbe3c6341a0930f0fc8572a417d6fd1bd5cba4d69586deb402cf8d9d70e695114138306
|
7
|
+
data.tar.gz: 38e22150bc23cf59501893becb24a39c98eb51d8ac12b5acad80f0a8ad108381a6d9cf88a5f1120a32e9388cfc36c0d1e1dfea5c6cf8b3cf42de74e2c6bda5d7
|
data/.rubocop.yml
CHANGED
data/.rubocop_todo.yml
CHANGED
@@ -1,11 +1,15 @@
|
|
1
1
|
# This configuration was generated by
|
2
2
|
# `rubocop --auto-gen-config`
|
3
|
-
# on
|
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:
|
9
|
+
# Offense count: 2
|
10
10
|
Metrics/AbcSize:
|
11
11
|
Max: 34
|
12
|
+
|
13
|
+
# Offense count: 1
|
14
|
+
Metrics/CyclomaticComplexity:
|
15
|
+
Max: 7
|
data/.travis.yml
CHANGED
@@ -3,12 +3,16 @@ cache: bundler
|
|
3
3
|
rvm:
|
4
4
|
- 2.5.3
|
5
5
|
- 2.6.4
|
6
|
+
- 2.7.1
|
6
7
|
|
7
8
|
env:
|
8
|
-
|
9
|
-
|
9
|
+
jobs:
|
10
|
+
- RAILS_VERSION=5.2.3
|
11
|
+
- RAILS_VERSION=6.0.0
|
12
|
+
global:
|
13
|
+
- CC_TEST_REPORTER_ID=02e8afad8d0b699828dd69b6f45b598e7317b2d9828ea23380c3a97113068a0c
|
10
14
|
|
11
|
-
before_install: gem install bundler -v 2.
|
15
|
+
before_install: gem install bundler -v 2.1.2
|
12
16
|
|
13
17
|
before_script:
|
14
18
|
- curl -L https://codeclimate.com/downloads/test-reporter/test-reporter-latest-linux-amd64 > ./cc-test-reporter
|
data/README.md
CHANGED
@@ -37,7 +37,7 @@ end
|
|
37
37
|
private
|
38
38
|
|
39
39
|
def client
|
40
|
-
@client ||= Preservation::Client.configure(url: Settings.preservation_catalog.url)
|
40
|
+
@client ||= Preservation::Client.configure(url: Settings.preservation_catalog.url, token: Settings.preservation_catalog.token)
|
41
41
|
end
|
42
42
|
```
|
43
43
|
|
@@ -47,7 +47,7 @@ OR
|
|
47
47
|
require 'preservation/client'
|
48
48
|
|
49
49
|
def initialize
|
50
|
-
Preservation::Client.configure(url: Settings.preservation_catalog.url)
|
50
|
+
Preservation::Client.configure(url: Settings.preservation_catalog.url, token: Settings.preservation_catalog.token)
|
51
51
|
end
|
52
52
|
|
53
53
|
def do_the_thing
|
@@ -55,7 +55,9 @@ def do_the_thing
|
|
55
55
|
end
|
56
56
|
```
|
57
57
|
|
58
|
-
Note that the client may **not** be used without first having been configured, and the `url`
|
58
|
+
Note that the client may **not** be used without first having been configured, and both the `url` and `token` keywords are **required**.
|
59
|
+
|
60
|
+
See https://github.com/sul-dlss/preservation_catalog#api for info on obtaining a valid API token.
|
59
61
|
|
60
62
|
Note that the preservation service is behind a firewall.
|
61
63
|
|
@@ -86,6 +88,10 @@ Note that the preservation service is behind a firewall.
|
|
86
88
|
- `client.objects.metadata(druid: 'oo000oo0000', filepath: 'identityMetadata.xml', version: '8')` - returns contents of identityMetadata.xml in version 8 of Moab object
|
87
89
|
- `client.objects.signature_catalog('oo000oo0000')` - returns latest Moab::SignatureCatalog from Moab
|
88
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
|
+
|
89
95
|
### Get difference information between passed contentMetadata.xml and files in the Moab
|
90
96
|
|
91
97
|
- `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
@@ -27,6 +27,7 @@ module Preservation
|
|
27
27
|
class ConnectionFailedError < Error; end
|
28
28
|
|
29
29
|
DEFAULT_API_VERSION = 'v1'
|
30
|
+
TOKEN_HEADER = 'Authorization'
|
30
31
|
|
31
32
|
include Singleton
|
32
33
|
|
@@ -42,8 +43,10 @@ module Preservation
|
|
42
43
|
|
43
44
|
class << self
|
44
45
|
# @param [String] url
|
45
|
-
|
46
|
+
# @param [String] token a bearer token for HTTP authentication
|
47
|
+
def configure(url:, token:)
|
46
48
|
instance.url = url
|
49
|
+
instance.token = token
|
47
50
|
|
48
51
|
# Force connection to be re-established when `.configure` is called
|
49
52
|
instance.connection = nil
|
@@ -54,7 +57,7 @@ module Preservation
|
|
54
57
|
delegate :objects, :update, to: :instance
|
55
58
|
end
|
56
59
|
|
57
|
-
attr_writer :url, :connection
|
60
|
+
attr_writer :url, :connection, :token
|
58
61
|
delegate :update, to: :catalog
|
59
62
|
|
60
63
|
private
|
@@ -63,6 +66,10 @@ module Preservation
|
|
63
66
|
@url || raise(Error, 'url has not yet been configured')
|
64
67
|
end
|
65
68
|
|
69
|
+
def token
|
70
|
+
@token || raise(Error, 'auth token has not been configured')
|
71
|
+
end
|
72
|
+
|
66
73
|
def connection
|
67
74
|
@connection ||= Faraday.new(url) do |builder|
|
68
75
|
builder.use ErrorFaradayMiddleware
|
@@ -70,6 +77,7 @@ module Preservation
|
|
70
77
|
builder.use Faraday::Response::RaiseError # raise exceptions on 40x, 50x responses
|
71
78
|
builder.adapter Faraday.default_adapter
|
72
79
|
builder.headers[:user_agent] = user_agent
|
80
|
+
builder.headers[TOKEN_HEADER] = "Bearer #{token}"
|
73
81
|
end
|
74
82
|
end
|
75
83
|
|
@@ -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,14 @@ module Preservation
|
|
70
71
|
file(druid, 'metadata', filepath, version)
|
71
72
|
end
|
72
73
|
|
74
|
+
# retrieve the storage location for the primary moab of the given druid
|
75
|
+
# @param [String] druid - with or without prefix: 'druid:ab123cd4567' or 'ab123cd4567'
|
76
|
+
# @return [String] the storage location of the primary moab for the given druid
|
77
|
+
# @raise [Preservation::Client::NotFoundError] when druid is not found
|
78
|
+
def primary_moab_location(druid:)
|
79
|
+
get("objects/#{druid}/primary_moab_location", {}, on_data: nil)
|
80
|
+
end
|
81
|
+
|
73
82
|
# convenience method for retrieving latest Moab::SignatureCatalog from a Moab object,
|
74
83
|
# @param [String] druid - with or without prefix: 'druid:ab123cd4567' OR 'ab123cd4567'
|
75
84
|
# @return [Moab::SignatureCatalog] the manifest of all files previously ingested
|
@@ -83,10 +92,11 @@ module Preservation
|
|
83
92
|
# @param [String] druid - with or without prefix: 'druid:ab123cd4567' OR 'ab123cd4567'
|
84
93
|
# @param [String] category - one of 'manifest', 'metadata' or 'content'
|
85
94
|
# @param [String] filepath - the path of the file relative to the moab category directory
|
86
|
-
# @param [String] version - the version of the file requested
|
95
|
+
# @param [String] version - the version of the file requested
|
96
|
+
# @param [Proc] on_data a block, if provided is called to do streaming responses
|
87
97
|
# @return the retrieved file
|
88
|
-
def file(druid, category, filepath, version
|
89
|
-
get("objects/#{druid}/file", category: category, filepath: filepath, version: version)
|
98
|
+
def file(druid, category, filepath, version, on_data: nil)
|
99
|
+
get("objects/#{druid}/file", { category: category, filepath: filepath, version: version }, on_data: on_data)
|
90
100
|
end
|
91
101
|
end
|
92
102
|
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'
|
@@ -36,23 +36,53 @@ module Preservation
|
|
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 =
|
55
|
-
resp =
|
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
|
56
86
|
return resp.body if resp.success?
|
57
87
|
|
58
88
|
errmsg = ResponseErrorFormatter.format(response: resp, client_method_name: caller_locations.first.label)
|
data/preservation-client.gemspec
CHANGED
@@ -29,15 +29,15 @@ Gem::Specification.new do |spec|
|
|
29
29
|
spec.require_paths = ['lib']
|
30
30
|
|
31
31
|
spec.add_dependency 'activesupport', '>= 4.2', '< 7'
|
32
|
-
spec.add_dependency 'faraday', '
|
32
|
+
spec.add_dependency 'faraday', '>= 0.15', '< 2.0'
|
33
33
|
spec.add_dependency 'moab-versioning', '~> 4.3'
|
34
34
|
spec.add_dependency 'zeitwerk', '~> 2.1'
|
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: 2.1
|
4
|
+
version: 3.2.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Naomi Dushay
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2020-06-25 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -34,16 +34,22 @@ dependencies:
|
|
34
34
|
name: faraday
|
35
35
|
requirement: !ruby/object:Gem::Requirement
|
36
36
|
requirements:
|
37
|
-
- - "
|
37
|
+
- - ">="
|
38
38
|
- !ruby/object:Gem::Version
|
39
39
|
version: '0.15'
|
40
|
+
- - "<"
|
41
|
+
- !ruby/object:Gem::Version
|
42
|
+
version: '2.0'
|
40
43
|
type: :runtime
|
41
44
|
prerelease: false
|
42
45
|
version_requirements: !ruby/object:Gem::Requirement
|
43
46
|
requirements:
|
44
|
-
- - "
|
47
|
+
- - ">="
|
45
48
|
- !ruby/object:Gem::Version
|
46
49
|
version: '0.15'
|
50
|
+
- - "<"
|
51
|
+
- !ruby/object:Gem::Version
|
52
|
+
version: '2.0'
|
47
53
|
- !ruby/object:Gem::Dependency
|
48
54
|
name: moab-versioning
|
49
55
|
requirement: !ruby/object:Gem::Requirement
|
@@ -104,16 +110,16 @@ dependencies:
|
|
104
110
|
name: rake
|
105
111
|
requirement: !ruby/object:Gem::Requirement
|
106
112
|
requirements:
|
107
|
-
- - "
|
113
|
+
- - ">="
|
108
114
|
- !ruby/object:Gem::Version
|
109
|
-
version:
|
115
|
+
version: 12.3.3
|
110
116
|
type: :development
|
111
117
|
prerelease: false
|
112
118
|
version_requirements: !ruby/object:Gem::Requirement
|
113
119
|
requirements:
|
114
|
-
- - "
|
120
|
+
- - ">="
|
115
121
|
- !ruby/object:Gem::Version
|
116
|
-
version:
|
122
|
+
version: 12.3.3
|
117
123
|
- !ruby/object:Gem::Dependency
|
118
124
|
name: rspec
|
119
125
|
requirement: !ruby/object:Gem::Requirement
|
@@ -146,16 +152,16 @@ dependencies:
|
|
146
152
|
name: simplecov
|
147
153
|
requirement: !ruby/object:Gem::Requirement
|
148
154
|
requirements:
|
149
|
-
- - "
|
155
|
+
- - "~>"
|
150
156
|
- !ruby/object:Gem::Version
|
151
|
-
version:
|
157
|
+
version: 0.17.0
|
152
158
|
type: :development
|
153
159
|
prerelease: false
|
154
160
|
version_requirements: !ruby/object:Gem::Requirement
|
155
161
|
requirements:
|
156
|
-
- - "
|
162
|
+
- - "~>"
|
157
163
|
- !ruby/object:Gem::Version
|
158
|
-
version:
|
164
|
+
version: 0.17.0
|
159
165
|
- !ruby/object:Gem::Dependency
|
160
166
|
name: webmock
|
161
167
|
requirement: !ruby/object:Gem::Requirement
|
@@ -219,7 +225,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
219
225
|
- !ruby/object:Gem::Version
|
220
226
|
version: '0'
|
221
227
|
requirements: []
|
222
|
-
rubygems_version: 3.1.
|
228
|
+
rubygems_version: 3.1.2
|
223
229
|
signing_key:
|
224
230
|
specification_version: 4
|
225
231
|
summary: A thin client for getting info from SDR preservation.
|