basecradle 0.14.3 → 0.14.4
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/CHANGELOG.md +58 -0
- data/README.md +5 -0
- data/lib/basecradle/api_object.rb +8 -20
- data/lib/basecradle/client.rb +45 -3
- data/lib/basecradle/header_value.rb +35 -0
- data/lib/basecradle/version.rb +1 -1
- metadata +2 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 15369066a66a4115017b92fc2e32e53a046a227c90bc3d39ea34b5afdb1740b3
|
|
4
|
+
data.tar.gz: 718f27aa9d46d2b8bb126b2cc5edf721e958d11cb8f2557f5438c1d4ce82b369
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: b63763f3c1021e0cd6e989c04cd72c24730e1cc28967ebc985fe6b895afbb93f9bda2529a92c719631d25c8eb50b410fec0920ac33b39900743485e01e80fe35
|
|
7
|
+
data.tar.gz: 45c156098df90bcfbfd1886576568c1ec9787c94720c457272f90ad3f660bf2b1e375b2884e5894ba964fb64b37e9113e60d14a2d4d10cf8b90ed3bd6892e4cf
|
data/CHANGELOG.md
CHANGED
|
@@ -9,6 +9,63 @@ section**. The newest heading is always the version `lib/basecradle/version.rb`
|
|
|
9
9
|
a release writes its entry and its version in the same PR — and `test/changelog_test.rb`
|
|
10
10
|
fails CI if the two ever disagree.
|
|
11
11
|
|
|
12
|
+
## [0.14.4] - 2026-11-17
|
|
13
|
+
|
|
14
|
+
A patch release with two behavior fixes, both about a credential. No verb is added or
|
|
15
|
+
removed, and no signature changes. It affects a caller whose token is one HTTP cannot
|
|
16
|
+
carry exactly as given: `Client.new` now raises `ArgumentError` before any request.
|
|
17
|
+
**Some such tokens used to authenticate, so a caller whose token can carry whitespace at
|
|
18
|
+
either end (a padded line in an env file, say) must pass it exactly as minted** (see
|
|
19
|
+
below). The `login` fix changes nothing for a caller who already passes a `max_retries`
|
|
20
|
+
of zero or more.
|
|
21
|
+
|
|
22
|
+
### Fixed
|
|
23
|
+
|
|
24
|
+
- **A token HTTP cannot carry raises `ArgumentError` when the client is built, and the
|
|
25
|
+
error never shows it**
|
|
26
|
+
([#304](https://github.com/basecradle/basecradle-ruby/pull/304),
|
|
27
|
+
[#301](https://github.com/basecradle/basecradle-ruby/issues/301)). A token follows the
|
|
28
|
+
same rule as an `idempotency_key` (0.14.3): printable ASCII, with spaces or tabs only
|
|
29
|
+
between characters. `BaseCradle::Client.new`, whether given the token or reading
|
|
30
|
+
`BASECRADLE_TOKEN`, raises `ArgumentError` for any other token, saying where the fault
|
|
31
|
+
is and never showing the token, not even the character at fault. The SDK never strips
|
|
32
|
+
or repairs a token. What a caller who passed such a token sees now:
|
|
33
|
+
- Whitespace at either end (`"bc_uat_… "`): until now, **the token was sent as given and
|
|
34
|
+
the request authenticated**, because a hop stripped the whitespace before the platform
|
|
35
|
+
read it. It now raises.
|
|
36
|
+
- A token made only of whitespace (`BASECRADLE_TOKEN=" "`): until now, a client was
|
|
37
|
+
built and every request failed. It now raises `ArgumentError`, not
|
|
38
|
+
`MissingTokenError`, which is still raised only for a missing or empty token.
|
|
39
|
+
- A trailing newline, as a token read from a file or an env file often keeps
|
|
40
|
+
(`"bc_uat_…\n"`): until now, the client was built and every request failed with
|
|
41
|
+
Net::HTTP's own `ArgumentError` ("header field value cannot include CR/LF"), which
|
|
42
|
+
named no argument. It now raises when the client is built, and the message says a
|
|
43
|
+
file or an env file often keeps the trailing newline.
|
|
44
|
+
- Any other control character, or a non-ASCII character: until now, the token was sent
|
|
45
|
+
as raw bytes. It now raises.
|
|
46
|
+
- A string in an encoding that is not ASCII-compatible (UTF-16, say): until now, every
|
|
47
|
+
request failed with an `Encoding::CompatibilityError`. It now raises `ArgumentError`
|
|
48
|
+
naming the encoding.
|
|
49
|
+
|
|
50
|
+
The Python SDK made the same change
|
|
51
|
+
([basecradle-python#359](https://github.com/basecradle/basecradle-python/issues/359)).
|
|
52
|
+
- **`Client.login` with a negative `max_retries` raises before it mints a credential**
|
|
53
|
+
([#305](https://github.com/basecradle/basecradle-ruby/pull/305)). `login` checked
|
|
54
|
+
`max_retries` only when it built the client, after `POST /session` had already minted a
|
|
55
|
+
token, so `login(max_retries: -1)` created a live credential the caller never received.
|
|
56
|
+
It still raises the same `ArgumentError`, but now before anything is sent, as the
|
|
57
|
+
Python SDK's `login` does.
|
|
58
|
+
|
|
59
|
+
### Security
|
|
60
|
+
|
|
61
|
+
- **The daily dependency scan writes as this repository's own bot, and only as it**
|
|
62
|
+
([#303](https://github.com/basecradle/basecradle-ruby/pull/303),
|
|
63
|
+
[#309](https://github.com/basecradle/basecradle-ruby/pull/309),
|
|
64
|
+
[basecradle#870](https://github.com/basecradle/basecradle/issues/870)). Its
|
|
65
|
+
`[SECURITY]` issues and their labels now come from `basecradle-ruby-ai[bot]`, not the
|
|
66
|
+
capital's App, and the scan reads only issues that bot wrote. Nothing in the gem itself
|
|
67
|
+
changes.
|
|
68
|
+
|
|
12
69
|
## [0.14.3] - 2026-11-16
|
|
13
70
|
|
|
14
71
|
A patch release with one behavior fix. No verb is added or removed, and no signature
|
|
@@ -858,6 +915,7 @@ the Python SDK's behavior in idiomatic Ruby. Zero runtime dependencies.
|
|
|
858
915
|
- **Quality bars** — a README-as-tested-doc harness (every example runs against a mocked
|
|
859
916
|
API) and a spec drift-guard (CI fails if the live API grows beyond the SDK).
|
|
860
917
|
|
|
918
|
+
[0.14.4]: https://github.com/basecradle/basecradle-ruby/releases/tag/v0.14.4
|
|
861
919
|
[0.14.3]: https://github.com/basecradle/basecradle-ruby/releases/tag/v0.14.3
|
|
862
920
|
[0.14.2]: https://github.com/basecradle/basecradle-ruby/releases/tag/v0.14.2
|
|
863
921
|
[0.14.1]: https://github.com/basecradle/basecradle-ruby/releases/tag/v0.14.1
|
data/README.md
CHANGED
|
@@ -27,6 +27,11 @@ bc = BaseCradle::Client.new # reads BASECRADLE_TOKEN
|
|
|
27
27
|
bc = BaseCradle::Client.new("bc_uat_...") # …or pass it explicitly
|
|
28
28
|
```
|
|
29
29
|
|
|
30
|
+
The token is sent exactly as given, so it must be one HTTP can carry. A token read from a
|
|
31
|
+
file or an env file often keeps its trailing newline, and a token with a control
|
|
32
|
+
character, a non-ASCII character, or whitespace at either end raises `ArgumentError` when
|
|
33
|
+
the client is built. The SDK never strips or repairs it, and the error never shows it.
|
|
34
|
+
|
|
30
35
|
No token yet? Mint one with your basecradle.com credentials. `login` hands back a
|
|
31
36
|
ready-to-use client — the new token is on `bc.token`:
|
|
32
37
|
|
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
require "json"
|
|
4
4
|
|
|
5
5
|
require_relative "errors"
|
|
6
|
+
require_relative "header_value"
|
|
6
7
|
require_relative "rendering"
|
|
7
8
|
|
|
8
9
|
module BaseCradle
|
|
@@ -34,28 +35,15 @@ module BaseCradle
|
|
|
34
35
|
end
|
|
35
36
|
|
|
36
37
|
# Why HTTP cannot carry this key exactly as given, or +nil+ when it can (#295). A key is
|
|
37
|
-
# sent as given and never repaired, so it must be a header value no hop can change:
|
|
38
|
-
#
|
|
39
|
-
#
|
|
40
|
-
# character and non-ASCII bytes, and a hop that receives whitespace at either end of a
|
|
41
|
-
# value strips it, so the platform would store a different key. The one meaning every
|
|
42
|
-
# SDK shares refuses all of them, not whatever one HTTP library tolerates. A string in
|
|
43
|
-
# an encoding that is not ASCII-compatible (UTF-16, say) is refused as a whole: its
|
|
44
|
-
# bytes are not the characters it holds.
|
|
38
|
+
# sent as given and never repaired, so it must be a header value no hop can change: the
|
|
39
|
+
# rule is +header_value_defect+, the one the token is held to as well. A key is not a
|
|
40
|
+
# secret, so the reason shows the character at fault.
|
|
45
41
|
def self.unsendable_idempotency_key_reason(key)
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
key.each_char.with_index do |char, index|
|
|
51
|
-
return "#{char.inspect} at index #{index} is not ASCII" unless char.ascii_only?
|
|
52
|
-
unless char == " " || char == "\t" || (0x21..0x7E).cover?(char.ord)
|
|
53
|
-
return "#{char.inspect} at index #{index} is a control character"
|
|
54
|
-
end
|
|
55
|
-
end
|
|
56
|
-
return unless key.start_with?(" ", "\t") || key.end_with?(" ", "\t")
|
|
42
|
+
index, reason = header_value_defect(key)
|
|
43
|
+
return if reason.nil?
|
|
44
|
+
return reason if index.nil?
|
|
57
45
|
|
|
58
|
-
"
|
|
46
|
+
"#{key[index].inspect} at index #{index} #{reason}"
|
|
59
47
|
end
|
|
60
48
|
|
|
61
49
|
# The per-request headers carrying an optional idempotency key — +nil+ when no key was
|
data/lib/basecradle/client.rb
CHANGED
|
@@ -7,6 +7,7 @@ require "uri"
|
|
|
7
7
|
require_relative "contact_messages"
|
|
8
8
|
require_relative "dashboard"
|
|
9
9
|
require_relative "errors"
|
|
10
|
+
require_relative "header_value"
|
|
10
11
|
require_relative "items"
|
|
11
12
|
require_relative "rendering"
|
|
12
13
|
require_relative "serialization"
|
|
@@ -78,13 +79,20 @@ module BaseCradle
|
|
|
78
79
|
# dedupes keyed creates, so a resend can't duplicate the record). An unkeyed +POST+ is
|
|
79
80
|
# never retried, whatever this is set to — and a blank key (empty, or only ASCII
|
|
80
81
|
# whitespace) is no key. Retries back off exponentially, capped at RETRY_MAX_DELAY seconds.
|
|
82
|
+
#
|
|
83
|
+
# The token is sent exactly as given, so it must be one HTTP can carry: a token with a
|
|
84
|
+
# control character (the trailing newline of one read from a file or an env file), a
|
|
85
|
+
# non-ASCII character, or whitespace at either end raises ArgumentError here, before
|
|
86
|
+
# any request. The SDK never strips or repairs it, and the error never shows it.
|
|
81
87
|
def initialize(token = nil, base_url: DEFAULT_BASE_URL, timeout: DEFAULT_TIMEOUT,
|
|
82
88
|
max_retries: DEFAULT_MAX_RETRIES)
|
|
83
89
|
resolved = token || ENV.fetch("BASECRADLE_TOKEN", nil)
|
|
84
90
|
raise MissingTokenError, MISSING_TOKEN_MESSAGE if resolved.nil? || resolved.empty?
|
|
85
|
-
|
|
91
|
+
self.class.refuse_negative_max_retries(max_retries)
|
|
86
92
|
|
|
87
|
-
@token
|
|
93
|
+
# The one string checked is the one sent: "Bearer #{@token}" interpolates it as is.
|
|
94
|
+
@token = resolved.to_s
|
|
95
|
+
refuse_unsendable_token(@token)
|
|
88
96
|
@base_url = base_url
|
|
89
97
|
@timeout = timeout
|
|
90
98
|
@max_retries = max_retries
|
|
@@ -123,9 +131,14 @@ module BaseCradle
|
|
|
123
131
|
# The minted token is on the returned client as +#token+ — save it; it is never
|
|
124
132
|
# retrievable again. The credential itself is on +#session+ (so +bc.session.uuid+ is
|
|
125
133
|
# what revokes it later), and +#start_here+ points at the Dashboard. +name+ is an
|
|
126
|
-
# optional label to tell credentials apart later.
|
|
134
|
+
# optional label to tell credentials apart later. A negative +max_retries+ raises
|
|
135
|
+
# ArgumentError before anything is sent, so no credential is minted.
|
|
127
136
|
def self.login(email_address:, password:, name: nil, base_url: DEFAULT_BASE_URL,
|
|
128
137
|
timeout: DEFAULT_TIMEOUT, max_retries: DEFAULT_MAX_RETRIES)
|
|
138
|
+
# Before the mint, as the Python SDK's login does: a bad count refused only when the
|
|
139
|
+
# client is built would have minted a credential the caller never receives.
|
|
140
|
+
refuse_negative_max_retries(max_retries)
|
|
141
|
+
|
|
129
142
|
payload = { "email_address" => email_address, "password" => password }
|
|
130
143
|
payload["name"] = name unless name.nil?
|
|
131
144
|
|
|
@@ -227,6 +240,11 @@ module BaseCradle
|
|
|
227
240
|
handle(deliver(method, path, json: json, params: params, form: form, headers: headers))
|
|
228
241
|
end
|
|
229
242
|
|
|
243
|
+
# One check for +new+ and +login+, so a count +new+ refuses never reaches the mint.
|
|
244
|
+
def self.refuse_negative_max_retries(max_retries)
|
|
245
|
+
raise ArgumentError, "max_retries must be >= 0" if max_retries.negative?
|
|
246
|
+
end
|
|
247
|
+
|
|
230
248
|
# The shared low-level send: returns the Net::HTTPResponse or raises APIConnectionError.
|
|
231
249
|
def self.perform(uri, request, timeout)
|
|
232
250
|
http = Net::HTTP.new(uri.host, uri.port)
|
|
@@ -291,6 +309,30 @@ module BaseCradle
|
|
|
291
309
|
"than the object: model.to_h holds no client."
|
|
292
310
|
end
|
|
293
311
|
|
|
312
|
+
# Refuse a token HTTP cannot carry exactly as given, when the client is built (#301).
|
|
313
|
+
# The idempotency key's rule (BaseCradle.header_value_defect), applied to the token: the
|
|
314
|
+
# caller's error, never stripped or repaired. Without it, a token read with its trailing
|
|
315
|
+
# newline built a client that failed every request with Net::HTTP's own ArgumentError,
|
|
316
|
+
# and every other such token was sent: a hop strips whitespace at either end, and the
|
|
317
|
+
# platform received the rest as given. The message says where the fault is and never
|
|
318
|
+
# shows the token, not even the character at fault.
|
|
319
|
+
def refuse_unsendable_token(token)
|
|
320
|
+
index, reason = BaseCradle.header_value_defect(token)
|
|
321
|
+
return if reason.nil?
|
|
322
|
+
|
|
323
|
+
where = index.nil? ? reason : "the character at index #{index} #{reason}"
|
|
324
|
+
# A token ending in CR or LF is the newline a file or an env file keeps (CRLF from
|
|
325
|
+
# Windows too); for any other fault, the token's source has to say. Read as bytes, so
|
|
326
|
+
# a token in an encoding that is not ASCII-compatible is answered rather than raised on.
|
|
327
|
+
hint = if token.b.end_with?("\n", "\r")
|
|
328
|
+
"A token read from a file or an env file often keeps its trailing newline."
|
|
329
|
+
else
|
|
330
|
+
"Check where the token was read from."
|
|
331
|
+
end
|
|
332
|
+
raise ArgumentError, "The token cannot be sent in an HTTP header: #{where}. It is not shown " \
|
|
333
|
+
"here, as it is a credential. #{hint} Pass it exactly as minted."
|
|
334
|
+
end
|
|
335
|
+
|
|
294
336
|
# Record what the mint response said about the credential just issued. Private: only
|
|
295
337
|
# +.login+ calls it, on a client it has just built.
|
|
296
338
|
def minted(body)
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module BaseCradle
|
|
4
|
+
# What stops HTTP carrying +value+ exactly as given, or +nil+ when nothing does. It is the
|
|
5
|
+
# one rule for a value the SDK sends in a header as the caller gave it, never stripped or
|
|
6
|
+
# repaired: an idempotency key (#295) and the bearer token (#301) alike. The rule lives
|
|
7
|
+
# here, below the client and the resources, so both can ask it.
|
|
8
|
+
#
|
|
9
|
+
# The value must be printable ASCII (+!+ to +~+), with spaces or tabs allowed only between
|
|
10
|
+
# those characters. Net::HTTP refuses only CR and LF. It sends NUL, every other control
|
|
11
|
+
# character and non-ASCII bytes. A hop that receives whitespace at either end of a value
|
|
12
|
+
# strips it, so the platform would read a different value. The rule every SDK shares
|
|
13
|
+
# refuses all of them, not whatever one HTTP library tolerates. A string in an encoding
|
|
14
|
+
# that is not ASCII-compatible (UTF-16, say) is refused as a whole: its bytes are not the
|
|
15
|
+
# characters it holds.
|
|
16
|
+
#
|
|
17
|
+
# The answer is <tt>[index, reason]</tt>: the index of the character at fault, or +nil+
|
|
18
|
+
# where no one character is (whitespace at either end, an encoding). The character itself
|
|
19
|
+
# is never part of the answer, so a caller describing the token can say where the fault
|
|
20
|
+
# is without showing any of it.
|
|
21
|
+
def self.header_value_defect(value)
|
|
22
|
+
unless value.encoding.ascii_compatible?
|
|
23
|
+
return [ nil, "its encoding, #{value.encoding}, is not ASCII-compatible; pass an ASCII or UTF-8 string" ]
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
value.each_char.with_index do |char, index|
|
|
27
|
+
# ascii_only? first: an invalid byte is not ASCII, and +ord+ would raise on it.
|
|
28
|
+
return [ index, "is not ASCII" ] unless char.ascii_only?
|
|
29
|
+
return [ index, "is a control character" ] unless char == " " || char == "\t" || (0x21..0x7E).cover?(char.ord)
|
|
30
|
+
end
|
|
31
|
+
return unless value.start_with?(" ", "\t") || value.end_with?(" ", "\t")
|
|
32
|
+
|
|
33
|
+
[ nil, "it begins or ends with whitespace, which a header value cannot" ]
|
|
34
|
+
end
|
|
35
|
+
end
|
data/lib/basecradle/version.rb
CHANGED
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: basecradle
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.14.
|
|
4
|
+
version: 0.14.4
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Drawk Kwast
|
|
@@ -25,6 +25,7 @@ files:
|
|
|
25
25
|
- lib/basecradle/contact_messages.rb
|
|
26
26
|
- lib/basecradle/dashboard.rb
|
|
27
27
|
- lib/basecradle/errors.rb
|
|
28
|
+
- lib/basecradle/header_value.rb
|
|
28
29
|
- lib/basecradle/headers.rb
|
|
29
30
|
- lib/basecradle/items.rb
|
|
30
31
|
- lib/basecradle/pagination.rb
|