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
package service
import (
"os"
"path"
"path/filepath"
"time"
"cocogo/pkg/common"
"cocogo/pkg/config"
"cocogo/pkg/logger"
)
var client = common.NewClient(30, "")
var authClient = common.NewClient(30, "")
func Initial() {
keyPath := config.Conf.AccessKeyFile
client.BaseHost = config.Conf.CoreHost
authClient.BaseHost = config.Conf.CoreHost
if !path.IsAbs(config.Conf.AccessKeyFile) {
keyPath = filepath.Join(config.Conf.RootPath, keyPath)
}
ak := AccessKey{Value: config.Conf.AccessKey, Path: keyPath}
_ = ak.Load()
authClient.Auth = ak
ValidateAccessAuth()
}
func ValidateAccessAuth() {
count := 0
for count < 100 {
user := getTerminalProfile()
if user.Id != "" {
break
}
msg := `Connect server error or access key is invalid,
remove %s run again`
logger.Errorf(msg, config.Conf.AccessKeyFile)
time.Sleep(3 * time.Second)
count++
if count >= 3 {
os.Exit(1)
}
}
}