Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in
Toggle navigation
M
mongo-php-library
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
sinan
mongo-php-library
Commits
c57450e7
Unverified
Commit
c57450e7
authored
Jan 24, 2020
by
Andreas Braun
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #709
parents
2fb70273
d777f5ff
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
129 additions
and
0 deletions
+129
-0
apiargs-MongoDBClient-method-createClientEncryption-param.yaml
...gs-MongoDBClient-method-createClientEncryption-param.yaml
+4
-0
MongoDBClient.txt
docs/reference/class/MongoDBClient.txt
+1
-0
MongoDBClient-createClientEncryption.txt
...reference/method/MongoDBClient-createClientEncryption.txt
+51
-0
Client.php
src/Client.php
+21
-0
ClientTest.php
tests/ClientTest.php
+52
-0
No files found.
docs/includes/apiargs-MongoDBClient-method-createClientEncryption-param.yaml
0 → 100644
View file @
c57450e7
source
:
file
:
apiargs-common-param.yaml
ref
:
$options
...
docs/reference/class/MongoDBClient.txt
View file @
c57450e7
...
@@ -30,6 +30,7 @@ Methods
...
@@ -30,6 +30,7 @@ Methods
/reference/method/MongoDBClient__construct
/reference/method/MongoDBClient__construct
/reference/method/MongoDBClient__get
/reference/method/MongoDBClient__get
/reference/method/MongoDBClient-createClientEncryption
/reference/method/MongoDBClient-dropDatabase
/reference/method/MongoDBClient-dropDatabase
/reference/method/MongoDBClient-getManager
/reference/method/MongoDBClient-getManager
/reference/method/MongoDBClient-getReadConcern
/reference/method/MongoDBClient-getReadConcern
...
...
docs/reference/method/MongoDBClient-createClientEncryption.txt
0 → 100644
View file @
c57450e7
=========================================
MongoDB\\Client::createClientEncryption()
=========================================
.. default-domain:: mongodb
.. contents:: On this page
:local:
:backlinks: none
:depth: 1
:class: singlecol
Definition
----------
.. phpmethod:: MongoDB\\Client::createClientEncryption()
Returns a :php:`MongoDB\\Driver\\ClientEncryption <class.mongodb-driver-clientencryption>`
object for manual encryption and decryption of values.
.. code-block:: php
function createClientEncryption(array $options): MongoDB\Driver\ClientEncryption
This method has the following parameters:
.. include:: /includes/apiargs/MongoDBClient-method-createClientEncryption-param.rst
The ``$options`` parameter supports all options documented in the
:php:`extension manual <manual/en/mongodb-driver-manager.createclientencryption.php>`.
For the ``keyVaultClient`` option, an instance of :phpclass:`MongoDB\\Client`
is automatically unwrapped and the :php:`MongoDB\\Driver\\Manager <class.mongodb-driver-manager>`
instance is passed to the extension.
Return Values
-------------
A :php:`MongoDB\\Driver\\ClientEncryption <class.mongodb-driver-clientencryption>`
instance which can be used to encrypt and decrypt values.
Errors/Exceptions
-----------------
.. include:: /includes/extracts/error-invalidargumentexception.rst
.. include:: /includes/extracts/error-driver-invalidargumentexception.rst
See Also
--------
- :php:`MongoDB\\Driver\\Manager::createClientEncryption()
<manual/en/mongodb-driver-manager.createclientencryption.php>`
src/Client.php
View file @
c57450e7
...
@@ -17,6 +17,7 @@
...
@@ -17,6 +17,7 @@
namespace
MongoDB
;
namespace
MongoDB
;
use
MongoDB\Driver\ClientEncryption
;
use
MongoDB\Driver\Exception\InvalidArgumentException
as
DriverInvalidArgumentException
;
use
MongoDB\Driver\Exception\InvalidArgumentException
as
DriverInvalidArgumentException
;
use
MongoDB\Driver\Exception\RuntimeException
as
DriverRuntimeException
;
use
MongoDB\Driver\Exception\RuntimeException
as
DriverRuntimeException
;
use
MongoDB\Driver\Manager
;
use
MongoDB\Driver\Manager
;
...
@@ -161,6 +162,26 @@ class Client
...
@@ -161,6 +162,26 @@ class Client
return
$this
->
uri
;
return
$this
->
uri
;
}
}
/**
* Returns a ClientEncryption instance for explicit encryption and decryption
*
* @param array $options Encryption options
*
* @return ClientEncryption
*/
public
function
createClientEncryption
(
array
$options
)
{
if
(
isset
(
$options
[
'keyVaultClient'
]))
{
if
(
$options
[
'keyVaultClient'
]
instanceof
self
)
{
$options
[
'keyVaultClient'
]
=
$options
[
'keyVaultClient'
]
->
manager
;
}
elseif
(
!
$options
[
'keyVaultClient'
]
instanceof
Manager
)
{
throw
InvalidArgumentException
::
invalidType
(
'"keyVaultClient" option'
,
$options
[
'keyVaultClient'
],
[
self
::
class
,
Manager
::
class
]);
}
}
return
$this
->
manager
->
createClientEncryption
(
$options
);
}
/**
/**
* Drop a database.
* Drop a database.
*
*
...
...
tests/ClientTest.php
View file @
c57450e7
...
@@ -3,6 +3,7 @@
...
@@ -3,6 +3,7 @@
namespace
MongoDB\Tests
;
namespace
MongoDB\Tests
;
use
MongoDB\Client
;
use
MongoDB\Client
;
use
MongoDB\Driver\ClientEncryption
;
use
MongoDB\Driver\ReadConcern
;
use
MongoDB\Driver\ReadConcern
;
use
MongoDB\Driver\ReadPreference
;
use
MongoDB\Driver\ReadPreference
;
use
MongoDB\Driver\WriteConcern
;
use
MongoDB\Driver\WriteConcern
;
...
@@ -173,4 +174,55 @@ class ClientTest extends TestCase
...
@@ -173,4 +174,55 @@ class ClientTest extends TestCase
$this
->
assertInstanceOf
(
WriteConcern
::
class
,
$debug
[
'writeConcern'
]);
$this
->
assertInstanceOf
(
WriteConcern
::
class
,
$debug
[
'writeConcern'
]);
$this
->
assertSame
(
WriteConcern
::
MAJORITY
,
$debug
[
'writeConcern'
]
->
getW
());
$this
->
assertSame
(
WriteConcern
::
MAJORITY
,
$debug
[
'writeConcern'
]
->
getW
());
}
}
public
function
testCreateClientEncryption
()
{
$client
=
new
Client
(
static
::
getUri
());
$options
=
[
'keyVaultNamespace'
=>
'default.keys'
,
'kmsProviders'
=>
[
'aws'
=>
[
'accessKeyId'
=>
'abc'
,
'secretAccessKey'
=>
'def'
]],
];
$clientEncryption
=
$client
->
createClientEncryption
(
$options
);
$this
->
assertInstanceOf
(
ClientEncryption
::
class
,
$clientEncryption
);
}
public
function
testCreateClientEncryptionWithKeyVaultClient
()
{
$client
=
new
Client
(
static
::
getUri
());
$options
=
[
'keyVaultClient'
=>
$client
,
'keyVaultNamespace'
=>
'default.keys'
,
'kmsProviders'
=>
[
'aws'
=>
[
'accessKeyId'
=>
'abc'
,
'secretAccessKey'
=>
'def'
]],
];
$clientEncryption
=
$client
->
createClientEncryption
(
$options
);
$this
->
assertInstanceOf
(
ClientEncryption
::
class
,
$clientEncryption
);
}
public
function
testCreateClientEncryptionWithManager
()
{
$client
=
new
Client
(
static
::
getUri
());
$options
=
[
'keyVaultClient'
=>
$client
->
getManager
(),
'keyVaultNamespace'
=>
'default.keys'
,
'kmsProviders'
=>
[
'aws'
=>
[
'accessKeyId'
=>
'abc'
,
'secretAccessKey'
=>
'def'
]],
];
$clientEncryption
=
$client
->
createClientEncryption
(
$options
);
$this
->
assertInstanceOf
(
ClientEncryption
::
class
,
$clientEncryption
);
}
public
function
testCreateClientEncryptionWithInvalidKeyVaultClient
()
{
$client
=
new
Client
(
static
::
getUri
());
$this
->
expectException
(
InvalidArgumentException
::
class
);
$this
->
expectExceptionMessage
(
'Expected "keyVaultClient" option to have type "MongoDB\Client" or "MongoDB\Driver\Manager" but found "string"'
);
$client
->
createClientEncryption
([
'keyVaultClient'
=>
'foo'
]);
}
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment