From 5110c5837da0cdcac5024ce6849de45a37fbe49a Mon Sep 17 00:00:00 2001 From: xun Date: Tue, 23 Jul 2024 22:35:10 +0800 Subject: [PATCH 1/3] Update logger and cicd --- .github/workflows/dev-deploy.yml | 116 +++++++++++++++--------------- src/api/v1/oauth_client_github.go | 23 +++--- src/log/logger.go | 1 + 3 files changed, 74 insertions(+), 66 deletions(-) diff --git a/.github/workflows/dev-deploy.yml b/.github/workflows/dev-deploy.yml index 4a0e86c..e08c2e2 100644 --- a/.github/workflows/dev-deploy.yml +++ b/.github/workflows/dev-deploy.yml @@ -10,29 +10,29 @@ on: jobs: build: - if: github.event.pull_request.merged + if: github.event.pull_request.merged runs-on: ubuntu-22.04 steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v3 - - name: Set up Docker Buildx - uses: docker/setup-buildx-action@v2 + - name: Set up Docker Buildx + uses: docker/setup-buildx-action@v3 - - name: Cache Docker layers - uses: actions/cache@v3 - with: - path: /tmp/.buildx-cache - key: ${{ runner.os }}-buildx-${{ github.sha }} - restore-keys: | - ${{ runner.os }}-buildx- + - name: Cache Docker layers + uses: actions/cache@v4 + with: + path: /tmp/.buildx-cache + key: ${{ runner.os }}-buildx-${{ github.sha }} + restore-keys: | + ${{ runner.os }}-buildx- - - name: Build Docker image - run: | - docker buildx build --platform linux/amd64 -t sast/sast-link -f docker/Dockerfile --output type=docker,dest=image.tar . + - name: Build Docker image + run: | + docker buildx build --platform linux/amd64 -t sast/sast-link -f docker/Dockerfile --output type=docker,dest=image.tar . - - name: Copy Docker image to server - uses: easingthemes/ssh-deploy@main - with: + - name: Copy Docker image to server + uses: easingthemes/ssh-deploy@main + with: SSH_PRIVATE_KEY: ${{ secrets.SSH_PRIVATE_KEY }} ARGS: "-rlgoDzvc -i --delete" SOURCE: "./image.tar" @@ -40,46 +40,46 @@ jobs: REMOTE_USER: ${{ secrets.REMOTE_USER }} TARGET: /tmp/image.tar - - name: Deploy in server - uses: appleboy/ssh-action@v1.0.3 - env: - WORKINGDIR: ${{ secrets.WORKINGDIR }} - with: - host: ${{ secrets.REMOTE_HOST }} - username: ${{ secrets.REMOTE_USER }} - key: ${{ secrets.SSH_PRIVATE_KEY }} - script_stop: true - envs: WORKINGDIR - script: | - ### Notice: run for develop ### - # Stop and remove existing container if it exists - if [ "$(docker ps -aq -f name=sastlink)" ]; then - docker stop sastlink - docker rm sastlink - fi - # Remove existing image if it exists - if [ "$(docker images -q sast/sast-link)" ]; then - docker rmi sast/sast-link - fi - # Load the new image and run it - # It will failed, for test - docker load -i /tmp/image.tar - docker run --restart always -d --name sastlink -p 8080:8080 -v $WORKINGDIR:/sastlink/config sast/sast-link + - name: Deploy in server + uses: appleboy/ssh-action@v1.0.3 + env: + WORKINGDIR: ${{ secrets.WORKINGDIR }} + with: + host: ${{ secrets.REMOTE_HOST }} + username: ${{ secrets.REMOTE_USER }} + key: ${{ secrets.SSH_PRIVATE_KEY }} + script_stop: true + envs: WORKINGDIR + script: | + ### Notice: run for develop ### + # Stop and remove existing container if it exists + if [ "$(docker ps -aq -f name=sastlink)" ]; then + docker stop sastlink + docker rm sastlink + fi + # Remove existing image if it exists + if [ "$(docker images -q sast/sast-link)" ]; then + docker rmi sast/sast-link + fi + # Load the new image and run it + # It will failed, for test + docker load -i /tmp/image.tar + docker run --restart always -d --name sastlink -p 8080:8080 -v $WORKINGDIR:/sastlink/config sast/sast-link - - name: Send Success Message - if: ${{ success() }} - run: | - bash ./scripts/webhook.sh \ - -u "${{ github.event.pull_request.html_url }}" \ - -w ${{ secrets.WEBHOOK_URL }} \ - -s sastlink -c "${{ github.event.pull_request.user.login }}" -f 'success' \ - -m "https://github.com/${{ github.repository }}/commit/${{ github.sha }}" + - name: Send Success Message + if: ${{ success() }} + run: | + bash ./scripts/webhook.sh \ + -u "${{ github.event.pull_request.html_url }}" \ + -w ${{ secrets.WEBHOOK_URL }} \ + -s sastlink -c "${{ github.event.pull_request.user.login }}" -f 'success' \ + -m "https://github.com/${{ github.repository }}/commit/${{ github.sha }}" - - name: Send Fail Message - if: ${{ failure() }} - run: | - bash ./scripts/webhook.sh \ - -u "${{ github.event.pull_request.html_url }}" \ - -w ${{ secrets.WEBHOOK_URL }} \ - -s sastlink -c "${{ github.event.pull_request.user.login }}" -f 'failure' \ - -m "https://github.com/${{ github.repository }}/commit/${{ github.sha }}" + - name: Send Fail Message + if: ${{ failure() }} + run: | + bash ./scripts/webhook.sh \ + -u "${{ github.event.pull_request.html_url }}" \ + -w ${{ secrets.WEBHOOK_URL }} \ + -s sastlink -c "${{ github.event.pull_request.user.login }}" -f 'failure' \ + -m "https://github.com/${{ github.repository }}/commit/${{ github.sha }}" diff --git a/src/api/v1/oauth_client_github.go b/src/api/v1/oauth_client_github.go index fb0d55e..b936485 100644 --- a/src/api/v1/oauth_client_github.go +++ b/src/api/v1/oauth_client_github.go @@ -37,13 +37,18 @@ func OauthGithubLogin(c *gin.Context) { oauthState := GenerateStateOauthCookie(c.Writer) url := githubConf.AuthCodeURL(oauthState) - log.Log.Warnf("Visit the URL for the auth dialog: %v\n", url) + // log.Log.Warnf("Visit the URL for the auth dialog: %v\n", url) + log.Debug("Visit the URL for the auth dialog: ", url) + log.Debug("RedirectURL: ", githubConf.RedirectURL) + log.Debug("ClientID: ", githubConf.ClientID) + c.SetCookie("oauthstate", oauthState, 3600, "", "", false, true) c.Redirect(http.StatusFound, url) } func OauthGithubCallback(c *gin.Context) { oauthState, _ := c.Request.Cookie("oauthstate") + log.Debugf("oauthState: %s", oauthState.Value) if c.Request.FormValue("state") != oauthState.Value { log.Log.Printf("invalid oauth state, expected '%s', got '%s'\n", oauthState.Value, c.Request.FormValue("state")) @@ -58,11 +63,11 @@ func OauthGithubCallback(c *gin.Context) { c.JSON(http.StatusOK, result.Failed(result.HandleError(err))) return } - if githubId == "" { c.JSON(http.StatusOK, result.Failed(result.HandleError(result.RequestParamError))) return } + log.Debug("GithubId: ", githubId) user, err := service.GetUserByGithubId(githubId) if err != nil { @@ -82,20 +87,22 @@ func getUserInfoFromGithub(ctx context.Context, code string) (string, error) { token, err := githubConf.Exchange(ctx, code) if err != nil { - log.Log.Errorf("exchange github code error: %s", err.Error()) - return "", fmt.Errorf("exchange github code error: %s", err.Error()) + // log.Log.Errorf("exchange github code error: %s", err.Error()) + log.Errorf("Exchange github code error: %s", err.Error()) + return "", fmt.Errorf("Exchange github code error: %s", err.Error()) } client := &http.Client{} req, err := http.NewRequest("GET", GithubUserInfoURL, nil) if err != nil { - log.Log.Errorf("new request error: %s", err.Error()) - return "", fmt.Errorf("new request error: %s", err.Error()) + // log.Log.Errorf("New request error: %s", err.Error()) + log.Errorf("New request error: %s", err.Error()) + return "", fmt.Errorf("New request error: %s", err.Error()) } req.Header.Set("Authorization", "Bearer "+token.AccessToken) res, err := client.Do(req) if err != nil { - log.Log.Errorf("failt to getting user info: %s", err.Error()) - return "", fmt.Errorf("failt to getting user info: %s", err.Error()) + log.Log.Errorf("Failt to getting user info: %s", err.Error()) + return "", fmt.Errorf("Failt to getting user info: %s", err.Error()) } body, err := io.ReadAll(res.Body) if err != nil { diff --git a/src/log/logger.go b/src/log/logger.go index 9440495..0c64bc9 100644 --- a/src/log/logger.go +++ b/src/log/logger.go @@ -106,6 +106,7 @@ func initLogger() { TimestampFormat: time.RFC3339, ForceQuote: true, }) + logger.SetLevel(logLevelSwitcher(logLevel)) } func SetLevel(level logrus.Level) { From 9bf20970687476832970a0e755c35778fb72598f Mon Sep 17 00:00:00 2001 From: xun Date: Thu, 25 Jul 2024 20:28:01 +0800 Subject: [PATCH 2/3] Update sql --- sql/ddl.sql | 10 +++++++++- sql/oauth2_info.sql | 10 +++++++++- 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/sql/ddl.sql b/sql/ddl.sql index bcf85b0..8197322 100644 --- a/sql/ddl.sql +++ b/sql/ddl.sql @@ -184,7 +184,7 @@ ALTER TABLE public.oauth2_clients OWNER TO postgres; CREATE TABLE public.oauth2_info ( id integer NOT NULL, client character varying NOT NULL, - info json[], + info jsonb[], oauth_user_id character varying NOT NULL, user_id character varying NOT NULL ); @@ -509,6 +509,14 @@ ALTER TABLE ONLY public.oauth2_clients ADD CONSTRAINT oauth2_clients_pkey PRIMARY KEY (id); +-- +-- Name: oauth2_info oauth2_info_unique; Type: CONSTRAINT; Schema: public; Owner: postgres +-- + +ALTER TABLE ONLY public.oauth2_info + ADD CONSTRAINT oauth2_info_unique UNIQUE (client, user_id); + + -- -- Name: oauth2_tokens oauth2_tokens_pkey; Type: CONSTRAINT; Schema: public; Owner: postgres -- diff --git a/sql/oauth2_info.sql b/sql/oauth2_info.sql index 460e52c..bf5380a 100644 --- a/sql/oauth2_info.sql +++ b/sql/oauth2_info.sql @@ -27,7 +27,7 @@ SET default_table_access_method = heap; CREATE TABLE public.oauth2_info ( id integer NOT NULL, client character varying NOT NULL, - info json[], + info jsonb[], oauth_user_id character varying NOT NULL, user_id character varying NOT NULL ); @@ -85,6 +85,14 @@ ALTER SEQUENCE public.oauth2_info_id_seq OWNED BY public.oauth2_info.id; ALTER TABLE ONLY public.oauth2_info ALTER COLUMN id SET DEFAULT nextval('public.oauth2_info_id_seq'::regclass); +-- +-- Name: oauth2_info oauth2_info_unique; Type: CONSTRAINT; Schema: public; Owner: postgres +-- + +ALTER TABLE ONLY public.oauth2_info + ADD CONSTRAINT oauth2_info_unique UNIQUE (client, user_id); + + -- -- PostgreSQL database dump complete -- From ac76a2c49706fb50eefdc3b4bd46589404a55594 Mon Sep 17 00:00:00 2001 From: xun Date: Thu, 25 Jul 2024 20:29:40 +0800 Subject: [PATCH 3/3] feat: Add github oauth2 login --- src/api/v1/oauth_client_github.go | 63 ++++++++++++++++++++----- src/api/v1/oauth_client_lark.go | 6 +-- src/api/v1/user.go | 42 +++++++++++------ src/go.mod | 23 +++++---- src/go.sum | 77 +++++++++++++------------------ src/model/common.go | 8 ++-- src/model/oauth.go | 57 +++++++++++++++++++++-- src/model/oauth_test.go | 27 +++++++++++ src/service/oauth.go | 20 +++++--- 9 files changed, 227 insertions(+), 96 deletions(-) create mode 100644 src/model/oauth_test.go diff --git a/src/api/v1/oauth_client_github.go b/src/api/v1/oauth_client_github.go index b936485..bf94022 100644 --- a/src/api/v1/oauth_client_github.go +++ b/src/api/v1/oauth_client_github.go @@ -5,12 +5,15 @@ import ( "fmt" "io" "net/http" + "time" "github.com/NJUPT-SAST/sast-link-backend/config" "github.com/NJUPT-SAST/sast-link-backend/endpoints" "github.com/NJUPT-SAST/sast-link-backend/log" + "github.com/NJUPT-SAST/sast-link-backend/model" "github.com/NJUPT-SAST/sast-link-backend/model/result" "github.com/NJUPT-SAST/sast-link-backend/service" + "github.com/NJUPT-SAST/sast-link-backend/util" "github.com/gin-gonic/gin" "github.com/tidwall/gjson" "golang.org/x/oauth2" @@ -25,7 +28,7 @@ var ( githubConf = oauth2.Config{ ClientID: config.Config.GetString("oauth.client.github.id"), ClientSecret: config.Config.GetString("oauth.client.github.secret"), - RedirectURL: config.Config.GetString("oauth.client.github.redirect_url"), + RedirectURL: "http://localhost:3000/callback/github", Scopes: []string{}, Endpoint: endpoints.GitHub, } @@ -33,6 +36,8 @@ var ( func OauthGithubLogin(c *gin.Context) { + redirectURL := c.Query("redirect_url") + githubConf.RedirectURL = redirectURL // Create oauthState cookie oauthState := GenerateStateOauthCookie(c.Writer) url := githubConf.AuthCodeURL(oauthState) @@ -58,29 +63,65 @@ func OauthGithubCallback(c *gin.Context) { code := c.Query("code") - githubId, err := getUserInfoFromGithub(c.Request.Context(), code) + // githubinfo is the user info from github + githubInfo, err := getUserInfoFromGithub(c.Request.Context(), code) if err != nil { c.JSON(http.StatusOK, result.Failed(result.HandleError(err))) return } - if githubId == "" { + if githubInfo == "" { c.JSON(http.StatusOK, result.Failed(result.HandleError(result.RequestParamError))) return } - log.Debug("GithubId: ", githubId) - user, err := service.GetUserByGithubId(githubId) + githubID := gjson.Get(githubInfo, "id").String() + // userInfo is the github user info in the database + userInfo, err := service.GetUserByGithubId(githubID) if err != nil { + log.Errorf("service.GetUserByGithubId ::: %s", err.Error()) c.JSON(http.StatusOK, result.Failed(result.HandleError(err))) return } + // Store to redis + model.Rdb.Set(model.RedisCtx, githubID, + githubInfo, time.Duration(model.OAUTH_USER_INFO_EXP)) + // User not found, Need to register to bind the github id - if user == nil { + if userInfo == nil { + log.Debugf("User not found, Need to register to bind the github id: %s", githubID) + oauthToken, err := util.GenerateTokenWithExp(c, model.OauthSubKey(githubID, model.OAUTH_GITHUB_SUB), model.OAUTH_TICKET_EXP) + + if err != nil { + c.JSON(http.StatusOK, result.Failed(result.GenerateToken)) + log.Log.Errorln("util.GenerateTokenWithExp ::: ", err) + return + } + c.JSON(http.StatusOK, result.Response{ + Success: false, + ErrCode: result.OauthUserUnbounded.ErrCode, + ErrMsg: result.OauthUserUnbounded.ErrMsg, + Data: gin.H{ + "oauthTicket": oauthToken, + }, + }) + return + } else { + // User already registered and bounded github, + // directly return token + uid := userInfo.UserID + log.Debugf("User already registered and bounded github: %s", uid) + token, err := util.GenerateTokenWithExp(c, model.LoginJWTSubKey(uid), model.LOGIN_TOKEN_EXP) + if err != nil { + c.JSON(http.StatusOK, result.Failed(result.GenerateToken)) + return + } + model.Rdb.Set(c, model.LoginTokenKey(uid), token, model.LOGIN_TOKEN_EXP) + c.JSON(http.StatusOK, result.Success(gin.H{ + model.LOGIN_TOKEN_SUB: token, + })) return } - - c.JSON(http.StatusOK, result.Success(githubId)) } func getUserInfoFromGithub(ctx context.Context, code string) (string, error) { @@ -109,7 +150,7 @@ func getUserInfoFromGithub(ctx context.Context, code string) (string, error) { return "", result.InternalErr } - // TODO:Now just get the github id - githubId := gjson.Get(string(body), "id").String() - return githubId, nil + log.Debugf("Github user info: %s", gjson.ParseBytes(body).String()) + + return gjson.ParseBytes(body).String(), nil } diff --git a/src/api/v1/oauth_client_lark.go b/src/api/v1/oauth_client_lark.go index 81fa08a..e0f9a6b 100644 --- a/src/api/v1/oauth_client_lark.go +++ b/src/api/v1/oauth_client_lark.go @@ -96,9 +96,9 @@ func OauthLarkCallback(c *gin.Context) { // save user info in redis (then retrive in login) userInfo := gjson.Get(userInfoBody, "data") model.Rdb.Set(model.RedisCtx, unionId, - userInfo, time.Duration(model.LARK_USER_INFO_EXP)) - + userInfo, time.Duration(model.OAUTH_USER_INFO_EXP)) + // FIXME: Use OauthInfoByUID to get user user, err := service.UserByLarkUnionID(unionId) if err != nil { c.JSON(http.StatusOK, result.Failed(result.InternalErr)) @@ -106,7 +106,7 @@ func OauthLarkCallback(c *gin.Context) { return } else if user == nil { // return with oauth lark ticket, which contains "union_id" - oauthToken, err := util.GenerateTokenWithExp(c, model.OauthSubKey(unionId), model.OAUTH_TICKET_EXP) + oauthToken, err := util.GenerateTokenWithExp(c, model.OauthSubKey(unionId, model.OAUTH_LARK_SUB), model.OAUTH_TICKET_EXP) if err != nil { c.JSON(http.StatusOK, result.Failed(result.GenerateToken)) diff --git a/src/api/v1/user.go b/src/api/v1/user.go index e79deab..c8379be 100644 --- a/src/api/v1/user.go +++ b/src/api/v1/user.go @@ -12,6 +12,8 @@ import ( "github.com/NJUPT-SAST/sast-link-backend/service" "github.com/NJUPT-SAST/sast-link-backend/util" "github.com/gin-gonic/gin" + + "gorm.io/datatypes" ) var controllerLogger = log.Log @@ -208,16 +210,6 @@ func Login(ctx *gin.Context) { return } - // Set Token with expire time and return - token, err := util.GenerateTokenWithExp(ctx, model.LoginJWTSubKey(uid), model.LOGIN_TOKEN_EXP) - if err != nil { - ctx.JSON(http.StatusOK, result.Failed(result.GenerateToken)) - } - model.Rdb.Set(ctx, model.LoginTokenKey(uid), token, model.LOGIN_TOKEN_EXP) - ctx.JSON(http.StatusOK, result.Success(gin.H{ - model.LOGIN_TOKEN_SUB: token, - })) - // Oauth: check if need to bound oauth servers like lark, github... // TODO: use cookie to manage ticket etc... oauthTicket := ctx.Request.Header.Get("OAUTH-TICKET") @@ -232,8 +224,10 @@ func Login(ctx *gin.Context) { } flagIn := strings.Split(audience[0], "-")[1] + log.Debugf("Login ::: Oauth ::: flagIn ::: %v", flagIn) + switch flagIn { - case "oauthLarkToken": + case model.OAUTH_LARK_SUB: unionID, err := util.IdentityFromToken(oauthTicket, model.OAUTH_LARK_SUB) if err != nil { ctx.JSON(http.StatusOK, result.Failed(result.OauthTokenError)) @@ -243,16 +237,36 @@ func Login(ctx *gin.Context) { // TODO: save oauth user info oauthLarkUserInfo, _ := model.Rdb.Get(ctx, unionID).Result() - if err := service.UpdateLarkUserInfo(username, model.LARK_CLIENT_TYPE, unionID, oauthLarkUserInfo); err != nil { - ctx.JSON(http.StatusOK, result.Failed(result.InternalErr)) - log.Log.Errorln("service.UpdateLarkUserInfo ::: ", err) + service.UpsetOauthInfo(username, model.LARK_CLIENT_TYPE, unionID, datatypes.JSON(oauthLarkUserInfo)) + case model.OAUTH_GITHUB_SUB: + unionID, err := util.IdentityFromToken(oauthTicket, model.OAUTH_GITHUB_SUB) + if err != nil { + ctx.JSON(http.StatusOK, result.Failed(result.OauthTokenError)) + log.Log.Errorln("util.IdentityFromToken ::: ", err) return } + + oauthGithubUserInfo, _ := model.Rdb.Get(ctx, unionID).Result() + + log.Debugf("Login ::: Oauth ::: github info ::: %v", oauthGithubUserInfo) + + service.UpsetOauthInfo(username, model.GITHUB_CLIENT_TYPE, unionID, datatypes.JSON(oauthGithubUserInfo)) default: + log.Errorf("Login ::: Oauth ::: flagIn ::: %v", flagIn) ctx.JSON(http.StatusOK, result.Failed(result.OauthTokenError)) return } } + + // Set Token with expire time and return + token, err := util.GenerateTokenWithExp(ctx, model.LoginJWTSubKey(uid), model.LOGIN_TOKEN_EXP) + if err != nil { + ctx.JSON(http.StatusOK, result.Failed(result.GenerateToken)) + } + model.Rdb.Set(ctx, model.LoginTokenKey(uid), token, model.LOGIN_TOKEN_EXP) + ctx.JSON(http.StatusOK, result.Success(gin.H{ + model.LOGIN_TOKEN_SUB: token, + })) } // Modify paassword diff --git a/src/go.mod b/src/go.mod index d591b7c..683b6d1 100644 --- a/src/go.mod +++ b/src/go.mod @@ -7,7 +7,7 @@ require ( github.com/spf13/viper v1.15.0 github.com/stretchr/testify v1.8.3 gorm.io/driver/postgres v1.5.0 - gorm.io/gorm v1.25.0 + gorm.io/gorm v1.25.9 ) require ( @@ -28,6 +28,7 @@ require ( github.com/vgarvardt/go-oauth2-pg/v4 v4.4.3 github.com/vgarvardt/go-pg-adapter v1.0.0 golang.org/x/oauth2 v0.12.0 + gorm.io/datatypes v1.2.1 ) require ( @@ -40,6 +41,7 @@ require ( ) require ( + filippo.io/edwards25519 v1.1.0 // indirect github.com/bytedance/sonic v1.9.2 // indirect github.com/cespare/xxhash/v2 v2.2.0 // indirect github.com/chenzhuoyu/base64x v0.0.0-20221115062448-fe3a3abad311 // indirect @@ -48,13 +50,13 @@ require ( github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f // indirect github.com/frankban/quicktest v1.14.4 // indirect github.com/gabriel-vasile/mimetype v1.4.2 // indirect - github.com/gin-contrib/logger v0.2.6 // indirect github.com/gin-contrib/sse v0.1.0 // indirect github.com/go-pkgz/expirable-cache v0.1.0 // indirect github.com/go-playground/locales v0.14.1 // indirect github.com/go-playground/universal-translator v0.18.1 // indirect github.com/go-playground/validator/v10 v10.14.1 // indirect github.com/go-redis/redis/v8 v8.11.4 // indirect + github.com/go-sql-driver/mysql v1.8.1 // indirect github.com/goccy/go-json v0.10.2 // indirect github.com/golang-jwt/jwt v3.2.1+incompatible // indirect github.com/golang/protobuf v1.5.3 // indirect @@ -66,10 +68,11 @@ require ( github.com/jackc/pgio v1.0.0 // indirect github.com/jackc/pgpassfile v1.0.0 // indirect github.com/jackc/pgproto3/v2 v2.2.0 // indirect - github.com/jackc/pgservicefile v0.0.0-20221227161230-091c0ba34f0a // indirect + github.com/jackc/pgservicefile v0.0.0-20231201235250-de7065d80cb9 // indirect github.com/jackc/pgtype v1.10.0 // indirect - github.com/jackc/pgx/v5 v5.3.1 // indirect + github.com/jackc/pgx/v5 v5.5.5 // indirect github.com/jackc/puddle v1.2.1 // indirect + github.com/jackc/puddle/v2 v2.2.1 // indirect github.com/jinzhu/inflection v1.0.0 // indirect github.com/jinzhu/now v1.1.5 // indirect github.com/jmoiron/sqlx v1.3.4 // indirect @@ -78,7 +81,6 @@ require ( github.com/klauspost/cpuid/v2 v2.2.5 // indirect github.com/leodido/go-urn v1.2.4 // indirect github.com/magiconair/properties v1.8.7 // indirect - github.com/mattn/go-colorable v0.1.13 // indirect github.com/mattn/go-isatty v0.0.19 // indirect github.com/mitchellh/mapstructure v1.5.0 // indirect github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect @@ -86,7 +88,6 @@ require ( github.com/mozillazg/go-httpheader v0.4.0 // indirect github.com/pelletier/go-toml/v2 v2.0.8 // indirect github.com/pmezard/go-difflib v1.0.0 // indirect - github.com/rs/zerolog v1.29.1 // indirect github.com/smarty/assertions v1.15.0 // indirect github.com/tidwall/match v1.1.1 // indirect github.com/tidwall/pretty v1.2.0 // indirect @@ -94,12 +95,14 @@ require ( github.com/ugorji/go/codec v1.2.11 // indirect github.com/vgarvardt/pgx-helpers/v4 v4.0.0-20200225100150-876aee3d1a22 // indirect golang.org/x/arch v0.4.0 // indirect - golang.org/x/crypto v0.13.0 // indirect - golang.org/x/net v0.15.0 // indirect - golang.org/x/sys v0.12.0 // indirect - golang.org/x/text v0.13.0 // indirect + golang.org/x/crypto v0.22.0 // indirect + golang.org/x/net v0.21.0 // indirect + golang.org/x/sync v0.1.0 // indirect + golang.org/x/sys v0.19.0 // indirect + golang.org/x/text v0.14.0 // indirect google.golang.org/appengine v1.6.7 // indirect google.golang.org/protobuf v1.31.0 // indirect gopkg.in/ini.v1 v1.67.0 // indirect gopkg.in/yaml.v3 v3.0.1 // indirect + gorm.io/driver/mysql v1.5.6 // indirect ) diff --git a/src/go.sum b/src/go.sum index 852606e..91decf0 100644 --- a/src/go.sum +++ b/src/go.sum @@ -37,6 +37,8 @@ cloud.google.com/go/storage v1.8.0/go.mod h1:Wv1Oy7z6Yz3DshWRJFhqM/UCfaWIRTdp0RX cloud.google.com/go/storage v1.10.0/go.mod h1:FLPqc6j+Ki4BU591ie1oL6qBQGu2Bl/tZ9ullr3+Kg0= cloud.google.com/go/storage v1.14.0/go.mod h1:GrKmX003DSIwi9o29oFT7YDnHYwZoctc3fOKtUw0Xmo= dmitri.shuralyov.com/gpu/mtl v0.0.0-20190408044501-666a987793e9/go.mod h1:H6x//7gZCb22OMCxBHrMx7a5I7Hp++hsVxbQ4BYO7hU= +filippo.io/edwards25519 v1.1.0 h1:FNf4tywRC1HmFuKW5xopWpigGjJKiJSV0Cqo0cJWDaA= +filippo.io/edwards25519 v1.1.0/go.mod h1:BxyFTGdWcka3PhytdK4V28tE5sGfRvvvRV7EaN4VDT4= github.com/Azure/go-ansiterm v0.0.0-20170929234023-d6e3b3328b78 h1:w+iIsaOQNcT7OZ575w+acHgRric5iCyQh+xv+KJ4HB8= github.com/Azure/go-ansiterm v0.0.0-20170929234023-d6e3b3328b78/go.mod h1:LmzpDX56iTiv29bbRTIsUNlaFfuhWRQBWjQdVyAevI8= github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU= @@ -55,8 +57,6 @@ github.com/andybalholm/brotli v1.0.4/go.mod h1:fO7iG3H7G2nSZ7m0zPUDn85XEX2GTukHG github.com/bsm/ginkgo/v2 v2.7.0 h1:ItPMPH90RbmZJt5GtkcNvIRuGEdwlBItdNVoyzaNQao= github.com/bsm/gomega v1.26.0 h1:LhQm+AFcgV2M0WyKroMASzAzCAJVpAxQXv4SaI9a69Y= github.com/bytedance/sonic v1.5.0/go.mod h1:ED5hyg4y6t3/9Ku1R6dU/4KyJ48DZ4jPhfY1O2AihPM= -github.com/bytedance/sonic v1.8.8 h1:Kj4AYbZSeENfyXicsYppYKO0K2YWab+i2UTSY7Ukz9Q= -github.com/bytedance/sonic v1.8.8/go.mod h1:i736AoUSYt75HyZLoJW9ERYxcy6eaN6h4BZXU064P/U= github.com/bytedance/sonic v1.9.2 h1:GDaNjuWSGu09guE9Oql0MSTNhNCLlWwO8y/xM5BzcbM= github.com/bytedance/sonic v1.9.2/go.mod h1:i736AoUSYt75HyZLoJW9ERYxcy6eaN6h4BZXU064P/U= github.com/cenkalti/backoff v2.2.1+incompatible h1:tNowT99t7UNflLxfYYSlKYsBpXdEet03Pg2g16Swow4= @@ -83,7 +83,6 @@ github.com/containerd/continuity v0.0.0-20200107194136-26c1120b8d41 h1:kIFnQBO7r github.com/containerd/continuity v0.0.0-20200107194136-26c1120b8d41/go.mod h1:Dq467ZllaHgAtVp4p1xUQWBrFXR9s/wyoTpG8zOJGkY= github.com/coreos/go-systemd v0.0.0-20190321100706-95778dfbb74e/go.mod h1:F5haX7vjVVG0kc13fIWeqUViNPyEJxv/OmvnBo0Yme4= github.com/coreos/go-systemd v0.0.0-20190719114852-fd7a80b32e1f/go.mod h1:F5haX7vjVVG0kc13fIWeqUViNPyEJxv/OmvnBo0Yme4= -github.com/coreos/go-systemd/v22 v22.5.0/go.mod h1:Y58oyj3AT4RCenI/lSvhwexgC+NSVTIJ3seZv2GcEnc= github.com/creack/pty v1.1.7/go.mod h1:lj5s0c3V2DBrqTV7llrYr5NG6My20zk30Fl46Y7DoTY= github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= @@ -117,12 +116,8 @@ github.com/gabriel-vasile/mimetype v1.4.2 h1:w5qFW6JKBz9Y393Y4q372O9A7cUSequkh1Q github.com/gabriel-vasile/mimetype v1.4.2/go.mod h1:zApsH/mKG4w07erKIaJPFiX0Tsq9BFQgN3qGY5GnNgA= github.com/gavv/httpexpect v2.0.0+incompatible h1:1X9kcRshkSKEjNJJxX9Y9mQ5BRfbxU5kORdjhlA1yX8= github.com/gavv/httpexpect v2.0.0+incompatible/go.mod h1:x+9tiU1YnrOvnB725RkpoLv1M62hOWzwo5OXotisrKc= -github.com/gin-contrib/logger v0.2.6 h1:u+tvbiQhGEyuJgZSHNja3WD800ILduVyk5xKop160dw= -github.com/gin-contrib/logger v0.2.6/go.mod h1:ZDkY/xiMqbZdz83enCHjMqxJUFRzB8bq0kjyMmjr3qU= github.com/gin-contrib/sse v0.1.0 h1:Y/yl/+YNO8GZSjAhjMsSuLt29uWRFHdHYUb5lYOV9qE= github.com/gin-contrib/sse v0.1.0/go.mod h1:RHrZQHXnP2xjPF+u1gW/2HnVO7nvIa9PG3Gm+fLHvGI= -github.com/gin-gonic/gin v1.9.0 h1:OjyFBKICoexlu99ctXNR2gg+c5pKrKMuyjgARg9qeY8= -github.com/gin-gonic/gin v1.9.0/go.mod h1:W1Me9+hsUSyj3CePGrd1/QrKJMSJ1Tu/0hFEH89961k= github.com/gin-gonic/gin v1.9.1 h1:4idEAncQnU5cB7BeOkPtxjfCSye0AAm1R0RVIqJ+Jmg= github.com/gin-gonic/gin v1.9.1/go.mod h1:hPrL7YrpYKXt5YId3A/Tnip5kqbEAP+KLuI3SUcPTeU= github.com/go-gl/glfw v0.0.0-20190409004039-e6da0acd62b1/go.mod h1:vR7hzQXu2zJy9AVAgeJqvqgH9Q5CA+iKCZ2gyEVpxRU= @@ -140,8 +135,6 @@ github.com/go-playground/locales v0.14.1 h1:EWaQ/wswjilfKLTECiXz7Rh+3BjFhfDFKv/o github.com/go-playground/locales v0.14.1/go.mod h1:hxrqLVvrK65+Rwrd5Fc6F2O76J/NuW9t0sjnWqG1slY= github.com/go-playground/universal-translator v0.18.1 h1:Bcnm0ZwsGyWbCzImXv+pAJnYK9S473LQFuzCbDbfSFY= github.com/go-playground/universal-translator v0.18.1/go.mod h1:xekY+UJKNuX9WP91TpwSH2VMlDf28Uj24BCp08ZFTUY= -github.com/go-playground/validator/v10 v10.13.0 h1:cFRQdfaSMCOSfGCCLB20MHvuoHb/s5G8L5pu2ppK5AQ= -github.com/go-playground/validator/v10 v10.13.0/go.mod h1:dwu7+CG8/CtBiJFZDz4e+5Upb6OLw04gtBYw0mcG/z4= github.com/go-playground/validator/v10 v10.14.1 h1:9c50NUPC30zyuKprjL3vNZ0m5oG+jU0zvx4AqHGnv4k= github.com/go-playground/validator/v10 v10.14.1/go.mod h1:9iXMNT7sEkjXb0I+enO7QXmzG6QCsPWY4zveKFVRSyU= github.com/go-redis/redis/v8 v8.11.4 h1:kHoYkfZP6+pe04aFTnhDH6GDROa5yJdHJVNxV3F46Tg= @@ -153,11 +146,13 @@ github.com/go-session/session/v3 v3.1.5 h1:G44Qx6wts5IA2jNLWYOVYxip/0LH5FTg8/Tde github.com/go-session/session/v3 v3.1.5/go.mod h1:sWg9Nca0XsmPHUnPypN+yl6zV/OSilR69vFBnkJgNjY= github.com/go-sql-driver/mysql v1.4.0/go.mod h1:zAC/RDZ24gD3HViQzih4MyKcchzm+sOG5ZlKdlhCg5w= github.com/go-sql-driver/mysql v1.5.0/go.mod h1:DCzpHaOWr8IXmIStZouvnhqoel9Qv2LBy8hT2VhHyBg= +github.com/go-sql-driver/mysql v1.7.0/go.mod h1:OXbVy3sEdcQ2Doequ6Z5BW6fXNQTmx+9S1MCJN5yJMI= +github.com/go-sql-driver/mysql v1.8.1 h1:LedoTUt/eveggdHS9qUFC1EFSa8bU2+1pZjSRpvNJ1Y= +github.com/go-sql-driver/mysql v1.8.1/go.mod h1:wEBSXgmK//2ZFJyE+qWnIsVGmvmEKlqwuVSjsCm7DZg= github.com/go-stack/stack v1.8.0/go.mod h1:v0f6uXyyMGvRgIKkXu+yp6POWl0qKG85gN/melR3HDY= github.com/go-task/slim-sprig v0.0.0-20210107165309-348f09dbbbc0/go.mod h1:fyg7847qk6SyHyPtNmDHnmrv/HOrqktSC+C9fM+CJOE= github.com/goccy/go-json v0.10.2 h1:CrxCmQqYDkv1z7lO7Wbh2HN93uovUHgrECaO5ZrCXAU= github.com/goccy/go-json v0.10.2/go.mod h1:6MelG93GURQebXPDq3khkgXZkazVtN9CRI+MGFi0w8I= -github.com/godbus/dbus/v5 v5.0.4/go.mod h1:xhWf0FNVPg57R7Z0UbKHbJfkEywrmjJnf7w5xrFpKfA= github.com/gofrs/uuid v3.2.0+incompatible/go.mod h1:b2aQJv3Z4Fp6yNu3cdSllBxTCLRxnplIgP/c0N/04lM= github.com/gofrs/uuid v4.0.0+incompatible h1:1SD/1F5pU8p29ybwgQSwpQk+mwdRrXCYuPhW6m+TnJw= github.com/gofrs/uuid v4.0.0+incompatible/go.mod h1:b2aQJv3Z4Fp6yNu3cdSllBxTCLRxnplIgP/c0N/04lM= @@ -165,6 +160,8 @@ github.com/golang-jwt/jwt v3.2.1+incompatible h1:73Z+4BJcrTC+KczS6WvTPvRGOp1WmfE github.com/golang-jwt/jwt v3.2.1+incompatible/go.mod h1:8pz2t5EyA70fFQQSrl6XZXzqecmYZeUEB8OUGHkxJ+I= github.com/golang-jwt/jwt/v5 v5.0.0 h1:1n1XNM9hk7O9mnQoNBGolZvzebBQ7p93ULHRc28XJUE= github.com/golang-jwt/jwt/v5 v5.0.0/go.mod h1:pqrtFR0X4osieyHYxtmOUWsAWrfe1Q5UVIyoH402zdk= +github.com/golang-sql/civil v0.0.0-20220223132316-b832511892a9 h1:au07oEsX2xN0ktxqI+Sida1w446QrXBRJ0nee3SNZlA= +github.com/golang-sql/sqlexp v0.1.0 h1:ZCD6MBpcuOVfGVqsEmY5/4FtYiKz6tSyUv9LPEDei6A= github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b/go.mod h1:SBH7ygxi8pfUlaOkMMuAQtPIUF8ecWP5IEl/CR7VP2Q= github.com/golang/groupcache v0.0.0-20190702054246-869f871628b6/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc= github.com/golang/groupcache v0.0.0-20191227052852-215e87163ea7/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc= @@ -288,8 +285,9 @@ github.com/jackc/pgproto3/v2 v2.2.0 h1:r7JypeP2D3onoQTCxWdTpCtJ4D+qpKr0TxvoyMhZ5 github.com/jackc/pgproto3/v2 v2.2.0/go.mod h1:WfJCnwN3HIg9Ish/j3sgWXnAfK8A9Y0bwXYU5xKaEdA= github.com/jackc/pgservicefile v0.0.0-20200307190119-3430c5407db8/go.mod h1:vsD4gTJCa9TptPL8sPkXrLZ+hDuNrZCnj29CQpr4X1E= github.com/jackc/pgservicefile v0.0.0-20200714003250-2b9c44734f2b/go.mod h1:vsD4gTJCa9TptPL8sPkXrLZ+hDuNrZCnj29CQpr4X1E= -github.com/jackc/pgservicefile v0.0.0-20221227161230-091c0ba34f0a h1:bbPeKD0xmW/Y25WS6cokEszi5g+S0QxI/d45PkRi7Nk= github.com/jackc/pgservicefile v0.0.0-20221227161230-091c0ba34f0a/go.mod h1:5TJZWKEWniPve33vlWYSoGYefn3gLQRzjfDlhSJ9ZKM= +github.com/jackc/pgservicefile v0.0.0-20231201235250-de7065d80cb9 h1:L0QtFUgDarD7Fpv9jeVMgy/+Ec0mtnmYuImjTz6dtDA= +github.com/jackc/pgservicefile v0.0.0-20231201235250-de7065d80cb9/go.mod h1:5TJZWKEWniPve33vlWYSoGYefn3gLQRzjfDlhSJ9ZKM= github.com/jackc/pgtype v0.0.0-20190421001408-4ed0de4755e0/go.mod h1:hdSHsc1V01CGwFsrv11mJRHWJ6aifDLfdV3aVjFF0zg= github.com/jackc/pgtype v0.0.0-20190824184912-ab885b375b90/go.mod h1:KcahbBH1nCMSo2DXpzsoWOAfFkdEtEJpPbVLq8eE+mc= github.com/jackc/pgtype v0.0.0-20190828014616-a8802b16cc59/go.mod h1:MWlu30kVJrUS8lot6TQqcg7mtthZ9T0EoIBFiJcmcyw= @@ -311,8 +309,8 @@ github.com/jackc/pgx/v4 v4.14.1/go.mod h1:RgDuE4Z34o7XE92RpLsvFiOEfrAUT0Xt2KxvX7 github.com/jackc/pgx/v4 v4.15.0 h1:B7dTkXsdILD3MF987WGGCcg+tvLW6bZJdEcqVFeU//w= github.com/jackc/pgx/v4 v4.15.0/go.mod h1:D/zyOyXiaM1TmVWnOM18p0xdDtdakRBa0RsVGI3U3bw= github.com/jackc/pgx/v5 v5.3.0/go.mod h1:t3JDKnCBlYIc0ewLF0Q7B8MXmoIaBOZj/ic7iHozM/8= -github.com/jackc/pgx/v5 v5.3.1 h1:Fcr8QJ1ZeLi5zsPZqQeUZhNhxfkkKBOgJuYkJHoBOtU= -github.com/jackc/pgx/v5 v5.3.1/go.mod h1:t3JDKnCBlYIc0ewLF0Q7B8MXmoIaBOZj/ic7iHozM/8= +github.com/jackc/pgx/v5 v5.5.5 h1:amBjrZVmksIdNjxGW/IiIMzxMKZFelXbUoPNb+8sjQw= +github.com/jackc/pgx/v5 v5.5.5/go.mod h1:ez9gk+OAat140fv9ErkZDYFWmXLfV+++K0uAOiwgm1A= github.com/jackc/puddle v0.0.0-20190413234325-e4ced69a3a2b/go.mod h1:m4B5Dj62Y0fbyuIc15OsIqK0+JU8nkqQjsgx7dvjSWk= github.com/jackc/puddle v0.0.0-20190608224051-11cab39313c9/go.mod h1:m4B5Dj62Y0fbyuIc15OsIqK0+JU8nkqQjsgx7dvjSWk= github.com/jackc/puddle v1.0.0/go.mod h1:m4B5Dj62Y0fbyuIc15OsIqK0+JU8nkqQjsgx7dvjSWk= @@ -322,6 +320,8 @@ github.com/jackc/puddle v1.2.0/go.mod h1:m4B5Dj62Y0fbyuIc15OsIqK0+JU8nkqQjsgx7dv github.com/jackc/puddle v1.2.1 h1:gI8os0wpRXFd4FiAY2dWiqRK037tjj3t7rKFeO4X5iw= github.com/jackc/puddle v1.2.1/go.mod h1:m4B5Dj62Y0fbyuIc15OsIqK0+JU8nkqQjsgx7dvjSWk= github.com/jackc/puddle/v2 v2.2.0/go.mod h1:vriiEXHvEE654aYKXXjOvZM39qJ0q+azkZFrfEOc3H4= +github.com/jackc/puddle/v2 v2.2.1 h1:RhxXJtFG022u4ibrCSMSiu5aOq1i77R3OHKNJj77OAk= +github.com/jackc/puddle/v2 v2.2.1/go.mod h1:vriiEXHvEE654aYKXXjOvZM39qJ0q+azkZFrfEOc3H4= github.com/jinzhu/inflection v1.0.0 h1:K317FqzuhWc8YvSVlFMCCUb36O/S9MCKRDI7QkRKD/E= github.com/jinzhu/inflection v1.0.0/go.mod h1:h+uFLlag+Qp1Va5pdKtLDYj+kHp5pxUVkryuEj+Srlc= github.com/jinzhu/now v1.1.5 h1:/o9tlHleP7gOFmsnYNz3RGnqzefHA47wQpKrrdTIwXQ= @@ -342,8 +342,6 @@ github.com/klauspost/compress v1.10.10/go.mod h1:aoV0uJVorq1K+umq18yTdKaF57EivdY github.com/klauspost/compress v1.15.0 h1:xqfchp4whNFxn5A4XFyyYtitiWI8Hy5EW59jEwcyL6U= github.com/klauspost/compress v1.15.0/go.mod h1:/3/Vjq9QcHkK5uEr5lBEmyoZ1iFhe47etQ6QUkpK6sk= github.com/klauspost/cpuid/v2 v2.0.9/go.mod h1:FInQzS24/EEf25PyTYn52gqo7WaD8xa0213Md/qVLRg= -github.com/klauspost/cpuid/v2 v2.2.4 h1:acbojRNwl3o09bUq+yDCtZFc1aiwaAAxtcn8YkZXnvk= -github.com/klauspost/cpuid/v2 v2.2.4/go.mod h1:RVVoqg1df56z8g3pUjL/3lE5UfnlrJX8tyFgg4nqhuY= github.com/klauspost/cpuid/v2 v2.2.5 h1:0E5MSMDEoAulmXNFquVs//DdoomxaoTY1kUhbc/qbZg= github.com/klauspost/cpuid/v2 v2.2.5/go.mod h1:Lcz8mBdAVJIBVzewtcLocK12l3Y+JytZYpaMropDUws= github.com/konsorten/go-windows-terminal-sequences v1.0.1/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ= @@ -373,22 +371,17 @@ github.com/mattn/go-colorable v0.1.1/go.mod h1:FuOcm+DKB9mbwrcAfNl7/TZVBZ6rcncea github.com/mattn/go-colorable v0.1.2/go.mod h1:U0ppj6V5qS13XJ6of8GYAs25YV2eR4EVcfRqFIhoBtE= github.com/mattn/go-colorable v0.1.6/go.mod h1:u6P/XSegPjTcexA+o6vUJrdnUu04hMope9wVRipJSqc= github.com/mattn/go-colorable v0.1.7/go.mod h1:u6P/XSegPjTcexA+o6vUJrdnUu04hMope9wVRipJSqc= -github.com/mattn/go-colorable v0.1.12/go.mod h1:u5H1YNBxpqRaxsYJYSkiCWKzEfiAb1Gb520KVy5xxl4= -github.com/mattn/go-colorable v0.1.13 h1:fFA4WZxdEF4tXPZVKMLwD8oUnCTTo08duU7wxecdEvA= -github.com/mattn/go-colorable v0.1.13/go.mod h1:7S9/ev0klgBDR4GtXTXX8a3vIGJpMovkB8vQcUbaXHg= github.com/mattn/go-isatty v0.0.5/go.mod h1:Iq45c/XA43vh69/j3iqttzPXn0bhXyGjM0Hdxcsrc5s= github.com/mattn/go-isatty v0.0.7/go.mod h1:Iq45c/XA43vh69/j3iqttzPXn0bhXyGjM0Hdxcsrc5s= github.com/mattn/go-isatty v0.0.8/go.mod h1:Iq45c/XA43vh69/j3iqttzPXn0bhXyGjM0Hdxcsrc5s= github.com/mattn/go-isatty v0.0.9/go.mod h1:YNRxwqDuOph6SZLI9vUUz6OYw3QyUt7WiY2yME+cCiQ= github.com/mattn/go-isatty v0.0.12/go.mod h1:cbi8OIDigv2wuxKPP5vlRcQ1OAZbq2CE4Kysco4FUpU= -github.com/mattn/go-isatty v0.0.14/go.mod h1:7GGIvUiUoEMVVmxf/4nioHXj79iQHKdU27kJ6hsGG94= -github.com/mattn/go-isatty v0.0.16/go.mod h1:kYGgaQfpe5nmfYZH+SKPsOc2e4SrIfOl2e/yFXSvRLM= -github.com/mattn/go-isatty v0.0.18 h1:DOKFKCQ7FNG2L1rbrmstDN4QVRdS89Nkh85u68Uwp98= -github.com/mattn/go-isatty v0.0.18/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y= github.com/mattn/go-isatty v0.0.19 h1:JITubQf0MOLdlGRuRq+jtsDlekdYPia9ZFsB8h/APPA= github.com/mattn/go-isatty v0.0.19/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y= github.com/mattn/go-sqlite3 v1.9.0/go.mod h1:FPy6KqzDD04eiIsT53CuJW3U88zkxoIYsOqkbpncsNc= github.com/mattn/go-sqlite3 v1.14.6/go.mod h1:NyWgC/yNuGj7Q9rpYnZvas74GogHl5/Z4A/KQRfk6bU= +github.com/mattn/go-sqlite3 v1.14.15 h1:vfoHhTN1af61xCRSWzFIWzx2YskyMTwHLrExkBOjvxI= +github.com/microsoft/go-mssqldb v0.17.0 h1:Fto83dMZPnYv1Zwx5vHHxpNraeEaUlQ/hhHLgZiaenE= github.com/mitchellh/mapstructure v1.4.3/go.mod h1:bFUtVrKA4DC2yAKiSyO/QUcy7e+RRV2QTWOzhPopBRo= github.com/mitchellh/mapstructure v1.5.0 h1:jeMsZIYE/09sWLaz43PL7Gy6RuMjD2eJVyuac5Z2hdY= github.com/mitchellh/mapstructure v1.5.0/go.mod h1:bFUtVrKA4DC2yAKiSyO/QUcy7e+RRV2QTWOzhPopBRo= @@ -424,8 +417,6 @@ github.com/opencontainers/runc v0.1.1 h1:GlxAyO6x8rfZYN9Tt0Kti5a/cP41iuiO2yYT0IJ github.com/opencontainers/runc v0.1.1/go.mod h1:qT5XzbpPznkRYVz/mWwUaVBUv2rmF59PVA73FjuZG0U= github.com/ory/dockertest v3.3.5+incompatible h1:iLLK6SQwIhcbrG783Dghaaa3WPzGc+4Emza6EbVUUGA= github.com/ory/dockertest v3.3.5+incompatible/go.mod h1:1vX4m9wsvi00u5bseYwXaSnhNrne+V0E6LAcBILJdPs= -github.com/pelletier/go-toml/v2 v2.0.7 h1:muncTPStnKRos5dpVKULv2FVd4bMOhNePj9CjgDb8Us= -github.com/pelletier/go-toml/v2 v2.0.7/go.mod h1:eumQOmlWiOPt5WriQQqoM5y18pDHwha2N+QD+EUNTek= github.com/pelletier/go-toml/v2 v2.0.8 h1:0ctb6s9mE31h0/lhu+J6OPmVeDxJn+kYnJc2jZR9tGQ= github.com/pelletier/go-toml/v2 v2.0.8/go.mod h1:vuYfssBdrU2XDZ9bYydBu6t+6a6PYNcZljzZR9VXg+4= github.com/pkg/diff v0.0.0-20210226163009-20ebb0f2a09e/go.mod h1:pJLUxLENpZxwdsKMEsNbx1VGcRFpLqf3715MtcvvzbA= @@ -444,11 +435,8 @@ github.com/rogpeppe/go-internal v1.6.1/go.mod h1:xXDCJY+GAPziupqXw64V24skbSoqbTE github.com/rogpeppe/go-internal v1.9.0 h1:73kH8U+JUqXU8lRuOHeVHaa/SZPifC7BkcraZVejAe8= github.com/rogpeppe/go-internal v1.9.0/go.mod h1:WtVeX8xhTBvf0smdhujwtBcq4Qrzq/fJaraNFVN+nFs= github.com/rs/xid v1.2.1/go.mod h1:+uKXf+4Djp6Md1KODXJxgGQPKngRmWyn10oCKFzNHOQ= -github.com/rs/xid v1.4.0/go.mod h1:trrq9SKmegXys3aeAKXMUTdJsYXVwGY3RLcfgqegfbg= github.com/rs/zerolog v1.13.0/go.mod h1:YbFCdg8HfsridGWAh22vktObvhZbQsZXe4/zB0OKkWU= github.com/rs/zerolog v1.15.0/go.mod h1:xYTKnLHcpfU2225ny5qZjxnj9NvkumZYjJHlAThCjNc= -github.com/rs/zerolog v1.29.1 h1:cO+d60CHkknCbvzEWxP0S9K6KqyTjrCNUy1LdQLCGPc= -github.com/rs/zerolog v1.29.1/go.mod h1:Le6ESbR7hc+DP6Lt1THiV8CQSdkkNrd3R0XbEgp3ZBU= github.com/satori/go.uuid v1.2.0/go.mod h1:dA0hQrYB0VpLJoorglMZABFdXlWrHn1NEOzdhQKdks0= github.com/sclevine/agouti v3.0.0+incompatible/go.mod h1:b4WX9W9L1sfQKXeJf1mUTLZKJ48R1S7H23Ji7oFO5Bw= github.com/sergi/go-diff v1.1.0 h1:we8PVUC3FE2uYfodKH/nBHMSetSfHDR6scGdBi+erh0= @@ -497,7 +485,6 @@ github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/ github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU= github.com/stretchr/testify v1.8.1/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4= -github.com/stretchr/testify v1.8.2 h1:+h33VjcLVPDHtOdpUCuF+7gSuG3yGIftsP1YvFihtJ8= github.com/stretchr/testify v1.8.2/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4= github.com/stretchr/testify v1.8.3 h1:RP3t2pwF7cMEbC1dqtB6poj3niw/9gnV4Cjg5oW5gtY= github.com/stretchr/testify v1.8.3/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo= @@ -581,8 +568,6 @@ go.uber.org/zap v1.9.1/go.mod h1:vwi/ZaCAaUcBkycHslxD9B2zi4UTXhF60s6SWpuDF0Q= go.uber.org/zap v1.10.0/go.mod h1:vwi/ZaCAaUcBkycHslxD9B2zi4UTXhF60s6SWpuDF0Q= go.uber.org/zap v1.13.0/go.mod h1:zwrFLgMcdUuIBviXEYEH1YKNaOBnKXsx2IPda5bBwHM= golang.org/x/arch v0.0.0-20210923205945-b76863e36670/go.mod h1:5om86z9Hs0C8fWVUuoMHwpExlXzs5Tkyp9hOrfG7pp8= -golang.org/x/arch v0.3.0 h1:02VY4/ZcO/gBOH6PUaoiptASxtXU10jazRCP865E97k= -golang.org/x/arch v0.3.0/go.mod h1:5om86z9Hs0C8fWVUuoMHwpExlXzs5Tkyp9hOrfG7pp8= golang.org/x/arch v0.4.0 h1:A8WCeEWhLwPBKNbFi5Wv5UTCBx5zzubnXDlMOFAzFMc= golang.org/x/arch v0.4.0/go.mod h1:5om86z9Hs0C8fWVUuoMHwpExlXzs5Tkyp9hOrfG7pp8= golang.org/x/crypto v0.0.0-20171113213409-9f005a07e0d3/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4= @@ -604,8 +589,8 @@ golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5y golang.org/x/crypto v0.0.0-20220214200702-86341886e292/go.mod h1:IxCIyHEi3zRg3s0A5j5BB6A9Jmi73HwBIUl50j+osU4= golang.org/x/crypto v0.0.0-20220722155217-630584e8d5aa/go.mod h1:IxCIyHEi3zRg3s0A5j5BB6A9Jmi73HwBIUl50j+osU4= golang.org/x/crypto v0.6.0/go.mod h1:OFC/31mSvZgRz0V1QTNCzfAI1aIRzbiufJtkMIlEp58= -golang.org/x/crypto v0.13.0 h1:mvySKfSWJ+UKUii46M40LOvyWfN0s2U+46/jDd0e6Ck= -golang.org/x/crypto v0.13.0/go.mod h1:y6Z2r+Rw4iayiXXAIxJIDAJ1zMW4yaTpebo8fPOliYc= +golang.org/x/crypto v0.22.0 h1:g1v0xeRhjcugydODzvb3mEM9SQ0HGp9s/nh3COQ/C30= +golang.org/x/crypto v0.22.0/go.mod h1:vr6Su+7cTlO45qkww3VDJlzDn0ctJvRgYbC2NvXHt+M= golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA= golang.org/x/exp v0.0.0-20190306152737-a1d7652674e8/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA= golang.org/x/exp v0.0.0-20190510132918-efd6b22b2522/go.mod h1:ZjyILWgesfNpC6sMxTJOJm9Kp84zZh5NQWvqDGG3Qr8= @@ -679,8 +664,8 @@ golang.org/x/net v0.0.0-20211112202133-69e39bad7dc2/go.mod h1:9nx3DQGgdP8bBQD5qx golang.org/x/net v0.0.0-20220225172249-27dd8689420f/go.mod h1:CfG3xpIq0wQ8r1q4Su4UZFWDARRcnwPjda9FqA0JpMk= golang.org/x/net v0.0.0-20220722155237-a158d28d115b/go.mod h1:XRhObCWvk6IyKnWLug+ECip1KBveYUHfp+8e9klMJ9c= golang.org/x/net v0.6.0/go.mod h1:2Tu9+aMcznHK/AK1HMvgo6xiTLG5rD5rZLDS+rp2Bjs= -golang.org/x/net v0.15.0 h1:ugBLEUaxABaB5AJqW9enI0ACdci2RUd4eP51NTBvuJ8= -golang.org/x/net v0.15.0/go.mod h1:idbUs1IY1+zTqbi8yxTbhexhEEk5ur9LInksu6HrEpk= +golang.org/x/net v0.21.0 h1:AQyQV4dYCvJ7vGmJyKki9+PBdyvhkSd8EIx/qb0AYv4= +golang.org/x/net v0.21.0/go.mod h1:bIjVDfnllIU7BJ2DNgfnXvpSvtn8VRwhlsaeUTyUS44= golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U= golang.org/x/oauth2 v0.0.0-20190226205417-e64efc72b421/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw= golang.org/x/oauth2 v0.0.0-20190604053449-0f29369cfe45/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw= @@ -703,6 +688,7 @@ golang.org/x/sync v0.0.0-20200625203802-6e8e738ad208/go.mod h1:RxMgew5VJxzue5/jJ golang.org/x/sync v0.0.0-20201020160332-67f06af15bc9/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20201207232520-09787c993a3a/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sync v0.1.0 h1:wsuoTGHzEhffawBOhz5CYhcrV4IdKZbEyZjBMuTp12o= golang.org/x/sync v0.1.0/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sys v0.0.0-20180830151530-49385e6e1522/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20180905080454-ebe1bf3edb33/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= @@ -754,20 +740,16 @@ golang.org/x/sys v0.0.0-20210225134936-a50acf3fe073/go.mod h1:h1NjWce9XRLGQEsW7w golang.org/x/sys v0.0.0-20210423082822-04245dca01da/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20210423185535-09eb48e85fd7/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.0.0-20210630005230-0f9fa26af87c/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.0.0-20210927094055-39ccf1dd6fa6/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20211216021012-1d35b9e2eb4e/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20220227234510-4e6760a101f9/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.0.0-20220704084225-05e143d24a9e/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20220715151400-c0bba94af5f8/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20220908164124-27713097b956/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.5.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.12.0 h1:CM0HF96J0hcLAwsHPJZjfdNzs0gftsLfgKt57wWHJ0o= -golang.org/x/sys v0.12.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= +golang.org/x/sys v0.19.0 h1:q5f1RH2jigJ1MoAWp2KTp3gm5zAGFUTarQZ5U386+4o= +golang.org/x/sys v0.19.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= golang.org/x/term v0.0.0-20201117132131-f5c789dd3221/go.mod h1:Nr5EML6q2oocZ2LXRh80K7BxOlk5/8JxuGnuhpl+muw= golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8= @@ -781,8 +763,8 @@ golang.org/x/text v0.3.4/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= golang.org/x/text v0.3.6/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ= golang.org/x/text v0.7.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8= -golang.org/x/text v0.13.0 h1:ablQoSUd0tRdKxZewP80B+BaqeKJuVhuRxj/dkrun3k= -golang.org/x/text v0.13.0/go.mod h1:TvPlkZtksWOMsz7fbANvkp4WM8x/WCo/om8BMLbz+aE= +golang.org/x/text v0.14.0 h1:ScX5w1eTa3QqT8oi6+ziP7dTV1S2+ALU0bI+0zXKWiQ= +golang.org/x/text v0.14.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU= golang.org/x/time v0.0.0-20181108054448-85acf8d2951c/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= golang.org/x/time v0.0.0-20190308202827-9d24e82272b4/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= golang.org/x/time v0.0.0-20191024005414-555d28b269f0/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= @@ -964,11 +946,18 @@ gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C gopkg.in/yaml.v3 v3.0.0-20200615113413-eeeca48fe776/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= +gorm.io/datatypes v1.2.1 h1:r+g0bk4LPCW2v4+Ls7aeNgGme7JYdNDQ2VtvlNUfBh0= +gorm.io/datatypes v1.2.1/go.mod h1:hYK6OTb/1x+m96PgoZZq10UXJ6RvEBb9kRDQ2yyhzGs= +gorm.io/driver/mysql v1.5.6 h1:Ld4mkIickM+EliaQZQx3uOJDJHtrd70MxAUqWqlx3Y8= +gorm.io/driver/mysql v1.5.6/go.mod h1:sEtPWMiqiN1N1cMXoXmBbd8C6/l+TESwriotuRRpkDM= gorm.io/driver/postgres v1.5.0 h1:u2FXTy14l45qc3UeCJ7QaAXZmZfDDv0YrthvmRq1l0U= gorm.io/driver/postgres v1.5.0/go.mod h1:FUZXzO+5Uqg5zzwzv4KK49R8lvGIyscBOqYrtI1Ce9A= +gorm.io/driver/sqlite v1.4.3 h1:HBBcZSDnWi5BW3B3rwvVTc510KGkBkexlOg0QrmLUuU= +gorm.io/driver/sqlserver v1.4.1 h1:t4r4r6Jam5E6ejqP7N82qAJIJAht27EGT41HyPfXRw0= gorm.io/gorm v1.24.7-0.20230306060331-85eaf9eeda11/go.mod h1:L4uxeKpfBml98NYqVqwAdmV1a2nBtAec/cf3fpucW/k= -gorm.io/gorm v1.25.0 h1:+KtYtb2roDz14EQe4bla8CbQlmb9dN3VejSai3lprfU= -gorm.io/gorm v1.25.0/go.mod h1:L4uxeKpfBml98NYqVqwAdmV1a2nBtAec/cf3fpucW/k= +gorm.io/gorm v1.25.7/go.mod h1:hbnx/Oo0ChWMn1BIhpy1oYozzpM15i4YPuHDmfYtwg8= +gorm.io/gorm v1.25.9 h1:wct0gxZIELDk8+ZqF/MVnHLkA1rvYlBWUMv2EdsK1g8= +gorm.io/gorm v1.25.9/go.mod h1:hbnx/Oo0ChWMn1BIhpy1oYozzpM15i4YPuHDmfYtwg8= gotest.tools v2.2.0+incompatible/go.mod h1:DsYFclhRJ6vuDpmuTbkuFWG+y2sxOXAzmJt81HFBacw= honnef.co/go/tools v0.0.0-20190102054323-c2f93a96b099/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= honnef.co/go/tools v0.0.0-20190106161140-3f1c8253044a/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= diff --git a/src/model/common.go b/src/model/common.go index ac7b5e7..823680c 100644 --- a/src/model/common.go +++ b/src/model/common.go @@ -14,9 +14,10 @@ const ( LOGIN_TICKET_EXP = time.Minute * 5 // This is login token expire time LOGIN_TOKEN_EXP = time.Hour * 24 * 7 - LARK_USER_INFO_EXP = time.Minute * 5 + OAUTH_USER_INFO_EXP = time.Minute * 5 LARK_CLIENT_TYPE = "lark" + GITHUB_CLIENT_TYPE = "github" // For JWT @@ -25,6 +26,7 @@ const ( REGIST_TICKET_SUB = "registerTicket" RESETPWD_TICKET_SUB = "resetPwdTicket" OAUTH_LARK_SUB = "oauthLarkToken" + OAUTH_GITHUB_SUB = "oauthGithubToken" ) var ( @@ -76,6 +78,6 @@ func VerifyCodeKey(username string) string { // identity is the unique identifier for oauth app user // like "union_id" for lark, "github_id" for github -func OauthSubKey(identity string) string { - return fmt.Sprintf("%s-%s", identity, OAUTH_LARK_SUB) +func OauthSubKey(identity, oauthType string) string { + return fmt.Sprintf("%s-%s", identity, oauthType) } diff --git a/src/model/oauth.go b/src/model/oauth.go index edf3380..036cc3d 100644 --- a/src/model/oauth.go +++ b/src/model/oauth.go @@ -1,9 +1,58 @@ package model -func UpdateLarkUserInfo(username, clientType, oauthID, larkUserInfo string) error { +import ( + // "encoding/json" + "errors" + + "github.com/NJUPT-SAST/sast-link-backend/log" + "github.com/NJUPT-SAST/sast-link-backend/model/result" + "gorm.io/datatypes" + "gorm.io/gorm" +) + +// OAuth2Info struct +type OAuth2Info struct { + ID uint `gorm:"primaryKey"` + Client string `gorm:"not null"` + Info datatypes.JSON `gorm:"default:'[]'"` + OauthID string `gorm:"not null"` + UserID string `gorm:"not null"` +} + +func UpdateLarkUserInfo(info OAuth2Info) error { return Db.Table("oauth2_info"). - Where("user_id = ?", username). + Where("user_id = ?", info.UserID). + Where("client = ?", info.Client). + Update("oauth_user_id = ?", info.OauthID). + Update("info = ?", info.Info).Error +} + +// OauthInfoByUID find user by specific client id in oauth2_info table +func OauthInfoByUID(clientType, oauthUID string) (*OAuth2Info, error) { + var client OAuth2Info + err := Db.Table("oauth2_info"). + Where("oauth_user_id = ?", oauthUID). Where("client = ?", clientType). - Update("oauth_user_id = ?", oauthID). - Update("info = ?", larkUserInfo).Error + First(&client).Error + if err != nil { + if errors.Is(err, gorm.ErrRecordNotFound) { + return nil, nil + } + log.Errorf("model.OauthInfoByUID ::: %s", err.Error()) + return nil, result.InternalErr + } + return &client, nil +} + +// UpsetOauthInfo insert or update oauth2_info table +func UpsetOauthInfo(oauthInfo OAuth2Info) { + // return Db.Table("oauth2_info").Save(oauthInfo).Error + stmt := ` + INSERT INTO oauth2_info (client, info, oauth_user_id, user_id) + VALUES (?, ?, ?, ?) + ON CONFLICT (client, user_id) DO UPDATE + SET info = EXCLUDED.info, oauth_user_id = EXCLUDED.oauth_user_id, client = EXCLUDED.client + ` + + Db.Exec(stmt, oauthInfo.Client, oauthInfo.Info, oauthInfo.OauthID, oauthInfo.UserID) } diff --git a/src/model/oauth_test.go b/src/model/oauth_test.go new file mode 100644 index 0000000..e33dcb3 --- /dev/null +++ b/src/model/oauth_test.go @@ -0,0 +1,27 @@ +package model + +import ( + "database/sql" + "log" + "testing" + + "gorm.io/datatypes" +) + +func TestInsertOAuth2Info(t *testing.T) { + db, err := sql.Open("postgres", "your-database-connection-string") + if err != nil { + log.Fatal(err) + } + defer db.Close() + + info := `{"login":"user","id":123,"node_id":"node_id","avatar_url":"url","gravatar_id":"","url":"url","html_url":"url","followers_url":"url","following_url":"url","gists_url":"url","starred_url":"url","subscriptions_url":"https://api.github.com/users/user/subscriptions","organizations_url":"https://api.github.com/users/user/orgs","repos_url":"https://api.github.com/users/user/repos","events_url":"https://api.github.com/users/user/events{/privacy}","received_events_url":"https://api.github.com/users/user/received_events","type":"User","site_admin":false,"name":"max","company":"@Xiaomi @sast @GreenPomelo","blog":"blog_url","location":"Nanjing","email":null,"hireable":null,"bio":"From Nanjing University of Posts and Telecommunications, member of @SAST. Working on 👀 visualization & 🌐 web dev\\r\\n","twitter_username":null,"public_repos":48,"public_gists":3,"followers":65,"following":148,"created_at":"2020-02-07T09:21:13Z","updated_at":"2024-07-19T12:26:27Z"}` + testData := OAuth2Info{ + Client: "github", + Info: datatypes.JSON(info), + OauthID: "60775796", + UserID: "b21041313", + } + + UpsetOauthInfo(testData) +} diff --git a/src/service/oauth.go b/src/service/oauth.go index ea4877c..a99be5e 100644 --- a/src/service/oauth.go +++ b/src/service/oauth.go @@ -4,12 +4,12 @@ import ( "fmt" "github.com/NJUPT-SAST/sast-link-backend/model" + "gorm.io/datatypes" ) - // Oauth Github -func GetUserByGithubId(githubId string) (*model.User, error) { - return model.UserByField("github_id", githubId) +func GetUserByGithubId(githubId string) (*model.OAuth2Info, error) { + return model.OauthInfoByUID(model.GITHUB_CLIENT_TYPE, githubId) } func GetUserInfoFromGithub(username, githubId string) (*model.User, error) { @@ -28,15 +28,21 @@ func GetUserInfoFromGithub(username, githubId string) (*model.User, error) { return nil, nil } +func UpsetOauthInfo(username, clientType, oauthID string, OAuth2Info datatypes.JSON) { + var oauthInfo = model.OAuth2Info{ + Client: clientType, + Info: OAuth2Info, + OauthID: oauthID, + UserID: username, + } + model.UpsetOauthInfo(oauthInfo) +} + // Oauth Lark func UserByLarkUnionID(unionID string) (*model.User, error) { return model.UserByField("lark_id", unionID) } -func UpdateLarkUserInfo(username, clientType, oauthID, larkUserInfo string) error { - return model.UpdateLarkUserInfo(username, clientType, oauthID, larkUserInfo) -} - // Oauth server func OauthUserInfo(userID string) (*model.User, error) { return model.UserInfo(userID)