-
Notifications
You must be signed in to change notification settings - Fork 269
PHPLIB-1708 Cast empty KMS provider into an object #1757
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: v1.21
Are you sure you want to change the base?
Conversation
1c52490
to
d96aa71
Compare
|
||
// The server requires an empty document for automatic credentials. | ||
if (isset($options['kmsProviders']) && is_array($options['kmsProviders'])) { | ||
foreach ($options['kmsProviders'] as $name => $provider) { |
Check notice
Code scanning / Psalm
MixedAssignment Note
Fixed in Doctrine MongoDB ODM Bundle by setting a DI |
src/Client.php
Outdated
@@ -457,6 +447,28 @@ public function watch(array $pipeline = [], array $options = []) | |||
return $operation->execute($server); | |||
} | |||
|
|||
private function formatEncryptionOptions(array $options): array |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
private function formatEncryptionOptions(array $options): array | |
private function prepareAutoEncryptionOptions(array $options): array |
I'm not sure if there's prior art in PHPLIB, but I use "prepare" extensively in PHPC for this sort of thing. Up to you, though.
I do like including "AutoEncryption" in the name here since it refers to that driver option.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok for "prepare", but no for "AutoEncryption": the method createClientEncryption
isn't specific to auto encryption.
src/Client.php
Outdated
if (isset($options['kmsProviders']) && is_array($options['kmsProviders'])) { | ||
foreach ($options['kmsProviders'] as $name => $provider) { | ||
if ($provider === []) { | ||
$options['kmsProviders'][$name] = Document::fromPHP([]); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Any reason to use Document::fromPHP([])
instead of (object) []
or new stdClass
? PHPC is going to end up encoding this as BSON anyway.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have no idea what's the more efficient. Changed to new stdClass
@@ -37,6 +37,18 @@ public function testConstructorAutoEncryptionOpts(): void | |||
new Client(static::getUri(), [], ['autoEncryption' => $autoEncryptionOpts]); | |||
} | |||
|
|||
#[DoesNotPerformAssertions] | |||
public function testConstructorEmptyKmsProvider(): void |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would this test have failed without the above patch? If not, is anything being tested at all?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes:
MongoDB\Driver\Exception\EncryptionException: expected BSON document for field: gcp
Fix PHPLIB-1708
For some KMS providers, all options can be omitted. The authentication is done using the env var or the system.
https://github.com/mongodb/specifications/blob/master/source/client-side-encryption/client-side-encryption.md#credentialproviders
The approach in doctrine/mongodb-odm#2801 is not sufficient because Symfony is not able to dump the empty object instance into the container.