From 00cad5b5866917cf829f38c5d11b869e01070a0a Mon Sep 17 00:00:00 2001 From: ssongliu <73214554+ssongliu@users.noreply.github.com> Date: Wed, 1 Nov 2023 13:49:30 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E5=A4=84=E7=90=86=E4=BB=A3=E7=A0=81?= =?UTF-8?q?=E8=AD=A6=E5=91=8A=20(#2756)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- backend/app/service/image.go | 5 +++-- backend/utils/common/common.go | 7 ++++--- backend/utils/ps/ps_test.go | 9 +++++---- backend/utils/ssl/acme_test.go | 9 ++++++--- 4 files changed, 18 insertions(+), 12 deletions(-) diff --git a/backend/app/service/image.go b/backend/app/service/image.go index 208c6b61a..3842febde 100644 --- a/backend/app/service/image.go +++ b/backend/app/service/image.go @@ -19,6 +19,7 @@ import ( "github.com/1Panel-dev/1Panel/backend/global" "github.com/1Panel-dev/1Panel/backend/utils/docker" "github.com/docker/docker/api/types" + "github.com/docker/docker/api/types/registry" "github.com/docker/docker/pkg/archive" ) @@ -239,7 +240,7 @@ func (u *ImageService) ImagePull(req dto.ImagePull) (string, error) { } options := types.ImagePullOptions{} if repo.Auth { - authConfig := types.AuthConfig{ + authConfig := registry.AuthConfig{ Username: repo.Username, Password: repo.Password, } @@ -336,7 +337,7 @@ func (u *ImageService) ImagePush(req dto.ImagePush) (string, error) { } options := types.ImagePushOptions{} if repo.Auth { - authConfig := types.AuthConfig{ + authConfig := registry.AuthConfig{ Username: repo.Username, Password: repo.Password, } diff --git a/backend/utils/common/common.go b/backend/utils/common/common.go index edd5cd0a7..487c2d8e1 100644 --- a/backend/utils/common/common.go +++ b/backend/utils/common/common.go @@ -98,11 +98,12 @@ func RandStr(n int) string { } func RandStrAndNum(n int) string { - mathRand.Seed(time.Now().UnixNano()) + source := mathRand.NewSource(time.Now().UnixNano()) + randGen := mathRand.New(source) const charset = "abcdefghijklmnopqrstuvwxyz0123456789" - b := make([]byte, 10) + b := make([]byte, n) for i := range b { - b[i] = charset[mathRand.Int63()%int64(len(charset))] + b[i] = charset[randGen.Intn(len(charset)-1)] } return (string(b)) } diff --git a/backend/utils/ps/ps_test.go b/backend/utils/ps/ps_test.go index 834f4866c..bda0ad144 100644 --- a/backend/utils/ps/ps_test.go +++ b/backend/utils/ps/ps_test.go @@ -2,11 +2,12 @@ package ps import ( "fmt" - "github.com/shirou/gopsutil/v3/host" - "github.com/shirou/gopsutil/v3/process" "strconv" "testing" "time" + + "github.com/shirou/gopsutil/v3/host" + "github.com/shirou/gopsutil/v3/process" ) func TestPs(t *testing.T) { @@ -67,8 +68,8 @@ func TestPs(t *testing.T) { fmt.Println(ss) } - fmt.Println(fmt.Sprintf("Name: %s PId: %v ParentID: %v Username: %v status:%s startTime: %s numThreads: %v numConnections:%v cpuPercent:%v rss:%s MB IORead: %s IOWrite: %s", - name, pro.Pid, parentID, userName, status, startTime, numThreads, numConnections, cpuPercent, rss, ioRead, ioWrite)) + fmt.Printf("Name: %s PId: %v ParentID: %v Username: %v status:%s startTime: %s numThreads: %v numConnections:%v cpuPercent:%v rss:%s MB IORead: %s IOWrite: %s \n", + name, pro.Pid, parentID, userName, status, startTime, numThreads, numConnections, cpuPercent, rss, ioRead, ioWrite) } users, err := host.Users() if err == nil { diff --git a/backend/utils/ssl/acme_test.go b/backend/utils/ssl/acme_test.go index 286c45ad9..a4f9a299f 100644 --- a/backend/utils/ssl/acme_test.go +++ b/backend/utils/ssl/acme_test.go @@ -8,13 +8,14 @@ import ( "encoding/json" "encoding/pem" "fmt" - "github.com/1Panel-dev/1Panel/backend/utils/files" - "gopkg.in/yaml.v3" "os" "path" "testing" "time" + "github.com/1Panel-dev/1Panel/backend/utils/files" + "gopkg.in/yaml.v3" + "github.com/go-acme/lego/v4/acme/api" "github.com/go-acme/lego/v4/certcrypto" "github.com/go-acme/lego/v4/certificate" @@ -105,7 +106,9 @@ func TestAppToV2(t *testing.T) { oldAppDir := oldDir + "/" + appDefine.Key newAppDir := newDir + "/" + appDefine.Key if !fileOp.Stat(newAppDir) { - fileOp.CreateDir(newAppDir, 0755) + if err := fileOp.CreateDir(newAppDir, 0755); err != nil { + panic(err) + } } // logo oldLogoPath := oldAppDir + "/metadata/logo.png"