Skip to content

Commit 2fb7027

Browse files
committed
Merge pull request #708
2 parents 7eead74 + 29e81bb commit 2fb7027

File tree

7 files changed

+80
-13
lines changed

7 files changed

+80
-13
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,5 @@ phpunit.xml
1111
# phpcs
1212
.phpcs-cache
1313
phpcs.xml
14+
15+
mongocryptd.pid

.travis.yml

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,9 @@ cache:
1414

1515
env:
1616
global:
17-
- DRIVER_VERSION=1.6.0
17+
- DRIVER_VERSION=1.7.0
18+
# TODO: remove once a 1.7 driver release has been tagged
19+
- DRIVER_BRANCH="master"
1820
- SERVER_DISTRO=ubuntu1604
1921
- SERVER_VERSION=4.2.0
2022
- DEPLOYMENT=STANDALONE
@@ -112,17 +114,19 @@ jobs:
112114
env:
113115
- DEPLOYMENT=SHARDED_CLUSTER_RS
114116

117+
# TODO: re-enable once v1.7 has been branched in PHPC
115118
# Test next patch release for driver
116-
- stage: Test
117-
php: "7.3"
118-
env:
119-
- DRIVER_BRANCH="v1.6"
119+
# - stage: Test
120+
# php: "7.3"
121+
# env:
122+
# - DRIVER_BRANCH="v1.7"
120123

124+
# TODO: re-enable once v1.7 has been branched in PHPC
121125
# Test next minor release for driver
122-
- stage: Test
123-
php: "7.3"
124-
env:
125-
- DRIVER_BRANCH="master"
126+
# - stage: Test
127+
# php: "7.3"
128+
# env:
129+
# - DRIVER_BRANCH="master"
126130

127131
before_install:
128132
- pip install "mongo-orchestration>=0.6.7,<1.0" --user `whoami`

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
"php": "^5.6 || ^7.0",
1414
"ext-hash": "*",
1515
"ext-json": "*",
16-
"ext-mongodb": "^1.6"
16+
"ext-mongodb": "^1.7"
1717
},
1818
"require-dev": {
1919
"phpunit/phpunit": "^5.7.27 || ^6.4 || ^8.3",

docs/includes/apiargs-MongoDBClient-method-construct-driverOptions.yaml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,4 +112,18 @@ description: |
112112
interface: phpmethod
113113
operation: ~
114114
optional: true
115+
---
116+
arg_name: option
117+
name: autoEncryption
118+
type: array
119+
description: |
120+
Options to configure client-side field-level encryption in the driver. The
121+
encryption options are documented in the :php:`extension documentation
122+
<manual/en/mongodb-driver-manager.construct.php#mongodb-driver-manager.construct-driveroptions>`.
123+
For the ``keyVaultClient`` option, you may pass a :phpclass:`MongoDB\\Client`
124+
instance, which will be unwrapped to provide a :php:`MongoDB\\Driver\\Manager <class.mongodb-driver-manager>`
125+
to the extension.
126+
interface: phpmethod
127+
operation: ~
128+
optional: true
115129
...

src/Client.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,14 @@ public function __construct($uri = 'mongodb://127.0.0.1/', array $uriOptions = [
9999
throw InvalidArgumentException::invalidType('"typeMap" driver option', $driverOptions['typeMap'], 'array');
100100
}
101101

102+
if (isset($driverOptions['autoEncryption']['keyVaultClient'])) {
103+
if ($driverOptions['autoEncryption']['keyVaultClient'] instanceof self) {
104+
$driverOptions['autoEncryption']['keyVaultClient'] = $driverOptions['autoEncryption']['keyVaultClient']->manager;
105+
} elseif (! $driverOptions['autoEncryption']['keyVaultClient'] instanceof Manager) {
106+
throw InvalidArgumentException::invalidType('"keyVaultClient" autoEncryption option', $driverOptions['autoEncryption']['keyVaultClient'], [self::class, Manager::class]);
107+
}
108+
}
109+
102110
$this->uri = (string) $uri;
103111
$this->typeMap = isset($driverOptions['typeMap']) ? $driverOptions['typeMap'] : null;
104112

src/Exception/InvalidArgumentException.php

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,12 @@
1818
namespace MongoDB\Exception;
1919

2020
use MongoDB\Driver\Exception\InvalidArgumentException as DriverInvalidArgumentException;
21+
use function array_pop;
22+
use function count;
2123
use function get_class;
2224
use function gettype;
25+
use function implode;
26+
use function is_array;
2327
use function is_object;
2428
use function sprintf;
2529

@@ -28,13 +32,32 @@ class InvalidArgumentException extends DriverInvalidArgumentException implements
2832
/**
2933
* Thrown when an argument or option has an invalid type.
3034
*
31-
* @param string $name Name of the argument or option
32-
* @param mixed $value Actual value (used to derive the type)
33-
* @param string $expectedType Expected type
35+
* @param string $name Name of the argument or option
36+
* @param mixed $value Actual value (used to derive the type)
37+
* @param string|string[] $expectedType Expected type
3438
* @return self
3539
*/
3640
public static function invalidType($name, $value, $expectedType)
3741
{
42+
if (is_array($expectedType)) {
43+
switch (count($expectedType)) {
44+
case 1:
45+
$typeString = array_pop($expectedType);
46+
break;
47+
48+
case 2:
49+
$typeString = implode('" or "', $expectedType);
50+
break;
51+
52+
default:
53+
$lastType = array_pop($expectedType);
54+
$typeString = sprintf('%s", or "%s', implode('", "', $expectedType), $lastType);
55+
break;
56+
}
57+
58+
$expectedType = $typeString;
59+
}
60+
3861
return new static(sprintf('Expected %s to have type "%s" but found "%s"', $name, $expectedType, is_object($value) ? get_class($value) : gettype($value)));
3962
}
4063
}

tests/ClientTest.php

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,20 @@ public function testConstructorDefaultUri()
2020
$this->assertEquals('mongodb://127.0.0.1/', (string) $client);
2121
}
2222

23+
/**
24+
* @doesNotPerformAssertions
25+
*/
26+
public function testConstructorAutoEncryptionOpts()
27+
{
28+
$autoEncryptionOpts = [
29+
'keyVaultClient' => new Client(static::getUri()),
30+
'keyVaultNamespace' => 'default.keys',
31+
'kmsProviders' => ['aws' => ['accessKeyId' => 'abc', 'secretAccessKey' => 'def']],
32+
];
33+
34+
new Client(static::getUri(), [], ['autoEncryption' => $autoEncryptionOpts]);
35+
}
36+
2337
/**
2438
* @dataProvider provideInvalidConstructorDriverOptions
2539
*/
@@ -37,6 +51,8 @@ public function provideInvalidConstructorDriverOptions()
3751
$options[][] = ['typeMap' => $value];
3852
}
3953

54+
$options[][] = ['autoEncryption' => ['keyVaultClient' => 'foo']];
55+
4056
return $options;
4157
}
4258

0 commit comments

Comments
 (0)