Merge pull request #743 from GLYASAI/V5.2

set user and pass
This commit is contained in:
黄润豪 2020-04-15 19:33:44 +08:00 committed by GitHub
commit 242757fac1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 19 additions and 12 deletions

View File

@ -51,16 +51,7 @@ func init() {
//InitTenant 实现中间件
func InitTenant(next http.Handler) http.Handler {
fn := func(w http.ResponseWriter, r *http.Request) {
if !apiExclude(r) {
body, err := ioutil.ReadAll(r.Body)
if err != nil {
logrus.Warningf("error reading request body: %v", err)
} else {
logrus.Debugf("method: %s; uri: %s; body: %s", r.Method, r.RequestURI, string(body))
}
// set a new body, which will simulate the same data we read
r.Body = ioutil.NopCloser(bytes.NewBuffer(body))
}
debugRequestBody(r)
tenantName := chi.URLParam(r, "tenant_name")
if tenantName == "" {
@ -117,6 +108,8 @@ func InitService(next http.Handler) http.Handler {
//InitPlugin 实现plugin init中间件
func InitPlugin(next http.Handler) http.Handler {
fn := func(w http.ResponseWriter, r *http.Request) {
debugRequestBody(r)
pluginID := chi.URLParam(r, "plugin_id")
tenantID := r.Context().Value(ContextKey("tenant_id")).(string)
if pluginID == "" {
@ -282,3 +275,16 @@ func WrapEL(f http.HandlerFunc, target, optType string, synType int) http.Handle
}
}
}
func debugRequestBody(r *http.Request) {
if !apiExclude(r) {
body, err := ioutil.ReadAll(r.Body)
if err != nil {
logrus.Warningf("error reading request body: %v", err)
}
logrus.Debugf("method: %s; uri: %s; body: %s", r.Method, r.RequestURI, string(body))
// set a new body, which will simulate the same data we read
r.Body = ioutil.NopCloser(bytes.NewBuffer(body))
}
}

View File

@ -326,7 +326,7 @@ func (b *BackupAPPNew) backupPluginInfo(appSnapshot *AppSnapshot) error {
func (b *BackupAPPNew) checkVersionExist(version *dbmodel.VersionInfo) (bool, error) {
if version.DeliveredType == "image" {
imageInfo := sources.ImageNameHandle(version.DeliveredPath)
reg, err := registry.NewInsecure(imageInfo.Host, "", "")
reg, err := registry.NewInsecure(imageInfo.Host, builder.REGISTRYUSER, builder.REGISTRYPASS)
if err != nil {
logrus.Errorf("new registry client error %s", err.Error())
return false, err

View File

@ -68,7 +68,8 @@ func (e *exectorManager) pluginImageBuild(task *pb.TaskMessage) {
}
func (e *exectorManager) run(t *model.BuildPluginTaskBody, logger event.Logger) error {
if _, err := sources.ImagePull(e.DockerClient, t.ImageURL, t.ImageInfo.HubUser, t.ImageInfo.HubPassword, logger, 10); err != nil {
hubUser, hubPass := builder.GetImageUserInfo(t.ImageInfo.HubUser, t.ImageInfo.HubPassword)
if _, err := sources.ImagePull(e.DockerClient, t.ImageURL, hubUser, hubPass, logger, 10); err != nil {
logrus.Errorf("pull image %v error, %v", t.ImageURL, err)
logger.Error("拉取镜像失败", map[string]string{"step": "builder-exector", "status": "failure"})
return err