|
8 | 8 | use MongoDB\Client;
|
9 | 9 | use MongoDB\Collection;
|
10 | 10 | use MongoDB\Database;
|
| 11 | +use MongoDB\Driver\ClientEncryption; |
11 | 12 | use MongoDB\Driver\Cursor;
|
12 | 13 | use MongoDB\Driver\Server;
|
13 | 14 | use MongoDB\Driver\Session;
|
@@ -186,6 +187,9 @@ private function execute()
|
186 | 187 | case Client::class:
|
187 | 188 | $result = $this->executeForClient($object);
|
188 | 189 | break;
|
| 190 | + case ClientEncryption::class: |
| 191 | + $result = $this->executeForClientEncryption($object); |
| 192 | + break; |
189 | 193 | case Database::class:
|
190 | 194 | $result = $this->executeForDatabase($object);
|
191 | 195 | break;
|
@@ -275,6 +279,61 @@ function (DatabaseInfo $info) {
|
275 | 279 | }
|
276 | 280 | }
|
277 | 281 |
|
| 282 | + private function executeForClientEncryption(ClientEncryption $clientEncryption) |
| 283 | + { |
| 284 | + $args = $this->prepareArguments(); |
| 285 | + Util::assertArgumentsBySchema(ClientEncryption::class, $this->name, $args); |
| 286 | + |
| 287 | + switch ($this->name) { |
| 288 | + case 'addKeyAltName': |
| 289 | + assertArrayHasKey('id', $args); |
| 290 | + assertArrayHasKey('keyAltName', $args); |
| 291 | + |
| 292 | + return $clientEncryption->addKeyAltName($args['id'], $args['keyAltName']); |
| 293 | + |
| 294 | + case 'createDataKey': |
| 295 | + assertArrayHasKey('kmsProvider', $args); |
| 296 | + // CSFLE spec tests nest options under an "opts" key (see: DRIVERS-2414) |
| 297 | + $options = array_key_exists('opts', $args) ? (array) $args['opts'] : []; |
| 298 | + |
| 299 | + return $clientEncryption->createDataKey($args['kmsProvider'], $options); |
| 300 | + |
| 301 | + case 'deleteKey': |
| 302 | + assertArrayHasKey('id', $args); |
| 303 | + |
| 304 | + return $clientEncryption->deleteKey($args['id']); |
| 305 | + |
| 306 | + case 'getKey': |
| 307 | + assertArrayHasKey('id', $args); |
| 308 | + |
| 309 | + return $clientEncryption->getKey($args['id']); |
| 310 | + |
| 311 | + case 'getKeyByAltName': |
| 312 | + assertArrayHasKey('keyAltName', $args); |
| 313 | + |
| 314 | + return $clientEncryption->getKeyByAltName($args['keyAltName']); |
| 315 | + |
| 316 | + case 'getKeys': |
| 317 | + return iterator_to_array($clientEncryption->getKeys()); |
| 318 | + |
| 319 | + case 'removeKeyAltName': |
| 320 | + assertArrayHasKey('id', $args); |
| 321 | + assertArrayHasKey('keyAltName', $args); |
| 322 | + |
| 323 | + return $clientEncryption->removeKeyAltName($args['id'], $args['keyAltName']); |
| 324 | + |
| 325 | + case 'rewrapManyDataKey': |
| 326 | + assertArrayHasKey('filter', $args); |
| 327 | + // CSFLE spec tests nest options under an "opts" key (see: DRIVERS-2414) |
| 328 | + $options = array_key_exists('opts', $args) ? (array) $args['opts'] : []; |
| 329 | + |
| 330 | + return $clientEncryption->rewrapManyDataKey($args['filter'], $options); |
| 331 | + |
| 332 | + default: |
| 333 | + Assert::fail('Unsupported clientEncryption operation: ' . $this->name); |
| 334 | + } |
| 335 | + } |
| 336 | + |
278 | 337 | private function executeForCollection(Collection $collection)
|
279 | 338 | {
|
280 | 339 | $args = $this->prepareArguments();
|
|
0 commit comments