Unverified Commit 2fb70273 authored by Andreas Braun's avatar Andreas Braun

Merge pull request #708

parents 7eead743 29e81bb7
......@@ -11,3 +11,5 @@ phpunit.xml
# phpcs
.phpcs-cache
phpcs.xml
mongocryptd.pid
......@@ -14,7 +14,9 @@ cache:
env:
global:
- DRIVER_VERSION=1.6.0
- DRIVER_VERSION=1.7.0
# TODO: remove once a 1.7 driver release has been tagged
- DRIVER_BRANCH="master"
- SERVER_DISTRO=ubuntu1604
- SERVER_VERSION=4.2.0
- DEPLOYMENT=STANDALONE
......@@ -112,17 +114,19 @@ jobs:
env:
- DEPLOYMENT=SHARDED_CLUSTER_RS
# TODO: re-enable once v1.7 has been branched in PHPC
# Test next patch release for driver
- stage: Test
php: "7.3"
env:
- DRIVER_BRANCH="v1.6"
# - stage: Test
# php: "7.3"
# env:
# - DRIVER_BRANCH="v1.7"
# TODO: re-enable once v1.7 has been branched in PHPC
# Test next minor release for driver
- stage: Test
php: "7.3"
env:
- DRIVER_BRANCH="master"
# - stage: Test
# php: "7.3"
# env:
# - DRIVER_BRANCH="master"
before_install:
- pip install "mongo-orchestration>=0.6.7,<1.0" --user `whoami`
......
......@@ -13,7 +13,7 @@
"php": "^5.6 || ^7.0",
"ext-hash": "*",
"ext-json": "*",
"ext-mongodb": "^1.6"
"ext-mongodb": "^1.7"
},
"require-dev": {
"phpunit/phpunit": "^5.7.27 || ^6.4 || ^8.3",
......
......@@ -112,4 +112,18 @@ description: |
interface: phpmethod
operation: ~
optional: true
---
arg_name: option
name: autoEncryption
type: array
description: |
Options to configure client-side field-level encryption in the driver. The
encryption options are documented in the :php:`extension documentation
<manual/en/mongodb-driver-manager.construct.php#mongodb-driver-manager.construct-driveroptions>`.
For the ``keyVaultClient`` option, you may pass a :phpclass:`MongoDB\\Client`
instance, which will be unwrapped to provide a :php:`MongoDB\\Driver\\Manager <class.mongodb-driver-manager>`
to the extension.
interface: phpmethod
operation: ~
optional: true
...
......@@ -99,6 +99,14 @@ class Client
throw InvalidArgumentException::invalidType('"typeMap" driver option', $driverOptions['typeMap'], 'array');
}
if (isset($driverOptions['autoEncryption']['keyVaultClient'])) {
if ($driverOptions['autoEncryption']['keyVaultClient'] instanceof self) {
$driverOptions['autoEncryption']['keyVaultClient'] = $driverOptions['autoEncryption']['keyVaultClient']->manager;
} elseif (! $driverOptions['autoEncryption']['keyVaultClient'] instanceof Manager) {
throw InvalidArgumentException::invalidType('"keyVaultClient" autoEncryption option', $driverOptions['autoEncryption']['keyVaultClient'], [self::class, Manager::class]);
}
}
$this->uri = (string) $uri;
$this->typeMap = isset($driverOptions['typeMap']) ? $driverOptions['typeMap'] : null;
......
......@@ -18,8 +18,12 @@
namespace MongoDB\Exception;
use MongoDB\Driver\Exception\InvalidArgumentException as DriverInvalidArgumentException;
use function array_pop;
use function count;
use function get_class;
use function gettype;
use function implode;
use function is_array;
use function is_object;
use function sprintf;
......@@ -28,13 +32,32 @@ class InvalidArgumentException extends DriverInvalidArgumentException implements
/**
* Thrown when an argument or option has an invalid type.
*
* @param string $name Name of the argument or option
* @param mixed $value Actual value (used to derive the type)
* @param string $expectedType Expected type
* @param string $name Name of the argument or option
* @param mixed $value Actual value (used to derive the type)
* @param string|string[] $expectedType Expected type
* @return self
*/
public static function invalidType($name, $value, $expectedType)
{
if (is_array($expectedType)) {
switch (count($expectedType)) {
case 1:
$typeString = array_pop($expectedType);
break;
case 2:
$typeString = implode('" or "', $expectedType);
break;
default:
$lastType = array_pop($expectedType);
$typeString = sprintf('%s", or "%s', implode('", "', $expectedType), $lastType);
break;
}
$expectedType = $typeString;
}
return new static(sprintf('Expected %s to have type "%s" but found "%s"', $name, $expectedType, is_object($value) ? get_class($value) : gettype($value)));
}
}
......@@ -20,6 +20,20 @@ class ClientTest extends TestCase
$this->assertEquals('mongodb://127.0.0.1/', (string) $client);
}
/**
* @doesNotPerformAssertions
*/
public function testConstructorAutoEncryptionOpts()
{
$autoEncryptionOpts = [
'keyVaultClient' => new Client(static::getUri()),
'keyVaultNamespace' => 'default.keys',
'kmsProviders' => ['aws' => ['accessKeyId' => 'abc', 'secretAccessKey' => 'def']],
];
new Client(static::getUri(), [], ['autoEncryption' => $autoEncryptionOpts]);
}
/**
* @dataProvider provideInvalidConstructorDriverOptions
*/
......@@ -37,6 +51,8 @@ class ClientTest extends TestCase
$options[][] = ['typeMap' => $value];
}
$options[][] = ['autoEncryption' => ['keyVaultClient' => 'foo']];
return $options;
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment