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

Merge pull request #708

parents 7eead743 29e81bb7
...@@ -11,3 +11,5 @@ phpunit.xml ...@@ -11,3 +11,5 @@ phpunit.xml
# phpcs # phpcs
.phpcs-cache .phpcs-cache
phpcs.xml phpcs.xml
mongocryptd.pid
...@@ -14,7 +14,9 @@ cache: ...@@ -14,7 +14,9 @@ cache:
env: env:
global: 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_DISTRO=ubuntu1604
- SERVER_VERSION=4.2.0 - SERVER_VERSION=4.2.0
- DEPLOYMENT=STANDALONE - DEPLOYMENT=STANDALONE
...@@ -112,17 +114,19 @@ jobs: ...@@ -112,17 +114,19 @@ jobs:
env: env:
- DEPLOYMENT=SHARDED_CLUSTER_RS - DEPLOYMENT=SHARDED_CLUSTER_RS
# TODO: re-enable once v1.7 has been branched in PHPC
# Test next patch release for driver # Test next patch release for driver
- stage: Test # - stage: Test
php: "7.3" # php: "7.3"
env: # env:
- DRIVER_BRANCH="v1.6" # - DRIVER_BRANCH="v1.7"
# TODO: re-enable once v1.7 has been branched in PHPC
# Test next minor release for driver # Test next minor release for driver
- stage: Test # - stage: Test
php: "7.3" # php: "7.3"
env: # env:
- DRIVER_BRANCH="master" # - DRIVER_BRANCH="master"
before_install: before_install:
- pip install "mongo-orchestration>=0.6.7,<1.0" --user `whoami` - pip install "mongo-orchestration>=0.6.7,<1.0" --user `whoami`
......
...@@ -13,7 +13,7 @@ ...@@ -13,7 +13,7 @@
"php": "^5.6 || ^7.0", "php": "^5.6 || ^7.0",
"ext-hash": "*", "ext-hash": "*",
"ext-json": "*", "ext-json": "*",
"ext-mongodb": "^1.6" "ext-mongodb": "^1.7"
}, },
"require-dev": { "require-dev": {
"phpunit/phpunit": "^5.7.27 || ^6.4 || ^8.3", "phpunit/phpunit": "^5.7.27 || ^6.4 || ^8.3",
......
...@@ -112,4 +112,18 @@ description: | ...@@ -112,4 +112,18 @@ description: |
interface: phpmethod interface: phpmethod
operation: ~ operation: ~
optional: true 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 ...@@ -99,6 +99,14 @@ class Client
throw InvalidArgumentException::invalidType('"typeMap" driver option', $driverOptions['typeMap'], 'array'); 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->uri = (string) $uri;
$this->typeMap = isset($driverOptions['typeMap']) ? $driverOptions['typeMap'] : null; $this->typeMap = isset($driverOptions['typeMap']) ? $driverOptions['typeMap'] : null;
......
...@@ -18,8 +18,12 @@ ...@@ -18,8 +18,12 @@
namespace MongoDB\Exception; namespace MongoDB\Exception;
use MongoDB\Driver\Exception\InvalidArgumentException as DriverInvalidArgumentException; use MongoDB\Driver\Exception\InvalidArgumentException as DriverInvalidArgumentException;
use function array_pop;
use function count;
use function get_class; use function get_class;
use function gettype; use function gettype;
use function implode;
use function is_array;
use function is_object; use function is_object;
use function sprintf; use function sprintf;
...@@ -30,11 +34,30 @@ class InvalidArgumentException extends DriverInvalidArgumentException implements ...@@ -30,11 +34,30 @@ class InvalidArgumentException extends DriverInvalidArgumentException implements
* *
* @param string $name Name of the argument or option * @param string $name Name of the argument or option
* @param mixed $value Actual value (used to derive the type) * @param mixed $value Actual value (used to derive the type)
* @param string $expectedType Expected type * @param string|string[] $expectedType Expected type
* @return self * @return self
*/ */
public static function invalidType($name, $value, $expectedType) 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))); 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 ...@@ -20,6 +20,20 @@ class ClientTest extends TestCase
$this->assertEquals('mongodb://127.0.0.1/', (string) $client); $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 * @dataProvider provideInvalidConstructorDriverOptions
*/ */
...@@ -37,6 +51,8 @@ class ClientTest extends TestCase ...@@ -37,6 +51,8 @@ class ClientTest extends TestCase
$options[][] = ['typeMap' => $value]; $options[][] = ['typeMap' => $value];
} }
$options[][] = ['autoEncryption' => ['keyVaultClient' => 'foo']];
return $options; 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