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 +4 -4
- data/.version +1 -1
- data/CHANGELOG.md +15 -0
- data/Gemfile.lock +1 -1
- data/lib/atlas_rb/faraday_helper.rb +23 -8
- data/lib/atlas_rb.rb +13 -10
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 7e6020b2b0ed84ff61541cdcc4ac4ef2634a4ee4573540c5e10888cab26ec2df
|
|
4
|
+
data.tar.gz: e18077da93ef29644e95cd94bc231bd42497d7bc21e05b5f97cd27df92346a6f
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: '068bedce232453c430a4e55c3f252f24a11b3710bc6870cc3061f9d3ec183c39600a5c814147d26ec054684afa5e3a7bc07ffc7d98a676b63904e5a11fc36343'
|
|
7
|
+
data.tar.gz: 546dd7050f56a82cd66f54bc38d0d003cc1099f1b998b64255a06ba31ee54d9fbb84a799d56bc46a635b68dd97bb9b87abbb5a94f09bcf2c539220bbb40278c8
|
data/.version
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
1.
|
|
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
|
@@ -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
|
|
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
|
-
#
|
|
171
|
-
|
|
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
|
-
|
|
180
|
-
|
|
181
|
-
|
|
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
|
-
#
|
|
127
|
-
#
|
|
128
|
-
#
|
|
129
|
-
#
|
|
130
|
-
#
|
|
131
|
-
#
|
|
132
|
-
#
|
|
133
|
-
#
|
|
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
|
|
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
|