ndb-rails 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/rails/record.rb +25 -2
- data/lib/ndb/rails/relation.rb +21 -5
- data/lib/ndb/rails/version.rb +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 75877e2f8425d5d6207cc105b3fcacf84c47c37fa09f61289cf03b21444e4fa0
|
|
4
|
+
data.tar.gz: 84528890b7a7230b4ff6d6f5ae65769af01e55d355b39457f78d412857cc22ea
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 9efe5423c482bd44ab58defbe01a4a1ef3daa72d5c608fbc2bac10dc4c94f5d081d2e1b4169a213dcc78056861d6726e1289ff20629fcff9fbdd06f1598e5e78
|
|
7
|
+
data.tar.gz: ddcb2f01811c5468ff5f51c17cb63e89b7affc79e5b9c7907b48033a88e80d4f974daac4f7ff4fe660f43a433f4cbee47ce35e2a141760bd9458508e562fd679
|
data/lib/ndb/rails/record.rb
CHANGED
|
@@ -26,7 +26,7 @@ module Ndb
|
|
|
26
26
|
|
|
27
27
|
class << self
|
|
28
28
|
QUERY_METHODS = %i[
|
|
29
|
-
where where_raw order limit offset page after group unwind includes lock find find_by find_by! first last count pluck exists?
|
|
29
|
+
where where_raw order limit offset page after group unwind includes lock encrypted find find_by find_by! first last count pluck exists?
|
|
30
30
|
find_each in_batches sum average minimum maximum to_a each destroy_all delete_all to_ndb
|
|
31
31
|
].freeze
|
|
32
32
|
|
|
@@ -150,9 +150,14 @@ module Ndb
|
|
|
150
150
|
@source
|
|
151
151
|
end
|
|
152
152
|
|
|
153
|
-
|
|
153
|
+
# encrypted: true makes the daemon encrypt the attribute before it
|
|
154
|
+
# stores it; blind: :numeric (or :exact, :lower, :upper) also lets where and
|
|
155
|
+
# find_by find it by value, and index or unique name it.
|
|
156
|
+
def attribute(name, *args, index: false, unique: false, time: false, expires: false, encrypted: false, blind: nil, **options)
|
|
154
157
|
own_indexed << name.to_s if index
|
|
155
158
|
own_unique << name.to_s if unique
|
|
159
|
+
own_encrypted << name.to_s if encrypted && !blind
|
|
160
|
+
own_blind[name.to_s] = blind.to_s if blind
|
|
156
161
|
@time_field = name.to_s if time
|
|
157
162
|
@expires_field = name.to_s if expires
|
|
158
163
|
|
|
@@ -201,12 +206,22 @@ module Ndb
|
|
|
201
206
|
inherited_list(:unique_fields) | own_unique
|
|
202
207
|
end
|
|
203
208
|
|
|
209
|
+
def encrypted_fields
|
|
210
|
+
inherited_list(:encrypted_fields) | own_encrypted
|
|
211
|
+
end
|
|
212
|
+
|
|
213
|
+
def blind_fields
|
|
214
|
+
(superclass.respond_to?(:blind_fields) ? superclass.blind_fields : {}).merge(own_blind)
|
|
215
|
+
end
|
|
216
|
+
|
|
204
217
|
# The ensure_collection body for this model.
|
|
205
218
|
def collection_definition
|
|
206
219
|
definition = {}
|
|
207
220
|
|
|
208
221
|
definition["indexes"] = indexed_fields if indexed_fields.any?
|
|
209
222
|
definition["unique"] = unique_fields if unique_fields.any?
|
|
223
|
+
definition["encrypted"] = encrypted_fields if encrypted_fields.any?
|
|
224
|
+
definition["blind"] = blind_fields if blind_fields.any?
|
|
210
225
|
definition["time"] = time_field if time_field
|
|
211
226
|
definition["expires_field"] = expires_field if expires_field
|
|
212
227
|
definition["ttl"] = ttl if ttl
|
|
@@ -308,6 +323,14 @@ module Ndb
|
|
|
308
323
|
@own_unique ||= []
|
|
309
324
|
end
|
|
310
325
|
|
|
326
|
+
def own_encrypted
|
|
327
|
+
@own_encrypted ||= []
|
|
328
|
+
end
|
|
329
|
+
|
|
330
|
+
def own_blind
|
|
331
|
+
@own_blind ||= {}
|
|
332
|
+
end
|
|
333
|
+
|
|
311
334
|
def inherited_list(name)
|
|
312
335
|
superclass.respond_to?(name) ? superclass.public_send(name) : []
|
|
313
336
|
end
|
data/lib/ndb/rails/relation.rb
CHANGED
|
@@ -61,6 +61,14 @@ module Ndb
|
|
|
61
61
|
# block, the record is yielded and the lock ends with the block; without
|
|
62
62
|
# one, it ends at the first save or destroy, or at unlock!. See
|
|
63
63
|
# Ndb::Locking. ttl and wait: see Ndb::Client#lock.
|
|
64
|
+
# Reads that keep the encrypted fields sealed ("ndb:e1:k1:..."): a list
|
|
65
|
+
# of secrets that shows none of them. The other reads get the values.
|
|
66
|
+
#
|
|
67
|
+
# Secret.encrypted.where(owner: user.id)
|
|
68
|
+
def encrypted
|
|
69
|
+
with(keep_encrypted: true)
|
|
70
|
+
end
|
|
71
|
+
|
|
64
72
|
def lock(ttl: nil, wait: nil)
|
|
65
73
|
with(lock: { ttl: ttl, wait: wait }.compact)
|
|
66
74
|
end
|
|
@@ -158,7 +166,7 @@ module Ndb
|
|
|
158
166
|
def load
|
|
159
167
|
return self if loaded?
|
|
160
168
|
|
|
161
|
-
@result =
|
|
169
|
+
@result = fetch(to_query)
|
|
162
170
|
@records = @result.rows.map { |row| klass.instantiate(row) }
|
|
163
171
|
|
|
164
172
|
self
|
|
@@ -265,14 +273,14 @@ module Ndb
|
|
|
265
273
|
end
|
|
266
274
|
|
|
267
275
|
def exists?
|
|
268
|
-
|
|
276
|
+
fetch(to_query.slice("query").merge("limit" => 1, "fields" => [klass.primary_key])).rows.any?
|
|
269
277
|
end
|
|
270
278
|
|
|
271
279
|
def pluck(*fields)
|
|
272
280
|
raise ArgumentError, "pluck needs at least one field" if fields.empty?
|
|
273
281
|
|
|
274
282
|
names = fields.map(&:to_s)
|
|
275
|
-
rows =
|
|
283
|
+
rows = fetch(to_query.merge("fields" => names)).rows
|
|
276
284
|
|
|
277
285
|
rows.map do |row|
|
|
278
286
|
values = names.map { |name| klass.attribute_types[name].cast(row.dig(*name.split("."))) }
|
|
@@ -284,7 +292,7 @@ module Ndb
|
|
|
284
292
|
def count
|
|
285
293
|
return calculate(:count) unless values[:group].empty? && values[:unwind].nil?
|
|
286
294
|
|
|
287
|
-
|
|
295
|
+
fetch(to_query.slice("query").merge("count" => true, "limit" => 1, "fields" => [klass.primary_key])).total
|
|
288
296
|
end
|
|
289
297
|
|
|
290
298
|
# Pagination
|
|
@@ -343,6 +351,14 @@ module Ndb
|
|
|
343
351
|
|
|
344
352
|
private
|
|
345
353
|
|
|
354
|
+
def fetch(body)
|
|
355
|
+
sealed_or_plain { klass.ndb_find(body) }
|
|
356
|
+
end
|
|
357
|
+
|
|
358
|
+
def sealed_or_plain(&)
|
|
359
|
+
values[:keep_encrypted] ? Rails.client.keep_encrypted(&) : yield
|
|
360
|
+
end
|
|
361
|
+
|
|
346
362
|
def add_clause(clause)
|
|
347
363
|
with(where: values[:where] + [clause])
|
|
348
364
|
end
|
|
@@ -418,7 +434,7 @@ module Ndb
|
|
|
418
434
|
|
|
419
435
|
def calculate(op, field = nil)
|
|
420
436
|
key = op.to_s
|
|
421
|
-
rows = klass.ndb_aggregate(aggregate_body(op, field)).rows
|
|
437
|
+
rows = sealed_or_plain { klass.ndb_aggregate(aggregate_body(op, field)) }.rows
|
|
422
438
|
|
|
423
439
|
return rows.to_h { |row| [group_key(row["_id"]), row[key]] } unless values[:group].empty?
|
|
424
440
|
|
data/lib/ndb/rails/version.rb
CHANGED
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: ndb-rails
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 1.
|
|
4
|
+
version: 1.21.1
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- thadeu
|
|
@@ -43,7 +43,7 @@ dependencies:
|
|
|
43
43
|
requirements:
|
|
44
44
|
- - ">="
|
|
45
45
|
- !ruby/object:Gem::Version
|
|
46
|
-
version: 1.
|
|
46
|
+
version: 1.21.1
|
|
47
47
|
- - "<"
|
|
48
48
|
- !ruby/object:Gem::Version
|
|
49
49
|
version: '2'
|
|
@@ -53,7 +53,7 @@ dependencies:
|
|
|
53
53
|
requirements:
|
|
54
54
|
- - ">="
|
|
55
55
|
- !ruby/object:Gem::Version
|
|
56
|
-
version: 1.
|
|
56
|
+
version: 1.21.1
|
|
57
57
|
- - "<"
|
|
58
58
|
- !ruby/object:Gem::Version
|
|
59
59
|
version: '2'
|