Skip to content

Commit

Permalink
GODRIVER-3333 (options.ClientOptions).SetAuth with MONGODB-AWS does n…
Browse files Browse the repository at this point in the history
…ot set default $external AuthSource
  • Loading branch information
blink1073 committed Sep 10, 2024
1 parent 06ccb6e commit a107bb4
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 18 deletions.
3 changes: 0 additions & 3 deletions x/mongo/driver/auth/auth.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,6 @@ import (

const sourceExternal = "$external"

// Config contains the configuration for an Authenticator.
type Config = driver.AuthConfig

// AuthenticatorFactory constructs an authenticator.
type AuthenticatorFactory func(*Cred, *http.Client) (Authenticator, error)

Expand Down
2 changes: 0 additions & 2 deletions x/mongo/driver/auth/plain_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@ import (
"strings"
"testing"

"encoding/base64"

"go.mongodb.org/mongo-driver/v2/internal/require"
"go.mongodb.org/mongo-driver/v2/x/bsonx/bsoncore"
"go.mongodb.org/mongo-driver/v2/x/mongo/driver"
Expand Down
18 changes: 5 additions & 13 deletions x/mongo/driver/topology/topology_options.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ import (
"go.mongodb.org/mongo-driver/v2/mongo/options"
"go.mongodb.org/mongo-driver/v2/x/mongo/driver"
"go.mongodb.org/mongo-driver/v2/x/mongo/driver/auth"
"go.mongodb.org/mongo-driver/v2/x/mongo/driver/description"
"go.mongodb.org/mongo-driver/v2/x/mongo/driver/ocsp"
"go.mongodb.org/mongo-driver/v2/x/mongo/driver/operation"
"go.mongodb.org/mongo-driver/v2/x/mongo/driver/session"
Expand Down Expand Up @@ -148,9 +147,9 @@ func NewConfigFromOptions(opts *options.ClientOptions, clock *session.ClusterClo
var err error
if opts.Auth != nil {
authenticator, err = auth.CreateAuthenticator(
co.Auth.AuthMechanism,
ConvertCreds(co.Auth),
co.HTTPClient,
opts.Auth.AuthMechanism,
ConvertCreds(opts.Auth),
opts.HTTPClient,
)
if err != nil {
return nil, fmt.Errorf("error creating authenticator: %w", err)
Expand Down Expand Up @@ -273,16 +272,9 @@ func NewConfigFromOptionsWithAuthenticator(opts *options.ClientOptions, clock *s
ClusterClock: clock,
}

if co.Auth.AuthMechanism == "" {
if opts.Auth.AuthMechanism == "" {
// Required for SASL mechanism negotiation during handshake
handshakeOpts.DBUser = co.Auth.AuthSource + "." + co.Auth.Username
}

if co.AuthenticateToAnything != nil && *co.AuthenticateToAnything {
// Authenticate arbiters
handshakeOpts.PerformAuthentication = func(serv description.Server) bool {
return true
}
handshakeOpts.DBUser = opts.Auth.AuthSource + "." + opts.Auth.Username
}

handshaker = func(driver.Handshaker) driver.Handshaker {
Expand Down

0 comments on commit a107bb4

Please sign in to comment.