atlas_rb 1.4.0 → 1.5.0

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: 31c36891a34eef17727397e17017db5eb1acea6cdfae4dfbba76b93e6f32954a
4
- data.tar.gz: 3871ca6703afa2ecccf780f089b22e8ff6fdcbcdaf5aaafb82e51bbf606e95a1
3
+ metadata.gz: 7e6020b2b0ed84ff61541cdcc4ac4ef2634a4ee4573540c5e10888cab26ec2df
4
+ data.tar.gz: e18077da93ef29644e95cd94bc231bd42497d7bc21e05b5f97cd27df92346a6f
5
5
  SHA512:
6
- metadata.gz: 84f906c748bd98acb961eb403950d98e1c46be9084ae21fde55b949bc1af6f2bc9f72c567c0bb826b854209b75f51d437196d7e7d0b1031d9f2497e132d305f8
7
- data.tar.gz: bac7488013b6d12db98806447405c27ae52d4fed86608c2fc96f2180cea48a931d0d43b1421b914de3218a742fb5bb53cfa46dc9d59f41ee3a92670571a52aee
6
+ metadata.gz: '068bedce232453c430a4e55c3f252f24a11b3710bc6870cc3061f9d3ec183c39600a5c814147d26ec054684afa5e3a7bc07ffc7d98a676b63904e5a11fc36343'
7
+ data.tar.gz: 546dd7050f56a82cd66f54bc38d0d003cc1099f1b998b64255a06ba31ee54d9fbb84a799d56bc46a635b68dd97bb9b87abbb5a94f09bcf2c539220bbb40278c8
data/.version CHANGED
@@ -1 +1 @@
1
- 1.4.0
1
+ 1.5.0
data/CHANGELOG.md CHANGED
@@ -1,5 +1,20 @@
1
1
  # Changelog
2
2
 
3
+ ## 1.5.0
4
+
5
+ ### Added — optional auth for `Reset.clean`
6
+
7
+ `AtlasRb::Reset.clean` now uses **optional auth**: it signs an assertion when a
8
+ credential is available and sends no `Authorization` header otherwise, instead
9
+ of raising `AtlasRb::ConfigurationError`. Atlas serves `GET /reset` with
10
+ `require_auth` skipped (env-gated), so the call no longer needs an acting nuid
11
+ or a configured signer just to satisfy the client-side header builder — fixing
12
+ test `before(:suite)` resets that run before any acting principal is set.
13
+
14
+ `FaradayHelper#connection` gains an `auth:` keyword (`:required` default,
15
+ `:optional`) to support this; every other endpoint stays strict and still
16
+ raises on a missing credential.
17
+
3
18
  ## 1.4.0
4
19
 
5
20
  ### Removed — legacy `ATLAS_TOKEN` relay
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- atlas_rb (1.4.0)
4
+ atlas_rb (1.5.0)
5
5
  faraday (~> 2.7)
6
6
  faraday-follow_redirects (~> 0.3.0)
7
7
  faraday-multipart (~> 1)
@@ -62,13 +62,20 @@ module AtlasRb
62
62
  # `POST /works`, `POST /file_sets`, `POST /files`) to deduplicate replays
63
63
  # against the originally-created resource. Generated by the caller —
64
64
  # this gem does not mint keys.
65
+ # @param auth [:required, :optional] auth strictness. `:required` (default)
66
+ # raises {AtlasRb::ConfigurationError} when no credential can be built —
67
+ # the right behaviour for every endpoint behind `require_auth`. `:optional`
68
+ # signs when it can but sends no `Authorization` header otherwise, for the
69
+ # handful of endpoints Atlas serves with auth skipped (currently only
70
+ # `GET /reset`).
65
71
  # @return [Faraday::Connection] a connection that follows redirects and
66
72
  # uses Faraday's default adapter.
67
73
  #
68
74
  # @example Fetching a community
69
75
  # AtlasRb::Community.connection({}).get('/communities/abc123')
70
- def connection(params, nuid=nil, on_behalf_of: nil, idempotency_key: nil)
71
- headers = auth_headers(nuid, on_behalf_of).merge("Content-Type" => "application/json")
76
+ def connection(params, nuid=nil, on_behalf_of: nil, idempotency_key: nil, auth: :required)
77
+ headers = auth_headers(nuid, on_behalf_of, optional: auth == :optional)
78
+ .merge("Content-Type" => "application/json")
72
79
  headers["Idempotency-Key"] = idempotency_key if idempotency_key
73
80
 
74
81
  Faraday.new(
@@ -167,18 +174,26 @@ module AtlasRb
167
174
  # Precedence: ATLAS_JWT (BYO-JWT) > relay-signing. The acting nuid /
168
175
  # on_behalf_of fall through to the configured `default_nuid` /
169
176
  # `default_on_behalf_of` callables here, once, for whichever mode applies.
170
- # Raises {ConfigurationError} when neither credential is configured.
171
- def auth_headers(nuid, on_behalf_of)
177
+ #
178
+ # Raises {ConfigurationError} when no credential can be built — unless
179
+ # `optional:` is set, in which case it returns no auth headers instead. That
180
+ # is only for endpoints Atlas serves with `require_auth` skipped (`GET
181
+ # /reset`); every normal endpoint leaves `optional` false so a
182
+ # misconfiguration fails loudly rather than silently going unauthenticated.
183
+ def auth_headers(nuid, on_behalf_of, optional: false)
172
184
  jwt = ENV.fetch("ATLAS_JWT", nil)
173
185
  return { "Authorization" => "Bearer #{jwt}" } if jwt
174
186
 
175
187
  nuid ||= AtlasRb.config.default_nuid&.call
176
188
  on_behalf_of ||= AtlasRb.config.default_on_behalf_of&.call
177
189
 
178
- signed_relay_headers(nuid, on_behalf_of) ||
179
- raise(ConfigurationError,
180
- "atlas_rb: no auth configured — set ATLAS_JWT or " \
181
- "AtlasRb.config.assertion_signing_key (with an acting nuid to sign)")
190
+ headers = signed_relay_headers(nuid, on_behalf_of)
191
+ return headers if headers
192
+ return {} if optional
193
+
194
+ raise(ConfigurationError,
195
+ "atlas_rb: no auth configured — set ATLAS_JWT or " \
196
+ "AtlasRb.config.assertion_signing_key (with an acting nuid to sign)")
182
197
  end
183
198
 
184
199
  # A signed-assertion Authorization header (sub = acting nuid), or nil when
data/lib/atlas_rb.rb CHANGED
@@ -123,20 +123,23 @@ module AtlasRb
123
123
 
124
124
  # Reset the connected Atlas instance to a clean state.
125
125
  #
126
- # @param nuid [String, nil] optional acting user's NUID. On the relay-signing
127
- # path it is signed into the assertion `sub`; on the BYO-JWT (`ATLAS_JWT`)
128
- # path it is ignored (identity lives in the token). Atlas's
129
- # `MaintenanceController#reset` runs through the standard `require_auth`
130
- # filter like any other endpoint.
131
- # @param on_behalf_of [String, nil] optional NUID for the `On-Behalf-Of`
132
- # header. Falls through to {AtlasRb.config}.default_on_behalf_of when
133
- # omitted.
126
+ # Atlas serves `GET /reset` with `require_auth` **skipped** (it is env-gated,
127
+ # not principal-gated), so this call uses **optional auth**: it signs an
128
+ # assertion when a credential is available, and sends no `Authorization`
129
+ # header otherwise never raising {AtlasRb::ConfigurationError} for lack of
130
+ # one. That lets a test `before(:suite)` reset before any acting nuid is set.
131
+ #
132
+ # @param nuid [String, nil] optional acting user's NUID. When a signing key
133
+ # is configured it is signed into the assertion `sub`; otherwise it is
134
+ # unused (Atlas ignores it on this endpoint). Mostly here for symmetry.
135
+ # @param on_behalf_of [String, nil] optional NUID. Falls through to
136
+ # {AtlasRb.config}.default_on_behalf_of when omitted.
134
137
  # @return [String, nil] the raw response body from `GET /reset`.
135
138
  #
136
139
  # @example
137
- # AtlasRb::Reset.clean(nuid: "000000000")
140
+ # AtlasRb::Reset.clean
138
141
  def self.clean(nuid: nil, on_behalf_of: nil)
139
- connection({}, nuid, on_behalf_of: on_behalf_of).get("/reset")&.body
142
+ connection({}, nuid, on_behalf_of: on_behalf_of, auth: :optional).get("/reset")&.body
140
143
  end
141
144
  end
142
145
  end
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.4.0
4
+ version: 1.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - David Cliff