From 4b3c9419f39e58c4aab1992b7bc062fca9cb8d0f Mon Sep 17 00:00:00 2001 From: ssongliu <73214554+ssongliu@users.noreply.github.com> Date: Tue, 30 May 2023 13:56:57 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E9=95=9C=E5=83=8F=E4=BB=93=E5=BA=93?= =?UTF-8?q?=E6=A0=A1=E9=AA=8C=E5=88=A4=E6=96=AD=E4=BF=AE=E6=94=B9=20(#1187?= =?UTF-8?q?)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- backend/app/service/image_repo.go | 26 ++++++++++++++++---------- 1 file changed, 16 insertions(+), 10 deletions(-) diff --git a/backend/app/service/image_repo.go b/backend/app/service/image_repo.go index 2714821c2..5083644ea 100644 --- a/backend/app/service/image_repo.go +++ b/backend/app/service/image_repo.go @@ -50,9 +50,11 @@ func (u *ImageRepoService) Login(req dto.OperateByID) error { if err != nil { return err } - if err := u.CheckConn(repo.DownloadUrl, repo.Username, repo.Password); err != nil { - _ = imageRepoRepo.Update(repo.ID, map[string]interface{}{"status": constant.StatusFailed, "message": err.Error}) - return err + if repo.Auth { + if err := u.CheckConn(repo.DownloadUrl, repo.Username, repo.Password); err != nil { + _ = imageRepoRepo.Update(repo.ID, map[string]interface{}{"status": constant.StatusFailed, "message": err.Error()}) + return err + } } _ = imageRepoRepo.Update(repo.ID, map[string]interface{}{"status": constant.StatusSuccess}) return nil @@ -111,9 +113,11 @@ func (u *ImageRepoService) Create(req dto.ImageRepoCreate) error { } imageRepo.Status = constant.StatusSuccess - if err := u.CheckConn(req.DownloadUrl, req.Username, req.Password); err != nil { - imageRepo.Status = constant.StatusFailed - imageRepo.Message = err.Error() + if req.Auth { + if err := u.CheckConn(req.DownloadUrl, req.Username, req.Password); err != nil { + imageRepo.Status = constant.StatusFailed + imageRepo.Message = err.Error() + } } if err := imageRepoRepo.Create(&imageRepo); err != nil { return err @@ -142,7 +146,7 @@ func (u *ImageRepoService) Update(req dto.ImageRepoUpdate) error { if err != nil { return err } - if repo.DownloadUrl != req.DownloadUrl { + if repo.DownloadUrl != req.DownloadUrl || (!repo.Auth && req.Auth) { _ = u.handleRegistries(req.DownloadUrl, repo.DownloadUrl, "update") if repo.Auth { _, _ = cmd.Execf("docker logout %s", repo.DownloadUrl) @@ -162,9 +166,11 @@ func (u *ImageRepoService) Update(req dto.ImageRepoUpdate) error { upMap["status"] = constant.StatusSuccess upMap["message"] = "" - if err := u.CheckConn(req.DownloadUrl, req.Username, req.Password); err != nil { - upMap["status"] = constant.StatusFailed - upMap["message"] = err.Error() + if req.Auth { + if err := u.CheckConn(req.DownloadUrl, req.Username, req.Password); err != nil { + upMap["status"] = constant.StatusFailed + upMap["message"] = err.Error() + } } return imageRepoRepo.Update(req.ID, upMap) }