Skip to content

Commit 77958d0

Browse files
Merge pull request #104 from devtron-labs/oss-enterprise-sync-ae9763fe
SYNC: OSS sync for ae9763f
2 parents 2914a1a + 04a3115 commit 77958d0

File tree

4 files changed

+15
-11
lines changed

4 files changed

+15
-11
lines changed

api/user/UserAuthHandler.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ func (handler UserAuthHandlerImpl) LoginHandler(w http.ResponseWriter, r *http.R
7575
}
7676
//token, err := handler.loginService.CreateLoginSession(up.Username, up.Password)
7777
clientIp := util.GetClientIP(r)
78-
token, err := handler.userAuthService.HandleLoginWithClientIp(up.Username, up.Password, clientIp)
78+
token, err := handler.userAuthService.HandleLoginWithClientIp(r.Context(),up.Username, up.Password, clientIp)
7979
if err != nil {
8080
common.WriteJsonResp(w, fmt.Errorf("invalid username or password"), nil, http.StatusForbidden)
8181
return

pkg/user/UserAuthService.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ import (
4747
)
4848

4949
type UserAuthService interface {
50-
HandleLoginWithClientIp(username, password, clientIp string) (string, error)
50+
HandleLoginWithClientIp(ctx context.Context, username, password, clientIp string) (string, error)
5151
HandleLogin(username string, password string) (string, error)
5252
HandleDexCallback(w http.ResponseWriter, r *http.Request)
5353
HandleRefresh(w http.ResponseWriter, r *http.Request)
@@ -256,10 +256,10 @@ func (impl UserAuthServiceImpl) HandleRefresh(w http.ResponseWriter, r *http.Req
256256
}
257257
}
258258

259-
func (impl UserAuthServiceImpl) HandleLoginWithClientIp(username, password, clientIp string) (string, error) {
259+
func (impl UserAuthServiceImpl) HandleLoginWithClientIp(ctx context.Context, username, password, clientIp string) (string, error) {
260260
token, err := impl.HandleLogin(username, password)
261261
if err == nil {
262-
id, _, err := impl.userService.GetUserByToken(token)
262+
id, _, err := impl.userService.GetUserByToken(ctx, token)
263263
if err != nil {
264264
impl.logger.Infow("error occured while getting user by token", "err", err)
265265
} else {

pkg/user/UserService.go

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
package user
1919

2020
import (
21+
"context"
2122
"fmt"
2223
"github.com/devtron-labs/authenticator/jwt"
2324
"github.com/devtron-labs/authenticator/middleware"
@@ -31,6 +32,7 @@ import (
3132
util2 "github.com/devtron-labs/devtron/util"
3233
"github.com/go-pg/pg"
3334
"github.com/gorilla/sessions"
35+
"go.opentelemetry.io/otel"
3436
"go.uber.org/zap"
3537
"net/http"
3638
"strings"
@@ -50,7 +52,7 @@ type UserService interface {
5052
DeleteUser(userInfo *bean.UserInfo) (bool, error)
5153
CheckUserRoles(id int32) ([]string, error)
5254
SyncOrchestratorToCasbin() (bool, error)
53-
GetUserByToken(token string) (int32, string, error)
55+
GetUserByToken(context context.Context, token string) (int32, string, error)
5456
IsSuperAdmin(userId int) (bool, error)
5557
GetByIdIncludeDeleted(id int32) (*bean.UserInfo, error)
5658
UserExists(emailId string) bool
@@ -1159,26 +1161,29 @@ func (impl UserServiceImpl) GetUserByEmail(emailId string) (*bean.UserInfo, erro
11591161
return response, nil
11601162
}
11611163
func (impl UserServiceImpl) GetLoggedInUser(r *http.Request) (int32, error) {
1164+
_, span := otel.Tracer("userService").Start(r.Context(), "GetLoggedInUser")
1165+
defer span.End()
11621166
token := ""
11631167
if strings.Contains(r.URL.Path, "/orchestrator/webhook/ext-ci/") {
11641168
token = r.Header.Get("api-token")
11651169
} else {
11661170
token = r.Header.Get("token")
11671171
}
1168-
userId, userType, err := impl.GetUserByToken(token)
1172+
userId, userType, err := impl.GetUserByToken(r.Context(), token)
11691173
// if user is of api-token type, then update lastUsedBy and lastUsedAt
11701174
if err == nil && userType == bean.USER_TYPE_API_TOKEN {
11711175
go impl.saveUserAudit(r, userId)
11721176
}
11731177
return userId, err
11741178
}
11751179

1176-
func (impl UserServiceImpl) GetUserByToken(token string) (int32, string, error) {
1180+
func (impl UserServiceImpl) GetUserByToken(context context.Context, token string) (int32, string, error) {
1181+
_, span := otel.Tracer("userService").Start(context, "GetUserByToken")
11771182
email, err := impl.GetEmailFromToken(token)
1183+
span.End()
11781184
if err != nil {
11791185
return http.StatusUnauthorized, "", err
11801186
}
1181-
11821187
userInfo, err := impl.GetUserByEmail(email)
11831188
if err != nil {
11841189
impl.logger.Errorw("unable to fetch user from db", "error", err)

wire_gen.go

Lines changed: 2 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)