atlas_rb 1.29.8 → 1.29.10

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: e016b99621f6333435a65b3e1b54cc6f39093c0670a2108acd3bd65dd3631802
4
- data.tar.gz: d0414e258bd7585c011d47603ebf02ee130e15f475115e9f68a5c559293c87d5
3
+ metadata.gz: a41cd3a20e9d87272ff866480fbdd650d9c9a286afa63ad0fe999a978342be6a
4
+ data.tar.gz: ed569b1627bdb06488a35fa4f7683fe4b82bfa4f674dcde6b603655f9e2a2082
5
5
  SHA512:
6
- metadata.gz: 14318eb1682f816587172df5197d402bdd877c26e39c86c896f82d7bc78d46f243bf20d40aba6ea8592c26fb64c93fa7e9c05a1ed43f526b80f96ae278c4fab7
7
- data.tar.gz: 0d7e9eb96b6c13b420cdfa68a15cadf0439a42386d7488ce611085b957ee6befaefbf8a531b648acd763f43276872f665223f74b4777634b8fe7fc9adb9b4fdf
6
+ metadata.gz: 7473a5fb3a8a87d1176f8b8832df36bd4c952210d3ee52f027cecf96d0285673e27659e3d06e27c2d53eabe6a9949e45406965cdc5558fa22943206e3dc270fa
7
+ data.tar.gz: f145be9dc509c7c9bd01f93f1fd672dfd75fd07ff43edeeffee437b51b097609aaa7571a0e724850f2ba9ec55632a253ad03f01050577f58029822d6a76f310c
data/.version CHANGED
@@ -1 +1 @@
1
- 1.29.8
1
+ 1.29.10
data/CHANGELOG.md CHANGED
@@ -1,5 +1,29 @@
1
1
  # Changelog
2
2
 
3
+ ## 1.29.10
4
+
5
+ ### Fixed — documentation that the code contradicts
6
+
7
+ No code changed. The README and YARD now describe what the bindings do:
8
+
9
+ - `Resource.history` and `Resource.mods_versions` raise
10
+ `AtlasRb::ResourceError` on a `401` or `403`. They do not return a raw
11
+ Faraday response.
12
+ - `AuditEvent.emit` authenticates as the actor through a signed assertion,
13
+ not with the system token. A `401` or `403` comes back parsed, unraised.
14
+ - `Resource.dwc_versions` returns `nil` for an id that is not a Work.
15
+ - `Resource.set_permissions` gets no error when the caller removes a grant
16
+ for a group it is not in. Atlas keeps that grant and saves the rest.
17
+
18
+ ## 1.29.9
19
+
20
+ ### Added — `config.request_id`, sent as `X-Request-Id`
21
+
22
+ A host can set `config.request_id = -> { Current.request_id }`. Every binding
23
+ call then sends that id to Atlas as `X-Request-Id`. Atlas adopts it in place of
24
+ minting its own and tags its log lines with it, so one page view's Atlas
25
+ requests share the host's id. With the slot unset, nothing changes.
26
+
3
27
  ## 1.29.8
4
28
 
5
29
  ### Changed — installs on Ruby 4
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- atlas_rb (1.29.8)
4
+ atlas_rb (1.29.10)
5
5
  faraday (~> 2.7)
6
6
  faraday-follow_redirects (~> 0.5)
7
7
  faraday-multipart (~> 1)
data/README.md CHANGED
@@ -248,6 +248,27 @@ transport's.
248
248
  Each attempt emits its own `request.atlas_rb` notification, so a host counting
249
249
  round-trips sees a retry as the second round-trip it really is.
250
250
 
251
+ ### Request ids
252
+
253
+ Set `request_id` to send the host's request id to Atlas as `X-Request-Id`:
254
+
255
+ ```ruby
256
+ AtlasRb.configure do |config|
257
+ config.request_id = -> { Current.request_id }
258
+ end
259
+ ```
260
+
261
+ Atlas adopts the id in place of minting its own and tags its log lines with
262
+ it. Every Atlas request that one page view makes then carries the same id the
263
+ host logged, so a single search finds them in both logs.
264
+
265
+ The slot is resolved on each binding call, on the thread that makes it. A host
266
+ that fans reads out on worker threads must copy its request context into each
267
+ worker, or those reads send no id. A blank result sends no header, and Atlas
268
+ mints an id as usual. The health and metrics probes do not send it.
269
+
270
+ The id is a log label only. Atlas trusts nothing about it.
271
+
251
272
  ## Resource hierarchy
252
273
 
253
274
  ```
@@ -384,8 +405,8 @@ result["resource_id"] # => "w-789"
384
405
  result["events"].first["action"] # => "update"
385
406
  ```
386
407
 
387
- Authorization errors (`401` / `403`) are not caught here — they surface as
388
- raw Faraday responses for the calling application's rescue layer.
408
+ A `401` or `403` raises `AtlasRb::ResourceError`, carrying Atlas's status and
409
+ body. A `404` returns `nil`.
389
410
 
390
411
  ### Session-scoped audit events
391
412
 
@@ -423,8 +444,8 @@ AtlasRb::AuditEvent.emit(
423
444
  `on_behalf_of_nuid`, `mode`, and `payload:` (free-form metadata) are
424
445
  omitted from the body when blank, so `emit` can also carry future,
425
446
  mode-less session events. Atlas stamps `occurred_at` server-side.
426
- Authorization errors (`401` / `403`) surface as raw Faraday responses,
427
- matching `Resource.history`.
447
+ `emit` is a POST, so the read guard does not apply: a `401` or `403` is not
448
+ raised, and Atlas's error envelope comes back parsed into a Mash.
428
449
 
429
450
  ### MODS version history
430
451
 
@@ -461,8 +482,9 @@ with `Work.mods` but XML is the only retained format.
461
482
  Version labels are **opaque, sortable OCFL `vN` strings**, not a 1-based
462
483
  counter — a Blob's preservation envelope occupies earlier versions, so the
463
484
  first MODS version is typically `v3`. Treat them as identifiers to feed back
464
- into `mods_version`. A resource with no MODS returns `{ "versions" => [] }`;
465
- `401` / `403` surface as raw Faraday responses, matching `Resource.history`.
485
+ into `mods_version`. A resource with no MODS returns `{ "versions" => [] }`.
486
+ A `401` or `403` raises `AtlasRb::ResourceError`, carrying Atlas's status and
487
+ body. A `404` returns `nil`.
466
488
 
467
489
  ### Re-parenting
468
490
 
@@ -60,16 +60,15 @@ module AtlasRb
60
60
  #
61
61
  # Wraps `POST /audit_events`. The principals and metadata travel in the
62
62
  # JSON body — not in request headers — so the recorded event does not
63
- # depend on the ambient {AtlasRb.config} identity. The request still
64
- # authenticates as the configured caller (system token + the admin
65
- # `User:` header); Atlas admin-gates the endpoint server-side.
63
+ # depend on the ambient {AtlasRb.config} identity. The request
64
+ # authenticates as the actor: atlas_rb signs an assertion for
65
+ # `actor_nuid`. Atlas lets admins and devolved admins create the event,
66
+ # and refuses `:system`.
66
67
  #
67
68
  # Atlas stamps `occurred_at` server-side, so it is not part of the body.
68
69
  #
69
- # Authorization errors (`401` / `403`) are intentionally **not** caught
70
- # here — they surface as raw Faraday responses for the calling
71
- # application's rescue layer to translate, matching
72
- # {AtlasRb::Resource.history}.
70
+ # `emit` is a POST, so the read guard does not apply: a `401` or `403` is
71
+ # not raised, and Atlas's error envelope comes back parsed into a Mash.
73
72
  #
74
73
  # @param action [String] the audit action, e.g. `"impersonation_started"`
75
74
  # or `"impersonation_ended"`.
@@ -22,6 +22,9 @@ module AtlasRb
22
22
  # header. Used by the acting-as / view-as feature on the consumer side.
23
23
  # `nil` (the default) sends no header.
24
24
  #
25
+ # - {#request_id} — the host's request id, sent as `X-Request-Id:` on every
26
+ # binding call so Atlas's log lines carry it.
27
+ #
25
28
  # ## Carve-outs
26
29
  #
27
30
  # System-path calls under {AtlasRb::System} route through
@@ -149,5 +152,19 @@ module AtlasRb
149
152
  #
150
153
  # @return [Integer, nil]
151
154
  attr_accessor :connection_max_requests
155
+
156
+ # The host's own request id, sent to Atlas as `X-Request-Id` on every
157
+ # binding call. Atlas adopts it in place of minting its own and tags its
158
+ # log lines with it, so one page view's Atlas requests can be found by the
159
+ # same id the host logged. Value or callable, resolved per call; typically
160
+ # `-> { Current.request_id }`. `nil` (the default), or a blank result,
161
+ # sends no header and Atlas mints an id as usual.
162
+ #
163
+ # The id is a log label, not a credential: Atlas trusts nothing about it.
164
+ # The health and metrics probes build their own connections and do not
165
+ # send it.
166
+ #
167
+ # @return [String, Proc, nil]
168
+ attr_accessor :request_id
152
169
  end
153
170
  end
@@ -366,9 +366,8 @@ module AtlasRb
366
366
  # The whole envelope is preserved so callers can confirm the events
367
367
  # belong to the requested resource; access events as `result["events"]`.
368
368
  #
369
- # Authorization errors (`401` / `403`) are intentionally **not** caught
370
- # here — they surface as raw Faraday responses for the calling
371
- # application's rescue layer to translate.
369
+ # A `401` or `403` raises {AtlasRb::ResourceError}, carrying Atlas's
370
+ # status and body. A `404` returns `nil`.
372
371
  #
373
372
  # @todo Add pagination support once Atlas's history endpoint exposes
374
373
  # page / per_page query params. Today the endpoint returns the full
@@ -521,8 +520,9 @@ module AtlasRb
521
520
  # List the retained versions of a Work's Darwin Core record.
522
521
  #
523
522
  # The same envelope as {mods_versions}, under the same admin gate, with
524
- # attribution drawn from the Darwin Core edits only. A Work with no record,
525
- # or an id that is not a Work, comes back as `{ "versions" => [] }`.
523
+ # attribution drawn from the Darwin Core edits only. A Work with no record
524
+ # comes back as `{ "versions" => [] }`. An id that is not a Work returns
525
+ # `nil`, as Atlas answers `404`.
526
526
  #
527
527
  # @param id [String] the Work's NOID.
528
528
  # @param nuid [String, nil] optional acting user's NUID.
@@ -119,9 +119,10 @@ module AtlasRb
119
119
  # header.
120
120
  # @return [AtlasRb::Mash] the resource, unwrapped from its type key.
121
121
  # @raise [AtlasRb::NotFoundError] on `404` — the write did not happen.
122
- # @raise [AtlasRb::ResourceError] on any other non-2xx, including the `403`
123
- # Atlas answers when a caller tries to remove a grant for a group it does
124
- # not belong to.
122
+ # @raise [AtlasRb::ResourceError] on any other non-2xx. A caller who removes
123
+ # a read or edit grant for a group it does not belong to gets no error:
124
+ # Atlas keeps that grant and saves the rest, so check the returned
125
+ # resource. Admins and devolved admins may remove any group.
125
126
  #
126
127
  # @example Publish, leaving every other key alone
127
128
  # AtlasRb::Resource.set_permissions("xsj3xmz", { "read" => ["public"] })
@@ -91,6 +91,11 @@ module AtlasRb
91
91
  # header, an `on_data` streaming handler), and those must keep working.
92
92
  # The block runs last so a call site can override anything set here.
93
93
  class Proxy
94
+ # Atlas adopts an incoming id as its own (Rails' ActionDispatch::RequestId)
95
+ # and tags its log lines with it, so one id names the host's request in
96
+ # both apps' logs.
97
+ REQUEST_ID_HEADER = "X-Request-Id"
98
+
94
99
  # Per-request headers and params, exposed so a caller (and the gem's own
95
100
  # transport specs) can read what a request will send without making one.
96
101
  attr_reader :headers, :params
@@ -106,7 +111,7 @@ module AtlasRb
106
111
  # @param params [Hash] per-request query/body params.
107
112
  def initialize(connection, headers, params = {})
108
113
  @connection = connection
109
- @headers = headers
114
+ @headers = with_request_id(headers)
110
115
  @params = params || {}
111
116
  end
112
117
 
@@ -141,6 +146,17 @@ module AtlasRb
141
146
 
142
147
  private
143
148
 
149
+ # Resolved here because a proxy is built per binding call, on the thread
150
+ # making it — so a host that copies its request context into worker
151
+ # threads gets the right id on each of them. A caller's own header wins.
152
+ def with_request_id(headers)
153
+ id = AtlasRb.config.request_id
154
+ id = id.call if id.respond_to?(:call)
155
+ return headers if id.nil? || id.to_s.empty? || headers.key?(REQUEST_ID_HEADER)
156
+
157
+ headers.merge(REQUEST_ID_HEADER => id.to_s)
158
+ end
159
+
144
160
  def run(method, path, body, headers, params, &block)
145
161
  @connection.run_request(method, path, body, headers) do |req|
146
162
  req.params.update(@params) unless @params.empty?
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.8
4
+ version: 1.29.10
5
5
  platform: ruby
6
6
  authors:
7
7
  - David Cliff