@@ -22,8 +22,15 @@ import com.mongodb.client.model.{ CreateCollectionOptions, CreateEncryptedCollec
22
22
import java .io .Closeable
23
23
import com .mongodb .reactivestreams .client .vault .{ ClientEncryption => JClientEncryption }
24
24
import 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
27
34
28
35
/**
29
36
* The Key vault.
@@ -40,7 +47,7 @@ case class ClientEncryption(private val wrapped: JClientEncryption) extends Clos
40
47
* Creates a new key document and inserts into the key vault collection.
41
48
*
42
49
* @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
44
51
*/
45
52
def createDataKey (kmsProvider : String ): SingleObservable [BsonBinary ] = createDataKey(kmsProvider, DataKeyOptions ())
46
53
@@ -51,7 +58,7 @@ case class ClientEncryption(private val wrapped: JClientEncryption) extends Clos
51
58
*
52
59
* @param kmsProvider the KMS provider
53
60
* @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
55
62
*/
56
63
def createDataKey (kmsProvider : String , dataKeyOptions : DataKeyOptions ): SingleObservable [BsonBinary ] =
57
64
wrapped.createDataKey(kmsProvider, dataKeyOptions)
@@ -62,7 +69,7 @@ case class ClientEncryption(private val wrapped: JClientEncryption) extends Clos
62
69
*
63
70
* @param value the value to encrypt
64
71
* @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
66
73
*/
67
74
def encrypt (value : BsonValue , options : EncryptOptions ): SingleObservable [BsonBinary ] =
68
75
wrapped.encrypt(value, options)
@@ -86,7 +93,7 @@ case class ClientEncryption(private val wrapped: JClientEncryption) extends Clos
86
93
* @note Requires MongoDB 8.0 or greater
87
94
* @param expression the Match Expression or Aggregate Expression
88
95
* @param options the options
89
- * @return a Publisher containing the queryable encrypted range expression
96
+ * @return an Observable containing the queryable encrypted range expression
90
97
* @since 4.9
91
98
*/
92
99
def encryptExpression (
@@ -99,10 +106,87 @@ case class ClientEncryption(private val wrapped: JClientEncryption) extends Clos
99
106
* Decrypt the given value.
100
107
*
101
108
* @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
103
110
*/
104
111
def decrypt (value : BsonBinary ): SingleObservable [BsonValue ] = wrapped.decrypt(value)
105
112
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
+
106
190
/**
107
191
* Create a new collection with encrypted fields,
108
192
* automatically creating
@@ -115,7 +199,7 @@ case class ClientEncryption(private val wrapped: JClientEncryption) extends Clos
115
199
* @param collectionName The name for the collection to create.
116
200
* @param createCollectionOptions Options for creating the collection.
117
201
* @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.
119
203
* A user may use this document to configure `com.mongodb.AutoEncryptionSettings.getEncryptedFieldsMap`.
120
204
*
121
205
* Produces MongoUpdatedEncryptedFieldsException` if an exception happens after creating at least one data key.
0 commit comments