ndb 1.20.1 → 1.21.1
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 +37 -2
- data/lib/ndb/collection.rb +17 -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: 742d59480dc61a6b3a11bcc75e37036995f1c2e5a24f77e34f5b402a3989d970
|
|
4
|
+
data.tar.gz: 259dccd7773250671b6872e384539f25df1ed2707c56454452f792af3124dd3f
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 71227603e6200672b3bfc4d95aedbc9778f9ea7706cc8856d24139468df29b1732c334d8cdb0bf1634683099938040c6641d2bef41fafd03a9a948296e235713
|
|
7
|
+
data.tar.gz: 59499efbb4198962233a432cb9c770b20f2623dc3ee14e1c8637097deba8635e87be4d278f5923a9bb196ed768645db73ade70dded4d47c4ea77261dfaeba36a
|
data/lib/ndb/client.rb
CHANGED
|
@@ -73,6 +73,17 @@ module Ndb
|
|
|
73
73
|
body.empty? ? nil : JSON.parse(body)
|
|
74
74
|
end
|
|
75
75
|
|
|
76
|
+
# Runs the block with the reads of this thread keeping the encrypted
|
|
77
|
+
# fields sealed (decrypt=0). Collection#encrypted uses it.
|
|
78
|
+
def keep_encrypted
|
|
79
|
+
before = Thread.current[:ndb_keep_encrypted]
|
|
80
|
+
Thread.current[:ndb_keep_encrypted] = true
|
|
81
|
+
|
|
82
|
+
yield
|
|
83
|
+
ensure
|
|
84
|
+
Thread.current[:ndb_keep_encrypted] = before
|
|
85
|
+
end
|
|
86
|
+
|
|
76
87
|
# The timeout of the connections of this client, in seconds.
|
|
77
88
|
def timeout = @pool.timeout
|
|
78
89
|
|
|
@@ -343,6 +354,18 @@ module Ndb
|
|
|
343
354
|
json(request("GET", "/_stats", nil))
|
|
344
355
|
end
|
|
345
356
|
|
|
357
|
+
# GET /_cluster/settings: the encryption key, masked, and the log
|
|
358
|
+
# settings, each with where its value comes from.
|
|
359
|
+
def settings
|
|
360
|
+
json(request("GET", "/_cluster/settings", nil))
|
|
361
|
+
end
|
|
362
|
+
|
|
363
|
+
# PUT /_cluster/settings: changes settings and stores them in the data
|
|
364
|
+
# dir, such as { log: { level: "debug" } }.
|
|
365
|
+
def put_settings(settings)
|
|
366
|
+
json(request("PUT", "/_cluster/settings", settings))
|
|
367
|
+
end
|
|
368
|
+
|
|
346
369
|
# GET /_size: disk use per collection and per part.
|
|
347
370
|
def size
|
|
348
371
|
json(request("GET", "/_size", nil))
|
|
@@ -408,6 +431,7 @@ module Ndb
|
|
|
408
431
|
end
|
|
409
432
|
|
|
410
433
|
def request(method, target, body, headers: {}, wait: true, timeout: nil)
|
|
434
|
+
target = with_decrypt(target)
|
|
411
435
|
payload = encode(body)
|
|
412
436
|
headers = authorize(headers)
|
|
413
437
|
|
|
@@ -424,7 +448,18 @@ module Ndb
|
|
|
424
448
|
end
|
|
425
449
|
|
|
426
450
|
def idempotent?(method, target)
|
|
427
|
-
method == "GET" || target.match?(%r{/(_search|_count|_aggregate)
|
|
451
|
+
method == "GET" || target.match?(%r{/(_search|_count|_aggregate)(\?|\z)})
|
|
452
|
+
end
|
|
453
|
+
|
|
454
|
+
# A collection route gets decrypt=1: the daemon gives the plain value of
|
|
455
|
+
# an encrypted field only with it and the decrypt right. decrypt=0 inside
|
|
456
|
+
# keep_encrypted. A system route (/_...) gets nothing.
|
|
457
|
+
def with_decrypt(target)
|
|
458
|
+
return target if target.start_with?("/_")
|
|
459
|
+
|
|
460
|
+
flag = Thread.current[:ndb_keep_encrypted] ? "decrypt=0" : "decrypt=1"
|
|
461
|
+
|
|
462
|
+
"#{target}#{target.include?("?") ? "&" : "?"}#{flag}"
|
|
428
463
|
end
|
|
429
464
|
|
|
430
465
|
# Runs the block again while the daemon is not ready. It repeats only
|
|
@@ -495,7 +530,7 @@ module Ndb
|
|
|
495
530
|
pending = +""
|
|
496
531
|
|
|
497
532
|
response = @pool.with do |conn|
|
|
498
|
-
conn.stream("POST", target, JSON.generate(body), headers: authorize({})) do |chunk|
|
|
533
|
+
conn.stream("POST", with_decrypt(target), JSON.generate(body), headers: authorize({})) do |chunk|
|
|
499
534
|
pending << chunk
|
|
500
535
|
|
|
501
536
|
while (newline = pending.index("\n"))
|
data/lib/ndb/collection.rb
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
+
require "delegate"
|
|
4
|
+
|
|
3
5
|
module Ndb
|
|
4
6
|
# One collection of the daemon, with the query builder. The first call
|
|
5
7
|
# declares it (PUT /{coll}) with its definition. A name with a "*" at the
|
|
@@ -33,6 +35,21 @@ module Ndb
|
|
|
33
35
|
|
|
34
36
|
def pattern? = name.include?("*")
|
|
35
37
|
|
|
38
|
+
# The same collection, with every read keeping the encrypted fields
|
|
39
|
+
# sealed ("ndb:e1:k1:..."): a list of secrets that shows none of them.
|
|
40
|
+
def encrypted
|
|
41
|
+
self.class.new(EncryptedClient.new(client), name, definition)
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
# A client whose every call runs inside Client#keep_encrypted.
|
|
45
|
+
class EncryptedClient < SimpleDelegator
|
|
46
|
+
def method_missing(name, ...)
|
|
47
|
+
__getobj__.keep_encrypted { super }
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
def respond_to_missing?(name, include_private = false) = super
|
|
51
|
+
end
|
|
52
|
+
|
|
36
53
|
# A Hash is one document (_doc) and returns {"_id", "_v"}; an Array is
|
|
37
54
|
# many in one transaction (_bulk) and returns the results. expire_in
|
|
38
55
|
# applies to every document.
|
data/lib/ndb/version.rb
CHANGED