1- // Copyright (C) MongoDB, Inc. 2017-present. 
21// 
2+ // Copyright (C) MongoDB, Inc. 2017-present. 
33// Licensed under the Apache License, Version 2.0 (the "License"); you may 
44// not use this file except in compliance with the License. You may obtain 
55// a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 
@@ -471,12 +471,7 @@ func (c *Client) endSessions(ctx context.Context) {
471471}
472472
473473func  (c  * Client ) configureAutoEncryption (args  * options.ClientOptions ) error  {
474- 	aeArgs , err  :=  mongoutil.NewOptions [options.AutoEncryptionOptions ](args .AutoEncryptionOptions )
475- 	if  err  !=  nil  {
476- 		return  fmt .Errorf ("failed to construct options from builder: %w" , err )
477- 	}
478- 
479- 	c .encryptedFieldsMap  =  aeArgs .EncryptedFieldsMap 
474+ 	c .encryptedFieldsMap  =  args .AutoEncryptionOptions .EncryptedFieldsMap 
480475	if  err  :=  c .configureKeyVaultClientFLE (args ); err  !=  nil  {
481476		return  err 
482477	}
@@ -519,60 +514,51 @@ func (c *Client) getOrCreateInternalClient(args *options.ClientOptions) (*Client
519514	return  c .internalClientFLE , err 
520515}
521516
522- func  (c  * Client ) configureKeyVaultClientFLE (clientArgs  * options.ClientOptions ) error  {
523- 	// parse key vault options and create new key vault client 
524- 	aeArgs , err  :=  mongoutil.NewOptions [options.AutoEncryptionOptions ](clientArgs .AutoEncryptionOptions )
525- 	if  err  !=  nil  {
526- 		return  fmt .Errorf ("failed to construct options from builder: %w" , err )
527- 	}
517+ func  (c  * Client ) configureKeyVaultClientFLE (clientOpts  * options.ClientOptions ) error  {
518+ 	aeOpts  :=  clientOpts .AutoEncryptionOptions 
519+ 
520+ 	var  err  error 
528521
529522	switch  {
530- 	case  aeArgs .KeyVaultClientOptions  !=  nil :
531- 		c .keyVaultClientFLE , err  =  newClient (aeArgs .KeyVaultClientOptions )
532- 	case  clientArgs .MaxPoolSize  !=  nil  &&  * clientArgs .MaxPoolSize  ==  0 :
523+ 	case  aeOpts .KeyVaultClientOptions  !=  nil :
524+ 		c .keyVaultClientFLE , err  =  newClient (aeOpts .KeyVaultClientOptions )
525+ 	case  clientOpts .MaxPoolSize  !=  nil  &&  * clientOpts .MaxPoolSize  ==  0 :
533526		c .keyVaultClientFLE  =  c 
534527	default :
535- 		c .keyVaultClientFLE , err  =  c .getOrCreateInternalClient (clientArgs )
528+ 		c .keyVaultClientFLE , err  =  c .getOrCreateInternalClient (clientOpts )
536529	}
537530
538531	if  err  !=  nil  {
539532		return  err 
540533	}
541534
542- 	dbName , collName  :=  splitNamespace (aeArgs .KeyVaultNamespace )
535+ 	dbName , collName  :=  splitNamespace (aeOpts .KeyVaultNamespace )
543536	c .keyVaultCollFLE  =  c .keyVaultClientFLE .Database (dbName ).Collection (collName , keyVaultCollOpts )
544537	return  nil 
545538}
546539
547- func  (c  * Client ) configureMetadataClientFLE (clientArgs  * options.ClientOptions ) error  {
548- 	// parse key vault options and create new key vault client 
549- 	aeArgs , err  :=  mongoutil.NewOptions [options.AutoEncryptionOptions ](clientArgs .AutoEncryptionOptions )
550- 	if  err  !=  nil  {
551- 		return  fmt .Errorf ("failed to construct options from builder: %w" , err )
552- 	}
540+ func  (c  * Client ) configureMetadataClientFLE (clientOpts  * options.ClientOptions ) error  {
541+ 	aeOpts  :=  clientOpts .AutoEncryptionOptions 
553542
554- 	if  aeArgs .BypassAutoEncryption  !=  nil  &&  * aeArgs .BypassAutoEncryption  {
543+ 	if  aeOpts .BypassAutoEncryption  !=  nil  &&  * aeOpts .BypassAutoEncryption  {
555544		// no need for a metadata client. 
556545		return  nil 
557546	}
558- 	if  clientArgs .MaxPoolSize  !=  nil  &&  * clientArgs .MaxPoolSize  ==  0  {
547+ 	if  clientOpts .MaxPoolSize  !=  nil  &&  * clientOpts .MaxPoolSize  ==  0  {
559548		c .metadataClientFLE  =  c 
560549		return  nil 
561550	}
562551
563- 	c .metadataClientFLE , err  =  c .getOrCreateInternalClient (clientArgs )
552+ 	var  err  error 
553+ 	c .metadataClientFLE , err  =  c .getOrCreateInternalClient (clientOpts )
554+ 
564555	return  err 
565556}
566557
567- func  (c  * Client ) newMongoCrypt (opts  options.Lister [options.AutoEncryptionOptions ]) (* mongocrypt.MongoCrypt , error ) {
568- 	args , err  :=  mongoutil.NewOptions [options.AutoEncryptionOptions ](opts )
569- 	if  err  !=  nil  {
570- 		return  nil , fmt .Errorf ("failed to construct options from builder: %w" , err )
571- 	}
572- 
558+ func  (c  * Client ) newMongoCrypt (opts  * options.AutoEncryptionOptions ) (* mongocrypt.MongoCrypt , error ) {
573559	// convert schemas in SchemaMap to bsoncore documents 
574560	cryptSchemaMap  :=  make (map [string ]bsoncore.Document )
575- 	for  k , v  :=  range  args .SchemaMap  {
561+ 	for  k , v  :=  range  opts .SchemaMap  {
576562		schema , err  :=  marshal (v , c .bsonOpts , c .registry )
577563		if  err  !=  nil  {
578564			return  nil , err 
@@ -582,23 +568,23 @@ func (c *Client) newMongoCrypt(opts options.Lister[options.AutoEncryptionOptions
582568
583569	// convert schemas in EncryptedFieldsMap to bsoncore documents 
584570	cryptEncryptedFieldsMap  :=  make (map [string ]bsoncore.Document )
585- 	for  k , v  :=  range  args .EncryptedFieldsMap  {
571+ 	for  k , v  :=  range  opts .EncryptedFieldsMap  {
586572		encryptedFields , err  :=  marshal (v , c .bsonOpts , c .registry )
587573		if  err  !=  nil  {
588574			return  nil , err 
589575		}
590576		cryptEncryptedFieldsMap [k ] =  encryptedFields 
591577	}
592578
593- 	kmsProviders , err  :=  marshal (args .KmsProviders , c .bsonOpts , c .registry )
579+ 	kmsProviders , err  :=  marshal (opts .KmsProviders , c .bsonOpts , c .registry )
594580	if  err  !=  nil  {
595581		return  nil , fmt .Errorf ("error creating KMS providers document: %w" , err )
596582	}
597583
598584	// Set the crypt_shared library override path from the "cryptSharedLibPath" extra option if one 
599585	// was set. 
600586	cryptSharedLibPath  :=  "" 
601- 	if  val , ok  :=  args .ExtraOptions ["cryptSharedLibPath" ]; ok  {
587+ 	if  val , ok  :=  opts .ExtraOptions ["cryptSharedLibPath" ]; ok  {
602588		str , ok  :=  val .(string )
603589		if  ! ok  {
604590			return  nil , fmt .Errorf (
@@ -611,12 +597,12 @@ func (c *Client) newMongoCrypt(opts options.Lister[options.AutoEncryptionOptions
611597	// intended for use from tests; there is no supported public API for explicitly disabling 
612598	// loading the crypt_shared library. 
613599	cryptSharedLibDisabled  :=  false 
614- 	if  v , ok  :=  args .ExtraOptions ["__cryptSharedLibDisabledForTestOnly" ]; ok  {
600+ 	if  v , ok  :=  opts .ExtraOptions ["__cryptSharedLibDisabledForTestOnly" ]; ok  {
615601		cryptSharedLibDisabled  =  v .(bool )
616602	}
617603
618- 	bypassAutoEncryption  :=  args .BypassAutoEncryption  !=  nil  &&  * args .BypassAutoEncryption 
619- 	bypassQueryAnalysis  :=  args .BypassQueryAnalysis  !=  nil  &&  * args .BypassQueryAnalysis 
604+ 	bypassAutoEncryption  :=  opts .BypassAutoEncryption  !=  nil  &&  * opts .BypassAutoEncryption 
605+ 	bypassQueryAnalysis  :=  opts .BypassQueryAnalysis  !=  nil  &&  * opts .BypassQueryAnalysis 
620606
621607	mc , err  :=  mongocrypt .NewMongoCrypt (mcopts .MongoCrypt ().
622608		SetKmsProviders (kmsProviders ).
@@ -625,13 +611,13 @@ func (c *Client) newMongoCrypt(opts options.Lister[options.AutoEncryptionOptions
625611		SetEncryptedFieldsMap (cryptEncryptedFieldsMap ).
626612		SetCryptSharedLibDisabled (cryptSharedLibDisabled  ||  bypassAutoEncryption ).
627613		SetCryptSharedLibOverridePath (cryptSharedLibPath ).
628- 		SetHTTPClient (args .HTTPClient ))
614+ 		SetHTTPClient (opts .HTTPClient ))
629615	if  err  !=  nil  {
630616		return  nil , err 
631617	}
632618
633619	var  cryptSharedLibRequired  bool 
634- 	if  val , ok  :=  args .ExtraOptions ["cryptSharedLibRequired" ]; ok  {
620+ 	if  val , ok  :=  opts .ExtraOptions ["cryptSharedLibRequired" ]; ok  {
635621		b , ok  :=  val .(bool )
636622		if  ! ok  {
637623			return  nil , fmt .Errorf (
@@ -652,10 +638,8 @@ func (c *Client) newMongoCrypt(opts options.Lister[options.AutoEncryptionOptions
652638}
653639
654640//nolint:unused // the unused linter thinks that this function is unreachable because "c.newMongoCrypt" always panics without the "cse" build tag set. 
655- func  (c  * Client ) configureCryptFLE (mc  * mongocrypt.MongoCrypt , opts  options.Lister [options.AutoEncryptionOptions ]) {
656- 	args , _  :=  mongoutil.NewOptions [options.AutoEncryptionOptions ](opts )
657- 
658- 	bypass  :=  args .BypassAutoEncryption  !=  nil  &&  * args .BypassAutoEncryption 
641+ func  (c  * Client ) configureCryptFLE (mc  * mongocrypt.MongoCrypt , opts  * options.AutoEncryptionOptions ) {
642+ 	bypass  :=  opts .BypassAutoEncryption  !=  nil  &&  * opts .BypassAutoEncryption 
659643	kr  :=  keyRetriever {coll : c .keyVaultCollFLE }
660644	var  cir  collInfoRetriever 
661645	// If bypass is true, c.metadataClientFLE is nil and the collInfoRetriever 
@@ -670,7 +654,7 @@ func (c *Client) configureCryptFLE(mc *mongocrypt.MongoCrypt, opts options.Liste
670654		CollInfoFn :           cir .cryptCollInfo ,
671655		KeyFn :                kr .cryptKeys ,
672656		MarkFn :               c .mongocryptdFLE .markCommand ,
673- 		TLSConfig :            args .TLSConfig ,
657+ 		TLSConfig :            opts .TLSConfig ,
674658		BypassAutoEncryption : bypass ,
675659	})
676660}
@@ -892,28 +876,23 @@ func (c *Client) createBaseCursorOptions() driver.CursorOptions {
892876
893877// newLogger will use the LoggerOptions to create an internal logger and publish 
894878// messages using a LogSink. 
895- func  newLogger (opts  options.Lister [options. LoggerOptions ] ) (* logger.Logger , error ) {
879+ func  newLogger (opts  * options.LoggerOptions ) (* logger.Logger , error ) {
896880	// If there are no logger options, then create a default logger. 
897881	if  opts  ==  nil  {
898882		opts  =  options .Logger ()
899883	}
900884
901- 	args , err  :=  mongoutil.NewOptions [options.LoggerOptions ](opts )
902- 	if  err  !=  nil  {
903- 		return  nil , fmt .Errorf ("failed to construct options from builder: %w" , err )
904- 	}
905- 
906885	// If there are no component-level options and the environment does not 
907886	// contain component variables, then do nothing. 
908- 	if  len (args .ComponentLevels ) ==  0  &&  ! logger .EnvHasComponentVariables () {
887+ 	if  len (opts .ComponentLevels ) ==  0  &&  ! logger .EnvHasComponentVariables () {
909888		return  nil , nil 
910889	}
911890
912891	// Otherwise, collect the component-level options and create a logger. 
913892	componentLevels  :=  make (map [logger.Component ]logger.Level )
914- 	for  component , level  :=  range  args .ComponentLevels  {
893+ 	for  component , level  :=  range  opts .ComponentLevels  {
915894		componentLevels [logger .Component (component )] =  logger .Level (level )
916895	}
917896
918- 	return  logger .New (args .Sink , args .MaxDocumentLength , componentLevels )
897+ 	return  logger .New (opts .Sink , opts .MaxDocumentLength , componentLevels )
919898}
0 commit comments