mirror of
https://gitee.com/rainbond/Rainbond.git
synced 2024-11-30 10:48:15 +08:00
[FIX] remove git auth when no user and password
This commit is contained in:
parent
a95dc2997a
commit
3f149edc71
@ -19,41 +19,43 @@
|
|||||||
package apiHandler
|
package apiHandler
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/Sirupsen/logrus"
|
"bytes"
|
||||||
"github.com/pquerna/ffjson/ffjson"
|
"fmt"
|
||||||
|
"io/ioutil"
|
||||||
|
"net/http"
|
||||||
"os"
|
"os"
|
||||||
"strings"
|
"strings"
|
||||||
"net/http"
|
|
||||||
"fmt"
|
"github.com/Sirupsen/logrus"
|
||||||
"bytes"
|
|
||||||
"github.com/goodrain/rainbond/pkg/worker/discover/model"
|
"github.com/goodrain/rainbond/pkg/worker/discover/model"
|
||||||
|
"github.com/pquerna/ffjson/ffjson"
|
||||||
)
|
)
|
||||||
|
|
||||||
//UpgradeService 滚动升级
|
//UpgradeService 滚动升级
|
||||||
func UpgradeService(tenantName, serviceAlias string ,ru *model.RollingUpgradeTaskBody) error {
|
func UpgradeService(tenantName, serviceAlias string, ru *model.RollingUpgradeTaskBody) error {
|
||||||
url := fmt.Sprintf("http://127.0.0.1:8888/v2/tenants/%s/services/%s/upgrade", tenantName, serviceAlias)
|
url := fmt.Sprintf("http://127.0.0.1:8888/v2/tenants/%s/services/%s/upgrade", tenantName, serviceAlias)
|
||||||
logrus.Debugf("rolling update new version: %s, url is %s", ru.NewDeployVersion, url)
|
logrus.Debugf("rolling update new version: %s, url is %s", ru.NewDeployVersion, url)
|
||||||
raw := struct {
|
raw := struct {
|
||||||
DeployVersion string `json:"deploy_version"`
|
DeployVersion string `json:"deploy_version"`
|
||||||
EventID string `json:"event_id"`
|
EventID string `json:"event_id"`
|
||||||
}{
|
}{
|
||||||
DeployVersion:ru.CurrentDeployVersion,
|
DeployVersion: ru.CurrentDeployVersion,
|
||||||
EventID:ru.EventID,
|
EventID: ru.EventID,
|
||||||
}
|
}
|
||||||
rawBody, err := ffjson.Marshal(raw)
|
rawBody, err := ffjson.Marshal(raw)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
return publicRequest("post", url,rawBody)
|
return publicRequest("post", url, rawBody)
|
||||||
}
|
}
|
||||||
|
|
||||||
func publicRequest(method, url string, body...[]byte) error {
|
func publicRequest(method, url string, body ...[]byte) error {
|
||||||
client := &http.Client{}
|
client := &http.Client{}
|
||||||
var rawBody *bytes.Buffer
|
var rawBody *bytes.Buffer
|
||||||
if len(body) != 0 {
|
if len(body) != 0 {
|
||||||
rawBody = bytes.NewBuffer(body[0])
|
rawBody = bytes.NewBuffer(body[0])
|
||||||
}else {
|
} else {
|
||||||
rawBody = nil
|
rawBody = nil
|
||||||
}
|
}
|
||||||
request, _ := http.NewRequest(strings.ToUpper(method), url, rawBody)
|
request, _ := http.NewRequest(strings.ToUpper(method), url, rawBody)
|
||||||
token := os.Getenv("TOKEN")
|
token := os.Getenv("TOKEN")
|
||||||
@ -61,9 +63,13 @@ func publicRequest(method, url string, body...[]byte) error {
|
|||||||
request.Header.Set("Authorization", "Token "+token)
|
request.Header.Set("Authorization", "Token "+token)
|
||||||
}
|
}
|
||||||
response, _ := client.Do(request)
|
response, _ := client.Do(request)
|
||||||
if response.StatusCode == 200 {
|
if response.StatusCode == 200 {
|
||||||
//body, _ := ioutil.ReadAll(response.Body)
|
return nil
|
||||||
return nil
|
|
||||||
}
|
}
|
||||||
return fmt.Errorf("send upgrade mission error")
|
str := ""
|
||||||
}
|
if response != nil && response.Body != nil {
|
||||||
|
body, _ := ioutil.ReadAll(response.Body)
|
||||||
|
str = string(body)
|
||||||
|
}
|
||||||
|
return fmt.Errorf("send upgrade mission error,response body:%s", str)
|
||||||
|
}
|
||||||
|
@ -110,6 +110,7 @@ func (i *ImageBuildItem) Run(timeout time.Duration) error {
|
|||||||
if err := apiHandler.UpgradeService(i.TenantName, i.ServiceAlias, i.CreateUpgradeTaskBody()); err != nil {
|
if err := apiHandler.UpgradeService(i.TenantName, i.ServiceAlias, i.CreateUpgradeTaskBody()); err != nil {
|
||||||
i.Logger.Error("启动应用失败,请手动启动", map[string]string{"step": "callback", "status": "failure"})
|
i.Logger.Error("启动应用失败,请手动启动", map[string]string{"step": "callback", "status": "failure"})
|
||||||
logrus.Errorf("rolling update service error, %s", err.Error())
|
logrus.Errorf("rolling update service error, %s", err.Error())
|
||||||
|
return err
|
||||||
}
|
}
|
||||||
i.Logger.Info("应用启动成功", map[string]string{"step": "build-exector"})
|
i.Logger.Info("应用启动成功", map[string]string{"step": "build-exector"})
|
||||||
return nil
|
return nil
|
||||||
|
@ -165,6 +165,7 @@ func (i *SourceCodeBuildItem) Run(timeout time.Duration) error {
|
|||||||
if err := apiHandler.UpgradeService(i.TenantName, i.ServiceAlias, i.CreateUpgradeTaskBody()); err != nil {
|
if err := apiHandler.UpgradeService(i.TenantName, i.ServiceAlias, i.CreateUpgradeTaskBody()); err != nil {
|
||||||
i.Logger.Error("启动应用失败,请手动启动", map[string]string{"step": "callback", "status": "failure"})
|
i.Logger.Error("启动应用失败,请手动启动", map[string]string{"step": "callback", "status": "failure"})
|
||||||
logrus.Errorf("rolling update service error, %s", err.Error())
|
logrus.Errorf("rolling update service error, %s", err.Error())
|
||||||
|
return err
|
||||||
}
|
}
|
||||||
i.Logger.Info("应用启动成功", map[string]string{"step": "build-exector"})
|
i.Logger.Info("应用启动成功", map[string]string{"step": "build-exector"})
|
||||||
return nil
|
return nil
|
||||||
|
@ -141,11 +141,13 @@ func GitClone(csi CodeSourceInfo, sourceDir string, logger event.Logger, timeout
|
|||||||
opts.Auth = sshAuth
|
opts.Auth = sshAuth
|
||||||
rs, err = git.PlainCloneContext(ctx, sourceDir, false, opts)
|
rs, err = git.PlainCloneContext(ctx, sourceDir, false, opts)
|
||||||
} else {
|
} else {
|
||||||
httpAuth := &http.BasicAuth{
|
if csi.User != "" && csi.Password != "" {
|
||||||
Username: csi.User,
|
httpAuth := &http.BasicAuth{
|
||||||
Password: csi.Password,
|
Username: csi.User,
|
||||||
|
Password: csi.Password,
|
||||||
|
}
|
||||||
|
opts.Auth = httpAuth
|
||||||
}
|
}
|
||||||
opts.Auth = httpAuth
|
|
||||||
rs, err = git.PlainCloneContext(ctx, sourceDir, false, opts)
|
rs, err = git.PlainCloneContext(ctx, sourceDir, false, opts)
|
||||||
}
|
}
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
Loading…
Reference in New Issue
Block a user