@@ -22,8 +22,15 @@ import com.mongodb.client.model.{ CreateCollectionOptions, CreateEncryptedCollec
2222import java .io .Closeable
2323import com .mongodb .reactivestreams .client .vault .{ ClientEncryption => JClientEncryption }
2424import org .bson .{ BsonBinary , BsonDocument , BsonValue }
25- import org .mongodb .scala .{ Document , MongoDatabase , SingleObservable , ToSingleObservablePublisher }
26- import org .mongodb .scala .model .vault .{ DataKeyOptions , EncryptOptions }
25+ import org .mongodb .scala .bson .conversions .Bson
26+ import org .mongodb .scala .{ Document , FindObservable , MongoDatabase , SingleObservable , ToSingleObservablePublisher }
27+ import org .mongodb .scala .model .vault .{
28+ DataKeyOptions ,
29+ EncryptOptions ,
30+ RewrapManyDataKeyOptions ,
31+ RewrapManyDataKeyResult
32+ }
33+ import org .mongodb .scala .result .DeleteResult
2734
2835/**
2936 * The Key vault.
@@ -40,7 +47,7 @@ case class ClientEncryption(private val wrapped: JClientEncryption) extends Clos
4047 * Creates a new key document and inserts into the key vault collection.
4148 *
4249 * @param kmsProvider the KMS provider
43- * @return a Publisher containing the identifier for the created data key
50+ * @return an Observable containing the identifier for the created data key
4451 */
4552 def createDataKey (kmsProvider : String ): SingleObservable [BsonBinary ] = createDataKey(kmsProvider, DataKeyOptions ())
4653
@@ -51,7 +58,7 @@ case class ClientEncryption(private val wrapped: JClientEncryption) extends Clos
5158 *
5259 * @param kmsProvider the KMS provider
5360 * @param dataKeyOptions the options for data key creation
54- * @return a Publisher containing the identifier for the created data key
61+ * @return an Observable containing the identifier for the created data key
5562 */
5663 def createDataKey (kmsProvider : String , dataKeyOptions : DataKeyOptions ): SingleObservable [BsonBinary ] =
5764 wrapped.createDataKey(kmsProvider, dataKeyOptions)
@@ -62,7 +69,7 @@ case class ClientEncryption(private val wrapped: JClientEncryption) extends Clos
6269 *
6370 * @param value the value to encrypt
6471 * @param options the options for data encryption
65- * @return a Publisher containing the encrypted value, a BSON binary of subtype 6
72+ * @return an Observable containing the encrypted value, a BSON binary of subtype 6
6673 */
6774 def encrypt (value : BsonValue , options : EncryptOptions ): SingleObservable [BsonBinary ] =
6875 wrapped.encrypt(value, options)
@@ -86,7 +93,7 @@ case class ClientEncryption(private val wrapped: JClientEncryption) extends Clos
8693 * @note Requires MongoDB 8.0 or greater
8794 * @param expression the Match Expression or Aggregate Expression
8895 * @param options the options
89- * @return a Publisher containing the queryable encrypted range expression
96+ * @return an Observable containing the queryable encrypted range expression
9097 * @since 4.9
9198 */
9299 def encryptExpression (
@@ -99,10 +106,87 @@ case class ClientEncryption(private val wrapped: JClientEncryption) extends Clos
99106 * Decrypt the given value.
100107 *
101108 * @param value the value to decrypt, which must be of subtype 6
102- * @return a Publisher containing the decrypted value
109+ * @return an Observable containing the decrypted value
103110 */
104111 def decrypt (value : BsonBinary ): SingleObservable [BsonValue ] = wrapped.decrypt(value)
105112
113+ /**
114+ * Finds a single key document with the given UUID (BSON binary subtype 0x04).
115+ *
116+ * @param id the data key UUID (BSON binary subtype 0x04)
117+ * @return an Observable containing the single key document or an empty Observable if there is no match
118+ * @since 5.6
119+ */
120+ def getKey (id : BsonBinary ): SingleObservable [BsonDocument ] = wrapped.getKey(id)
121+
122+ /**
123+ * Returns a key document in the key vault collection with the given keyAltName.
124+ *
125+ * @param keyAltName the alternative key name
126+ * @return an Observable containing the matching key document or an empty Observable if there is no match
127+ * @since 5.6
128+ */
129+ def getKeyByAltName (keyAltName : String ): SingleObservable [BsonDocument ] = wrapped.getKeyByAltName(keyAltName)
130+
131+ /**
132+ * Finds all documents in the key vault collection.
133+ *
134+ * @return a find Observable for the documents in the key vault collection
135+ * @since 5.6
136+ */
137+ def keys : FindObservable [BsonDocument ] = FindObservable (wrapped.getKeys)
138+
139+ /**
140+ * Adds a keyAltName to the keyAltNames array of the key document in the key vault collection with the given UUID.
141+ *
142+ * @param id the data key UUID (BSON binary subtype 0x04)
143+ * @param keyAltName the alternative key name to add to the keyAltNames array
144+ * @return an Observable containing the previous version of the key document or an empty Observable if no match
145+ * @since 5.6
146+ */
147+ def addKeyAltName (id : BsonBinary , keyAltName : String ): SingleObservable [BsonDocument ] =
148+ wrapped.addKeyAltName(id, keyAltName)
149+
150+ /**
151+ * Removes the key document with the given data key from the key vault collection.
152+ *
153+ * @param id the data key UUID (BSON binary subtype 0x04)
154+ * @return an Observable containing the delete result
155+ * @since 5.6
156+ */
157+ def deleteKey (id : BsonBinary ): SingleObservable [DeleteResult ] = wrapped.deleteKey(id)
158+
159+ /**
160+ * Removes a keyAltName from the keyAltNames array of the key document in the key vault collection with the given id.
161+ *
162+ * @param id the data key UUID (BSON binary subtype 0x04)
163+ * @param keyAltName the alternative key name
164+ * @return an Observable containing the previous version of the key document or an empty Observable if there is no match
165+ * @since 5.6
166+ */
167+ def removeKeyAltName (id : BsonBinary , keyAltName : String ): SingleObservable [BsonDocument ] =
168+ wrapped.removeKeyAltName(id, keyAltName)
169+
170+ /**
171+ * Decrypts multiple data keys and (re-)encrypts them with the current masterKey.
172+ *
173+ * @param filter the filter
174+ * @return an Observable containing the result
175+ * @since 5.6
176+ */
177+ def rewrapManyDataKey (filter : Bson ): SingleObservable [RewrapManyDataKeyResult ] = wrapped.rewrapManyDataKey(filter)
178+
179+ /**
180+ * Decrypts multiple data keys and (re-)encrypts them with a new masterKey, or with their current masterKey if a new one is not given.
181+ *
182+ * @param filter the filter
183+ * @param options the options
184+ * @return an Observable containing the result
185+ * @since 5.6
186+ */
187+ def rewrapManyDataKey (filter : Bson , options : RewrapManyDataKeyOptions ): SingleObservable [RewrapManyDataKeyResult ] =
188+ wrapped.rewrapManyDataKey(filter, options)
189+
106190 /**
107191 * Create a new collection with encrypted fields,
108192 * automatically creating
@@ -115,7 +199,7 @@ case class ClientEncryption(private val wrapped: JClientEncryption) extends Clos
115199 * @param collectionName The name for the collection to create.
116200 * @param createCollectionOptions Options for creating the collection.
117201 * @param createEncryptedCollectionParams Auxiliary parameters for creating an encrypted collection.
118- * @return A publisher of the (potentially updated) `encryptedFields` configuration that was used to create the collection.
202+ * @return An Observable of the (potentially updated) `encryptedFields` configuration that was used to create the collection.
119203 * A user may use this document to configure `com.mongodb.AutoEncryptionSettings.getEncryptedFieldsMap`.
120204 *
121205 * Produces MongoUpdatedEncryptedFieldsException` if an exception happens after creating at least one data key.
0 commit comments