bson 4.1.1 → 5.2.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 +5 -5
- data/README.md +106 -7
- data/Rakefile +86 -43
- data/ext/bson/{native-endian.h → bson-endian.h} +14 -107
- data/ext/bson/bson-native.h +135 -0
- data/ext/bson/bytebuf.c +133 -0
- data/ext/bson/endian.c +117 -0
- data/ext/bson/extconf.rb +8 -3
- data/ext/bson/init.c +364 -0
- data/ext/bson/libbson-utf8.c +230 -0
- data/ext/bson/read.c +470 -0
- data/ext/bson/util.c +250 -0
- data/ext/bson/write.c +675 -0
- data/lib/bson/active_support.rb +19 -0
- data/lib/bson/array.rb +97 -30
- data/lib/bson/big_decimal.rb +77 -0
- data/lib/bson/binary.rb +510 -70
- data/lib/bson/boolean.rb +15 -4
- data/lib/bson/code.rb +25 -12
- data/lib/bson/code_with_scope.rb +41 -15
- data/lib/bson/config.rb +3 -28
- data/lib/bson/date.rb +16 -4
- data/lib/bson/date_time.rb +6 -4
- data/lib/bson/db_pointer.rb +110 -0
- data/lib/bson/dbref.rb +154 -0
- data/lib/bson/decimal128/builder.rb +456 -0
- data/lib/bson/decimal128.rb +272 -0
- data/lib/bson/document.rb +177 -7
- data/lib/bson/environment.rb +17 -2
- data/lib/bson/error/bson_decode_error.rb +11 -0
- data/lib/bson/error/ext_json_parse_error.rb +11 -0
- data/lib/bson/error/illegal_key.rb +23 -0
- data/lib/bson/error/invalid_binary_type.rb +37 -0
- data/lib/bson/error/invalid_dbref_argument.rb +12 -0
- data/lib/bson/error/invalid_decimal128_argument.rb +25 -0
- data/lib/bson/error/invalid_decimal128_range.rb +27 -0
- data/lib/bson/error/invalid_decimal128_string.rb +26 -0
- data/lib/bson/error/invalid_key.rb +24 -0
- data/lib/bson/error/invalid_object_id.rb +11 -0
- data/lib/bson/error/invalid_regexp_pattern.rb +13 -0
- data/lib/bson/error/unrepresentable_precision.rb +19 -0
- data/lib/bson/error/unserializable_class.rb +13 -0
- data/lib/bson/error/unsupported_binary_subtype.rb +12 -0
- data/lib/bson/error/unsupported_type.rb +11 -0
- data/lib/bson/error.rb +22 -0
- data/lib/bson/ext_json.rb +389 -0
- data/lib/bson/false_class.rb +6 -4
- data/lib/bson/float.rb +43 -7
- data/lib/bson/hash.rb +152 -37
- data/lib/bson/int32.rb +104 -6
- data/lib/bson/int64.rb +111 -8
- data/lib/bson/integer.rb +43 -9
- data/lib/bson/json.rb +3 -1
- data/lib/bson/max_key.rb +21 -10
- data/lib/bson/min_key.rb +21 -10
- data/lib/bson/nil_class.rb +7 -3
- data/lib/bson/object.rb +25 -17
- data/lib/bson/object_id.rb +98 -113
- data/lib/bson/open_struct.rb +59 -0
- data/lib/bson/regexp.rb +129 -56
- data/lib/bson/registry.rb +7 -10
- data/lib/bson/specialized.rb +8 -4
- data/lib/bson/string.rb +12 -32
- data/lib/bson/symbol.rb +107 -11
- data/lib/bson/time.rb +68 -7
- data/lib/bson/time_with_zone.rb +67 -0
- data/lib/bson/timestamp.rb +50 -10
- data/lib/bson/true_class.rb +6 -4
- data/lib/bson/undefined.rb +28 -2
- data/lib/bson/vector.rb +44 -0
- data/lib/bson/version.rb +6 -14
- data/lib/bson.rb +22 -12
- data/spec/README.md +14 -0
- data/spec/bson/array_spec.rb +38 -62
- data/spec/bson/big_decimal_spec.rb +328 -0
- data/spec/bson/binary_spec.rb +199 -53
- data/spec/bson/binary_uuid_spec.rb +190 -0
- data/spec/bson/boolean_spec.rb +2 -1
- data/spec/bson/byte_buffer_read_spec.rb +198 -0
- data/spec/bson/byte_buffer_spec.rb +122 -381
- data/spec/bson/byte_buffer_write_spec.rb +855 -0
- data/spec/bson/code_spec.rb +6 -4
- data/spec/bson/code_with_scope_spec.rb +6 -4
- data/spec/bson/config_spec.rb +1 -35
- data/spec/bson/date_spec.rb +2 -1
- data/spec/bson/date_time_spec.rb +55 -1
- data/spec/bson/dbref_legacy_spec.rb +186 -0
- data/spec/bson/dbref_spec.rb +487 -0
- data/spec/bson/decimal128_spec.rb +1840 -0
- data/spec/bson/document_as_spec.rb +61 -0
- data/spec/bson/document_spec.rb +205 -32
- data/spec/bson/ext_json_parse_spec.rb +346 -0
- data/spec/bson/false_class_spec.rb +9 -1
- data/spec/bson/float_spec.rb +42 -1
- data/spec/bson/hash_as_spec.rb +58 -0
- data/spec/bson/hash_spec.rb +318 -66
- data/spec/bson/int32_spec.rb +248 -1
- data/spec/bson/int64_spec.rb +308 -1
- data/spec/bson/integer_spec.rb +61 -3
- data/spec/bson/json_spec.rb +2 -1
- data/spec/bson/max_key_spec.rb +6 -4
- data/spec/bson/min_key_spec.rb +6 -4
- data/spec/bson/nil_class_spec.rb +2 -1
- data/spec/bson/object_id_spec.rb +95 -5
- data/spec/bson/object_spec.rb +3 -2
- data/spec/bson/open_struct_spec.rb +87 -0
- data/spec/bson/raw_spec.rb +594 -0
- data/spec/bson/regexp_spec.rb +61 -8
- data/spec/bson/registry_spec.rb +3 -2
- data/spec/bson/string_spec.rb +26 -33
- data/spec/bson/symbol_raw_spec.rb +70 -0
- data/spec/bson/symbol_spec.rb +77 -20
- data/spec/bson/time_spec.rb +206 -2
- data/spec/bson/time_with_zone_spec.rb +69 -0
- data/spec/bson/timestamp_spec.rb +58 -2
- data/spec/bson/true_class_spec.rb +9 -1
- data/spec/bson/undefined_spec.rb +28 -1
- data/spec/bson/vector_spec.rb +33 -0
- data/spec/bson_spec.rb +2 -1
- data/spec/runners/binary_vector.rb +78 -0
- data/spec/runners/common_driver.rb +348 -0
- data/spec/runners/corpus.rb +191 -0
- data/spec/runners/corpus_legacy.rb +248 -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 +281 -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 +61 -1
- data/spec/spec_tests/binary_vector_spec.rb +82 -0
- data/spec/spec_tests/common_driver_spec.rb +84 -0
- data/spec/spec_tests/corpus_legacy_spec.rb +72 -0
- data/spec/spec_tests/corpus_spec.rb +134 -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/README.md +15 -0
- data/spec/spec_tests/data/corpus/array.json +49 -0
- data/spec/spec_tests/data/corpus/binary.json +153 -0
- data/spec/spec_tests/data/corpus/boolean.json +27 -0
- data/spec/spec_tests/data/corpus/code.json +67 -0
- data/spec/spec_tests/data/corpus/code_w_scope.json +78 -0
- data/spec/spec_tests/data/corpus/datetime.json +42 -0
- data/spec/spec_tests/data/corpus/dbpointer.json +56 -0
- data/spec/spec_tests/data/corpus/dbref.json +51 -0
- data/spec/spec_tests/data/corpus/decimal128-1.json +317 -0
- data/spec/spec_tests/data/corpus/decimal128-2.json +793 -0
- data/spec/spec_tests/data/corpus/decimal128-3.json +1771 -0
- data/spec/spec_tests/data/corpus/decimal128-4.json +165 -0
- data/spec/spec_tests/data/corpus/decimal128-5.json +402 -0
- data/spec/spec_tests/data/corpus/decimal128-6.json +131 -0
- data/spec/spec_tests/data/corpus/decimal128-7.json +327 -0
- data/spec/spec_tests/data/corpus/document.json +60 -0
- data/spec/spec_tests/data/corpus/double.json +87 -0
- data/spec/spec_tests/data/corpus/int32.json +43 -0
- data/spec/spec_tests/data/corpus/int64.json +43 -0
- data/spec/spec_tests/data/corpus/maxkey.json +12 -0
- data/spec/spec_tests/data/corpus/minkey.json +12 -0
- data/spec/spec_tests/data/corpus/multi-type-deprecated.json +15 -0
- data/spec/spec_tests/data/corpus/multi-type.json +11 -0
- data/spec/spec_tests/data/corpus/null.json +12 -0
- data/spec/spec_tests/data/corpus/oid.json +28 -0
- data/spec/spec_tests/data/corpus/regex.json +65 -0
- data/spec/spec_tests/data/corpus/string.json +72 -0
- data/spec/spec_tests/data/corpus/symbol.json +80 -0
- data/spec/spec_tests/data/corpus/timestamp.json +34 -0
- data/spec/spec_tests/data/corpus/top.json +262 -0
- data/spec/spec_tests/data/corpus/undefined.json +15 -0
- data/spec/spec_tests/data/corpus_legacy/array.json +49 -0
- data/spec/spec_tests/data/corpus_legacy/binary.json +69 -0
- data/spec/spec_tests/data/corpus_legacy/boolean.json +27 -0
- data/spec/spec_tests/data/corpus_legacy/code.json +67 -0
- data/spec/spec_tests/data/corpus_legacy/code_w_scope.json +78 -0
- data/spec/spec_tests/data/corpus_legacy/document.json +36 -0
- data/spec/spec_tests/data/corpus_legacy/double.json +69 -0
- data/spec/spec_tests/data/corpus_legacy/failures/datetime.json +31 -0
- data/spec/spec_tests/data/corpus_legacy/failures/dbpointer.json +42 -0
- data/spec/spec_tests/data/corpus_legacy/failures/int64.json +38 -0
- data/spec/spec_tests/data/corpus_legacy/failures/symbol.json +62 -0
- data/spec/spec_tests/data/corpus_legacy/int32.json +38 -0
- data/spec/spec_tests/data/corpus_legacy/maxkey.json +12 -0
- data/spec/spec_tests/data/corpus_legacy/minkey.json +12 -0
- data/spec/spec_tests/data/corpus_legacy/null.json +12 -0
- data/spec/spec_tests/data/corpus_legacy/oid.json +28 -0
- data/spec/spec_tests/data/corpus_legacy/regex.json +37 -0
- data/spec/spec_tests/data/corpus_legacy/string.json +67 -0
- data/spec/spec_tests/data/corpus_legacy/timestamp.json +18 -0
- data/spec/spec_tests/data/corpus_legacy/top.json +62 -0
- data/spec/spec_tests/data/corpus_legacy/undefined.json +13 -0
- data/spec/spec_tests/data/decimal128/decimal128-1.json +363 -0
- data/spec/spec_tests/data/decimal128/decimal128-2.json +793 -0
- data/spec/spec_tests/data/decimal128/decimal128-3.json +1771 -0
- data/spec/spec_tests/data/decimal128/decimal128-4.json +165 -0
- data/spec/spec_tests/data/decimal128/decimal128-5.json +402 -0
- data/spec/spec_tests/data/decimal128/decimal128-6.json +131 -0
- data/spec/spec_tests/data/decimal128/decimal128-7.json +327 -0
- data/spec/support/shared_examples.rb +32 -11
- data/spec/support/spec_config.rb +17 -0
- data/spec/support/utils.rb +58 -0
- metadata +284 -45
- checksums.yaml.gz.sig +0 -3
- data/ext/bson/native.c +0 -722
- data.tar.gz.sig +0 -0
- metadata.gz.sig +0 -0
|
@@ -0,0 +1,248 @@
|
|
|
1
|
+
# rubocop:todo all
|
|
2
|
+
# Copyright (C) 2016-2020 MongoDB Inc.
|
|
3
|
+
#
|
|
4
|
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
|
5
|
+
# you may not use this file except in compliance with the License.
|
|
6
|
+
# You may obtain a copy of the License at
|
|
7
|
+
#
|
|
8
|
+
# http://www.apache.org/licenses/LICENSE-2.0
|
|
9
|
+
#
|
|
10
|
+
# Unless required by applicable law or agreed to in writing, software
|
|
11
|
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
|
12
|
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
13
|
+
# See the License for the specific language governing permissions and
|
|
14
|
+
# limitations under the License.
|
|
15
|
+
|
|
16
|
+
require 'json'
|
|
17
|
+
|
|
18
|
+
module BSON
|
|
19
|
+
module CorpusLegacy
|
|
20
|
+
|
|
21
|
+
# Represents a test from the driver BSON Corpus.
|
|
22
|
+
class Spec
|
|
23
|
+
|
|
24
|
+
# The spec description.
|
|
25
|
+
#
|
|
26
|
+
# @return [ String ] The spec description.
|
|
27
|
+
attr_reader :description
|
|
28
|
+
|
|
29
|
+
# The document key of the object to test.
|
|
30
|
+
#
|
|
31
|
+
# @return [ String ] The document key.
|
|
32
|
+
attr_reader :test_key
|
|
33
|
+
|
|
34
|
+
# Instantiate the new spec.
|
|
35
|
+
#
|
|
36
|
+
# @example Create the spec.
|
|
37
|
+
# Spec.new(file)
|
|
38
|
+
#
|
|
39
|
+
# @param [ String ] file The name of the json file.
|
|
40
|
+
def initialize(file)
|
|
41
|
+
@spec = ::JSON.parse(File.read(file))
|
|
42
|
+
@valid = @spec['valid'] || []
|
|
43
|
+
@invalid = @spec['decodeErrors'] || []
|
|
44
|
+
@description = @spec['description']
|
|
45
|
+
@test_key = @spec['test_key']
|
|
46
|
+
end
|
|
47
|
+
|
|
48
|
+
# Get a list of tests that are expected to pass.
|
|
49
|
+
#
|
|
50
|
+
# @example Get the list of valid tests.
|
|
51
|
+
# spec.valid_tests
|
|
52
|
+
#
|
|
53
|
+
# @return [ Array<BSON::CorpusLegacy::Test> ] The list of valid Tests.
|
|
54
|
+
def valid_tests
|
|
55
|
+
@valid_tests ||=
|
|
56
|
+
@valid.collect do |test|
|
|
57
|
+
BSON::CorpusLegacy::Test.new(self, test)
|
|
58
|
+
end
|
|
59
|
+
end
|
|
60
|
+
|
|
61
|
+
# Get a list of tests that raise exceptions.
|
|
62
|
+
#
|
|
63
|
+
# @example Get the list of invalid tests.
|
|
64
|
+
# spec.invalid_tests
|
|
65
|
+
#
|
|
66
|
+
# @return [ Array<BSON::CorpusLegacy::Test> ] The list of invalid Tests.
|
|
67
|
+
def invalid_tests
|
|
68
|
+
@invalid_tests ||=
|
|
69
|
+
@invalid.collect do |test|
|
|
70
|
+
BSON::CorpusLegacy::Test.new(self, test)
|
|
71
|
+
end
|
|
72
|
+
end
|
|
73
|
+
|
|
74
|
+
# The class of the bson object to test.
|
|
75
|
+
#
|
|
76
|
+
# @example Get the class of the object to test.
|
|
77
|
+
# spec.klass
|
|
78
|
+
#
|
|
79
|
+
# @return [ Class ] The object class.
|
|
80
|
+
def klass
|
|
81
|
+
@klass ||= BSON.const_get(description)
|
|
82
|
+
end
|
|
83
|
+
end
|
|
84
|
+
|
|
85
|
+
# Represents a single BSON Corpus test.
|
|
86
|
+
class Test
|
|
87
|
+
|
|
88
|
+
# The test description.
|
|
89
|
+
#
|
|
90
|
+
# @return [ String ] The test description.
|
|
91
|
+
attr_reader :description
|
|
92
|
+
|
|
93
|
+
# Name of a field in a valid test case extjson document that should be
|
|
94
|
+
# checked against the case's string field.
|
|
95
|
+
#
|
|
96
|
+
# @return [ String ] The json representation of the object.
|
|
97
|
+
attr_reader :test_key
|
|
98
|
+
|
|
99
|
+
# Instantiate the new Test.
|
|
100
|
+
#
|
|
101
|
+
# @example Create the test.
|
|
102
|
+
# Test.new(test)
|
|
103
|
+
#
|
|
104
|
+
# @param [ Corpus::Spec ] spec The test specification.
|
|
105
|
+
# @param [ Hash ] test The test specification.
|
|
106
|
+
def initialize(spec, test)
|
|
107
|
+
@spec = spec
|
|
108
|
+
@description = test['description']
|
|
109
|
+
@canonical_bson = test['canonical_bson']
|
|
110
|
+
@extjson = ::JSON.parse(test['extjson']) if test['extjson']
|
|
111
|
+
@bson = test['bson']
|
|
112
|
+
@test_key = spec.test_key
|
|
113
|
+
end
|
|
114
|
+
|
|
115
|
+
# The correct representation of the subject as bson.
|
|
116
|
+
#
|
|
117
|
+
# @example Get the correct representation of the subject as bson.
|
|
118
|
+
# test.correct_bson
|
|
119
|
+
#
|
|
120
|
+
# @return [ String ] The correct bson bytes.
|
|
121
|
+
def correct_bson
|
|
122
|
+
@correct_bson ||= decode_hex(@canonical_bson || @bson)
|
|
123
|
+
end
|
|
124
|
+
|
|
125
|
+
# Create a BSON::Document object from the test's bson representation
|
|
126
|
+
#
|
|
127
|
+
# @return [ BSON::Document ] The BSON::Document object
|
|
128
|
+
def document_from_bson
|
|
129
|
+
bson_bytes = decode_hex(@bson)
|
|
130
|
+
buffer = BSON::ByteBuffer.new(bson_bytes)
|
|
131
|
+
BSON::Document.from_bson(buffer)
|
|
132
|
+
end
|
|
133
|
+
|
|
134
|
+
# Create a BSON::Document object from the test's canonical bson
|
|
135
|
+
# representation
|
|
136
|
+
#
|
|
137
|
+
# @return [ BSON::Document ] The BSON::Document object
|
|
138
|
+
def document_from_canonical_bson
|
|
139
|
+
bson_bytes = decode_hex(@canonical_bson)
|
|
140
|
+
buffer = BSON::ByteBuffer.new(bson_bytes)
|
|
141
|
+
BSON::Document.from_bson(buffer)
|
|
142
|
+
end
|
|
143
|
+
|
|
144
|
+
# Given the hex representation of bson, decode it into a Document,
|
|
145
|
+
# then reencoded it to bson.
|
|
146
|
+
#
|
|
147
|
+
# @example Decoded the bson hex representation, then reencode.
|
|
148
|
+
# test.reencoded_bson
|
|
149
|
+
#
|
|
150
|
+
# @return [ String ] The reencoded bson bytes.
|
|
151
|
+
def reencoded_bson
|
|
152
|
+
document_from_bson.to_bson.to_s
|
|
153
|
+
end
|
|
154
|
+
|
|
155
|
+
# Given the hex representation of the canonical bson, decode it into a Document,
|
|
156
|
+
# then reencoded it to bson.
|
|
157
|
+
#
|
|
158
|
+
# @example Decoded the canonical bson hex representation, then reencode.
|
|
159
|
+
# test.reencoded_canonical_bson
|
|
160
|
+
#
|
|
161
|
+
# @return [ String ] The reencoded canonical bson bytes.
|
|
162
|
+
def reencoded_canonical_bson
|
|
163
|
+
document_from_canonical_bson.to_bson.to_s
|
|
164
|
+
end
|
|
165
|
+
|
|
166
|
+
# Whether the canonical bson should be tested.
|
|
167
|
+
#
|
|
168
|
+
# @example Determine if the canonical bson should be tested.
|
|
169
|
+
# test.test_canonical_bson?
|
|
170
|
+
#
|
|
171
|
+
# @return [ true, false ] Whether the canonical bson should be tested.
|
|
172
|
+
def test_canonical_bson?
|
|
173
|
+
@canonical_bson && (@bson != @canonical_bson)
|
|
174
|
+
end
|
|
175
|
+
|
|
176
|
+
# The correct representation of the subject as extended json.
|
|
177
|
+
#
|
|
178
|
+
# @example Get the correct representation of the subject as extended json.
|
|
179
|
+
# test.correct_extjson
|
|
180
|
+
#
|
|
181
|
+
# @return [ String ] The correct extended json representation.
|
|
182
|
+
def correct_extjson
|
|
183
|
+
@canonical_extjson || @extjson
|
|
184
|
+
end
|
|
185
|
+
|
|
186
|
+
# Whether the extended json should be tested.
|
|
187
|
+
#
|
|
188
|
+
# @example Determine if the extended json should be tested.
|
|
189
|
+
# test.test_extjson?
|
|
190
|
+
#
|
|
191
|
+
# @return [ true, false ] Whether the extended json should be tested.
|
|
192
|
+
def test_extjson?
|
|
193
|
+
!!@extjson
|
|
194
|
+
end
|
|
195
|
+
|
|
196
|
+
# Get the extended json representation of the decoded doc from the provided
|
|
197
|
+
# bson hex representation.
|
|
198
|
+
#
|
|
199
|
+
# @example Get the extended json representation of the decoded doc.
|
|
200
|
+
# test.extjson_from_encoded_bson
|
|
201
|
+
#
|
|
202
|
+
# @return [ Hash ] The extended json representation.
|
|
203
|
+
def extjson_from_bson
|
|
204
|
+
as_legacy_extended_json(document_from_bson)
|
|
205
|
+
end
|
|
206
|
+
|
|
207
|
+
# Get the extended json representation of the decoded doc from the provided
|
|
208
|
+
# canonical bson hex representation.
|
|
209
|
+
#
|
|
210
|
+
# @example Get the extended json representation of the canonical decoded doc.
|
|
211
|
+
# test.extjson_from_canonical_bson
|
|
212
|
+
#
|
|
213
|
+
# @return [ Hash ] The extended json representation.
|
|
214
|
+
def extjson_from_canonical_bson
|
|
215
|
+
as_legacy_extended_json(document_from_canonical_bson)
|
|
216
|
+
end
|
|
217
|
+
|
|
218
|
+
# Get the extended json representation of the decoded doc from the provided
|
|
219
|
+
# extended json representation. (Verifies roundtrip)
|
|
220
|
+
#
|
|
221
|
+
# @example Get the extended json representation of the canonical decoded doc.
|
|
222
|
+
# test.extjson_from_encoded_extjson
|
|
223
|
+
#
|
|
224
|
+
# @return [ Hash ] The extended json representation.
|
|
225
|
+
def extjson_from_encoded_extjson
|
|
226
|
+
doc = BSON::Document.new(@extjson)
|
|
227
|
+
as_legacy_extended_json(doc)
|
|
228
|
+
end
|
|
229
|
+
|
|
230
|
+
private
|
|
231
|
+
|
|
232
|
+
def as_legacy_extended_json(object)
|
|
233
|
+
result = object.as_extended_json(mode: :legacy)
|
|
234
|
+
if object.respond_to?(:as_json)
|
|
235
|
+
old_result = object.as_json
|
|
236
|
+
unless result == old_result
|
|
237
|
+
raise "Serializing #{object} to legacy extended json did not match between new and old APIs"
|
|
238
|
+
end
|
|
239
|
+
end
|
|
240
|
+
result
|
|
241
|
+
end
|
|
242
|
+
|
|
243
|
+
def decode_hex(obj)
|
|
244
|
+
[ obj ].pack('H*')
|
|
245
|
+
end
|
|
246
|
+
end
|
|
247
|
+
end
|
|
248
|
+
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
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
# encoding: utf-8
|
|
3
|
+
|
|
4
|
+
autoload :ChildProcess, 'childprocess'
|
|
5
|
+
autoload :Tempfile, 'tempfile'
|
|
6
|
+
|
|
7
|
+
module Mrss
|
|
8
|
+
module ChildProcessHelper
|
|
9
|
+
class SpawnError < StandardError; end
|
|
10
|
+
|
|
11
|
+
module_function def call(cmd, env: nil, cwd: nil)
|
|
12
|
+
process = ChildProcess.new(*cmd)
|
|
13
|
+
process.io.inherit!
|
|
14
|
+
if cwd
|
|
15
|
+
process.cwd = cwd
|
|
16
|
+
end
|
|
17
|
+
if env
|
|
18
|
+
env.each do |k, v|
|
|
19
|
+
process.environment[k.to_s] = v
|
|
20
|
+
end
|
|
21
|
+
end
|
|
22
|
+
process.start
|
|
23
|
+
process.wait
|
|
24
|
+
process
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
module_function def check_call(cmd, env: nil, cwd: nil)
|
|
28
|
+
process = call(cmd, env: env, cwd: cwd)
|
|
29
|
+
unless process.exit_code == 0
|
|
30
|
+
raise SpawnError, "Failed to execute: #{cmd}"
|
|
31
|
+
end
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
module_function def get_output(cmd, env: nil, cwd: nil)
|
|
35
|
+
process = ChildProcess.new(*cmd)
|
|
36
|
+
process.io.inherit!
|
|
37
|
+
if cwd
|
|
38
|
+
process.cwd = cwd
|
|
39
|
+
end
|
|
40
|
+
if env
|
|
41
|
+
env.each do |k, v|
|
|
42
|
+
process.environment[k.to_s] = v
|
|
43
|
+
end
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
output = ''
|
|
47
|
+
r, w = IO.pipe
|
|
48
|
+
|
|
49
|
+
begin
|
|
50
|
+
process.io.stdout = w
|
|
51
|
+
process.start
|
|
52
|
+
w.close
|
|
53
|
+
|
|
54
|
+
thread = Thread.new do
|
|
55
|
+
begin
|
|
56
|
+
loop do
|
|
57
|
+
output << r.readpartial(16384)
|
|
58
|
+
end
|
|
59
|
+
rescue EOFError
|
|
60
|
+
end
|
|
61
|
+
end
|
|
62
|
+
|
|
63
|
+
process.wait
|
|
64
|
+
thread.join
|
|
65
|
+
ensure
|
|
66
|
+
r.close
|
|
67
|
+
end
|
|
68
|
+
|
|
69
|
+
[process, output]
|
|
70
|
+
end
|
|
71
|
+
|
|
72
|
+
module_function def check_output(*args)
|
|
73
|
+
process, output = get_output(*args)
|
|
74
|
+
unless process.exit_code == 0
|
|
75
|
+
raise SpawnError,"Failed to execute: #{args}"
|
|
76
|
+
end
|
|
77
|
+
output
|
|
78
|
+
end
|
|
79
|
+
end
|
|
80
|
+
end
|