From 13b1661a77cce14f69bf21866ebc336e2fc2895c Mon Sep 17 00:00:00 2001 From: skiffer-git <72860476+skiffer-git@users.noreply.github.com> Date: Wed, 15 May 2024 15:42:35 +0800 Subject: [PATCH 1/4] Delete .github/dependabot.yml --- .github/dependabot.yml | 59 ------------------------------------------ 1 file changed, 59 deletions(-) delete mode 100644 .github/dependabot.yml diff --git a/.github/dependabot.yml b/.github/dependabot.yml deleted file mode 100644 index 49ffd7173..000000000 --- a/.github/dependabot.yml +++ /dev/null @@ -1,59 +0,0 @@ -# Copyright © 2023 OpenIM. All rights reserved. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -# To get started with Dependabot version updates, you'll need to specify which -# package ecosystems to update and where the package manifests are located. -# Please see the documentation for all configuration options: -# https://docs.github.com/github/administering-a-repository/configuration-options-for-dependency-updates - -version: 2 -updates: - - package-ecosystem: "gomod" - directory: "/" - schedule: - interval: "daily" - time: "08:00" - labels: - - "dependencies" - commit-message: - prefix: "feat" - include: "scope" - groups: - gomod-deps: - patterns: - - "*" - - package-ecosystem: "github-actions" - directory: "/" - schedule: - interval: "daily" - time: "08:00" - labels: - - "dependencies" - commit-message: - prefix: "chore" - include: "scope" - groups: - github-actions: - patterns: - - "*" - - package-ecosystem: "docker" - directory: "/" - schedule: - interval: "daily" - time: "08:00" - labels: - - "dependencies" - commit-message: - prefix: "feat" - include: "scope" \ No newline at end of file From 814e378fa1a6f24b5c0295c6c90d6905b3f61e21 Mon Sep 17 00:00:00 2001 From: skiffer-git <72860476+skiffer-git@users.noreply.github.com> Date: Wed, 15 May 2024 15:53:48 +0800 Subject: [PATCH 2/4] Update CONTRIBUTING-zh_CN.md --- CONTRIBUTING-zh_CN.md | 46 ++++++++++++++++++++++++++++--------------- 1 file changed, 30 insertions(+), 16 deletions(-) diff --git a/CONTRIBUTING-zh_CN.md b/CONTRIBUTING-zh_CN.md index c10d7337f..47965a9f4 100644 --- a/CONTRIBUTING-zh_CN.md +++ b/CONTRIBUTING-zh_CN.md @@ -1,7 +1,9 @@ -# 如何给OpenIM贡献代码(提交pull request) + + +# 如何给 OpenIM 贡献代码(提交 Pull Request)

- Englist · + English · 中文 · Українська · Česky · @@ -28,55 +30,67 @@ Türkçe

+本指南将以 [openimsdk/open-im-server](https://github.com/openimsdk/open-im-server) 为例,详细说明如何为 OpenIM 项目贡献代码。我们采用“一问题一分支”的策略,确保每个 Issue 都对应一个专门的分支,以便有效管理代码变更。 -本指南将以 [openimsdk/open-im-server](https://github.com/openimsdk/open-im-server)为例详细说明如何为 OpenIM 项目贡献代码。我们采用“一问题一分支”的策略,确保每个 Issue 都对应一个专门的分支,以便有效管理代码变更。 - -## 1. Fork 仓库 +### 1. Fork 仓库 前往 [openimsdk/open-im-server](https://github.com/openimsdk/open-im-server) GitHub 页面,点击右上角的 "Fork" 按钮,将仓库 Fork 到你的 GitHub 账户下。 -## 2. 克隆仓库 +### 2. 克隆仓库 将你 Fork 的仓库克隆到本地: ```bash git clone https://github.com/your-username/open-im-server.git ``` -## 3. 设置远程上游 +### 3. 设置远程上游 添加原始仓库为远程上游以便跟踪其更新: ```bash git remote add upstream https://github.com/openimsdk/open-im-server.git ``` -## 4. 创建 Issue -在原始仓库中创建一个新的 Issue,详细描述你遇到的问题或希望添加的新功能。 +### 4. 创建 Issue +在原始仓库中创建一个新的 Issue,详细描述你遇到的问题或希望添加 -## 5. 创建新分支 +的新功能。 + +### 5. 创建新分支 基于主分支创建一个新分支,并使用描述性的名称与 Issue ID,例如: ```bash git checkout -b fix-bug-123 ``` -## 6. 提交更改 +### 6. 提交更改 在你的本地分支上进行更改后,提交这些更改: ```bash git add . git commit -m "Describe your changes in detail" ``` -## 7. 推送分支 +### 7. 推送分支 将你的分支推送回你的 GitHub Fork: ```bash git push origin fix-bug-123 ``` -## 8. 创建 Pull Request +### 8. 创建 Pull Request 在 GitHub 上转到你的 Fork 仓库,点击 "Pull Request" 按钮。确保 PR 描述清楚,并链接到相关的 Issue。 -## 9. 签署 CLA +### 9. 签署 CLA 如果这是你第一次提交 PR,你需要在 PR 的评论中回复: ``` I have read the CLA Document and I hereby sign the CLA ``` -## 其他说明 -如果需要将同一修改提交到两个不同的分支(例如 `main` 和 `release-v3.7`),应从对应的远程分支分别创建两个新分支。首先在一个分支上完成修改,然后使用 `cherry-pick` 命令将这些更改应用到另一个分支。之后,为每个分支独立提交 Pull Request。 +### 编程规范 +请参考以下文档以了解关于 Go 语言编程规范的详细信息: +- [Go 编码规范](https://github.com/openimsdk/open-im-server/blob/main/docs/contrib/go-code.md) +- [代码约定](https://github.com/openimsdk/open-im-server/blob/main/docs/contrib/code-conventions.md) + +### 日志规范 +- **禁止使用标准的 `log` 包**。 +- 应使用 `"github.com/openimsdk/tools/log"` 包来打印日志,该包支持多种日志级别:`debug`、`info`、`warn`、`error`。 +- **错误日志应仅在首次调用的函数中打印**,以防止日志重复,并确保错误的上下文清晰。 +### 异常及错误处理 +- **禁止使用 `panic`**:程序中不应使用 `panic`,以避免在遇到不可恢复的错误时突然终止。 +- **错误包裹**:使用 `"github.com/openimsdk/tools/errs"` 来包裹错误,保持错误信息的完整性并增加调试便利。 +- **错误传递**:如果函数本身不能处理错误,应将错误返回给调用者,而不是隐藏或忽略这些错误。 From ddf8cc98ce10dc624c4231226277405e09a39488 Mon Sep 17 00:00:00 2001 From: skiffer-git <72860476+skiffer-git@users.noreply.github.com> Date: Wed, 15 May 2024 15:56:14 +0800 Subject: [PATCH 3/4] Update CONTRIBUTING.md --- CONTRIBUTING.md | 41 +++++++++++++++++++++++++++-------------- 1 file changed, 27 insertions(+), 14 deletions(-) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index a85ba891f..0aa07393e 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -1,7 +1,7 @@ -# How do I contribute code to OpenIM +# How to Contribute to OpenIM (Submitting Pull Requests)

- Englist · + English · 中文 · Українська · Česky · @@ -27,13 +27,14 @@ Ελληνικά · Türkçe

-This guide will explain in detail how to contribute code to the OpenIM project, using `openimsdk/open-im-server` as an example. We adopt a "one issue, one branch" strategy to ensure each issue corresponds to a dedicated branch, allowing for effective management of code changes. + +This guide will use [openimsdk/open-im-server](https://github.com/openimsdk/open-im-server) as an example to explain in detail how to contribute code to the OpenIM project. We adopt a "one issue, one branch" strategy to ensure each issue corresponds to a dedicated branch for effective code change management. ### 1. Fork the Repository -Go to the `openimsdk/open-im-server` GitHub page, click the "Fork" button in the upper right corner to fork the repository to your GitHub account. +Go to the [openimsdk/open-im-server](https://github.com/openimsdk/open-im-server) GitHub page, click the "Fork" button in the upper right corner to fork the repository to your GitHub account. ### 2. Clone the Repository -Clone the forked repository to your local machine: +Clone the repository you forked to your local machine: ```bash git clone https://github.com/your-username/open-im-server.git ``` @@ -45,19 +46,21 @@ git remote add upstream https://github.com/openimsdk/open-im-server.git ``` ### 4. Create an Issue -Create a new issue in the original repository describing the problem you are facing or the new feature you want to add. For significant feature adjustments, propose an RFC issue to facilitate broad discussion and participation from community members. +Create a new issue in the original repository detailing the problem you encountered or the new feature you wish to add. ### 5. Create a New Branch -Create a new branch based on the main branch and name it descriptively, including the Issue ID, for example: +Create a new branch off the main branch with a descriptive name and Issue ID, for example: ```bash git checkout -b fix-bug-123 ``` ### 6. Commit Changes -After making changes on your local branch, commit them: +After making changes on your local branch, commit these changes: ```bash git add . -git commit -m "Describe your changes in detail" +git commit -m "Describe your changes + + in detail" ``` ### 7. Push the Branch @@ -67,15 +70,25 @@ git push origin fix-bug-123 ``` ### 8. Create a Pull Request -Go to your fork on GitHub, click the "Pull Request" button. Make sure the PR description is clear and links to the related Issue. -#### 🅰 Fixed issue #issueID +Go to your fork on GitHub and click the "Pull Request" button. Ensure the PR description is clear and links to the related issue. ### 9. Sign the CLA -If this is your first time submitting a PR, you need to reply in the PR comments: +If this is your first time submitting a PR, you will need to reply in the comments of the PR: ``` I have read the CLA Document and I hereby sign the CLA ``` -### Additional Notes -If the same modification needs to be submitted to two different branches (e.g., main and release-v3.7), create two new branches from the corresponding remote branches. First complete the modification in one branch, then use the `cherry-pick` command to apply these changes to the other branch. After that, submit a separate Pull Request for each branch. +### Programming Standards +Please refer to the following documents for detailed information on Go language programming standards: +- [Go Coding Standards](https://github.com/openimsdk/open-im-server/blob/main/docs/contrib/go-code.md) +- [Code Conventions](https://github.com/openimsdk/open-im-server/blob/main/docs/contrib/code-conventions.md) + +### Logging Standards +- **Do not use the standard `log` package**. +- Use the `"github.com/openimsdk/tools/log"` package for logging, which supports multiple log levels: `debug`, `info`, `warn`, `error`. +- **Error logs should only be printed in the function where they are first actively called** to prevent log duplication and ensure clear error context. +### Exception and Error Handling +- **Prohibit the use of `panic`**: The code should not use `panic` to avoid abrupt termination when encountering unrecoverable errors. +- **Error Wrapping**: Use `"github.com/openimsdk/tools/errs"` to wrap errors, maintaining the integrity of error information and facilitating debugging. +- **Error Propagation**: If a function cannot handle an error itself, it should return the error to the caller, rather than hiding or ignoring it. From 285523751d1d52f9bc1dc628a499e08c7ad31364 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=A3=AE=E5=B1=BF?= <42713450+memory-qianxiao@users.noreply.github.com> Date: Fri, 17 May 2024 10:43:54 +0800 Subject: [PATCH 4/4] feat: middleware authentication and whitelist are used to release permissions. (#2309) --- internal/api/router.go | 76 +++++++++++++++++++++++++----------------- 1 file changed, 45 insertions(+), 31 deletions(-) diff --git a/internal/api/router.go b/internal/api/router.go index 1fbb33b09..600567178 100644 --- a/internal/api/router.go +++ b/internal/api/router.go @@ -15,6 +15,7 @@ import ( "google.golang.org/grpc" "google.golang.org/grpc/credentials/insecure" "net/http" + "strings" ) func newGinRouter(disCov discovery.SvcDiscoveryRegistry, config *Config) *gin.Engine { @@ -25,7 +26,6 @@ func newGinRouter(disCov discovery.SvcDiscoveryRegistry, config *Config) *gin.En if v, ok := binding.Validator.Engine().(*validator.Validate); ok { _ = v.RegisterValidation("required_if", RequiredIf) } - r.Use(gin.Recovery(), mw.CorsHandler(), mw.GinParseOperationID()) // init rpc client here userRpc := rpcclient.NewUser(disCov, config.Share.RpcRegisterName.User, config.Share.RpcRegisterName.MessageGateway, config.Share.IMAdminUserID) @@ -36,37 +36,37 @@ func newGinRouter(disCov discovery.SvcDiscoveryRegistry, config *Config) *gin.En authRpc := rpcclient.NewAuth(disCov, config.Share.RpcRegisterName.Auth) thirdRpc := rpcclient.NewThird(disCov, config.Share.RpcRegisterName.Third, config.API.Prometheus.GrafanaURL) + r.Use(gin.Recovery(), mw.CorsHandler(), mw.GinParseOperationID(), GinParseToken(authRpc)) u := NewUserApi(*userRpc) m := NewMessageApi(messageRpc, userRpc, config.Share.IMAdminUserID) - ParseToken := GinParseToken(authRpc) userRouterGroup := r.Group("/user") { userRouterGroup.POST("/user_register", u.UserRegister) - userRouterGroup.POST("/update_user_info", ParseToken, u.UpdateUserInfo) - userRouterGroup.POST("/update_user_info_ex", ParseToken, u.UpdateUserInfoEx) - userRouterGroup.POST("/set_global_msg_recv_opt", ParseToken, u.SetGlobalRecvMessageOpt) - userRouterGroup.POST("/get_users_info", ParseToken, u.GetUsersPublicInfo) - userRouterGroup.POST("/get_all_users_uid", ParseToken, u.GetAllUsersID) - userRouterGroup.POST("/account_check", ParseToken, u.AccountCheck) - userRouterGroup.POST("/get_users", ParseToken, u.GetUsers) - userRouterGroup.POST("/get_users_online_status", ParseToken, u.GetUsersOnlineStatus) - userRouterGroup.POST("/get_users_online_token_detail", ParseToken, u.GetUsersOnlineTokenDetail) - userRouterGroup.POST("/subscribe_users_status", ParseToken, u.SubscriberStatus) - userRouterGroup.POST("/get_users_status", ParseToken, u.GetUserStatus) - userRouterGroup.POST("/get_subscribe_users_status", ParseToken, u.GetSubscribeUsersStatus) + userRouterGroup.POST("/update_user_info", u.UpdateUserInfo) + userRouterGroup.POST("/update_user_info_ex", u.UpdateUserInfoEx) + userRouterGroup.POST("/set_global_msg_recv_opt", u.SetGlobalRecvMessageOpt) + userRouterGroup.POST("/get_users_info", u.GetUsersPublicInfo) + userRouterGroup.POST("/get_all_users_uid", u.GetAllUsersID) + userRouterGroup.POST("/account_check", u.AccountCheck) + userRouterGroup.POST("/get_users", u.GetUsers) + userRouterGroup.POST("/get_users_online_status", u.GetUsersOnlineStatus) + userRouterGroup.POST("/get_users_online_token_detail", u.GetUsersOnlineTokenDetail) + userRouterGroup.POST("/subscribe_users_status", u.SubscriberStatus) + userRouterGroup.POST("/get_users_status", u.GetUserStatus) + userRouterGroup.POST("/get_subscribe_users_status", u.GetSubscribeUsersStatus) - userRouterGroup.POST("/process_user_command_add", ParseToken, u.ProcessUserCommandAdd) - userRouterGroup.POST("/process_user_command_delete", ParseToken, u.ProcessUserCommandDelete) - userRouterGroup.POST("/process_user_command_update", ParseToken, u.ProcessUserCommandUpdate) - userRouterGroup.POST("/process_user_command_get", ParseToken, u.ProcessUserCommandGet) - userRouterGroup.POST("/process_user_command_get_all", ParseToken, u.ProcessUserCommandGetAll) + userRouterGroup.POST("/process_user_command_add", u.ProcessUserCommandAdd) + userRouterGroup.POST("/process_user_command_delete", u.ProcessUserCommandDelete) + userRouterGroup.POST("/process_user_command_update", u.ProcessUserCommandUpdate) + userRouterGroup.POST("/process_user_command_get", u.ProcessUserCommandGet) + userRouterGroup.POST("/process_user_command_get_all", u.ProcessUserCommandGetAll) - userRouterGroup.POST("/add_notification_account", ParseToken, u.AddNotificationAccount) - userRouterGroup.POST("/update_notification_account", ParseToken, u.UpdateNotificationAccountInfo) - userRouterGroup.POST("/search_notification_account", ParseToken, u.SearchNotificationAccount) + userRouterGroup.POST("/add_notification_account", u.AddNotificationAccount) + userRouterGroup.POST("/update_notification_account", u.UpdateNotificationAccountInfo) + userRouterGroup.POST("/search_notification_account", u.SearchNotificationAccount) } // friend routing group - friendRouterGroup := r.Group("/friend", ParseToken) + friendRouterGroup := r.Group("/friend") { f := NewFriendApi(*friendRpc) friendRouterGroup.POST("/delete_friend", f.DeleteFriend) @@ -88,7 +88,7 @@ func newGinRouter(disCov discovery.SvcDiscoveryRegistry, config *Config) *gin.En friendRouterGroup.POST("/update_friends", f.UpdateFriends) } g := NewGroupApi(*groupRpc) - groupRouterGroup := r.Group("/group", ParseToken) + groupRouterGroup := r.Group("/group") { groupRouterGroup.POST("/create_group", g.CreateGroup) groupRouterGroup.POST("/set_group_info", g.SetGroupInfo) @@ -120,12 +120,12 @@ func newGinRouter(disCov discovery.SvcDiscoveryRegistry, config *Config) *gin.En { a := NewAuthApi(*authRpc) authRouterGroup.POST("/user_token", a.UserToken) - authRouterGroup.POST("/get_user_token", ParseToken, a.GetUserToken) + authRouterGroup.POST("/get_user_token", a.GetUserToken) authRouterGroup.POST("/parse_token", a.ParseToken) - authRouterGroup.POST("/force_logout", ParseToken, a.ForceLogout) + authRouterGroup.POST("/force_logout", a.ForceLogout) } // Third service - thirdGroup := r.Group("/third", ParseToken) + thirdGroup := r.Group("/third") { t := NewThirdApi(*thirdRpc) thirdGroup.GET("/prometheus", t.GetPrometheus) @@ -137,7 +137,7 @@ func newGinRouter(disCov discovery.SvcDiscoveryRegistry, config *Config) *gin.En logs.POST("/delete", t.DeleteLogs) logs.POST("/search", t.SearchLogs) - objectGroup := r.Group("/object", ParseToken) + objectGroup := r.Group("/object") objectGroup.POST("/part_limit", t.PartLimit) objectGroup.POST("/part_size", t.PartSize) @@ -150,7 +150,7 @@ func newGinRouter(disCov discovery.SvcDiscoveryRegistry, config *Config) *gin.En objectGroup.GET("/*name", t.ObjectRedirect) } // Message - msgGroup := r.Group("/msg", ParseToken) + msgGroup := r.Group("/msg") { msgGroup.POST("/newest_seq", m.GetSeq) msgGroup.POST("/search_msg", m.SearchMsg) @@ -174,7 +174,7 @@ func newGinRouter(disCov discovery.SvcDiscoveryRegistry, config *Config) *gin.En msgGroup.POST("/get_server_time", m.GetServerTime) } // Conversation - conversationGroup := r.Group("/conversation", ParseToken) + conversationGroup := r.Group("/conversation") { c := NewConversationApi(*conversationRpc) conversationGroup.POST("/get_sorted_conversation_list", c.GetSortedConversationList) @@ -185,7 +185,7 @@ func newGinRouter(disCov discovery.SvcDiscoveryRegistry, config *Config) *gin.En conversationGroup.POST("/get_conversation_offline_push_user_ids", c.GetConversationOfflinePushUserIDs) } - statisticsGroup := r.Group("/statistics", ParseToken) + statisticsGroup := r.Group("/statistics") { statisticsGroup.POST("/user/register", u.UserRegisterCount) statisticsGroup.POST("/user/active", m.GetActiveUser) @@ -199,6 +199,13 @@ func GinParseToken(authRPC *rpcclient.Auth) gin.HandlerFunc { return func(c *gin.Context) { switch c.Request.Method { case http.MethodPost: + for _, wApi := range Whitelist { + if strings.HasPrefix(c.Request.URL.Path, wApi) { + c.Next() + return + } + } + token := c.Request.Header.Get(constant.Token) if token == "" { log.ZWarn(c, "header get token error", servererrs.ErrArgs.WrapMsg("header must have token")) @@ -218,3 +225,10 @@ func GinParseToken(authRPC *rpcclient.Auth) gin.HandlerFunc { } } } + +// Whitelist api not parse token +var Whitelist = []string{ + "/user/user_register", + "/auth/user_token", + "/auth/parse_token", +}