bson 5.0.2 → 5.1.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/Rakefile +2 -0
- data/ext/bson/extconf.rb +1 -1
- data/lib/bson/binary.rb +126 -4
- data/lib/bson/document.rb +8 -0
- data/lib/bson/object_id.rb +1 -1
- data/lib/bson/regexp.rb +3 -3
- data/lib/bson/vector.rb +44 -0
- data/lib/bson/version.rb +5 -16
- data/lib/bson.rb +1 -0
- data/spec/bson/document_as_spec.rb +14 -0
- data/spec/bson/vector_spec.rb +33 -0
- data/spec/runners/binary_vector.rb +78 -0
- data/spec/shared/LICENSE +20 -0
- data/spec/shared/bin/get-mongodb-download-url +17 -0
- data/spec/shared/bin/s3-copy +45 -0
- data/spec/shared/bin/s3-upload +69 -0
- data/spec/shared/lib/mrss/child_process_helper.rb +80 -0
- data/spec/shared/lib/mrss/cluster_config.rb +231 -0
- data/spec/shared/lib/mrss/constraints.rb +378 -0
- data/spec/shared/lib/mrss/docker_runner.rb +298 -0
- data/spec/shared/lib/mrss/eg_config_utils.rb +51 -0
- data/spec/shared/lib/mrss/event_subscriber.rb +210 -0
- data/spec/shared/lib/mrss/lite_constraints.rb +238 -0
- data/spec/shared/lib/mrss/release/candidate.rb +284 -0
- data/spec/shared/lib/mrss/release/product_data.rb +144 -0
- data/spec/shared/lib/mrss/server_version_registry.rb +113 -0
- data/spec/shared/lib/mrss/session_registry.rb +69 -0
- data/spec/shared/lib/mrss/session_registry_legacy.rb +60 -0
- data/spec/shared/lib/mrss/spec_organizer.rb +179 -0
- data/spec/shared/lib/mrss/utils.rb +37 -0
- data/spec/shared/lib/tasks/candidate.rake +64 -0
- data/spec/shared/share/Dockerfile.erb +251 -0
- data/spec/shared/share/haproxy-1.conf +16 -0
- data/spec/shared/share/haproxy-2.conf +17 -0
- data/spec/shared/shlib/config.sh +27 -0
- data/spec/shared/shlib/distro.sh +84 -0
- data/spec/shared/shlib/server.sh +423 -0
- data/spec/shared/shlib/set_env.sh +110 -0
- data/spec/spec_helper.rb +2 -0
- data/spec/spec_tests/binary_vector_spec.rb +82 -0
- data/spec/spec_tests/data/binary_vector/README.md +61 -0
- data/spec/spec_tests/data/binary_vector/float32.json +65 -0
- data/spec/spec_tests/data/binary_vector/int8.json +57 -0
- data/spec/spec_tests/data/binary_vector/packed_bit.json +83 -0
- data/spec/spec_tests/data/corpus/binary.json +30 -0
- metadata +70 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: db8071ad65b8a0ef6e4c10b76f1143ce627b5d2ba0e3c9f7eed13d3868425c3e
|
4
|
+
data.tar.gz: 3d76edf4c97a81d2362e1b08c4cee08074561f16b74f468b7cb1aac70fb614c4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: dde49d3d741174610fa32ba697c238285209f0074ba04a1d6758604665c1c817a9d96bc1c44c7a731530ebdc94a8ac9e74da3c4ea340a6d6d6d4a0bf4d6ab17e
|
7
|
+
data.tar.gz: f29560d3d3830b34d33567671328dca0dc9b7b5ba173d6a193ed2b3150ae79a17f715666bc106a3c6fda0399ab4e7724bb3efc9a97733076464cd10698a366b3
|
data/Rakefile
CHANGED
data/ext/bson/extconf.rb
CHANGED
data/lib/bson/binary.rb
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
|
-
|
2
|
+
# rubocop:todo all
|
3
3
|
# Copyright (C) 2009-2020 MongoDB Inc.
|
4
4
|
#
|
5
5
|
# Licensed under the Apache License, Version 2.0 (the "License");
|
@@ -50,6 +50,7 @@ module BSON
|
|
50
50
|
ciphertext: 6.chr,
|
51
51
|
column: 7.chr,
|
52
52
|
sensitive: 8.chr,
|
53
|
+
vector: 9.chr,
|
53
54
|
user: 128.chr,
|
54
55
|
}.freeze
|
55
56
|
|
@@ -61,6 +62,16 @@ module BSON
|
|
61
62
|
# @since 2.0.0
|
62
63
|
TYPES = SUBTYPES.invert.freeze
|
63
64
|
|
65
|
+
# Types of vector data.
|
66
|
+
VECTOR_DATA_TYPES = {
|
67
|
+
int8: '0x03'.hex,
|
68
|
+
float32: '0x27'.hex,
|
69
|
+
packed_bit: '0x10'.hex
|
70
|
+
}.freeze
|
71
|
+
|
72
|
+
# @api private
|
73
|
+
VECTOR_DATA_TYPES_INVERSE = VECTOR_DATA_TYPES.invert.freeze
|
74
|
+
|
64
75
|
# @return [ String ] The raw binary data.
|
65
76
|
#
|
66
77
|
# The string is always stored in BINARY encoding.
|
@@ -89,6 +100,7 @@ module BSON
|
|
89
100
|
|
90
101
|
type == other.type && data == other.data
|
91
102
|
end
|
103
|
+
|
92
104
|
alias eql? ==
|
93
105
|
|
94
106
|
# Compare this binary object to another object. The two objects must have
|
@@ -113,7 +125,7 @@ module BSON
|
|
113
125
|
#
|
114
126
|
# @since 2.3.1
|
115
127
|
def hash
|
116
|
-
[
|
128
|
+
[data, type].hash
|
117
129
|
end
|
118
130
|
|
119
131
|
# Return a representation of the object for use in
|
@@ -146,6 +158,26 @@ module BSON
|
|
146
158
|
end
|
147
159
|
end
|
148
160
|
|
161
|
+
# Decode the binary data as a vector data type.
|
162
|
+
#
|
163
|
+
# @return [ BSON::Vector ] The decoded vector data.
|
164
|
+
def as_vector
|
165
|
+
raise BSON::Error, "Cannot decode subtype #{type} as vector" unless type == :vector
|
166
|
+
|
167
|
+
dtype_value, padding, = data[0..1].unpack('CC')
|
168
|
+
dtype = VECTOR_DATA_TYPES_INVERSE[dtype_value]
|
169
|
+
raise ArgumentError, "Unsupported vector type: #{dtype_value}" unless dtype
|
170
|
+
|
171
|
+
format = case dtype
|
172
|
+
when :int8 then 'c*'
|
173
|
+
when :float32 then 'f*'
|
174
|
+
when :packed_bit then 'C*'
|
175
|
+
else
|
176
|
+
raise ArgumentError, "Unsupported type: #{dtype}"
|
177
|
+
end
|
178
|
+
BSON::Vector.new(data[2..-1].unpack(format), dtype, padding)
|
179
|
+
end
|
180
|
+
|
149
181
|
# Instantiate the new binary object.
|
150
182
|
#
|
151
183
|
# This method accepts a string in any encoding; however, if a string is
|
@@ -368,8 +400,97 @@ module BSON
|
|
368
400
|
new(uuid_binary, :uuid_old)
|
369
401
|
end
|
370
402
|
|
403
|
+
# Constructs a new binary object from a binary vector.
|
404
|
+
|
405
|
+
# @param [ BSON::Vector | Array ] vector The vector data.
|
406
|
+
# @param [ Symbol | nil ] dtype The vector data type, must be nil if vector is a BSON::Vector.
|
407
|
+
# @param [ Integer ] padding The number of bits in the final byte that are to
|
408
|
+
# be ignored when a vector element's size is less than a byte. Must be 0 if vector is a BSON::Vector.
|
409
|
+
# @param [ Boolean ] validate_vector_data Whether to validate the vector data.
|
410
|
+
#
|
411
|
+
# @return [ BSON::Binary ] The binary object.
|
412
|
+
def self.from_vector(vector, dtype = nil, padding = 0, validate_vector_data: false)
|
413
|
+
data, dtype, padding = extract_args_for_vector(vector, dtype, padding)
|
414
|
+
validate_args_for_vector!(data, dtype, padding)
|
415
|
+
|
416
|
+
format = case dtype
|
417
|
+
when :int8 then 'c*'
|
418
|
+
when :float32 then 'f*'
|
419
|
+
when :packed_bit then 'C*'
|
420
|
+
else raise ArgumentError, "Unsupported type: #{dtype}"
|
421
|
+
end
|
422
|
+
if validate_vector_data
|
423
|
+
validate_vector_data!(data, dtype)
|
424
|
+
end
|
425
|
+
metadata = [ VECTOR_DATA_TYPES[dtype], padding ].pack('CC')
|
426
|
+
data = data.pack(format)
|
427
|
+
new(metadata.concat(data), :vector)
|
428
|
+
end
|
429
|
+
|
371
430
|
private
|
372
431
|
|
432
|
+
# Extracts the arguments for a binary vector.
|
433
|
+
#
|
434
|
+
# @param [ BSON::Vector | Array ] vector The vector data.
|
435
|
+
# @param [ ::Symbol | nil ] dtype The vector data type, must be nil if vector is a BSON::Vector.
|
436
|
+
# @param [ Integer ] padding The padding. Must be 0 if vector is a BSON::Vector.
|
437
|
+
#
|
438
|
+
# @return [ Array ] The extracted data, dtype, and padding.
|
439
|
+
def self.extract_args_for_vector(vector, dtype, padding)
|
440
|
+
if vector.is_a?(BSON::Vector)
|
441
|
+
if dtype || padding != 0
|
442
|
+
raise ArgumentError, 'Do not specify dtype and padding if the first argument is BSON::Vector'
|
443
|
+
end
|
444
|
+
|
445
|
+
data = vector.data
|
446
|
+
dtype = vector.dtype
|
447
|
+
padding = vector.padding
|
448
|
+
else
|
449
|
+
data = vector
|
450
|
+
end
|
451
|
+
[ data, dtype, padding ]
|
452
|
+
end
|
453
|
+
private_class_method :extract_args_for_vector
|
454
|
+
|
455
|
+
# Validate the arguments for a binary vector.
|
456
|
+
# @param [ Array ] data The vector data.
|
457
|
+
# @param [ ::Symbol ] dtype The vector data type.
|
458
|
+
# @param [ Integer ] padding The padding. Must be 0 if vector is a BSON::Vector.
|
459
|
+
# @raise [ ArgumentError ] If the arguments are invalid.
|
460
|
+
def self.validate_args_for_vector!(data, dtype, padding)
|
461
|
+
raise ArgumentError, "Unknown dtype #{dtype}" unless VECTOR_DATA_TYPES.key?(dtype)
|
462
|
+
|
463
|
+
if %i[int8 float32].include?(dtype)
|
464
|
+
raise ArgumentError, 'Padding applies only to packed_bit' if padding != 0
|
465
|
+
elsif padding.positive? && data.empty?
|
466
|
+
raise ArgumentError, 'Padding must be zero when the vector is empty for PACKED_BIT'
|
467
|
+
elsif padding.negative? || padding > 7
|
468
|
+
raise ArgumentError, "Padding must be between 0 and 7, got #{padding}"
|
469
|
+
end
|
470
|
+
end
|
471
|
+
private_class_method :validate_args_for_vector!
|
472
|
+
|
473
|
+
# Validate that all the values in the vector data are valid for the given dtype.
|
474
|
+
#
|
475
|
+
# @param [ Array ] data The vector data.
|
476
|
+
# @param [ ::Symbol ] dtype The vector data type.
|
477
|
+
def self.validate_vector_data!(data, dtype)
|
478
|
+
validator = case dtype
|
479
|
+
when :int8
|
480
|
+
->(v) { v.is_a?(Integer) && v.between?(-128, 127) }
|
481
|
+
when :float32
|
482
|
+
->(v) { v.is_a?(Float) }
|
483
|
+
when :packed_bit
|
484
|
+
->(v) { v.is_a?(Integer) && v.between?(0, 255) }
|
485
|
+
else
|
486
|
+
raise ArgumentError, "Unsupported type: #{dtype}"
|
487
|
+
end
|
488
|
+
data.each do |v|
|
489
|
+
raise ArgumentError, "Invalid value #{v} for type #{dtype}" unless validator.call(v)
|
490
|
+
end
|
491
|
+
end
|
492
|
+
private_class_method :validate_vector_data!
|
493
|
+
|
373
494
|
# initializes an instance of BSON::Binary.
|
374
495
|
#
|
375
496
|
# @param [ String ] data the data to initialize the object with
|
@@ -398,7 +519,7 @@ module BSON
|
|
398
519
|
if representation != :standard
|
399
520
|
raise ArgumentError,
|
400
521
|
'Binary of type :uuid can only be stringified to :standard representation, ' \
|
401
|
-
|
522
|
+
"requested: #{representation.inspect}"
|
402
523
|
end
|
403
524
|
|
404
525
|
data
|
@@ -490,7 +611,8 @@ module BSON
|
|
490
611
|
validate_integer_type!(type.bytes.first)
|
491
612
|
end
|
492
613
|
when Symbol then validate_symbol_type!(type)
|
493
|
-
else
|
614
|
+
else
|
615
|
+
raise BSON::Error::InvalidBinaryType, type
|
494
616
|
end
|
495
617
|
end
|
496
618
|
|
data/lib/bson/document.rb
CHANGED
@@ -321,6 +321,14 @@ module BSON
|
|
321
321
|
raise ArgumentError, 'symbolize_keys! is not supported on BSON::Document instances. Please convert the document to hash first (using #to_h), then call #symbolize_keys! on the Hash instance'
|
322
322
|
end
|
323
323
|
|
324
|
+
def deep_symbolize_keys!
|
325
|
+
warn <<~WARN
|
326
|
+
[DEPRECATION] `deep_symbolize_keys!` is not supported on BSON::Document instances.
|
327
|
+
Please convert the document to a Hash first (using `#to_h`), then call `#deep_symbolize_keys!` on the Hash.
|
328
|
+
This will raise an error starting with the v6.0.0 release.
|
329
|
+
WARN
|
330
|
+
end
|
331
|
+
|
324
332
|
# Override the Hash implementation of to_bson_normalized_value.
|
325
333
|
#
|
326
334
|
# BSON::Document is already of the correct type and already provides
|
data/lib/bson/object_id.rb
CHANGED
@@ -360,7 +360,7 @@ module BSON
|
|
360
360
|
# NUM2UINT. Further, the spec dictates that the time component of an
|
361
361
|
# ObjectID must be no more than 4 bytes long, so the spec itself is
|
362
362
|
# constrained in this regard.
|
363
|
-
MAX_INTEGER = 2
|
363
|
+
MAX_INTEGER = 2**32
|
364
364
|
|
365
365
|
# Returns an integer timestamp (seconds since the Epoch). Primarily used
|
366
366
|
# by the generator to produce object ids.
|
data/lib/bson/regexp.rb
CHANGED
@@ -99,16 +99,16 @@ module BSON
|
|
99
99
|
end
|
100
100
|
|
101
101
|
def bson_extended
|
102
|
-
(
|
102
|
+
options.nobits?(::Regexp::EXTENDED) ? NO_VALUE : EXTENDED_VALUE
|
103
103
|
end
|
104
104
|
|
105
105
|
def bson_ignorecase
|
106
|
-
(
|
106
|
+
options.nobits?(::Regexp::IGNORECASE) ? NO_VALUE : IGNORECASE_VALUE
|
107
107
|
end
|
108
108
|
|
109
109
|
def bson_dotall
|
110
110
|
# Ruby Regexp's MULTILINE is equivalent to BSON's dotall value
|
111
|
-
(
|
111
|
+
options.nobits?(::Regexp::MULTILINE) ? NO_VALUE : NEWLINE_VALUE
|
112
112
|
end
|
113
113
|
|
114
114
|
# Represents the raw values for the regular expression.
|
data/lib/bson/vector.rb
ADDED
@@ -0,0 +1,44 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# Copyright (C) 2025-present MongoDB Inc.
|
4
|
+
#
|
5
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
6
|
+
# you may not use this file except in compliance with the License.
|
7
|
+
# You may obtain a copy of the License at
|
8
|
+
#
|
9
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
10
|
+
#
|
11
|
+
# Unless required by applicable law or agreed to in writing, software
|
12
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
13
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
14
|
+
# See the License for the specific language governing permissions and
|
15
|
+
# limitations under the License.
|
16
|
+
|
17
|
+
module BSON
|
18
|
+
# Vector of numbers along with metadata for binary interoperability.
|
19
|
+
class Vector < ::Array
|
20
|
+
# @return [ Integer ] The data type stored in the vector.
|
21
|
+
attr_reader :dtype
|
22
|
+
|
23
|
+
# @return [ Integer ] The number of bits in the final byte that are to
|
24
|
+
# be ignored when a vector element's size is less than a byte
|
25
|
+
# and the length of the vector is not a multiple of 8.
|
26
|
+
attr_reader :padding
|
27
|
+
|
28
|
+
# @return [ BSON::ByteBuffer ] The data in the vector.
|
29
|
+
def data
|
30
|
+
self
|
31
|
+
end
|
32
|
+
|
33
|
+
# @param [ ::Array ] data The data to initialize the vector with.
|
34
|
+
# @param [ Integer ] dtype The data type of the vector.
|
35
|
+
# @param [ Integer ] padding The number of bits in the final byte that are to
|
36
|
+
# be ignored when a vector element's size is less than a byte
|
37
|
+
# and the length of the vector is not a multiple of 8.
|
38
|
+
def initialize(data, dtype, padding = 0)
|
39
|
+
@dtype = dtype
|
40
|
+
@padding = padding
|
41
|
+
super(data.dup)
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
data/lib/bson/version.rb
CHANGED
@@ -1,20 +1,9 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
|
-
# rubocop:todo all
|
3
|
-
|
4
|
-
# Copyright (C) 2009-2020 MongoDB Inc.
|
5
|
-
#
|
6
|
-
# Licensed under the Apache License, Version 2.0 (the "License");
|
7
|
-
# you may not use this file except in compliance with the License.
|
8
|
-
# You may obtain a copy of the License at
|
9
|
-
#
|
10
|
-
# http://www.apache.org/licenses/LICENSE-2.0
|
11
|
-
#
|
12
|
-
# Unless required by applicable law or agreed to in writing, software
|
13
|
-
# distributed under the License is distributed on an "AS IS" BASIS,
|
14
|
-
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
15
|
-
# See the License for the specific language governing permissions and
|
16
|
-
# limitations under the License.
|
17
2
|
|
18
3
|
module BSON
|
19
|
-
|
4
|
+
# The current version of the library.
|
5
|
+
#
|
6
|
+
# NOTE: this file is automatically updated via `rake candidate:create`.
|
7
|
+
# Manual changes to this file may be overwritten by that rake task.
|
8
|
+
VERSION = '5.1.0'
|
20
9
|
end
|
data/lib/bson.rb
CHANGED
@@ -44,4 +44,18 @@ describe BSON::Document do
|
|
44
44
|
end
|
45
45
|
end
|
46
46
|
end
|
47
|
+
|
48
|
+
describe '#deep_symbolize_keys!' do
|
49
|
+
context 'string keys' do
|
50
|
+
let(:doc) do
|
51
|
+
described_class.new('foo' => 'bar')
|
52
|
+
end
|
53
|
+
|
54
|
+
it 'raises ArgumentError' do
|
55
|
+
expect do
|
56
|
+
doc.deep_symbolize_keys!
|
57
|
+
end.to output(/\[DEPRECATION\] `deep_symbolize_keys!` is not supported on BSON::Document instances./).to_stderr
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
47
61
|
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# Copyright (C) 2025-present MongoDB Inc.
|
4
|
+
#
|
5
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
6
|
+
# you may not use this file except in compliance with the License.
|
7
|
+
# You may obtain a copy of the License at
|
8
|
+
#
|
9
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
10
|
+
#
|
11
|
+
# Unless required by applicable law or agreed to in writing, software
|
12
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
13
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
14
|
+
# See the License for the specific language governing permissions and
|
15
|
+
# limitations under the License.
|
16
|
+
|
17
|
+
require 'spec_helper'
|
18
|
+
|
19
|
+
describe BSON::Vector do
|
20
|
+
it 'behaves like an Array' do
|
21
|
+
expect(described_class.new([ 1, 2, 3 ], :int8)).to be_a(Array)
|
22
|
+
end
|
23
|
+
|
24
|
+
describe '#initialize' do
|
25
|
+
context 'when padding is not provided' do
|
26
|
+
let(:vector) { described_class.new([ 1, 2, 3 ], :int8) }
|
27
|
+
|
28
|
+
it 'sets the padding to 0' do
|
29
|
+
expect(vector.padding).to eq(0)
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
@@ -0,0 +1,78 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require 'runners/common_driver'
|
4
|
+
|
5
|
+
module BSON
|
6
|
+
module BinaryVector
|
7
|
+
class Spec < CommonDriver::Spec
|
8
|
+
def initialize(file)
|
9
|
+
super
|
10
|
+
@valid = @invalid = nil
|
11
|
+
end
|
12
|
+
|
13
|
+
def tests
|
14
|
+
@spec['tests'].collect do |test|
|
15
|
+
BSON::BinaryVector::Test.new(self, test)
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
def valid_tests
|
20
|
+
tests.select(&:valid?)
|
21
|
+
end
|
22
|
+
|
23
|
+
def invalid_tests
|
24
|
+
tests.reject(&:valid?)
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
class Test
|
29
|
+
attr_reader :canonical_bson, :description, :dtype, :padding, :vector
|
30
|
+
|
31
|
+
def initialize(spec, test)
|
32
|
+
@spec = spec
|
33
|
+
@description = test['description']
|
34
|
+
@valid = test['valid']
|
35
|
+
@vector = ExtJSON.parse_obj(test['vector'])
|
36
|
+
@dtype_hex = test['dtype_hex']
|
37
|
+
@dtype_alias = test['dtype_alias']
|
38
|
+
@dtype = @dtype_alias.downcase.to_sym
|
39
|
+
@padding = test['padding']
|
40
|
+
@canonical_bson = test['canonical_bson']
|
41
|
+
end
|
42
|
+
|
43
|
+
def valid?
|
44
|
+
@valid
|
45
|
+
end
|
46
|
+
|
47
|
+
def document_from_canonical_bson
|
48
|
+
bson_bytes = decode_hex(@canonical_bson)
|
49
|
+
buffer = BSON::ByteBuffer.new(bson_bytes)
|
50
|
+
BSON::Document.from_bson(buffer)
|
51
|
+
end
|
52
|
+
|
53
|
+
def canonical_bson_from_document(use_vector_type: false, validate_vector_data: false)
|
54
|
+
args = if use_vector_type
|
55
|
+
[ BSON::Vector.new(@vector, @dtype, @padding) ]
|
56
|
+
else
|
57
|
+
[ @vector, @dtype, @padding ]
|
58
|
+
end
|
59
|
+
{
|
60
|
+
@spec.test_key => BSON::Binary.from_vector(
|
61
|
+
*args,
|
62
|
+
validate_vector_data: validate_vector_data
|
63
|
+
),
|
64
|
+
}.to_bson.to_s
|
65
|
+
end
|
66
|
+
|
67
|
+
def bson
|
68
|
+
decode_hex(@canonical_bson)
|
69
|
+
end
|
70
|
+
|
71
|
+
private
|
72
|
+
|
73
|
+
def decode_hex(obj)
|
74
|
+
[ obj ].pack('H*')
|
75
|
+
end
|
76
|
+
end
|
77
|
+
end
|
78
|
+
end
|
data/spec/shared/LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2020 MongoDB, Inc.
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
@@ -0,0 +1,17 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
desired_version, arch = ARGV
|
4
|
+
if arch.nil?
|
5
|
+
STDERR.puts "Usage: get-mongodb-download-url desired-version arch"
|
6
|
+
exit 1
|
7
|
+
end
|
8
|
+
|
9
|
+
$: << File.join(File.dirname(__FILE__), '../lib')
|
10
|
+
require 'mrss/server_version_registry'
|
11
|
+
|
12
|
+
begin
|
13
|
+
puts Mrss::ServerVersionRegistry.new(desired_version, arch).download_url
|
14
|
+
rescue Mrss::ServerVersionRegistry::Error => exc
|
15
|
+
STDERR.puts "Error: #{exc}"
|
16
|
+
exit 2
|
17
|
+
end
|
@@ -0,0 +1,45 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'optparse'
|
4
|
+
require 'aws-sdk-s3'
|
5
|
+
|
6
|
+
options = {}
|
7
|
+
OptionParser.new do |opts|
|
8
|
+
opts.banner = "Usage: s3-copy options"
|
9
|
+
|
10
|
+
opts.on("-r", "--region=REGION", "AWS region to use (default us-east-1)") do |v|
|
11
|
+
options[:region] = v
|
12
|
+
end
|
13
|
+
|
14
|
+
opts.on("-p", "--param=KEY=VALUE", "Specify parameter for new files") do |v|
|
15
|
+
options[:params] ||= {}
|
16
|
+
k, v = v.split('=', 2)
|
17
|
+
options[:params][k.to_sym] = v
|
18
|
+
end
|
19
|
+
|
20
|
+
opts.on("-f", "--from=BUCKET:PATH", "Bucket name and key (or path) to copy from") do |v|
|
21
|
+
options[:from] = v
|
22
|
+
end
|
23
|
+
|
24
|
+
opts.on("-t", "--to=BUCKET:PATH", "Bucket name and key (or path) to write to (may be specified more than once)") do |v|
|
25
|
+
options[:to] ||= []
|
26
|
+
options[:to] << v
|
27
|
+
end
|
28
|
+
end.parse!
|
29
|
+
|
30
|
+
ENV['AWS_REGION'] ||= options[:region] || 'us-east-1'
|
31
|
+
|
32
|
+
bucket, key = options.fetch(:from).split(':', 2)
|
33
|
+
|
34
|
+
s3 = Aws::S3::Client.new
|
35
|
+
|
36
|
+
options.fetch(:to).each do |dest|
|
37
|
+
STDERR.puts "Copying to #{dest}"
|
38
|
+
dbucket, dkey = dest.split(':', 2)
|
39
|
+
s3.copy_object(
|
40
|
+
bucket: dbucket,
|
41
|
+
key: dkey,
|
42
|
+
copy_source: "/#{bucket}/#{key}",
|
43
|
+
**options[:params] || {},
|
44
|
+
)
|
45
|
+
end
|
@@ -0,0 +1,69 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require 'optparse'
|
4
|
+
require 'aws-sdk-s3'
|
5
|
+
|
6
|
+
options = {}
|
7
|
+
OptionParser.new do |opts|
|
8
|
+
opts.banner = "Usage: s3-upload options"
|
9
|
+
|
10
|
+
opts.on("-r", "--region=REGION", "AWS region to use (default us-east-1)") do |v|
|
11
|
+
options[:region] = v
|
12
|
+
end
|
13
|
+
|
14
|
+
opts.on("-p", "--param=KEY=VALUE", "Specify parameter for S3 upload") do |v|
|
15
|
+
options[:params] ||= {}
|
16
|
+
k, v = v.split('=', 2)
|
17
|
+
options[:params][k.to_sym] = v
|
18
|
+
end
|
19
|
+
|
20
|
+
opts.on("-f", "--file=PATH", "Path to the file to upload, - to upload standard input") do |v|
|
21
|
+
options[:file] = v
|
22
|
+
end
|
23
|
+
|
24
|
+
opts.on("-w", "--write=BUCKET:PATH", "Bucket name and key (or path) to upload to") do |v|
|
25
|
+
options[:write] = v
|
26
|
+
end
|
27
|
+
|
28
|
+
opts.on("-c", "--copy=BUCKET:PATH", "Bucket name and key (or path) to copy to (may be specified more than once)") do |v|
|
29
|
+
options[:copy] ||= []
|
30
|
+
options[:copy] << v
|
31
|
+
end
|
32
|
+
end.parse!
|
33
|
+
|
34
|
+
ENV['AWS_REGION'] ||= options[:region] || 'us-east-1'
|
35
|
+
|
36
|
+
def upload(f, options)
|
37
|
+
s3 = Aws::S3::Client.new
|
38
|
+
write = options.fetch(:write)
|
39
|
+
STDERR.puts "Writing #{write}"
|
40
|
+
bucket, key = write.split(':', 2)
|
41
|
+
s3.put_object(
|
42
|
+
body: f.read,
|
43
|
+
bucket: bucket,
|
44
|
+
key: key,
|
45
|
+
**options[:params] || {},
|
46
|
+
)
|
47
|
+
if copy = options[:copy]
|
48
|
+
copy.each do |dest|
|
49
|
+
STDERR.puts "Copying to #{dest}"
|
50
|
+
dbucket, dkey = dest.split(':', 2)
|
51
|
+
s3.copy_object(
|
52
|
+
bucket: dbucket,
|
53
|
+
key: dkey,
|
54
|
+
copy_source: "/#{bucket}/#{key}",
|
55
|
+
**options[:params] || {},
|
56
|
+
)
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
if options[:file] == '-'
|
62
|
+
upload(STDIN, options)
|
63
|
+
elsif options[:file]
|
64
|
+
File.open(options[:file]) do |f|
|
65
|
+
upload(f, options)
|
66
|
+
end
|
67
|
+
else
|
68
|
+
upload(STDIN, options)
|
69
|
+
end
|