This commit is contained in:
ZJY 2021-09-02 14:26:10 +08:00
parent c52abaca8c
commit adad04034d
2 changed files with 18 additions and 33 deletions

View File

@ -3,6 +3,8 @@ containers:
- address: http://192.168.31.233:5700
username: admin
password: admin
cid: admin
secret: admin
weigth:
mode: parallel
limit: 9999

View File

@ -29,6 +29,8 @@ type Container struct {
Address string
Username string
Password string
Cid string
Secret string
Path string
Version string
Token string
@ -353,7 +355,7 @@ func (c *Container) getToken() error {
logs.Warn(err)
if version == "2.9" {
logs.Info("获取新版token")
req := httplib.Get(c.Address + fmt.Sprintf(`/open/auth/token?client_id=%s&client_secret=%s`, c.Username, c.Password))
req := httplib.Get(c.Address + fmt.Sprintf(`/open/auth/token?client_id=%s&client_secret=%s`, c.Cid, c.Secret))
req.Header("Content-Type", "application/json;charset=UTF-8")
if rsp, err := req.Response(); err == nil {
data, err := ioutil.ReadAll(rsp.Body)
@ -515,39 +517,20 @@ func (c *Container) postConfig(handle func(config string) string) error {
}
func (c *Container) getSession() error {
if c.Version == "2.9" {
req := httplib.Post(c.Address + "/auth")
req.Param("username", c.Username)
req.Param("password", c.Password)
rsp, err := req.Response()
if err != nil {
return err
}
c.Token = rsp.Header.Get("Set-Cookie")
if data, err := ioutil.ReadAll(rsp.Body); err != nil {
return err
} else {
err, _ := jsonparser.GetInt(data, "err")
if err != 0 {
return errors.New(string(data))
}
}
req := httplib.Post(c.Address + "/auth")
req.Param("username", c.Username)
req.Param("password", c.Password)
rsp, err := req.Response()
if err != nil {
return err
}
c.Token = rsp.Header.Get("Set-Cookie")
if data, err := ioutil.ReadAll(rsp.Body); err != nil {
return err
} else {
req := httplib.Post(c.Address + "/auth")
req.Param("username", c.Username)
req.Param("password", c.Password)
rsp, err := req.Response()
if err != nil {
return err
}
c.Token = rsp.Header.Get("Set-Cookie")
if data, err := ioutil.ReadAll(rsp.Body); err != nil {
return err
} else {
err, _ := jsonparser.GetInt(data, "err")
if err != 0 {
return errors.New(string(data))
}
err, _ := jsonparser.GetInt(data, "err")
if err != 0 {
return errors.New(string(data))
}
}
return nil