vallkey 0.1.0 → 0.2.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: 074654bc2f673408657502e765d210f70111952010045420dc5ebc9e9145e8f6
4
- data.tar.gz: 8afe3aa50b9cfb716e50479bd512f8434350469c4fb31a535b4bf71e9d05115a
3
+ metadata.gz: 58237aacff3a14626297ec257d52fc8e403ef687a3b982314650dee3d5fca384
4
+ data.tar.gz: bc697f3b2153a60f54e97de40032aa4e4115bf7c87e206cc09c67b6f972212da
5
5
  SHA512:
6
- metadata.gz: a26f6c8a1f422ff6dd939c9019b44f6f35d85711edfb386a2750031335b62d9ecd4c1f24978a688843faea2dcbac7bbd290f5355256cdb0de56ae49f6b8732c9
7
- data.tar.gz: 45ef6f57c399b065d32faa0699520a55bc22f5dbc6c7c64d3f5ed94dbe2e69896030700649fc86c9e1b1ac91cc3a4cfa6d7156476de436b8806e88926caaec6f
6
+ metadata.gz: a9472118b607a55f00afecfb68197fa0ef7e3b60085067d9d30713bcb5f777527e61f520de0fc42c0ee33ef3e4c45b560a11eb0cf04fa1182680bd91612e58c9
7
+ data.tar.gz: c0123dfbe198a67423622690bd7589e8723f33f59cf5a5cfd43e76e11353e3bd45a31f8bfd2bef860ca01ad88e5f6d4c5135d815bf9d1158565f9c22f81b8a3d
data/README.md CHANGED
@@ -1,6 +1,8 @@
1
+ ![Vallkey ruby](https://raw.githubusercontent.com/vallkeyhq/developer-tools/main/assets/covers/ruby.png)
2
+
1
3
  # vallkey (Ruby)
2
4
 
3
- Send any Ruby SDK through [Vallkey](https://vallkey.com) with no code changes. Requests that carry a ghost key go to Vallkey, which swaps in the real key under your rules. Every other request is left alone.
5
+ Route ghost-key requests through [Vallkey](https://vallkey.com) using the supported HTTP clients below. Requests that carry a ghost key go to Vallkey, which swaps in the real key under your rules. Every other request is left alone.
4
6
 
5
7
  ```sh
6
8
  gem install vallkey
@@ -9,10 +11,14 @@ RUBYOPT=-rvallkey/auto bundle exec rails server
9
11
 
10
12
  Using `bundle exec`? Add `gem "vallkey"` to your Gemfile too: Bundler only loads the gems it lists.
11
13
 
12
- Covers Net::HTTP, which carries almost every Ruby SDK (Stripe, OpenAI, Anthropic, AWS, and Twilio, Octokit and Slack through Faraday).
14
+ Covers Net::HTTP, used by SDKs configured for this transport (Stripe, OpenAI, Anthropic, AWS, and Twilio, Octokit and Slack through Faraday).
15
+
16
+ | Setting | What it does |
17
+ | ----------------- | ------------------------------------------------------ |
18
+ | `VALLKEY_API` | The Vallkey server (default `https://api.vallkey.com`) |
19
+ | `VALLKEY_AUTO=0` | Turns it off |
20
+ | `VALLKEY_DEBUG=1` | Logs each request sent to Vallkey (never the key) |
21
+
22
+ ## Compatibility and security
13
23
 
14
- | Setting | What it does |
15
- |---|---|
16
- | `VALLKEY_API` | The Vallkey server (default `https://api.vallkey.com`) |
17
- | `VALLKEY_AUTO=0` | Turns it off |
18
- | `VALLKEY_DEBUG=1` | Logs each request sent to Vallkey (never the key) |
24
+ Read the [transport boundaries](https://github.com/vallkeyhq/developer-tools/blob/main/docs/compatibility.md) and [security policy](../SECURITY.md). Local transport tests do not certify every SDK version or cloud deployment. Use a dedicated key and verify requests from the actual application after deployment.
data/lib/vallkey/patch.rb CHANGED
@@ -1,19 +1,6 @@
1
- # Sends every request that carries a ghost key to Vallkey instead of the provider, with
2
- # the same path, so any SDK works without setting a base URL. Requests without a ghost
3
- # key are not touched.
4
- #
5
- # Covers Net::HTTP, which carries almost every Ruby SDK: on its own (Stripe, OpenAI,
6
- # Anthropic, AWS), and under Faraday, HTTParty and rest-client (Twilio, Octokit, Slack).
7
- # Net::HTTP is patched once the app loads it, never loaded from here: under Bundler,
8
- # loading it before the app could pick another version than the app's Gemfile.lock.
9
- #
10
- # Each request sent to Vallkey says in x-vallkey-host which address it was for, and in
11
- # x-vallkey-hook what sent it: this hook, Ruby's version, the platform and VALLKEY_ENV, so
12
- # the dashboard can show each place a key is used. Never app names or secrets.
13
- #
14
- # VALLKEY_API the Vallkey server (default https://api.vallkey.com)
15
- # VALLKEY_DEBUG=1 logs each request sent to Vallkey (never the key)
16
- # VALLKEY_ENV a name for this place (production, staging...), shown in the dashboard
1
+ # Redirect recognized ghost credentials in Net::HTTP requests.
2
+ # Install after Net::HTTP loads so Bundler retains control of its version.
3
+ # See README.md for configuration and transport boundaries.
17
4
  module Vallkey
18
5
  module Patch
19
6
  GHOST = /gk_[a-z]{2,20}_[A-Za-z0-9_-]{22}_[A-Za-z0-9_-]{43}/.freeze
@@ -150,6 +137,7 @@ module Vallkey
150
137
  def request(req, body = nil, &block)
151
138
  moved = Vallkey::Patch.installed && Vallkey::Patch.redirect?(self, req, body)
152
139
  unless moved
140
+ Vallkey::Patch.tag(self, req, body) if Vallkey::Patch.installed
153
141
  if @vallkey_deferred
154
142
  @vallkey_deferred = false
155
143
  connect
@@ -182,6 +170,7 @@ module Vallkey
182
170
 
183
171
  class << self
184
172
  def redirect?(http, req, body)
173
+ return false if ENV["VALLKEY_AUTO"] == "0" # a .env file loaded after start can turn it off
185
174
  t = target
186
175
  return false if http.address == t.host && http.port == t.port
187
176
  headers = []
@@ -190,11 +179,25 @@ module Vallkey
190
179
  scheme = http.use_ssl? ? "https" : "http"
191
180
  default = http.use_ssl? ? 443 : 80
192
181
  from = http.port == default ? http.address : "#{http.address}:#{http.port}"
193
- log("#{scheme}://#{from}#{req.path.to_s.split('?', 2)[0]}", "#{t.scheme}://#{t.host_with_port}")
182
+ log("#{scheme}://#{from}", "#{t.scheme}://#{t.host_with_port}")
194
183
  [t, from]
195
184
  rescue StandardError
196
185
  false # anything unusual goes out as it was
197
186
  end
187
+
188
+ # Already addressed to Vallkey by an SDK's address setting: say which app it is, so
189
+ # one app is one place on the dashboard however each SDK reaches Vallkey.
190
+ def tag(http, req, body)
191
+ return if ENV["VALLKEY_AUTO"] == "0"
192
+ t = target
193
+ return unless http.address == t.host && http.port == t.port
194
+ return if req[WHO_HEADER]
195
+ headers = []
196
+ req.each_header { |name, value| headers << [name, value] }
197
+ req[WHO_HEADER] = who if ghost?(req.path, headers, body || req.body)
198
+ rescue StandardError
199
+ nil # anything unusual goes out as it was
200
+ end
198
201
  end
199
202
  end
200
203
  end
@@ -1,3 +1,3 @@
1
1
  module Vallkey
2
- VERSION = "0.1.0"
2
+ VERSION = "0.2.0"
3
3
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: vallkey
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Vallkey
8
8
  bindir: bin
9
9
  cert_chain: []
10
- date: 1980-01-02 00:00:00.000000000 Z
10
+ date: 2026-10-27 00:00:00.000000000 Z
11
11
  dependencies: []
12
12
  description: Requests that carry a Vallkey ghost key go to Vallkey; nothing else is
13
13
  touched. Turn it on with RUBYOPT=-rvallkey/auto.
@@ -26,6 +26,8 @@ licenses:
26
26
  - MIT
27
27
  metadata:
28
28
  documentation_uri: https://vallkey.com/docs/
29
+ source_code_uri: https://github.com/vallkeyhq/developer-tools/tree/main/ruby
30
+ bug_tracker_uri: https://github.com/vallkeyhq/developer-tools/issues
29
31
  rubygems_mfa_required: 'true'
30
32
  rdoc_options: []
31
33
  require_paths:
@@ -41,7 +43,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
41
43
  - !ruby/object:Gem::Version
42
44
  version: '0'
43
45
  requirements: []
44
- rubygems_version: 4.0.11
46
+ rubygems_version: 3.6.9
45
47
  specification_version: 4
46
- summary: Send any Ruby SDK through Vallkey with no code changes.
48
+ summary: Vallkey runtime integration for Net::HTTP.
47
49
  test_files: []