Skip to content

CSHARP-5453: Add builder for CSFLE schemas #1631

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

Open
wants to merge 39 commits into
base: main
Choose a base branch
from

Conversation

papafe
Copy link
Contributor

@papafe papafe commented Mar 7, 2025

No description provided.

@papafe papafe requested review from damieng and sanych-sun March 12, 2025 12:55
@papafe
Copy link
Contributor Author

papafe commented Mar 12, 2025

@sanych-sun @damieng Can you give a look at the current state of the API? It's mostly functioning too, but I would like to get some feedback before writing tests.
Some notes:

  • At the moment the naming is derived from the name the fields have in the json schema, as presented in the documentation(here and here).
  • I taken examples mostly from the documentation pages, with some differences regarding the keyId.
  • I'll take care of the xml docs only at the end.

@papafe papafe marked this pull request as ready for review May 5, 2025 09:30
@papafe papafe requested a review from a team as a code owner May 5, 2025 09:30
@papafe papafe changed the title CSHARP-5453: Improve field encryption usability with attributes/API CSHARP-5453: Add builder for CSFLE schemas May 5, 2025
@papafe
Copy link
Contributor Author

papafe commented May 5, 2025

@sanych-sun @damieng A couple of notes for the review:

  • I have decided to reuse EncryptionAlgorithm and not create a new enum, even though EncryptionAlgorithm contains some values that are not valid for the schema, but will throw an exception.
  • bsonType is actually optional, differently from what we discussed together. For this reason I slightly modified the overloads to avoid ambiguities when calling the methods.
  • The whole encrypt section of a field could be empty. This is supported in the PR

@rstam rstam removed the request for review from a team May 22, 2025 21:34
Copy link
Member

@damieng damieng left a comment

Choose a reason for hiding this comment

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

LGTM

Copy link
Member

@sanych-sun sanych-sun left a comment

Choose a reason for hiding this comment

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

LGTM

@papafe papafe requested review from damieng and sanych-sun June 18, 2025 14:58
@papafe
Copy link
Contributor Author

papafe commented Jun 18, 2025

@damieng @sanych-sun I know you've already LGMTd this, but I've added added a method to convert BsonType to its string representation to our public API as was also requested by @damieng.
Just wanted to have a check if the naming makes sense, and if we should keep it as an extension method, or we prefer to have it as a static method on BsonUtils, for instance.

/// Maps a <see cref="BsonType"/> to its corresponding string representation.
/// </summary>
/// <param name="type">The input type to map.</param>
public static string ToStringRepresentation(this BsonType type)
Copy link
Contributor Author

@papafe papafe Jun 18, 2025

Choose a reason for hiding this comment

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

@rstam this is the new method

Copy link
Contributor

Choose a reason for hiding this comment

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

I'm not sure we should add this to the public API just so EF Core can use it. EF Core can easily duplicate this very small method.

Unless there is a clear scenario where a USER would find this useful, I wouldn't add it to the public API.

Definitely a good idea to centralize this conversion in an internal method for our own consumption.

If we do make this public I suggest it be done as a separate JIRA ticket so that users can see it.

Copy link
Member

Choose a reason for hiding this comment

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

It's a useful method with a clear and defined purpose and limited API surface. If I need it in the EF provider chances are other people need it too and probably also had to reproduce it. They'd need it right now if they're doing their own queryable encryption or CSFLE work and are trying to leverage BsonType in order to generate the schema.

/// Maps a <see cref="BsonType"/> to its corresponding string representation.
/// </summary>
/// <param name="type">The input type to map.</param>
public static string ToStringRepresentation(this BsonType type)
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm not sure we should add this to the public API just so EF Core can use it. EF Core can easily duplicate this very small method.

Unless there is a clear scenario where a USER would find this useful, I wouldn't add it to the public API.

Definitely a good idea to centralize this conversion in an internal method for our own consumption.

If we do make this public I suggest it be done as a separate JIRA ticket so that users can see it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants