3434 tlsClientCertificateKeyFile = os .Getenv ("CSFLE_TLS_CLIENT_CERT_FILE" )
3535)
3636
37- var placeholderDoc = bsoncore .NewDocumentBuilder ().AppendInt32 ("$$placeholder" , 1 ).Build ()
37+ var (
38+ // qeCollectionPattern matches collections automatically created for
39+ // queryable encryption.
40+ qeCollectionPattern = regexp .MustCompile ("^enxcol_.*.e(sc|coc)$" )
41+
42+ placeholderDoc = bsoncore .NewDocumentBuilder ().AppendInt32 ("$$placeholder" , 1 ).Build ()
43+ )
3844
3945const defaultLocalKeyBase64 = "Mng0NCt4ZHVUYUJCa1kxNkVyNUR1QURhZ2h2UzR2d2RrZzh0cFBwM3R6NmdWMDFBMUN3YkQ5aXRRMkhGRGdQV09wOGVNYUMxT2k3NjZKelhaQmRCZGJkTXVyZG9uSjFk"
4046
@@ -510,15 +516,14 @@ func (em *EntityMap) close(ctx context.Context) []error {
510516 }
511517
512518 // Clear automatically created collections used for queryable encryption
513- re := regexp .MustCompile ("^enxcol_.*.e(sc|coc)$" )
514519 for id , db := range em .dbEntites {
515520 colls , err := db .ListCollectionNames (ctx , bson.D {})
516521 if err != nil {
517522 errs = append (errs , fmt .Errorf ("error listing collections in database with ID %q: %w" , id , err ))
518523 continue
519524 }
520525 for _ , coll := range colls {
521- if re .MatchString (coll ) {
526+ if qeCollectionPattern .MatchString (coll ) {
522527 err = db .Collection (coll ).Drop (ctx )
523528 if err != nil {
524529 errs = append (errs , fmt .Errorf ("error clearing collection %q: %w" , coll , err ))
@@ -710,9 +715,6 @@ func getKmsProvider(key string, opt bson.Raw) (map[string]any, error) {
710715 default :
711716 return nil , fmt .Errorf ("unrecognized KMS provider: %s" , key )
712717 }
713- if len (provider ) == 0 {
714- return nil , nil
715- }
716718 return provider , nil
717719}
718720
@@ -726,7 +728,7 @@ func (em *EntityMap) addClientEncryptionEntity(entityOptions *entityOptions) err
726728 if err != nil {
727729 return err
728730 }
729- if provider == nil {
731+ if len ( provider ) == 0 {
730732 continue
731733 }
732734 kmsProviders [key ] = provider
0 commit comments