basecradle 0.14.4 → 0.15.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: 15369066a66a4115017b92fc2e32e53a046a227c90bc3d39ea34b5afdb1740b3
4
- data.tar.gz: 718f27aa9d46d2b8bb126b2cc5edf721e958d11cb8f2557f5438c1d4ce82b369
3
+ metadata.gz: 5d56a7fe24eeefe9a3e86258a703bfb8650bc5f357077772097759ffc7c61451
4
+ data.tar.gz: e4ac5b57cdb61c49a89e5d6cffda5b05a909fa45e535628cd853f26492c1e664
5
5
  SHA512:
6
- metadata.gz: b63763f3c1021e0cd6e989c04cd72c24730e1cc28967ebc985fe6b895afbb93f9bda2529a92c719631d25c8eb50b410fec0920ac33b39900743485e01e80fe35
7
- data.tar.gz: 45c156098df90bcfbfd1886576568c1ec9787c94720c457272f90ad3f660bf2b1e375b2884e5894ba964fb64b37e9113e60d14a2d4d10cf8b90ed3bd6892e4cf
6
+ metadata.gz: c6bb6ccf04c1dd5d20072f42a8a6fed6cc69897bc1f6d9d1952c1e05aa3844e3524b7e916b8e6bc9e1c987f61ddea1d14d8059738a48c5354c2d394a572f9732
7
+ data.tar.gz: 0d8beaaa166bb8e1077569e457b8d8e547587263320e0c428b0788ef8e3af59db29cf95cf57f727f7966cfd3fcc6c26ed953f7a80a2ba96b08e82350a86a289f
data/CHANGELOG.md CHANGED
@@ -9,6 +9,54 @@ 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.15.0] - 2026-11-20
13
+
14
+ A minor release that adds two verbs for an API operation the platform documented on
15
+ 2026-11-20. Nothing is removed and no signature changes. Its release pipeline also moved
16
+ to a Ruby with Ruby's 2026-11-18 security fixes. That is not a fix you get by upgrading
17
+ the gem: the SDK is pure Ruby and ships no interpreter, so the fixes reach you only when
18
+ you upgrade your own Ruby, to 3.3.14, 3.4.13 or 4.0.10.
19
+
20
+ ### Added
21
+
22
+ - **`WebhookEndpoint#configure_verification` and `#clear_verification`**
23
+ ([#314](https://github.com/basecradle/basecradle-ruby/pull/314), mirroring
24
+ [basecradle-python#376](https://github.com/basecradle/basecradle-python/issues/376)).
25
+ They set and remove an endpoint's signature verification by wrapping
26
+ `PATCH /webhook_endpoints/{uuid}`, which the platform documented together with a second
27
+ scheme, `github`.
28
+ - **`configure_verification(verifier:, credential:, signature_header:)`** sends only the
29
+ keywords you pass, as `verifier`, `verification_credential` and `signature_header`.
30
+ It raises `ArgumentError` before any request when you pass none.
31
+ - **`verifier:`** is passed through as a string: `"hmac_sha256_hex"` or `"github"`
32
+ today, so a scheme added later needs no release. One the platform does not know
33
+ raises `BaseCradle::ValidationError`.
34
+ - **`credential:`** is the signing secret. A blank one is sent as given, and the API
35
+ treats it as no change, so the current secret stays. It is sent as its bytes, which
36
+ must be UTF-8. A credential that is not a String, or whose bytes are not UTF-8,
37
+ raises `ArgumentError` without showing it, and nothing is sent. It is write-only: the
38
+ API never returns it, and the SDK keeps no copy and never puts it in an `inspect` or
39
+ an error message.
40
+ - **`signature_header:`** names the header the signature is read from, for
41
+ `hmac_sha256_hex` only. A `github` endpoint always reads `X-Hub-Signature-256`.
42
+ - **`clear_verification`** sends `clear_credential: true`, which removes the secret and
43
+ turns verification off.
44
+ - Both update the endpoint in place and return it, like `rotate`, so the new state
45
+ reads at `endpoint.content.verification`.
46
+
47
+ ### Security
48
+
49
+ - **The release pipeline runs on a Ruby with the 2026-11-18 Regexp and String fixes**
50
+ ([#312](https://github.com/basecradle/basecradle-ruby/pull/312),
51
+ [#311](https://github.com/basecradle/basecradle-ruby/issues/311)). The release and
52
+ the daily dependency scan pinned `ruby/setup-ruby` v1.338.0, which predates the fixed
53
+ builds. They now pin v1.343.0, which installs 3.3.14, 3.4.13 and 4.0.10, so the publish
54
+ job that builds and pushes the gem runs on 3.4.13. CI now pins every action it runs to a
55
+ full commit, and `lint` runs on 3.4. Ruby 3.2, the gem's floor, is past its end of
56
+ life and has no fixed build. It still runs where the floor itself is under test: the
57
+ `test (3.2)` job, the release rehearsal's build-and-install check, and the scan's 3.2
58
+ resolution.
59
+
12
60
  ## [0.14.4] - 2026-11-17
13
61
 
14
62
  A patch release with two behavior fixes, both about a credential. No verb is added or
@@ -915,6 +963,7 @@ the Python SDK's behavior in idiomatic Ruby. Zero runtime dependencies.
915
963
  - **Quality bars** — a README-as-tested-doc harness (every example runs against a mocked
916
964
  API) and a spec drift-guard (CI fails if the live API grows beyond the SDK).
917
965
 
966
+ [0.15.0]: https://github.com/basecradle/basecradle-ruby/releases/tag/v0.15.0
918
967
  [0.14.4]: https://github.com/basecradle/basecradle-ruby/releases/tag/v0.14.4
919
968
  [0.14.3]: https://github.com/basecradle/basecradle-ruby/releases/tag/v0.14.3
920
969
  [0.14.2]: https://github.com/basecradle/basecradle-ruby/releases/tag/v0.14.2
data/README.md CHANGED
@@ -197,6 +197,11 @@ endpoint.disable # pause deliveries (410 to senders) without losing history
197
197
  endpoint.enable # resume
198
198
  endpoint.rotate # leaked URL? new ingest_url, old one dies, uuid unchanged
199
199
 
200
+ # Require signed deliveries. Here: a GitHub webhook, whose Secret at GitHub is this value
201
+ endpoint.configure_verification(verifier: "github", credential: "kT9vQ2mXw7RbLp4ZsYc81NdHaUeJ3gFo")
202
+ puts endpoint.content.verification.signature_header # X-Hub-Signature-256
203
+ endpoint.clear_verification # remove the secret: unsigned deliveries are accepted again
204
+
200
205
  # Read what came in — across all timelines, or narrowed
201
206
  bc.webhook_events.filter(endpoint: endpoint).each do |event|
202
207
  puts [event.content.content_type, event.content.payload].inspect
@@ -211,9 +216,28 @@ An endpoint's identity is `endpoint.content.uuid` — the wire carries no top-le
211
216
  and the SDK invents none. `BaseCradle.uuid_of(endpoint)` reads it too, and is what
212
217
  `.filter(endpoint:)` uses, so you can pass either an endpoint or a uuid.
213
218
 
219
+ **Signature verification is configured with two verbs.**
220
+ `endpoint.configure_verification(verifier:, credential:, signature_header:)` sends only
221
+ the keywords you pass, so anything left out stays as it is; passing none raises
222
+ `ArgumentError` before any request. `verifier:` is the scheme — `"hmac_sha256_hex"` (the
223
+ default; any sender you control) or `"github"` (GitHub's own `X-Hub-Signature-256`, so a
224
+ GitHub webhook can point straight at the `ingest_url`) — and is passed through as given,
225
+ so a scheme the platform adds later needs no SDK release; one it does not know raises
226
+ `BaseCradle::ValidationError`. `credential:` is the signing secret, and setting it turns
227
+ verification on; a blank one is no change at all (the API's rule): the current secret
228
+ stays, and `verification.enabled` cannot tell you a rotation was skipped, so make sure a
229
+ secret read from the environment is not empty before passing it. It is **write-only**: the
230
+ API never returns it, and the SDK keeps no copy and never puts it in an `inspect` or an
231
+ error message. `signature_header:` names the header an `hmac_sha256_hex` endpoint reads the
232
+ signature from. `endpoint.clear_verification` removes the secret and turns verification
233
+ off. Both return the endpoint, updated in place; read the result at
234
+ `endpoint.content.verification`. How senders sign is in the API docs:
235
+ [Verifying Inbound Deliveries](https://basecradle.com/docs/api#verifying-inbound-deliveries-optional).
236
+
214
237
  Each event embeds its endpoint **in full**, so `event.webhook_endpoint` is a live
215
238
  `BaseCradle::WebhookEndpoint` — its *current* state reads without a second request, and
216
- `disable` / `enable` / `rotate` work straight off the event. Two fields are the event's
239
+ its verbs (`disable`, `enable`, `rotate`, `configure_verification`, `clear_verification`)
240
+ work straight off the event. Two fields are the event's
217
241
  **historical** facts, fixed when the delivery arrived, and they are the only ones:
218
242
  `content.ingest_token_at_receipt` (which — possibly since-rotated — URL it came in on) and
219
243
  `content.verified_at_receipt` (whether its signature was verified). Everything inside the
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module BaseCradle
4
- VERSION = "0.14.4"
4
+ VERSION = "0.15.0"
5
5
  end
@@ -10,10 +10,15 @@ module BaseCradle
10
10
  # --- models ---------------------------------------------------------------------------
11
11
 
12
12
  # Whether inbound deliveries must be signed, and how.
13
+ #
14
+ # +enabled+ is true once a signing secret is set. The secret itself is write-only: the
15
+ # API never returns it, so it is never here. Set it, the scheme and the header with
16
+ # +endpoint.configure_verification+; turn verification off with
17
+ # +endpoint.clear_verification+.
13
18
  class WebhookVerification < ApiObject
14
19
  attribute :enabled
15
- attribute :signature_header
16
- attribute :verifier # "hmac_sha256_hex"
20
+ attribute :signature_header # for a "github" endpoint, always "X-Hub-Signature-256"
21
+ attribute :verifier # "hmac_sha256_hex" or "github" — an open set; read it as a string
17
22
  end
18
23
 
19
24
  # An endpoint's content: identity, state, and the rotatable ingest URL.
@@ -27,7 +32,10 @@ module BaseCradle
27
32
 
28
33
  # An inbound webhook URL on a timeline. An endpoint is authored: +user+ is the peer who
29
34
  # created it (nested-actor form), and every event delivered to it inherits that author.
30
- # Verbs update this object from the full endpoint the API returns (live objects).
35
+ # Verbs update this object from the full endpoint the API returns (live objects). The
36
+ # API models enablement and rotation as singular state resources, and signature
37
+ # verification as a +PATCH+ of the endpoint itself; the SDK expresses all of them as
38
+ # verbs here, never as raw paths.
31
39
  #
32
40
  # The endpoint's identity is +content.uuid+ — the wire carries no top-level +uuid+, and
33
41
  # the SDK does not invent one. +BaseCradle.uuid_of(endpoint)+ yields it too, which is
@@ -54,13 +62,75 @@ module BaseCradle
54
62
  # Regenerate the ingest URL. The old URL dies immediately; the uuid is unchanged.
55
63
  # Use this when an ingest URL leaks. Recorded events are preserved.
56
64
  def rotate
57
- adopt(require_client.request("POST", "/webhook_endpoints/#{content.uuid}/rotation"))
65
+ adopt(require_client.request("POST", "#{endpoint_path}/rotation"))
66
+ end
67
+
68
+ # Set how inbound deliveries must be signed: the scheme, the secret, the header.
69
+ #
70
+ # Every keyword is optional and only the ones you pass are sent, so anything left out
71
+ # stays as it is; pass at least one, or this raises ArgumentError before any request
72
+ # is made.
73
+ #
74
+ # - +verifier+ is the scheme: "hmac_sha256_hex" (the default) or "github". It is
75
+ # passed through as given, so a scheme the platform adds later works here unchanged;
76
+ # one it does not know raises ValidationError.
77
+ # - +credential+ is the signing secret, sent as +verification_credential+: setting it
78
+ # turns verification on. A blank one is sent as given and the API treats it as no
79
+ # change: the current secret, if any, stays, and +content.verification.enabled+
80
+ # cannot tell that skipped rotation from a real one, so make sure a secret read from
81
+ # the environment is not empty before passing it. It is sent as its bytes, which
82
+ # must be UTF-8 (a BINARY string read from a file is fine); a credential that is not
83
+ # a String, or whose bytes are not UTF-8, raises ArgumentError before any request,
84
+ # and the error never shows it. It is write-only: the API never returns it, and this
85
+ # SDK keeps no copy and never puts it in an inspect or an error message.
86
+ # - +signature_header+ is the header the signature is read from, for
87
+ # "hmac_sha256_hex" only; a "github" endpoint always reads X-Hub-Signature-256.
88
+ #
89
+ # Any viewer of the endpoint's timeline may configure it, locked timeline or not.
90
+ # Returns this endpoint, which adopts the one the API returns, so
91
+ # +content.verification+ shows the new state.
92
+ def configure_verification(verifier: nil, credential: nil, signature_header: nil)
93
+ given = { "verifier" => verifier, "verification_credential" => credential,
94
+ "signature_header" => signature_header }.compact
95
+ if given.empty?
96
+ raise ArgumentError, "configure_verification needs at least one of verifier:, credential: " \
97
+ "or signature_header:. Nothing was sent."
98
+ end
99
+ given["verification_credential"] = sendable_secret(credential) unless credential.nil?
100
+
101
+ adopt(require_client.request("PATCH", endpoint_path, json: { "webhook_endpoint" => given }))
102
+ end
103
+
104
+ # Remove the signing secret and turn verification off: deliveries are accepted
105
+ # unsigned again, and +content.verification.enabled+ reads false. Returns this
106
+ # endpoint, which adopts the one the API returns.
107
+ def clear_verification
108
+ adopt(require_client.request("PATCH", endpoint_path,
109
+ json: { "webhook_endpoint" => { "clear_credential" => true } }))
58
110
  end
59
111
 
60
112
  private
61
113
 
114
+ # The credential's bytes as given, read as UTF-8, or ArgumentError. JSON refuses a
115
+ # string it cannot read as UTF-8, and its error holds the whole string, so a secret
116
+ # with the wrong bytes would ride out on an exception's +invalid_object+. Refusing it
117
+ # here, with a message that names the fault and never the value, closes that door.
118
+ def sendable_secret(credential)
119
+ if credential.is_a?(String)
120
+ secret = credential.b.force_encoding(Encoding::UTF_8)
121
+ return secret if secret.valid_encoding?
122
+ end
123
+
124
+ raise ArgumentError, "credential: must be a String whose bytes are UTF-8. It is not shown. " \
125
+ "Nothing was sent."
126
+ end
127
+
128
+ def endpoint_path
129
+ "/webhook_endpoints/#{content.uuid}"
130
+ end
131
+
62
132
  def enablement_path
63
- "/webhook_endpoints/#{content.uuid}/enablement"
133
+ "#{endpoint_path}/enablement"
64
134
  end
65
135
 
66
136
  # Live-object update: the API returned the complete endpoint, so this object points at
@@ -113,7 +183,8 @@ module BaseCradle
113
183
  attribute :timeline, wrap: Reference
114
184
  # The endpoint this arrived on, embedded in full (its own subject form) rather than by
115
185
  # reference — so its current state reads without a second request, and its verbs
116
- # (disable / enable / rotate) are reachable straight off the event. Its uuid is
186
+ # (disable / enable / rotate / configure_verification / clear_verification) are
187
+ # reachable straight off the event. Its uuid is
117
188
  # +event.webhook_endpoint.content.uuid+, or +BaseCradle.uuid_of(...)+.
118
189
  attribute :webhook_endpoint, wrap: WebhookEndpoint
119
190
  attribute :content, wrap: WebhookEventContent
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
4
+ version: 0.15.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Drawk Kwast