-
Notifications
You must be signed in to change notification settings - Fork 4.7k
/
mongodb.go
59 lines (50 loc) · 1.41 KB
/
mongodb.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
package db
import (
"errors"
"fmt"
"github.com/openshift/origin/test/extended/util"
)
// MongoDB is a MongoDB helper for executing commands.
type MongoDB struct {
podName string
masterPodName string
}
// NewMongoDB creates a new util.Database instance.
func NewMongoDB(podName, masterPodName string) util.Database {
if masterPodName == "" {
masterPodName = podName
}
return &MongoDB{
podName: podName,
masterPodName: masterPodName,
}
}
// PodName implements Database.
func (m MongoDB) PodName() string {
return m.podName
}
// IsReady pings the MongoDB server.
func (m MongoDB) IsReady(oc *util.CLI) (bool, error) {
return isReady(
oc,
m.podName,
`mongo --quiet --eval '{"ping", 1}'`,
"1",
)
}
// Query executes a query as an ordinary user and returns the result.
func (m MongoDB) Query(oc *util.CLI, query string) (string, error) {
return executeShellCommand(
oc,
m.podName,
fmt.Sprintf(`mongo --quiet "$MONGODB_DATABASE" --username "$MONGODB_USER" --password "$MONGODB_PASSWORD" --eval '%s'`, query),
)
}
// QueryPrivileged queries the database as a privileged user.
func (m MongoDB) QueryPrivileged(oc *util.CLI, query string) (string, error) {
return "", errors.New("not implemented")
}
// TestRemoteLogin tests wheather it is possible to remote login to hostAddress.
func (m MongoDB) TestRemoteLogin(oc *util.CLI, hostAddress string) error {
return errors.New("not implemented")
}