ndb 1.20.1 → 1.21.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: f788ae85ba41e2ce24bd608595386b79c3fe4be99f19152d7fd1c68f12288d42
4
- data.tar.gz: e6eee4cc20ee490fe6f9be4c813e937ab73beb9b27cc7bfa529b1e62957edd8d
3
+ metadata.gz: 9470970553d79984489d939f6ec7a7dab5cc3fbe1745172029185f1458d2048e
4
+ data.tar.gz: b15f92e0cbe1472ada92c58307cb7f9b178ab26fa3069eabad9788ba2fff17d1
5
5
  SHA512:
6
- metadata.gz: bd3ff114deafa0b00efc42b03b75b3254e4648b541a58e8979803be8555dadeb1d3edce4553e448d04d543ea3a384a123a2c42d7e178f11aa45b2af50932a6c8
7
- data.tar.gz: a35640f851ec9888ae9061710e3450c85ded9d8f2e772f81a77a9f2dc9b57905fb5eef89dfc2500601ab0743a5b135720003d85c228741ebd89cac1d76a2abec
6
+ metadata.gz: 62ba4e92160ba7cfd01efab484b44376b8f1159a362c15fb9193e54276d87ce63382fea52ff5aa04f63014b019a31ccddf27491507a0bf773583a98a0a9a589b
7
+ data.tar.gz: 40a64b1cf059ecf6c04afd17d93f116c69d5f373e60ca68acc75730d5139a64b42f580666d84c2092f2a37885bdd194cfac5fc5b087d27da2de8efaff7548179
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)\z})
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"))
@@ -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
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Ndb
4
- VERSION = "1.20.1"
4
+ VERSION = "1.21.0"
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ndb
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.20.1
4
+ version: 1.21.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - thadeu