atlas_rb 1.29.4 → 1.29.5

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: bc6d758d43135f85f61b7a8a0aa8ba86af108d4894d84f17cee9d91b7bdffbb8
4
- data.tar.gz: ca3e2c5a080af089e4fd2734b2a8b185f3ad54d2ee58a53b3aef61ec3b518691
3
+ metadata.gz: 7cdd1ba747d179bcbbb626b2b7c30019528bc178f44989eb29675db8652cd97d
4
+ data.tar.gz: ea5c28d889908432a4fa9886c4b8f724123037094e0fd67d724513273dc927a2
5
5
  SHA512:
6
- metadata.gz: fd67f7abf09587a4dc0d5fc284a76108e618fa34e0c32f38a900a5ccda11d5e31255f5ab01461435674a03d08a067b71eabba49a37ceada0ad034ee5dc7d1531
7
- data.tar.gz: eae45b648e6322aeefefc3e67f4e35c53fda0a87a36a29613b2b7d27183237a104ec5ecd5082bde721b6dfe6f049109aa247ea7d027f7762574adc9e50ab6ea7
6
+ metadata.gz: 7c4ea4ec7ffb45e9e7457e5fbfa0d7db47d42468f9a6269c170e71ad0c1ee0033fa125995131ea4f21231dd42716a666d3060e93e356cb85ea396ea9e535dc65
7
+ data.tar.gz: cb8fdeb2c48af7f6850489ff77a88a3063dfe3071b9cc0149f517c927156f64db8eb2a106dc42d7fbf54b9d1a5dc3c3f2c7883dd6fbccc76ad3ccf161c53f271
data/.version CHANGED
@@ -1 +1 @@
1
- 1.29.4
1
+ 1.29.5
data/CHANGELOG.md CHANGED
@@ -1,5 +1,35 @@
1
1
  # Changelog
2
2
 
3
+ ## 1.29.5
4
+
5
+ Needs an Atlas that records a v1 pid (0.6.279 or later). An older Atlas ignores
6
+ the `legacy_pid:` param, and the lookup answers `nil`.
7
+
8
+ ### Changed — needs Ruby 3.2 or later
9
+
10
+ `required_ruby_version` rises from 2.6 to 3.2, the oldest Ruby a consumer runs
11
+ (Cerberus). The gem's CI already builds on 3.4 only.
12
+
13
+ ### Added — `legacy_pid:` on `Community.create`, `Collection.create` and `Work.create`
14
+
15
+ Records the v1 pid a migrated object came from, on its first save. Admin only:
16
+ anyone else gets `ForbiddenError` with `action` `"supply_legacy_pid"`, and
17
+ nothing is created. There is no way to change the pid after the create.
18
+
19
+ ### Added — `LegacyPidError`
20
+
21
+ Raised when Atlas refuses the pid: `code` is `"invalid_legacy_pid"` (a `422`)
22
+ or `"legacy_pid_taken"` (a `409`). On a `409`, `holder_id` is the NOID of the
23
+ resource that holds the pid. A subclass of `ResourceError`.
24
+
25
+ ### Added — `Resource.find_by_legacy_pid` and `System.find_by_legacy_pid`
26
+
27
+ Wrap `GET /resources/legacy/<pid>` and return `id`, `type` and `tombstoned`, or
28
+ `nil` when nothing holds the pid. A tombstoned holder is still returned. The
29
+ user-path method answers `nil` for a holder the caller may not read; the system
30
+ method reads past that gate, so a host can redirect an old v1 URL for any
31
+ visitor.
32
+
3
33
  ## 1.29.4
4
34
 
5
35
  Needs an Atlas that accepts a supplied handle (0.6.277 or later). An older
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- atlas_rb (1.29.4)
4
+ atlas_rb (1.29.5)
5
5
  faraday (~> 2.7)
6
6
  faraday-follow_redirects (~> 0.3.0)
7
7
  faraday-multipart (~> 1)
@@ -14,7 +14,7 @@ GEM
14
14
  remote: https://rubygems.org/
15
15
  specs:
16
16
  base64 (0.3.0)
17
- connection_pool (2.5.5)
17
+ connection_pool (3.0.2)
18
18
  diff-lcs (1.6.1)
19
19
  faraday (2.15.1)
20
20
  faraday-net_http (>= 2.0, < 3.6)
@@ -72,10 +72,18 @@ module AtlasRb
72
72
  # while attributing it to the anonymous NUID, since nobody personally owns
73
73
  # those containers and access to them is via Grouper groups. The depositor
74
74
  # is immutable post-create; there is no setter on the update surface.
75
+ # @param legacy_pid [String, nil] optional v1 pid the Collection migrated
76
+ # from, such as `"neu:5678"`. Admin only; anyone else gets
77
+ # {ForbiddenError} with `action` `"supply_legacy_pid"`. It lands on the
78
+ # first save, so send it here and not on a later `put_mods`. There is no
79
+ # way to change it after the create. Needs Atlas 0.6.279 or later.
75
80
  # @return [Hash] the created Collection payload (post-update if
76
81
  # `xml_path` was supplied).
77
82
  # @raise [AtlasRb::NotFoundError] if Atlas answers `404` — the id names no such
78
83
  # resource, so the write did not happen.
84
+ # @raise [AtlasRb::LegacyPidError] if Atlas refuses the `legacy_pid:` as
85
+ # malformed (`422`) or held by another resource (`409`, with
86
+ # {LegacyPidError#holder_id}).
79
87
  # @raise [AtlasRb::ResourceError] on any other non-2xx, carrying Atlas's status
80
88
  # and body.
81
89
  #
@@ -84,9 +92,14 @@ module AtlasRb
84
92
  #
85
93
  # @example An institutional container owned by nobody
86
94
  # AtlasRb::Collection.create("c-123", depositor: "000000099")
87
- def self.create(id, xml_path = nil, featured: false, nuid: nil, on_behalf_of: nil, depositor: nil)
95
+ #
96
+ # @example A migrated Collection that records its v1 pid
97
+ # AtlasRb::Collection.create("c-123", legacy_pid: "neu:5678", nuid: admin_nuid)
98
+ def self.create(id, xml_path = nil, featured: false, nuid: nil, on_behalf_of: nil, depositor: nil,
99
+ legacy_pid: nil)
88
100
  params = { parent_id: id, featured: featured }
89
- params[:depositor] = depositor if depositor
101
+ params[:depositor] = depositor if depositor
102
+ params[:legacy_pid] = legacy_pid if legacy_pid
90
103
  result = AtlasRb::Mash.new(write_resource(
91
104
  connection(params, nuid, on_behalf_of: on_behalf_of).post(ROUTE)
92
105
  ))["collection"]
@@ -67,10 +67,18 @@ module AtlasRb
67
67
  # while attributing it to the anonymous NUID, since nobody personally owns
68
68
  # those containers and access to them is via Grouper groups. The depositor
69
69
  # is immutable post-create; there is no setter on the update surface.
70
+ # @param legacy_pid [String, nil] optional v1 pid the Community migrated
71
+ # from, such as `"neu:1"`. Admin only; anyone else gets
72
+ # {ForbiddenError} with `action` `"supply_legacy_pid"`. It lands on the
73
+ # first save, so send it here and not on a later `put_mods`. There is no
74
+ # way to change it after the create. Needs Atlas 0.6.279 or later.
70
75
  # @return [Hash] the created Community payload (post-update if `xml_path`
71
76
  # was supplied).
72
77
  # @raise [AtlasRb::NotFoundError] if Atlas answers `404` — the id names no such
73
78
  # resource, so the write did not happen.
79
+ # @raise [AtlasRb::LegacyPidError] if Atlas refuses the `legacy_pid:` as
80
+ # malformed (`422`) or held by another resource (`409`, with
81
+ # {LegacyPidError#holder_id}).
74
82
  # @raise [AtlasRb::ResourceError] on any other non-2xx, carrying Atlas's status
75
83
  # and body.
76
84
  #
@@ -82,9 +90,13 @@ module AtlasRb
82
90
  #
83
91
  # @example An institutional container owned by nobody
84
92
  # AtlasRb::Community.create("c-parent", depositor: "000000099")
85
- def self.create(id = nil, xml_path = nil, nuid: nil, on_behalf_of: nil, depositor: nil)
93
+ #
94
+ # @example The migrated repository root, which stands in for v1's neu:1
95
+ # AtlasRb::Community.create(nil, legacy_pid: "neu:1", nuid: admin_nuid)
96
+ def self.create(id = nil, xml_path = nil, nuid: nil, on_behalf_of: nil, depositor: nil, legacy_pid: nil)
86
97
  params = { parent_id: id }
87
- params[:depositor] = depositor if depositor
98
+ params[:depositor] = depositor if depositor
99
+ params[:legacy_pid] = legacy_pid if legacy_pid
88
100
  result = AtlasRb::Mash.new(write_resource(
89
101
  connection(params, nuid, on_behalf_of: on_behalf_of).post(ROUTE)
90
102
  ))["community"]
@@ -378,6 +378,50 @@ module AtlasRb
378
378
  # a caller that only wants "the write failed" can rescue the parent.
379
379
  class NotFoundError < ResourceError; end
380
380
 
381
+ # Raised when Atlas refuses a create's `legacy_pid:`: a value that is not a
382
+ # v1 pid (`422`, `invalid_legacy_pid`), or one another resource already
383
+ # holds (`409`, `legacy_pid_taken`).
384
+ #
385
+ # On a `409`, {#holder_id} is the holder's NOID. A migration that crashed
386
+ # between the create and its own bookkeeping reads it to recover, rather
387
+ # than parsing the message:
388
+ #
389
+ # rescue AtlasRb::LegacyPidError => e
390
+ # raise unless e.code == "legacy_pid_taken"
391
+ # ledger.record(pid, e.holder_id)
392
+ #
393
+ # A subclass of {ResourceError}, so a caller that only wants "the create
394
+ # failed" can rescue the parent. Needs Atlas 0.6.279 or later.
395
+ class LegacyPidError < ResourceError
396
+ # The discriminators Atlas renders. An exact-match wire contract.
397
+ CODES = %w[invalid_legacy_pid legacy_pid_taken].freeze
398
+
399
+ # @return [String] the envelope's `error` code.
400
+ attr_reader :code
401
+
402
+ # @return [String, nil] NOID of the resource that holds the pid, on a `409`.
403
+ attr_reader :holder_id
404
+
405
+ # @param message [String] human-readable refusal description.
406
+ # @param envelope [Hash] Atlas's parsed refusal body.
407
+ # @param response [Faraday::Response, nil] the originating response.
408
+ def initialize(message, envelope, response: nil)
409
+ super(message, response: response)
410
+ @code = envelope["error"]
411
+ @holder_id = envelope["resource_id"]
412
+ end
413
+
414
+ # @return [Hash, nil] the envelope when `body` is a legacy-pid refusal,
415
+ # parsed; `nil` for any other body.
416
+ # @api private
417
+ def self.envelope(body)
418
+ parsed = body.is_a?(Hash) ? body : JSON.parse(body.to_s)
419
+ parsed if parsed.is_a?(Hash) && CODES.include?(parsed["error"])
420
+ rescue JSON::ParserError
421
+ nil
422
+ end
423
+ end
424
+
381
425
  # Raised when Atlas withholds a file, or a Work's file list, because of a
382
426
  # tombstone: an HTTP `410` whose body carries `error: "tombstoned"`.
383
427
  #
@@ -133,6 +133,38 @@ module AtlasRb
133
133
  "resource" => result.first[1])
134
134
  end
135
135
 
136
+ # Find the Community, Collection or Work a v1 pid migrated to.
137
+ #
138
+ # Wraps `GET /resources/legacy/<pid>`. A tombstoned holder is still
139
+ # answered, flagged, so an old v1 URL can land on its tombstone page. Atlas
140
+ # answers a holder the caller may not read exactly as an unknown pid, so
141
+ # `nil` means "nothing this caller can see holds it". To resolve a pid for
142
+ # any visitor, use {AtlasRb::System.find_by_legacy_pid}.
143
+ #
144
+ # @param pid [String] a v1 pid, `neu:` prefix included.
145
+ # @param nuid [String, nil] optional acting user's NUID. On the relay-signing
146
+ # path it is signed into the assertion `sub`; on the BYO-JWT (`ATLAS_JWT`)
147
+ # path it is ignored (identity lives in the token).
148
+ # @return [AtlasRb::Mash, nil] `id` (the NOID), `type` (`"Community"`,
149
+ # `"Collection"` or `"Work"`) and `tombstoned`, or `nil` on a `404`.
150
+ # @raise [AtlasRb::ResourceError] on any other non-2xx.
151
+ #
152
+ # @example
153
+ # AtlasRb::Resource.find_by_legacy_pid("neu:1234")
154
+ # # => { "id" => "abc123", "type" => "Work", "tombstoned" => false }
155
+ def self.find_by_legacy_pid(pid, nuid: nil)
156
+ result = fetch_resource(legacy_pid_path(pid), nuid: nuid)
157
+ result && AtlasRb::Mash.new(result["resource"])
158
+ end
159
+
160
+ # The lookup path for a pid. The colon is put back after encoding,
161
+ # because Atlas's route matches the literal `neu:` prefix.
162
+ #
163
+ # @api private
164
+ def self.legacy_pid_path(pid)
165
+ "/resources/legacy/#{URI.encode_uri_component(pid.to_s).gsub('%3A', ':')}"
166
+ end
167
+
136
168
  # Resolve many resources by NOID in a single round-trip.
137
169
  #
138
170
  # Wraps Atlas's `POST /resources/find_many`, which returns one lightweight
@@ -606,7 +638,11 @@ module AtlasRb
606
638
  end
607
639
  return if resp.success? || resp.status == 410
608
640
 
609
- raise AtlasRb::ResourceError.new("#{request_target(resp)} → #{resp.status}: #{resp.body}", response: resp)
641
+ message = "#{request_target(resp)} → #{resp.status}: #{resp.body}"
642
+ envelope = AtlasRb::LegacyPidError.envelope(resp.body)
643
+ raise AtlasRb::LegacyPidError.new(message, envelope, response: resp) if envelope
644
+
645
+ raise AtlasRb::ResourceError.new(message, response: resp)
610
646
  end
611
647
  private_class_method :guard_write
612
648
 
@@ -76,5 +76,23 @@ module AtlasRb
76
76
  path = since ? "/embargoes/release?since=#{since.iso8601}" : "/embargoes/release"
77
77
  JSON.parse(system_connection.post(path).body)["released"]
78
78
  end
79
+
80
+ # Find the Community, Collection or Work a v1 pid migrated to, whoever the
81
+ # visitor is. The `:system` role reads past the per-resource gate, so a
82
+ # host redirecting an old v1 URL gets the holder even when the visitor
83
+ # could not read it; the destination page applies the visitor's own gate.
84
+ # {AtlasRb::Resource.find_by_legacy_pid} is the user-path lookup.
85
+ #
86
+ # @param pid [String] a v1 pid, `neu:` prefix included.
87
+ # @return [AtlasRb::Mash, nil] `id`, `type` and `tombstoned`, or `nil`
88
+ # when no resource holds the pid.
89
+ # @raise [AtlasRb::ResourceError] on any other non-2xx.
90
+ #
91
+ # @example Redirect an inbound /files/neu:xyz
92
+ # holder = AtlasRb::System.find_by_legacy_pid("neu:xyz")
93
+ def self.find_by_legacy_pid(pid)
94
+ result = read_body(system_connection.get(AtlasRb::Resource.legacy_pid_path(pid)))
95
+ result && AtlasRb::Mash.new(result["resource"])
96
+ end
79
97
  end
80
98
  end
data/lib/atlas_rb/work.rb CHANGED
@@ -133,14 +133,23 @@ module AtlasRb
133
133
  # re-points it. There is no way to change it after the create. Needs
134
134
  # Atlas 0.6.277 or later; an older Atlas ignores the param and mints a
135
135
  # second handle on `complete`.
136
+ # @param legacy_pid [String, nil] optional v1 pid the Work migrated from,
137
+ # such as `"neu:1234"`. Admin only. It lands on the Work's first save, so
138
+ # send it here and not on a later `put_mods`. There is no way to change
139
+ # it after the create. Needs Atlas 0.6.279 or later; an older Atlas
140
+ # ignores it.
136
141
  # @return [Hash] the created Work payload (post-update if `xml_path` was
137
142
  # supplied).
138
143
  # @raise [AtlasRb::NotFoundError] if Atlas answers `404` — the id names no such
139
144
  # resource, so the write did not happen.
140
145
  # @raise [AtlasRb::ForbiddenError] if Atlas answers `403`: the caller holds no
141
- # edit rights on the Collection, or sent `handle:` without being an admin
142
- # or delegated admin (`action` is then `"supply_handle"`). No Work is
146
+ # edit rights on the Collection, sent `handle:` without being an admin or
147
+ # delegated admin (`action` is then `"supply_handle"`), or sent
148
+ # `legacy_pid:` without being an admin (`"supply_legacy_pid"`). No Work is
143
149
  # created.
150
+ # @raise [AtlasRb::LegacyPidError] if Atlas refuses the `legacy_pid:` as
151
+ # malformed (`422`) or held by another resource (`409`, with
152
+ # {LegacyPidError#holder_id}).
144
153
  # @raise [AtlasRb::ResourceError] on any other non-2xx, carrying Atlas's status
145
154
  # and body. With `handle:`, a `422` (`invalid_handle`) means the value is
146
155
  # not `<prefix>/<suffix>`, and a `409` (`handle_taken`) means another
@@ -161,11 +170,15 @@ module AtlasRb
161
170
  #
162
171
  # @example Migrated Work that keeps its v1 handle
163
172
  # AtlasRb::Work.create("col-456", handle: "2047/d20001234", nuid: admin_nuid)
173
+ #
174
+ # @example Migrated Work that records its v1 pid
175
+ # AtlasRb::Work.create("col-456", legacy_pid: "neu:1234", nuid: admin_nuid)
164
176
  def self.create(id, xml_path = nil, idempotency_key: nil, nuid: nil,
165
- on_behalf_of: nil, depositor: nil, handle: nil)
177
+ on_behalf_of: nil, depositor: nil, handle: nil, legacy_pid: nil)
166
178
  params = { collection_id: id }
167
- params[:depositor] = depositor if depositor
168
- params[:handle] = handle if handle
179
+ params[:depositor] = depositor if depositor
180
+ params[:handle] = handle if handle
181
+ params[:legacy_pid] = legacy_pid if legacy_pid
169
182
  result = AtlasRb::Mash.new(write_resource(
170
183
  connection(params, nuid,
171
184
  on_behalf_of: on_behalf_of, idempotency_key: idempotency_key).post(ROUTE)
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: atlas_rb
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.29.4
4
+ version: 1.29.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - David Cliff
@@ -201,7 +201,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
201
201
  requirements:
202
202
  - - ">="
203
203
  - !ruby/object:Gem::Version
204
- version: 2.6.0
204
+ version: 3.2.0
205
205
  required_rubygems_version: !ruby/object:Gem::Requirement
206
206
  requirements:
207
207
  - - ">="