Skip to content

Commit 9ebe54a

Browse files
committed
PHPLIB-511: Handle autoEncryptionOpts in MongoDB\Client
1 parent b2cd286 commit 9ebe54a

File tree

2 files changed

+24
-0
lines changed

2 files changed

+24
-0
lines changed

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

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)