forked from mongodb/mongo-tools-common
/
auth.go
45 lines (38 loc) · 1.07 KB
/
auth.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
// Copyright (C) MongoDB, Inc. 2014-present.
//
// Licensed under the Apache License, Version 2.0 (the "License"); you may
// not use this file except in compliance with the License. You may obtain
// a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
package testutil
import (
"os"
"github.com/mongodb/mongo-tools-common/options"
"github.com/mongodb/mongo-tools-common/testtype"
)
var (
UserAdmin = "uAdmin"
UserAdminPassword = "password"
CreatedUserNameEnv = "TOOLS_TESTING_AUTH_USERNAME"
CreatedUserPasswordEnv = "TOOLS_TESTING_AUTH_PASSWORD"
)
func GetAuthOptions() options.Auth {
if testtype.HasTestType(testtype.AuthTestType) {
return options.Auth{
Username: os.Getenv(CreatedUserNameEnv),
Password: os.Getenv(CreatedUserPasswordEnv),
Source: "admin",
}
}
return options.Auth{}
}
func GetAuthArgs() []string {
authOpts := GetAuthOptions()
if authOpts.IsSet() {
return []string{
"--username", authOpts.Username,
"--password", authOpts.Password,
"--authenticationDatabase", authOpts.Source,
}
}
return nil
}