-
Notifications
You must be signed in to change notification settings - Fork 5
/
localLoginHandler.go
76 lines (65 loc) · 1.82 KB
/
localLoginHandler.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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
package utils
import (
"bufio"
"fmt"
"os"
"strings"
"syscall"
"github.com/trimble-oss/tierceron/buildopts/coreopts"
helperkv "github.com/trimble-oss/tierceron/pkg/vaulthelper/kv"
//pb "github.com/trimble-oss/tierceron/trcweb/rpc/apinator"
tm "golang.org/x/term"
)
// LoginToLocal prompts the user to enter credentials from the terminal and resolves granular local environment
func LoginToLocal() (string, error) {
var username, environment string
var err error
httpsClient, err := helperkv.CreateHTTPClient(false, coreopts.BuildOptions.GetVaultHost(), "nonprod", false)
if err != nil {
return "", err
}
//client := pb.NewEnterpriseServiceBrokerProtobufClient(coreopts.BuildOptions.GetVaultHost(), httpsClient)
console := bufio.NewReader(os.Stdin)
fmt.Println("Login needed to use a local environment")
for {
// Get Sign in environment
fmt.Print("Sign In Environment: ")
environment, err = console.ReadString('\n')
if err != nil {
return "", err
}
environment = strings.TrimSpace(environment)
// Get Username
fmt.Print("Username: ")
username, err = console.ReadString('\n')
if err != nil {
return "", err
}
username = strings.TrimSpace(username)
// Get Password
fmt.Print("Password: ")
password, err := tm.ReadPassword(int(syscall.Stdin))
fmt.Println()
if err != nil {
return "", err
}
// resp, err := client.APILogin(context.Background(), &pb.LoginReq{
// Environment: environment,
// Username: username,
// Password: string(password),
// })
for i := 0; i < len(password); i++ {
password[i] = 0
}
httpsClient.CloseIdleConnections()
if err != nil {
return "", err
}
if false /* resp.Success */ {
break
} else {
fmt.Printf("Could not login for user %s in %s\n", username, environment)
}
}
return "local/" + environment + "/" + username, nil
}