Skip to content
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 10 additions & 9 deletions mongo/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -651,15 +651,16 @@ func (c *Client) newMongoCrypt(opts *options.AutoEncryptionOptions) (*mongocrypt
bypassAutoEncryption := opts.BypassAutoEncryption != nil && *opts.BypassAutoEncryption
bypassQueryAnalysis := opts.BypassQueryAnalysis != nil && *opts.BypassQueryAnalysis

mc, err := mongocrypt.NewMongoCrypt(mcopts.MongoCrypt().
SetKmsProviders(kmsProviders).
SetLocalSchemaMap(cryptSchemaMap).
SetBypassQueryAnalysis(bypassQueryAnalysis).
SetEncryptedFieldsMap(cryptEncryptedFieldsMap).
SetCryptSharedLibDisabled(cryptSharedLibDisabled || bypassAutoEncryption).
SetCryptSharedLibOverridePath(cryptSharedLibPath).
SetHTTPClient(opts.HTTPClient).
SetKeyExpiration(opts.KeyExpiration))
mc, err := mongocrypt.NewMongoCrypt(&mcopts.MongoCryptOptions{
KmsProviders: kmsProviders,
LocalSchemaMap: cryptSchemaMap,
BypassQueryAnalysis: bypassQueryAnalysis,
EncryptedFieldsMap: cryptEncryptedFieldsMap,
CryptSharedLibDisabled: cryptSharedLibDisabled || bypassAutoEncryption,
CryptSharedLibOverridePath: cryptSharedLibPath,
HTTPClient: opts.HTTPClient,
KeyExpiration: opts.KeyExpiration,
})
if err != nil {
return nil, err
}
Expand Down
14 changes: 6 additions & 8 deletions mongo/client_encryption.go
Original file line number Diff line number Diff line change
Expand Up @@ -53,14 +53,12 @@ func NewClientEncryption(keyVaultClient *Client, opts ...options.Lister[options.
return nil, fmt.Errorf("error creating KMS providers map: %w", err)
}

mc, err := mongocrypt.NewMongoCrypt(mcopts.MongoCrypt().
SetKmsProviders(kmsProviders).
// Explicitly disable loading the crypt_shared library for the Crypt used for
// ClientEncryption because it's only needed for AutoEncryption and we don't expect users to
// have the crypt_shared library installed if they're using ClientEncryption.
SetCryptSharedLibDisabled(true).
SetHTTPClient(cea.HTTPClient).
SetKeyExpiration(cea.KeyExpiration))
mc, err := mongocrypt.NewMongoCrypt(&mcopts.MongoCryptOptions{
KmsProviders: kmsProviders,
CryptSharedLibDisabled: true,
HTTPClient: cea.HTTPClient,
KeyExpiration: cea.KeyExpiration,
})
if err != nil {
return nil, err
}
Expand Down
55 changes: 0 additions & 55 deletions x/mongo/driver/mongocrypt/options/mongocrypt_options.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,58 +24,3 @@ type MongoCryptOptions struct {
HTTPClient *http.Client
KeyExpiration *time.Duration
}

// MongoCrypt creates a new MongoCryptOptions instance.
func MongoCrypt() *MongoCryptOptions {
return &MongoCryptOptions{}
}

// SetKmsProviders specifies the KMS providers map.
func (mo *MongoCryptOptions) SetKmsProviders(kmsProviders bsoncore.Document) *MongoCryptOptions {
mo.KmsProviders = kmsProviders
return mo
}

// SetLocalSchemaMap specifies the local schema map.
func (mo *MongoCryptOptions) SetLocalSchemaMap(localSchemaMap map[string]bsoncore.Document) *MongoCryptOptions {
mo.LocalSchemaMap = localSchemaMap
return mo
}

// SetBypassQueryAnalysis skips the NeedMongoMarkings state.
func (mo *MongoCryptOptions) SetBypassQueryAnalysis(bypassQueryAnalysis bool) *MongoCryptOptions {
mo.BypassQueryAnalysis = bypassQueryAnalysis
return mo
}

// SetEncryptedFieldsMap specifies the encrypted fields map.
func (mo *MongoCryptOptions) SetEncryptedFieldsMap(efcMap map[string]bsoncore.Document) *MongoCryptOptions {
mo.EncryptedFieldsMap = efcMap
return mo
}

// SetCryptSharedLibDisabled explicitly disables loading the crypt_shared library if set to true.
func (mo *MongoCryptOptions) SetCryptSharedLibDisabled(disabled bool) *MongoCryptOptions {
mo.CryptSharedLibDisabled = disabled
return mo
}

// SetCryptSharedLibOverridePath sets the override path to the crypt_shared library file. Setting
// an override path disables the default operating system dynamic library search path.
func (mo *MongoCryptOptions) SetCryptSharedLibOverridePath(path string) *MongoCryptOptions {
mo.CryptSharedLibOverridePath = path
return mo
}

// SetHTTPClient sets the http client.
func (mo *MongoCryptOptions) SetHTTPClient(httpClient *http.Client) *MongoCryptOptions {
mo.HTTPClient = httpClient
return mo
}

// SetKeyExpiration sets the key expiration duration. 0 means "never expire".
// The granularity is in milliseconds. Any sub-millisecond fraction will be rounded up.
func (mo *MongoCryptOptions) SetKeyExpiration(expiration *time.Duration) *MongoCryptOptions {
mo.KeyExpiration = expiration
return mo
}
Loading