Skip to content

Commit 42b3754

Browse files
committed
GODRIVER-3429 Revert internal-only "AuthenticateToAnything".
1 parent dbd7837 commit 42b3754

File tree

6 files changed

+94
-112
lines changed

6 files changed

+94
-112
lines changed

internal/options/options.go

+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
// Copyright (C) MongoDB, Inc. 2025-present.
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License"); you may
4+
// not use this file except in compliance with the License. You may obtain
5+
// a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
6+
7+
package options
8+
9+
// Options stores internal options.
10+
type Options struct {
11+
values map[string]any
12+
}
13+
14+
// WithValue sets an option value with the associated key.
15+
func WithValue(opts Options, key string, option any) Options {
16+
if opts.values == nil {
17+
opts.values = make(map[string]any)
18+
}
19+
opts.values[key] = option
20+
return opts
21+
}
22+
23+
// Value returns the value associated with the options for key.
24+
func Value(opts Options, key string) any {
25+
if opts.values == nil {
26+
return nil
27+
}
28+
if val, ok := opts.values[key]; ok {
29+
return val
30+
}
31+
return nil
32+
}

mongo/options/clientoptions.go

+7
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ import (
2626
"go.mongodb.org/mongo-driver/v2/bson"
2727
"go.mongodb.org/mongo-driver/v2/event"
2828
"go.mongodb.org/mongo-driver/v2/internal/httputil"
29+
"go.mongodb.org/mongo-driver/v2/internal/options"
2930
"go.mongodb.org/mongo-driver/v2/mongo/readconcern"
3031
"go.mongodb.org/mongo-driver/v2/mongo/readpref"
3132
"go.mongodb.org/mongo-driver/v2/mongo/writeconcern"
@@ -295,6 +296,12 @@ type ClientOptions struct {
295296
// release.
296297
Deployment driver.Deployment
297298

299+
// Custom specifies internal options for the new Client.
300+
//
301+
// Deprecated: This option is for internal use only and should not be set. It may be changed or removed in any
302+
// release.
303+
Custom options.Options
304+
298305
connString *connstring.ConnString
299306
err error
300307
}

mongo/options/internaloptions.go

-39
This file was deleted.

mongo/options/internaloptions_test.go

-73
This file was deleted.

x/mongo/driver/options/options.go

+45
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
// Copyright (C) MongoDB, Inc. 2025-present.
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License"); you may
4+
// not use this file except in compliance with the License. You may obtain
5+
// a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
6+
7+
package options
8+
9+
import (
10+
"fmt"
11+
12+
internalOptions "go.mongodb.org/mongo-driver/v2/internal/options"
13+
"go.mongodb.org/mongo-driver/v2/mongo/options"
14+
"go.mongodb.org/mongo-driver/v2/x/mongo/driver"
15+
)
16+
17+
// SetInternalClientOptions sets internal options for ClientOptions.
18+
//
19+
// Deprecated: This function is for internal use only. It may be changed or removed in any release.
20+
func SetInternalClientOptions(opts *options.ClientOptions, key string, option any) error {
21+
const typeErr = "unexpected type for %s"
22+
switch key {
23+
case "crypt":
24+
c, ok := option.(driver.Crypt)
25+
if !ok {
26+
return fmt.Errorf(typeErr, key)
27+
}
28+
opts.Crypt = c
29+
case "deployment":
30+
d, ok := option.(driver.Deployment)
31+
if !ok {
32+
return fmt.Errorf(typeErr, key)
33+
}
34+
opts.Deployment = d
35+
case "authenticateToAnything":
36+
b, ok := option.(bool)
37+
if !ok {
38+
return fmt.Errorf(typeErr, key)
39+
}
40+
opts.Custom = internalOptions.WithValue(opts.Custom, key, b)
41+
default:
42+
return fmt.Errorf("unsupported option: %s", key)
43+
}
44+
return nil
45+
}

x/mongo/driver/topology/topology_options.go

+10
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,11 @@ import (
1515

1616
"go.mongodb.org/mongo-driver/v2/event"
1717
"go.mongodb.org/mongo-driver/v2/internal/logger"
18+
internalOptions "go.mongodb.org/mongo-driver/v2/internal/options"
1819
"go.mongodb.org/mongo-driver/v2/mongo/options"
1920
"go.mongodb.org/mongo-driver/v2/x/mongo/driver"
2021
"go.mongodb.org/mongo-driver/v2/x/mongo/driver/auth"
22+
"go.mongodb.org/mongo-driver/v2/x/mongo/driver/description"
2123
"go.mongodb.org/mongo-driver/v2/x/mongo/driver/ocsp"
2224
"go.mongodb.org/mongo-driver/v2/x/mongo/driver/operation"
2325
"go.mongodb.org/mongo-driver/v2/x/mongo/driver/session"
@@ -270,6 +272,14 @@ func NewConfigFromOptionsWithAuthenticator(opts *options.ClientOptions, clock *s
270272
// Required for SASL mechanism negotiation during handshake
271273
handshakeOpts.DBUser = opts.Auth.AuthSource + "." + opts.Auth.Username
272274
}
275+
if a := internalOptions.Value(opts.Custom, "authenticateToAnything"); a != nil {
276+
if v, ok := a.(bool); ok && v {
277+
// Authenticate arbiters
278+
handshakeOpts.PerformAuthentication = func(serv description.Server) bool {
279+
return true
280+
}
281+
}
282+
}
273283

274284
handshaker = func(driver.Handshaker) driver.Handshaker {
275285
return auth.Handshaker(nil, handshakeOpts)

0 commit comments

Comments
 (0)