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
bac7cfa7
Unverified
Commit
bac7cfa7
authored
Apr 20, 2020
by
Andreas Braun
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
PHPLIB-545: Support the authorizedDatabases options for listDatabases
parent
94403732
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
57 additions
and
2 deletions
+57
-2
apiargs-MongoDBClient-method-listDatabases-option.yaml
...es/apiargs-MongoDBClient-method-listDatabases-option.yaml
+12
-0
ListDatabases.php
src/Operation/ListDatabases.php
+14
-0
ListDatabasesFunctionalTest.php
tests/Operation/ListDatabasesFunctionalTest.php
+27
-2
ListDatabasesTest.php
tests/Operation/ListDatabasesTest.php
+4
-0
No files found.
docs/includes/apiargs-MongoDBClient-method-listDatabases-option.yaml
View file @
bac7cfa7
arg_name
:
option
arg_name
:
option
name
:
authorizedDatabases
type
:
boolean
description
:
|
A flag that determines which databases are returned based on the user
privileges when access control is enabled. For more information, see the
`listDatabases command documentation <https://docs.mongodb.com/manual/reference/command/listDatabases/#dbcmd.listDatabases>`_.
For servers < 4.0.5, this option is ignored.
.. versionadded:: 1.7
---
arg_name
:
option
name
:
filter
name
:
filter
type
:
array|object
type
:
array|object
description
:
|
description
:
|
...
...
src/Operation/ListDatabases.php
View file @
bac7cfa7
...
@@ -27,6 +27,7 @@ use MongoDB\Model\DatabaseInfoIterator;
...
@@ -27,6 +27,7 @@ use MongoDB\Model\DatabaseInfoIterator;
use
MongoDB\Model\DatabaseInfoLegacyIterator
;
use
MongoDB\Model\DatabaseInfoLegacyIterator
;
use
function
current
;
use
function
current
;
use
function
is_array
;
use
function
is_array
;
use
function
is_bool
;
use
function
is_integer
;
use
function
is_integer
;
use
function
is_object
;
use
function
is_object
;
...
@@ -47,6 +48,11 @@ class ListDatabases implements Executable
...
@@ -47,6 +48,11 @@ class ListDatabases implements Executable
*
*
* Supported options:
* Supported options:
*
*
* * authorizedDatabases (boolean): Determines which databases are returned
* based on the user privileges.
*
* For servers < 4.0.5, this option is ignored.
*
* * filter (document): Query by which to filter databases.
* * filter (document): Query by which to filter databases.
*
*
* For servers < 3.6, this option is ignored.
* For servers < 3.6, this option is ignored.
...
@@ -63,6 +69,10 @@ class ListDatabases implements Executable
...
@@ -63,6 +69,10 @@ class ListDatabases implements Executable
*/
*/
public
function
__construct
(
array
$options
=
[])
public
function
__construct
(
array
$options
=
[])
{
{
if
(
isset
(
$options
[
'authorizedDatabases'
])
&&
!
is_bool
(
$options
[
'authorizedDatabases'
]))
{
throw
InvalidArgumentException
::
invalidType
(
'"authorizedDatabases" option'
,
$options
[
'authorizedDatabases'
],
'boolean'
);
}
if
(
isset
(
$options
[
'filter'
])
&&
!
is_array
(
$options
[
'filter'
])
&&
!
is_object
(
$options
[
'filter'
]))
{
if
(
isset
(
$options
[
'filter'
])
&&
!
is_array
(
$options
[
'filter'
])
&&
!
is_object
(
$options
[
'filter'
]))
{
throw
InvalidArgumentException
::
invalidType
(
'"filter" option'
,
$options
[
'filter'
],
'array or object'
);
throw
InvalidArgumentException
::
invalidType
(
'"filter" option'
,
$options
[
'filter'
],
'array or object'
);
}
}
...
@@ -91,6 +101,10 @@ class ListDatabases implements Executable
...
@@ -91,6 +101,10 @@ class ListDatabases implements Executable
{
{
$cmd
=
[
'listDatabases'
=>
1
];
$cmd
=
[
'listDatabases'
=>
1
];
if
(
isset
(
$this
->
options
[
'authorizedDatabases'
]))
{
$cmd
[
'authorizedDatabases'
]
=
$this
->
options
[
'authorizedDatabases'
];
}
if
(
!
empty
(
$this
->
options
[
'filter'
]))
{
if
(
!
empty
(
$this
->
options
[
'filter'
]))
{
$cmd
[
'filter'
]
=
(
object
)
$this
->
options
[
'filter'
];
$cmd
[
'filter'
]
=
(
object
)
$this
->
options
[
'filter'
];
}
}
...
...
tests/Operation/ListDatabasesFunctionalTest.php
View file @
bac7cfa7
...
@@ -19,8 +19,17 @@ class ListDatabasesFunctionalTest extends FunctionalTestCase
...
@@ -19,8 +19,17 @@ class ListDatabasesFunctionalTest extends FunctionalTestCase
$writeResult
=
$insertOne
->
execute
(
$server
);
$writeResult
=
$insertOne
->
execute
(
$server
);
$this
->
assertEquals
(
1
,
$writeResult
->
getInsertedCount
());
$this
->
assertEquals
(
1
,
$writeResult
->
getInsertedCount
());
$databases
=
null
;
(
new
CommandObserver
())
->
observe
(
function
()
use
(
&
$databases
,
$server
)
{
$operation
=
new
ListDatabases
();
$operation
=
new
ListDatabases
();
$databases
=
$operation
->
execute
(
$server
);
$databases
=
$operation
->
execute
(
$server
);
},
function
(
array
$event
)
{
$this
->
assertObjectNotHasAttribute
(
'authorizedDatabases'
,
$event
[
'started'
]
->
getCommand
());
}
);
$this
->
assertInstanceOf
(
DatabaseInfoIterator
::
class
,
$databases
);
$this
->
assertInstanceOf
(
DatabaseInfoIterator
::
class
,
$databases
);
...
@@ -29,6 +38,22 @@ class ListDatabasesFunctionalTest extends FunctionalTestCase
...
@@ -29,6 +38,22 @@ class ListDatabasesFunctionalTest extends FunctionalTestCase
}
}
}
}
public
function
testAuthorizedDatabasesOption
()
{
(
new
CommandObserver
())
->
observe
(
function
()
{
$operation
=
new
ListDatabases
(
[
'authorizedDatabases'
=>
true
]
);
$operation
->
execute
(
$this
->
getPrimaryServer
());
},
function
(
array
$event
)
{
$this
->
assertObjectHasAttribute
(
'authorizedDatabases'
,
$event
[
'started'
]
->
getCommand
());
}
);
}
public
function
testFilterOption
()
public
function
testFilterOption
()
{
{
if
(
version_compare
(
$this
->
getServerVersion
(),
'3.6.0'
,
'<'
))
{
if
(
version_compare
(
$this
->
getServerVersion
(),
'3.6.0'
,
'<'
))
{
...
...
tests/Operation/ListDatabasesTest.php
View file @
bac7cfa7
...
@@ -20,6 +20,10 @@ class ListDatabasesTest extends TestCase
...
@@ -20,6 +20,10 @@ class ListDatabasesTest extends TestCase
{
{
$options
=
[];
$options
=
[];
foreach
(
$this
->
getInvalidBooleanValues
()
as
$value
)
{
$options
[][]
=
[
'authorizedDatabases'
=>
$value
];
}
foreach
(
$this
->
getInvalidDocumentValues
()
as
$value
)
{
foreach
(
$this
->
getInvalidDocumentValues
()
as
$value
)
{
$options
[][]
=
[
'filter'
=>
$value
];
$options
[][]
=
[
'filter'
=>
$value
];
}
}
...
...
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