summaryrefslogtreecommitdiff
path: root/buildscripts
diff options
context:
space:
mode:
authorSophia Tan <sophia_tll@hotmail.com>2022-04-28 14:02:48 +0000
committerEvergreen Agent <no-reply@evergreen.mongodb.com>2022-04-28 15:28:28 +0000
commit5268b0ce77f81f4a26636e1abc7ab7eb850b2628 (patch)
treeefbc496ecdfcb1b1fa1529e1fd0f17d02a22c429 /buildscripts
parentea67f8909049edd2b8abf55a48999bdd20e7ab87 (diff)
downloadmongo-5268b0ce77f81f4a26636e1abc7ab7eb850b2628.tar.gz
SERVER-65449 Add $tenant field to IDL for commands
Diffstat (limited to 'buildscripts')
-rw-r--r--buildscripts/idl/idl/binder.py13
-rw-r--r--buildscripts/idl/tests/test_binder.py139
2 files changed, 56 insertions, 96 deletions
diff --git a/buildscripts/idl/idl/binder.py b/buildscripts/idl/idl/binder.py
index 1511b6c1b07..c90019b2191 100644
--- a/buildscripts/idl/idl/binder.py
+++ b/buildscripts/idl/idl/binder.py
@@ -410,6 +410,19 @@ def _inject_hidden_command_fields(command):
command.fields.append(db_field)
+ # Inject "$tenant" for use by cluster administrators overriding tenant in multitenancy.
+ tenant_field = syntax.Field(command.file_name, command.line, command.column)
+ tenant_field.name = "$tenant"
+ tenant_field.type = syntax.FieldTypeSingle(command.file_name, command.line, command.column)
+ tenant_field.type.type_name = "tenant_id" # This comes from basic_types.idl
+ tenant_field.cpp_name = "dollarTenant"
+ tenant_field.optional = True
+ # The $tenant field should be injected when serializing to OpMsgRequest and to
+ # BSONObjBuilder if it exists.
+ tenant_field.serialize_op_msg_request_only = False
+
+ command.fields.append(tenant_field)
+
def _bind_struct_type(struct):
# type: (syntax.Struct) -> ast.Type
diff --git a/buildscripts/idl/tests/test_binder.py b/buildscripts/idl/tests/test_binder.py
index b52c755e34b..7e693af16fd 100644
--- a/buildscripts/idl/tests/test_binder.py
+++ b/buildscripts/idl/tests/test_binder.py
@@ -71,6 +71,39 @@ class TestBinder(testcase.IDLTestcase):
# pylint: disable=too-many-public-methods
+ # Create a text wrap for common types.
+ common_types = textwrap.dedent("""
+ types:
+ object:
+ description: foo
+ cpp_type: foo
+ bson_serialization_type: object
+ serializer: foo
+ deserializer: foo
+
+ string:
+ description: foo
+ cpp_type: foo
+ bson_serialization_type: string
+ serializer: foo
+ deserializer: foo
+
+ any_type:
+ description: foo
+ cpp_type: foo
+ bson_serialization_type: any
+ serializer: foo
+ deserializer: foo
+
+ tenant_id:
+ bson_serialization_type: any
+ description: foo
+ cpp_type: foo
+ deserializer: foo
+ serializer: foo
+
+ """)
+
def test_empty(self):
# type: () -> None
"""Test an empty document works."""
@@ -1687,16 +1720,7 @@ class TestBinder(testcase.IDLTestcase):
"""Positive command tests."""
# Setup some common types
- test_preamble = textwrap.dedent("""
- types:
- string:
- description: foo
- cpp_type: foo
- bson_serialization_type: string
- serializer: foo
- deserializer: foo
- default: foo
-
+ test_preamble = self.common_types + textwrap.dedent("""
structs:
reply:
description: foo
@@ -1722,17 +1746,7 @@ class TestBinder(testcase.IDLTestcase):
"""Negative command tests."""
# Setup some common types
- test_preamble = textwrap.dedent("""
- types:
- string:
- description: foo
- cpp_type: foo
- bson_serialization_type: string
- serializer: foo
- deserializer: foo
- default: foo
- """)
-
+ test_preamble = self.common_types
# Commands cannot be fields in other commands
self.assert_bind_fail(
test_preamble + textwrap.dedent("""
@@ -1816,22 +1830,7 @@ class TestBinder(testcase.IDLTestcase):
# pylint: disable=invalid-name
# Setup some common types
- test_preamble = textwrap.dedent("""
- types:
- object:
- description: foo
- cpp_type: foo
- bson_serialization_type: object
- serializer: foo
- deserializer: foo
-
- string:
- description: foo
- cpp_type: foo
- bson_serialization_type: string
- serializer: foo
- deserializer: foo
-
+ test_preamble = self.common_types + textwrap.dedent("""
structs:
foo_struct:
description: foo
@@ -1872,29 +1871,7 @@ class TestBinder(testcase.IDLTestcase):
# pylint: disable=invalid-name
# Setup some common types
- test_preamble = textwrap.dedent("""
- types:
- object:
- description: foo
- cpp_type: foo
- bson_serialization_type: object
- serializer: foo
- deserializer: foo
-
- string:
- description: foo
- cpp_type: foo
- bson_serialization_type: string
- serializer: foo
- deserializer: foo
-
- any_type:
- description: foo
- cpp_type: foo
- bson_serialization_type: any
- serializer: foo
- deserializer: foo
- """)
+ test_preamble = self.common_types
test_preamble2 = test_preamble + textwrap.dedent("""
structs:
@@ -1965,15 +1942,8 @@ class TestBinder(testcase.IDLTestcase):
def test_command_type_positive(self):
# type: () -> None
"""Positive command custom type test cases."""
- test_preamble = textwrap.dedent("""
- types:
- string:
- description: foo
- cpp_type: foo
- bson_serialization_type: string
- serializer: foo
- deserializer: foo
- """)
+ # Setup some common types
+ test_preamble = self.common_types
# string
self.assert_bind(test_preamble + textwrap.dedent("""
@@ -2006,15 +1976,8 @@ class TestBinder(testcase.IDLTestcase):
def test_command_type_negative(self):
# type: () -> None
"""Negative command type test cases."""
- test_preamble = textwrap.dedent("""
- types:
- string:
- description: foo
- cpp_type: foo
- bson_serialization_type: string
- serializer: foo
- deserializer: foo
- """)
+ # Setup some common types
+ test_preamble = self.common_types
# supports_doc_sequence must be a bool
self.assert_bind_fail(
@@ -2448,15 +2411,7 @@ class TestBinder(testcase.IDLTestcase):
# type: () -> None
"""Test access check."""
- test_preamble = textwrap.dedent("""
- types:
- string:
- description: foo
- cpp_type: foo
- bson_serialization_type: string
- serializer: foo
- deserializer: foo
-
+ test_preamble = self.common_types + textwrap.dedent("""
enums:
AccessCheck:
description: "test"
@@ -2560,15 +2515,7 @@ class TestBinder(testcase.IDLTestcase):
# type: () -> None
"""Negative access check tests."""
- test_preamble = textwrap.dedent("""
- types:
- string:
- description: foo
- cpp_type: foo
- bson_serialization_type: string
- serializer: foo
- deserializer: foo
-
+ test_preamble = self.common_types + textwrap.dedent("""
enums:
AccessCheck:
description: "test"