Skip to content

Commit

Permalink
add fork err msg, add query url
Browse files Browse the repository at this point in the history
  • Loading branch information
wj00037 committed Oct 28, 2024
1 parent f17261e commit 7600130
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 10 deletions.
12 changes: 11 additions & 1 deletion auth/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ import (
"fmt"
"io"
"net/http"
"strings"

"github.com/sirupsen/logrus"
)

type Client struct {
Expand All @@ -23,6 +26,13 @@ func getParsedResponse(method, path string, header http.Header, body io.Reader,
panic(err)
}
defer response.Body.Close()

if splitPath := strings.Split(path, "?"); len(splitPath) != 1 {
logrus.Infof("query %s with token | %d", splitPath[0], response.StatusCode)
} else {
logrus.Infof("query %s without token | %d", splitPath[0], response.StatusCode)
}

if response.StatusCode/100 != 2 {
if response.StatusCode == http.StatusNotFound {
return errors.New("not_found")
Expand All @@ -31,7 +41,7 @@ func getParsedResponse(method, path string, header http.Header, body io.Reader,
} else if response.StatusCode == http.StatusForbidden {
return errors.New("forbidden")
}
return fmt.Errorf("other error: %v", response.StatusCode)
return fmt.Errorf("system_error: %v", response.StatusCode)
}
data, err := io.ReadAll(response.Body)
if err != nil {
Expand Down
21 changes: 12 additions & 9 deletions auth/gitee.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ func CheckRepoOwner(userInRepo UserInRepo) error {
}
}
msg := "forbidden: repo has no permission to use this lfs server"
logrus.Error(fmt.Sprintf("CheckRepoOwner: %s", msg))
logrus.Error(fmt.Sprintf("CheckRepoOwner | %s", msg))
return errors.New(msg)
}

Expand Down Expand Up @@ -160,7 +160,7 @@ func verifyUser(userInRepo UserInRepo) error {
err := getParsedResponse("GET", path, headers, nil, &giteeUser)
if err != nil {
msg := err.Error() + ": verify user permission failed"
logrus.Error(fmt.Sprintf("verifyUser: %s", msg))
logrus.Error(fmt.Sprintf("verifyUser | %s", msg))
return errors.New(msg)
}

Expand All @@ -170,21 +170,24 @@ func verifyUser(userInRepo UserInRepo) error {
return nil
}
}
msg := "forbidden: user has no permission to upload"
logrus.Error(fmt.Sprintf("verifyUser: %s", msg))
return errors.New(msg)
msg := fmt.Sprintf("forbidden: user %s has no permission to upload", userInRepo.Username)
remindMsg := " \n如果您正在向fork仓库上传文件,请确认您已修改过在仓库根路径下的" +
"`.lfsconfig`文件,文件里url所包含的仓库名称应改为您fork之后的仓库的名称。" +
"详阅:https://github.com/opensourceways/BigFiles/blob/master/docs/QuickStart.md"
logrus.Error(fmt.Sprintf("verifyUser | %s", msg))
return errors.New(msg + remindMsg)
} else if userInRepo.Operation == "download" {
for _, v := range downloadPermissions {
if giteeUser.Permission == v {
return nil
}
}
msg := "forbidden: user has no permission to download"
logrus.Error(fmt.Sprintf("verifyUser: %s", msg))
msg := fmt.Sprintf("forbidden: user %s has no permission to download", userInRepo.Username)
logrus.Error(fmt.Sprintf("verifyUser | %s", msg))
return errors.New(msg)
} else {
msg := "other error: unknow operation"
logrus.Error(fmt.Sprintf("verifyUser: %s", msg))
msg := "system_error: unknow operation"
logrus.Error(fmt.Sprintf("verifyUser | %s", msg))
return errors.New(msg)
}
}

0 comments on commit 7600130

Please sign in to comment.