-
Notifications
You must be signed in to change notification settings - Fork 4.4k
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
Source MongoDB fetch authorized collections only #9238
Merged
VitaliiMaltsev
merged 30 commits into
master
from
vmaltsev/8752-source-mongodb-show-authorized-collections
Jan 13, 2022
Merged
Changes from 24 commits
Commits
Show all changes
30 commits
Select commit
Hold shift + click to select a range
93d53ac
fix for jdk 17
ede8d38
Merge branch 'master' of github.com:airbytehq/airbyte
27be3fe
Merge branch 'master' of github.com:airbytehq/airbyte
ca75033
Merge branch 'master' of github.com:airbytehq/airbyte
72ab46f
Merge branch 'master' of github.com:airbytehq/airbyte
aec3384
Merge branch 'master' of github.com:airbytehq/airbyte
7efd5aa
Merge branch 'master' of github.com:airbytehq/airbyte
6a773f9
Merge branch 'master' of github.com:airbytehq/airbyte
fa18537
Merge branch 'master' of github.com:airbytehq/airbyte
b0ba37b
Merge branch 'master' of github.com:airbytehq/airbyte
fa31a0d
Merge branch 'master' of github.com:airbytehq/airbyte
67e0bd6
Merge branch 'master' of github.com:airbytehq/airbyte
ec0d1bd
Merge branch 'master' of github.com:airbytehq/airbyte
23598ec
Merge branch 'master' of github.com:airbytehq/airbyte
59d63e6
Merge branch 'master' of github.com:airbytehq/airbyte
4d10720
Source MongoDB show authorized collections
e2cb62c
Merge branch 'master' of github.com:airbytehq/airbyte
f622758
add javadoc
aae25d6
fixed checkstyle
632583a
Merge branch 'master' of github.com:airbytehq/airbyte
2bc76ce
Merge branch 'master' of github.com:airbytehq/airbyte
0556234
add CHANGELOG
131c45f
Merge branch 'master' into vmaltsev/8752-source-mongodb-show-authoriz…
a1c94e1
fix checkstyle
a51ec08
refactoring
45dfc2d
bump version anf fix checkstyle
9baf2e1
Merge branch 'master' of github.com:airbytehq/airbyte
9942d14
Merge branch 'master' into vmaltsev/8752-source-mongodb-show-authoriz…
ed4f1ba
Merge branch 'master' of github.com:airbytehq/airbyte
6d073b7
Merge branch 'master' into vmaltsev/8752-source-mongodb-show-authoriz…
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -90,7 +90,7 @@ public List<CheckedConsumer<MongoDatabase, Exception>> getCheckOperations(final | |
throws Exception { | ||
final List<CheckedConsumer<MongoDatabase, Exception>> checkList = new ArrayList<>(); | ||
checkList.add(database -> { | ||
if (database.getCollectionNames().isEmpty()) { | ||
if (getAuthorizedCollections(database).isEmpty()) { | ||
throw new Exception("Unable to execute any operation on the source!"); | ||
} else { | ||
LOGGER.info("The source passed the basic operation test!"); | ||
|
@@ -114,7 +114,7 @@ protected List<TableInfo<CommonField<BsonType>>> discoverInternal(final MongoDat | |
throws Exception { | ||
final List<TableInfo<CommonField<BsonType>>> tableInfos = new ArrayList<>(); | ||
|
||
for (final String collectionName : database.getCollectionNames()) { | ||
for (final String collectionName : getAuthorizedCollections(database)) { | ||
final MongoCollection<Document> collection = database.getCollection(collectionName); | ||
final Map<String, BsonType> uniqueFields = MongoUtils.getUniqueFields(collection); | ||
|
||
|
@@ -135,7 +135,26 @@ protected List<TableInfo<CommonField<BsonType>>> discoverInternal(final MongoDat | |
return tableInfos; | ||
} | ||
|
||
@Override | ||
private Set<String> getAuthorizedCollections(MongoDatabase database) { | ||
/* db.runCommand ({listCollections: 1.0, authorizedCollections: true, nameOnly: true }) | ||
the command returns only those collections for which the user has privileges. | ||
For example, if a user has find action on specific collections, the command returns only those collections; | ||
or, if a user has find or any other action, on the database resource, the command lists all collections in the database. | ||
*/ | ||
Document document = database.getDatabase().runCommand(new Document("listCollections", 1) | ||
.append("authorizedCollections", true).append("nameOnly", true)); | ||
|
||
return document.toBsonDocument() | ||
.get("cursor").asDocument() | ||
.getArray("firstBatch") | ||
.stream() | ||
.filter(bsonValue -> bsonValue.asDocument().getString("type").getValue().equals("collection")) | ||
.map(bsonValue -> bsonValue.asDocument().getString("name").getValue()) | ||
.collect(Collectors.toSet()); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Looks great) |
||
|
||
} | ||
|
||
@Override | ||
protected List<TableInfo<CommonField<BsonType>>> discoverInternal(final MongoDatabase database, final String schema) throws Exception { | ||
// MondoDb doesn't support schemas | ||
return discoverInternal(database); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Nitpick .The
listCollections
command can take in afilter
parameter to filter on any field in the returned document directly.Reference: https://docs.mongodb.com/manual/reference/command/listCollections/#definition
I think if you add the filter parameter, you won't need to do the filter here:
I am not 100% sure this is the correct syntax though.
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.
added filter into mongo shell command