summaryrefslogtreecommitdiff
path: root/common/db
diff options
context:
space:
mode:
Diffstat (limited to 'common/db')
-rw-r--r--common/db/connector.go4
-rw-r--r--common/db/connector_test.go14
-rw-r--r--common/db/db.go7
-rw-r--r--common/db/kerberos/gssapi.go3
-rw-r--r--common/db/openssl/openssl.go6
5 files changed, 13 insertions, 21 deletions
diff --git a/common/db/connector.go b/common/db/connector.go
index 22b79c661c0..24f55286a9b 100644
--- a/common/db/connector.go
+++ b/common/db/connector.go
@@ -1,8 +1,6 @@
package db
import (
- "time"
-
"github.com/mongodb/mongo-tools/common/options"
"github.com/mongodb/mongo-tools/common/util"
"gopkg.in/mgo.v2"
@@ -32,7 +30,7 @@ func (self *VanillaDBConnector) Configure(opts options.ToolOptions) error {
// set up the dial info
self.dialInfo = &mgo.DialInfo{
Addrs: connectionAddrs,
- Timeout: time.Duration(opts.HiddenOptions.DialTimeoutSeconds) * time.Second,
+ Timeout: DefaultDialTimeout,
Direct: opts.Direct,
ReplicaSetName: opts.ReplicaSetName,
Username: opts.Auth.Username,
diff --git a/common/db/connector_test.go b/common/db/connector_test.go
index a8b4040abe0..8d5ff9a361b 100644
--- a/common/db/connector_test.go
+++ b/common/db/connector_test.go
@@ -26,15 +26,12 @@ func TestVanillaDBConnector(t *testing.T) {
Host: "host1,host2",
Port: "20000",
},
- HiddenOptions: &options.HiddenOptions{
- DialTimeoutSeconds: options.DefaultDialTimeoutSeconds,
- },
Auth: &options.Auth{},
}
So(connector.Configure(opts), ShouldBeNil)
So(connector.dialInfo.Addrs, ShouldResemble,
[]string{"host1:20000", "host2:20000"})
- So(connector.dialInfo.Timeout, ShouldResemble, options.DefaultDialTimeoutSeconds)
+ So(connector.dialInfo.Timeout, ShouldResemble, DefaultDialTimeout)
})
@@ -48,9 +45,6 @@ func TestVanillaDBConnector(t *testing.T) {
Host: "localhost",
Port: DefaultTestPort,
},
- HiddenOptions: &options.HiddenOptions{
- DialTimeoutSeconds: options.DefaultDialTimeoutSeconds,
- },
Auth: &options.Auth{},
}
So(connector.Configure(opts), ShouldBeNil)
@@ -95,9 +89,6 @@ func TestVanillaDBConnectorWithAuth(t *testing.T) {
Host: "localhost",
Port: DefaultTestPort,
},
- HiddenOptions: &options.HiddenOptions{
- DialTimeoutSeconds: options.DefaultDialTimeoutSeconds,
- },
Auth: &options.Auth{},
}
So(connector.Configure(opts), ShouldBeNil)
@@ -121,9 +112,6 @@ func TestVanillaDBConnectorWithAuth(t *testing.T) {
Host: "localhost",
Port: DefaultTestPort,
},
- HiddenOptions: &options.HiddenOptions{
- DialTimeoutSeconds: options.DefaultDialTimeoutSeconds,
- },
Auth: &options.Auth{
Username: "cAdmin",
Password: "password",
diff --git a/common/db/db.go b/common/db/db.go
index 8d617b8ff10..e100ef42de1 100644
--- a/common/db/db.go
+++ b/common/db/db.go
@@ -3,15 +3,15 @@
package db
import (
+ "fmt"
"github.com/mongodb/mongo-tools/common/options"
"github.com/mongodb/mongo-tools/common/password"
"gopkg.in/mgo.v2"
"gopkg.in/mgo.v2/bson"
-
- "fmt"
"io"
"strings"
"sync"
+ "time"
)
type (
@@ -51,7 +51,8 @@ const (
)
var (
- GetConnectorFuncs = []GetConnectorFunc{}
+ DefaultDialTimeout = time.Second * 3
+ GetConnectorFuncs = []GetConnectorFunc{}
)
// Used to manage database sessions
diff --git a/common/db/kerberos/gssapi.go b/common/db/kerberos/gssapi.go
index c97c34a7188..51f531fab1b 100644
--- a/common/db/kerberos/gssapi.go
+++ b/common/db/kerberos/gssapi.go
@@ -12,6 +12,7 @@ import (
)
const (
+ KERBEROS_DIAL_TIMEOUT = time.Second * 3
KERBEROS_AUTHENTICATION_MECHANISM = "GSSAPI"
)
@@ -29,7 +30,7 @@ func (self *KerberosDBConnector) Configure(opts options.ToolOptions) error {
// set up the dial info
self.dialInfo = &mgo.DialInfo{
Addrs: connectionAddrs,
- Timeout: time.Duration(opts.HiddenOptions.DialTimeoutSeconds) * time.Second,
+ Timeout: KERBEROS_DIAL_TIMEOUT,
Direct: opts.Direct,
ReplicaSetName: opts.ReplicaSetName,
diff --git a/common/db/openssl/openssl.go b/common/db/openssl/openssl.go
index 2fa725676bf..36a788de027 100644
--- a/common/db/openssl/openssl.go
+++ b/common/db/openssl/openssl.go
@@ -13,6 +13,10 @@ import (
"github.com/spacemonkeygo/openssl"
)
+var (
+ DefaultSSLDialTimeout = time.Second * 3
+)
+
// For connecting to the database over ssl
type SSLDBConnector struct {
dialInfo *mgo.DialInfo
@@ -49,7 +53,7 @@ func (self *SSLDBConnector) Configure(opts options.ToolOptions) error {
// set up the dial info
self.dialInfo = &mgo.DialInfo{
Addrs: connectionAddrs,
- Timeout: time.Duration(opts.HiddenOptions.DialTimeoutSeconds) * time.Second,
+ Timeout: DefaultSSLDialTimeout,
Direct: opts.Direct,
ReplicaSetName: opts.ReplicaSetName,
DialServer: dialer,