ndb 1.17.2 → 1.18.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/lib/ndb/client.rb +13 -2
- data/lib/ndb/errors.rb +5 -0
- data/lib/ndb/version.rb +1 -1
- 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: 30b4a083bf1345ca3fb8bc98311a6e77f302b25e6e105bfb1313dbfcd4615d8a
|
|
4
|
+
data.tar.gz: ebf5a033faf6bade4848b870f98443a2841aee86540f9e6b8adffc11d4d4d882
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 562aafd9f37e5d92d1f4c6ee329946b023a82f423533274cfd9cdc3db284f16060de927b91744c55916bfe3aaee038b9416bb2caabca47e03a214313aab1de17
|
|
7
|
+
data.tar.gz: 664fcb84102346e5a54bc645aa35f9aa987c9886069137eaec8168fe2dcea658b13e3414521635fe222ea6a69408bf7a282749febee44a41f2fa7ff09c48b868
|
data/lib/ndb/client.rb
CHANGED
|
@@ -19,7 +19,11 @@ module Ndb
|
|
|
19
19
|
|
|
20
20
|
DEFAULT_SOCKET = "/run/ndb/ndb.sock"
|
|
21
21
|
|
|
22
|
-
attr_reader :pool, :endpoint
|
|
22
|
+
attr_reader :pool, :endpoint, :user_agent
|
|
23
|
+
|
|
24
|
+
# The User-Agent of the gem: its version, the Ruby version and the
|
|
25
|
+
# platform.
|
|
26
|
+
USER_AGENT = "ndb-ruby/#{VERSION} (ruby #{RUBY_VERSION}; #{RUBY_PLATFORM})".freeze
|
|
23
27
|
|
|
24
28
|
RETRY_BASE = 0.05
|
|
25
29
|
RETRY_CAP = 1.0
|
|
@@ -31,11 +35,15 @@ module Ndb
|
|
|
31
35
|
# ready_timeout is how many seconds a call retries while the daemon is
|
|
32
36
|
# starting or recovering (not_ready, socket missing or refusing), with
|
|
33
37
|
# exponential backoff and jitter. 0 turns it off.
|
|
34
|
-
|
|
38
|
+
#
|
|
39
|
+
# user_agent is the token of the app (for example "myapp/1.2"). It goes
|
|
40
|
+
# after the User-Agent of the gem, so the daemon can tell the apps apart.
|
|
41
|
+
def initialize(url: nil, socket: nil, token: nil, timeout: 30, pool_size: 16, ready_timeout: 10, user_agent: nil)
|
|
35
42
|
@endpoint = Endpoint.parse(url || socket || presence(ENV["NDB_URL"]) || DEFAULT_SOCKET)
|
|
36
43
|
@token = presence(token) || presence(ENV["NDB_TOKEN"])
|
|
37
44
|
@pool = Pool.new(@endpoint, timeout: timeout, size: pool_size)
|
|
38
45
|
@ready_timeout = ready_timeout.to_f
|
|
46
|
+
@user_agent = [USER_AGENT, presence(user_agent.to_s.strip)].compact.join(" ")
|
|
39
47
|
end
|
|
40
48
|
|
|
41
49
|
def socket = @endpoint.path
|
|
@@ -393,7 +401,10 @@ module Ndb
|
|
|
393
401
|
end
|
|
394
402
|
end
|
|
395
403
|
|
|
404
|
+
# Adds the User-Agent, and the bearer token when the client has one.
|
|
396
405
|
def authorize(headers)
|
|
406
|
+
headers = headers.merge("User-Agent" => @user_agent)
|
|
407
|
+
|
|
397
408
|
@token ? headers.merge("Authorization" => "Bearer #{@token}") : headers
|
|
398
409
|
end
|
|
399
410
|
|
data/lib/ndb/errors.rb
CHANGED
|
@@ -71,6 +71,10 @@ module Ndb
|
|
|
71
71
|
# The daemon refused a token for this route, or a route over TCP.
|
|
72
72
|
class Forbidden < Error; end
|
|
73
73
|
|
|
74
|
+
# The IP failed the token check too many times, or max_watches streams are
|
|
75
|
+
# open (HTTP 429). Wait for the Retry-After seconds.
|
|
76
|
+
class TooManyRequests < Error; end
|
|
77
|
+
|
|
74
78
|
# A document, an id, a batch, a path or an index definition is not valid.
|
|
75
79
|
class InvalidDocument < Error; end
|
|
76
80
|
|
|
@@ -153,6 +157,7 @@ module Ndb
|
|
|
153
157
|
"lookup_too_large" => LookupError,
|
|
154
158
|
"invalid_pipeline" => InvalidQuery,
|
|
155
159
|
"forbidden" => Forbidden,
|
|
160
|
+
"too_many_requests" => TooManyRequests,
|
|
156
161
|
"invalid_doc" => InvalidDocument,
|
|
157
162
|
"missing_id" => InvalidDocument,
|
|
158
163
|
"invalid_id" => InvalidDocument,
|
data/lib/ndb/version.rb
CHANGED