-
Notifications
You must be signed in to change notification settings - Fork 457
CDRIVER-4584 support Queryable Encryption v2 #1228
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 9 commits
aa82b19
db13c19
8c4bd22
65c6f85
521f7b7
1e45855
5851073
56bfe11
acb4284
7db4bcf
aee8b36
f3f7ebc
bd7c24a
ca32612
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,184 @@ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| #!/usr/bin/env python3 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| """ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| setfle2parameter.py modifies and prints an orchestration config file to add the `--setParameter featureFlagFLE2ProtocolVersion2=1` option to mongod and mongos. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Usage: setfle2parameter.py <orchestration config file path> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| This file is a temporary workaround until featureFlagFLE2ProtocolVersion2 is enabled by default in SERVER-69563. Once latest server builds have SERVER-69563, this file may be removed. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| DRIVERS-2590 tracks removal of this file. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| """ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import json | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import sys | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import unittest | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| import os | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| def do_rewrite(config): | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| did_rewrite = False | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| def rewrite_server(server): | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if "procParams" in server: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if "setParameter" in server["procParams"]: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| server["procParams"]["setParameter"]["featureFlagFLE2ProtocolVersion2"] = "1" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| else: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| server["procParams"]["setParameter"] = { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| "featureFlagFLE2ProtocolVersion2": "1" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return True | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return False | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if "procParams" in server: | |
| if "setParameter" in server["procParams"]: | |
| server["procParams"]["setParameter"]["featureFlagFLE2ProtocolVersion2"] = "1" | |
| else: | |
| server["procParams"]["setParameter"] = { | |
| "featureFlagFLE2ProtocolVersion2": "1" | |
| } | |
| return True | |
| return False | |
| params = server.get("procParams") | |
| if params is None: | |
| return False | |
| setParams = params.setdefault("setParameter", {}) | |
| setParams["featureFlagFLE2ProtocolVersion2"] = "1" | |
| return True |
Dict.get returns None if the key is absent. Dict.setdefault(K, V) returns the existing value if present or performs Dict[K] = V, and then returns Dict[V]. dicts are by-reference mutable.
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I got nerd-sniped into flattening this code :)
| # Rewrite for a server. | |
| if rewrite_server(config): | |
| did_rewrite = True | |
| # Rewrite for each member in a replica set. | |
| if "members" in config: | |
| for server in config["members"]: | |
| if rewrite_server(server): | |
| did_rewrite = True | |
| # Rewrite each shard. | |
| if "shards" in config: | |
| for shard in config["shards"]: | |
| if "shardParams" in shard: | |
| if "members" in shard["shardParams"]: | |
| for server in shard["shardParams"]["members"]: | |
| if rewrite_server (server): | |
| did_rewrite = True | |
| # Rewrite each router. | |
| if "routers" in config: | |
| for router in config["routers"]: | |
| # routers do not use `procParams`. Use setParameter directly. | |
| if "setParameter" in router: | |
| router["setParameter"]["featureFlagFLE2ProtocolVersion2"] = "1" | |
| else: | |
| router["setParameter"] = { | |
| "featureFlagFLE2ProtocolVersion2": "1" | |
| } | |
| did_rewrite = True | |
| import itertools | |
| # We will rewrite the root config: | |
| root = [config] | |
| # And any top-level members: | |
| root_members = config.get("members", []) | |
| # As well as the members within any defined shards: | |
| shards = config.get("shards", []) | |
| # Get a list of lists of membres: | |
| shard_member_lists = (s.get("shardParams", {}).get("members", []) for s in shards) | |
| # Flatten the list of lists: | |
| shard_members = itertools.chain.from_iterable(shard_member_lists) | |
| # For all members in all groups: | |
| all_members = itertools.chain(root, root_members, shard_members) | |
| # Rewrite them all: | |
| all_rewrites = list(map(rewrite_server, all_members)) | |
| # Did we actually rewrite anything? | |
| did_rewrite = any(all_rewrites) | |
| # Rewrite each router. | |
| for rtr in config.get("routers", []): | |
| ps = rtr.setdefault("setParameter", {}) | |
| ps["featureFlagFLE2ProtocolVersion2"] = "1" | |
| did_rewrite = True |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh that is really neat. I did not know about itertools.chain.
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
| pass |
Uh oh!
There was an error while loading. Please reload this page.