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 29, 2024
1 parent 749af9b commit 57b01d6
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 11 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,5 @@ v2.12.0](https://github.com/git-lfs/git-lfs/tree/v2.12.0/docs/api) server.
5. ~~认证时校验用户在仓库内权限。~~
6. 支持ssh。
7. ~~仓库添加github action。~~
8. 添加日志。
8. ~~添加日志。~~
9. 支持cdn。
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
23 changes: 14 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,26 @@ 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 to %s/%s",
userInRepo.Username, userInRepo.Owner, userInRepo.Repo)
remindMsg := " \n如果您正在向fork仓库上传大文件,请确认您已使用如下命令修改了本地仓库的配置:" +
"\n`git config --local lfs.url https://openeuler-bigfiles.test.osinfra.cn/{owner}/{repo}`" +
",\n其中{owner}/{repo}请改为您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 57b01d6

Please sign in to comment.