Skip to content

CSHARP-4255: Automatically create Queryable Encryption keys.#961

Merged
DmitryLukyanov merged 9 commits intomongodb:masterfrom
DmitryLukyanov:csharp4255
Dec 14, 2022
Merged

CSHARP-4255: Automatically create Queryable Encryption keys.#961
DmitryLukyanov merged 9 commits intomongodb:masterfrom
DmitryLukyanov:csharp4255

Conversation

@DmitryLukyanov
Copy link
Copy Markdown
Contributor

No description provided.

/// <param name="kmsProvider">The kms provider.</param>
/// <param name="dataKeyOptions">The datakey options.</param>
/// <param name="cancellationToken">The cancellation token.</param>
public (IMongoCollection<TCollection> Collection, BsonDocument EncryptedFields) CreateEncryptedCollection<TCollection>(CollectionNamespace collectionNamespace, CreateCollectionOptions createCollectionOptions, string kmsProvider, DataKeyOptions dataKeyOptions, CancellationToken cancellationToken = default)
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm going to discuss whether we can add a different return type than this, so might be not the final form

Copy link
Copy Markdown
Contributor Author

@DmitryLukyanov DmitryLukyanov Dec 7, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've discussed this question with spec author and he's confirmed that we can define public API in the consistent way with previous driver's API methods. So, I consider 2 changes:

  1. Do not return created collection from this helper method. Instead do the same logic as we do with a regular CreateCollection method ie return nothing and request retrieving collection via GetCollection.
  2. Instead returning EncryptedFields, we can simply modify input EncryptedFields in the provided options.

I'm not too confident about these changes (as well as about the initial requirement), but I would probably want to avoid returning tuple in public API, thoughts?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think Tuples are not recommended in public APIs.

Agreed that there is no need to return the IMongoCollection<TDocument> .

Do we need to return anything?

Also, shouldn't the type parameter be TDocument (not TCollection). But if we don't return the IMongoCollection<TDocument> I don't think this type parameter is needed any more anyway.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need to return anything?

yeah, I also think it can be simply void method

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

changed

@JamesKovacs JamesKovacs requested review from BorisDog and removed request for JamesKovacs November 23, 2022 22:34

if (storedEncryptedFields.TryGetValue("fields", out var fields) && fields is BsonArray fieldsArray)
{
foreach (var field in fieldsArray)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fieldsArray.OfType<BsonDocument>() ?
or even

fieldsArray
    .OfType< BsonDocument>()
    .Where(b => b.TryGetElement("keyId", out var keyId) && keyId.Value == BsonNull.Value)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good point, I like first one, second one probably is a bit harder to read, done

}
}

yield break;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not needed?

Copy link
Copy Markdown
Contributor

@BorisDog BorisDog left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

/// <param name="kmsProvider">The kms provider.</param>
/// <param name="dataKeyOptions">The datakey options.</param>
/// <param name="cancellationToken">The cancellation token.</param>
public (IMongoCollection<TCollection> Collection, BsonDocument EncryptedFields) CreateEncryptedCollection<TCollection>(CollectionNamespace collectionNamespace, CreateCollectionOptions createCollectionOptions, string kmsProvider, DataKeyOptions dataKeyOptions, CancellationToken cancellationToken = default)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think Tuples are not recommended in public APIs.

Agreed that there is no need to return the IMongoCollection<TDocument> .

Do we need to return anything?

Also, shouldn't the type parameter be TDocument (not TCollection). But if we don't return the IMongoCollection<TDocument> I don't think this type parameter is needed any more anyway.

foreach (var fieldDocument in EncryptedCollectionHelper.IterateEmptyKeyIds(collectionNamespace, effectiveEncryptedFields))
{
var dataKey = CreateDataKey(kmsProvider, dataKeyOptions, cancellationToken);
EncryptedCollectionHelper.ModifyEndryptedFields(fieldDocument, dataKey);
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like ModifyEndryptedFields is spelled wrong.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

true

@DmitryLukyanov DmitryLukyanov merged commit e379ebd into mongodb:master Dec 14, 2022
BorisDog pushed a commit to BorisDog/mongo-csharp-driver that referenced this pull request Dec 22, 2022
dnickless pushed a commit to dnickless/mongo-csharp-driver that referenced this pull request Aug 24, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants